diff --git a/dist/altcha.iife.js b/dist/altcha.iife.js index e588fa6..41b331f 100644 --- a/dist/altcha.iife.js +++ b/dist/altcha.iife.js @@ -1,2 +1,2 @@ -var altcha=function(V){"use strict";var Wt=Object.defineProperty;var Bt=(V,S,W)=>S in V?Wt(V,S,{enumerable:!0,configurable:!0,writable:!0,value:W}):V[S]=W;var Z=(V,S,W)=>(Bt(V,typeof S!="symbol"?S+"":S,W),W);function S(){}function W(r){return r()}function pe(){return Object.create(null)}function q(r){r.forEach(W)}function ye(r){return typeof r=="function"}function Xe(r,e){return r!=r?e==e:r!==e||r&&typeof r=="object"||typeof r=="function"}function Ke(r){return Object.keys(r).length===0}function w(r,e){r.appendChild(e)}function Je(r,e,t){const i=ze(r);if(!i.getElementById(e)){const l=$("style");l.id=e,l.textContent=t,Qe(i,l)}}function ze(r){if(!r)return document;const e=r.getRootNode?r.getRootNode():r.ownerDocument;return e&&e.host?e:r.ownerDocument}function Qe(r,e){return w(r.head||r,e),e.sheet}function T(r,e,t){r.insertBefore(e,t||null)}function N(r){r.parentNode&&r.parentNode.removeChild(r)}function $(r){return document.createElement(r)}function O(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function qe(r){return document.createTextNode(r)}function U(){return qe(" ")}function ce(r,e,t,i){return r.addEventListener(e,t,i),()=>r.removeEventListener(e,t,i)}function c(r,e,t){t==null?r.removeAttribute(e):r.getAttribute(e)!==t&&r.setAttribute(e,t)}function et(r){return Array.from(r.childNodes)}function ve(r,e,t){r.classList.toggle(e,!!t)}function tt(r,e,{bubbles:t=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:e,bubbles:t,cancelable:i})}function rt(r){const e={};return r.childNodes.forEach(t=>{e[t.slot||"default"]=!0}),e}let ee;function te(r){ee=r}function ae(){if(!ee)throw new Error("Function called outside component initialization");return ee}function nt(r){ae().$$.on_mount.push(r)}function it(r){ae().$$.on_destroy.push(r)}function lt(){const r=ae();return(e,t,{cancelable:i=!1}={})=>{const l=r.$$.callbacks[e];if(l){const o=tt(e,t,{cancelable:i});return l.slice().forEach(s=>{s.call(r,o)}),!o.defaultPrevented}return!0}}const J=[],fe=[];let z=[];const we=[],_e=Promise.resolve();let ue=!1;function ke(){ue||(ue=!0,_e.then(_))}function ot(){return ke(),_e}function he(r){z.push(r)}const de=new Set;let Q=0;function _(){if(Q!==0)return;const r=ee;do{try{for(;Qr.indexOf(i)===-1?e.push(i):t.push(i)),t.forEach(i=>i()),z=e}const at=new Set;function ft(r,e){r&&r.i&&(at.delete(r),r.i(e))}function ut(r,e,t){const{fragment:i,after_update:l}=r.$$;i&&i.m(e,t),he(()=>{const o=r.$$.on_mount.map(W).filter(ye);r.$$.on_destroy?r.$$.on_destroy.push(...o):q(o),r.$$.on_mount=[]}),l.forEach(he)}function ht(r,e){const t=r.$$;t.fragment!==null&&(ct(t.after_update),q(t.on_destroy),t.fragment&&t.fragment.d(e),t.on_destroy=t.fragment=null,t.ctx=[])}function dt(r,e){r.$$.dirty[0]===-1&&(J.push(r),ke(),r.$$.dirty.fill(0)),r.$$.dirty[e/31|0]|=1<{const H=G.length?G[0]:M;return u.ctx&&l(u.ctx[m],u.ctx[m]=H)&&(!u.skip_bound&&u.bound[m]&&u.bound[m](H),R&&dt(r,m)),M}):[],u.update(),R=!0,q(u.before_update),u.fragment=i?i(u.ctx):!1,e.target){if(e.hydrate){const m=et(e.target);u.fragment&&u.fragment.l(m),m.forEach(N)}else u.fragment&&u.fragment.c();e.intro&&ft(r.$$.fragment),ut(r,e.target,e.anchor),_()}te(f)}let xe;typeof HTMLElement=="function"&&(xe=class extends HTMLElement{constructor(e,t,i){super();Z(this,"$$ctor");Z(this,"$$s");Z(this,"$$c");Z(this,"$$cn",!1);Z(this,"$$d",{});Z(this,"$$r",!1);Z(this,"$$p_d",{});Z(this,"$$l",{});Z(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=t,i&&this.attachShadow({mode:"open"})}addEventListener(e,t,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(t),this.$$c){const l=this.$$c.$on(e,t);this.$$l_u.set(t,l)}super.addEventListener(e,t,i)}removeEventListener(e,t,i){if(super.removeEventListener(e,t,i),this.$$c){const l=this.$$l_u.get(t);l&&(l(),this.$$l_u.delete(t))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(o){return()=>{let s;return{c:function(){s=$("slot"),o!=="default"&&c(s,"name",o)},m:function(u,R){T(u,s,R)},d:function(u){u&&N(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const t={},i=rt(this);for(const o of this.$$s)o in i&&(t[o]=[e(o)]);for(const o of this.attributes){const s=this.$$g_p(o.name);s in this.$$d||(this.$$d[s]=re(s,o.value,this.$$p_d,"toProp"))}for(const o in this.$$p_d)!(o in this.$$d)&&this[o]!==void 0&&(this.$$d[o]=this[o],delete this[o]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:t,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const o in this.$$p_d)if(this.$$d[o]=this.$$c.$$.ctx[this.$$c.$$.props[o]],this.$$p_d[o].reflect){const s=re(o,this.$$d[o],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[o].attribute||o):this.setAttribute(this.$$p_d[o].attribute||o,s)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const o in this.$$l)for(const s of this.$$l[o]){const a=this.$$c.$on(o,s);this.$$l_u.set(s,a)}this.$$l={}}}attributeChangedCallback(e,t,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=re(e,i,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(t=>this.$$p_d[t].attribute===e||!this.$$p_d[t].attribute&&t.toLowerCase()===e)||e}});function re(r,e,t,i){var o;const l=(o=t[r])==null?void 0:o.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!t[r])return e;if(i==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function mt(r,e,t,i,l,o){let s=class extends xe{constructor(){super(r,t,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(s.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(f){var u;f=re(a,f,e),this.$$d[a]=f,(u=this.$$c)==null||u.$set({[a]:f})}})}),i.forEach(a=>{Object.defineProperty(s.prototype,a,{get(){var f;return(f=this.$$c)==null?void 0:f[a]}})}),o&&(s=o(s)),r.element=s,s}class bt{constructor(){Z(this,"$$");Z(this,"$$set")}$destroy(){ht(this,1),this.$destroy=S}$on(e,t){if(!ye(t))return S;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(t),()=>{const l=i.indexOf(t);l!==-1&&i.splice(l,1)}}$set(e){this.$$set&&!Ke(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const pt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(pt);const Ee="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+aT9zKG51bGwpOmgoZSxsLG8pLnRoZW4odz0+e3c9PT10P3Moe251bWJlcjpsLHRvb2s6RGF0ZS5ub3coKS1yfSk6ZChsKzEpfSkuY2F0Y2goYyl9O2QocCl9KSxjb250cm9sbGVyOmF9fWxldCBuO29ubWVzc2FnZT1hc3luYyB0PT57Y29uc3R7dHlwZTplLHBheWxvYWQ6b309dC5kYXRhO2lmKGU9PT0iYWJvcnQiKW49PW51bGx8fG4uYWJvcnQoKSxuPXZvaWQgMDtlbHNlIGlmKGU9PT0id29yayIpe2NvbnN0e2FsZzppLGNoYWxsZW5nZTpwLG1heDphLHNhbHQ6dSxzdGFydDpzfT1vfHx7fSxjPW0ocCx1LGksYSxzKTtuPWMuY29udHJvbGxlcixjLnByb21pc2UudGhlbihyPT57c2VsZi5wb3N0TWVzc2FnZShyJiZ7Li4ucix3b3JrZXI6ITB9KX0pfX19KSgpOwo=",yt=r=>Uint8Array.from(atob(r),e=>e.charCodeAt(0)),$e=typeof window<"u"&&window.Blob&&new Blob([yt(Ee)],{type:"text/javascript;charset=utf-8"});function vt(r){let e;try{if(e=$e&&(window.URL||window.webkitURL).createObjectURL($e),!e)throw"";const t=new Worker(e,{name:r==null?void 0:r.name});return t.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;base64,"+Ee,{name:r==null?void 0:r.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const wt=new TextEncoder;function _t(r){return[...new Uint8Array(r)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function kt(r,e="SHA-256",t=1e5){const i=Date.now().toString(16);r||(r=Math.round(Math.random()*t));const l=await Ce(i,r,e);return{algorithm:e,challenge:l,salt:i,signature:""}}async function Ce(r,e,t){return _t(await crypto.subtle.digest(t.toUpperCase(),wt.encode(r+e)))}function xt(r,e,t="SHA-256",i=1e6,l=0){const o=new AbortController;return{promise:new Promise((a,f)=>{const u=Date.now(),R=m=>{o.signal.aborted||m>i?a(null):Ce(e,m,t).then(M=>{M===r?a({number:m,took:Date.now()-u}):R(m+1)}).catch(f)};R(l)}),controller:o}}var y=(r=>(r.ERROR="error",r.VERIFIED="verified",r.VERIFYING="verifying",r.UNVERIFIED="unverified",r.EXPIRED="expired",r))(y||{});function Et(r){Je(r,"svelte-14ngypa",`.altcha.svelte-14ngypa.svelte-14ngypa{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid - var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-14ngypa.svelte-14ngypa:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-14ngypa.svelte-14ngypa{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-14ngypa.svelte-14ngypa{flex-grow:1}.altcha-label.svelte-14ngypa label.svelte-14ngypa{cursor:pointer}.altcha-logo.svelte-14ngypa.svelte-14ngypa{color:currentColor;opacity:0.3}.altcha-logo.svelte-14ngypa.svelte-14ngypa:hover{opacity:1}.altcha-error.svelte-14ngypa.svelte-14ngypa{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-14ngypa.svelte-14ngypa{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-14ngypa.svelte-14ngypa:hover{opacity:1}.altcha-footer.svelte-14ngypa>.svelte-14ngypa:first-child{flex-grow:1}.altcha-footer.svelte-14ngypa a{color:currentColor}.altcha-checkbox.svelte-14ngypa.svelte-14ngypa{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-14ngypa input.svelte-14ngypa{width:18px;height:18px;margin:0}.altcha-hidden.svelte-14ngypa.svelte-14ngypa{display:none}.altcha-spinner.svelte-14ngypa.svelte-14ngypa{animation:svelte-14ngypa-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-14ngypa-altcha-spinner{100%{transform:rotate(360deg)}}`)}function Le(r){let e,t,i;return{c(){e=O("svg"),t=O("path"),i=O("path"),c(t,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(t,"fill","currentColor"),c(t,"opacity",".25"),c(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(i,"fill","currentColor"),c(i,"class","altcha-spinner svelte-14ngypa"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(l,o){T(l,e,o),w(e,t),w(e,i)},d(l){l&&N(e)}}}function $t(r){let e,t=r[9].label+"",i;return{c(){e=$("label"),c(e,"for",i=r[3]+"_checkbox"),c(e,"class","svelte-14ngypa")},m(l,o){T(l,e,o),e.innerHTML=t},p(l,o){o[0]&512&&t!==(t=l[9].label+"")&&(e.innerHTML=t),o[0]&8&&i!==(i=l[3]+"_checkbox")&&c(e,"for",i)},d(l){l&&N(e)}}}function Ct(r){let e,t=r[9].verifying+"";return{c(){e=$("span")},m(i,l){T(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].verifying+"")&&(e.innerHTML=t)},d(i){i&&N(e)}}}function Lt(r){let e,t=r[9].verified+"",i,l;return{c(){e=$("span"),i=U(),l=$("input"),c(l,"type","hidden"),c(l,"name",r[3]),l.value=r[4]},m(o,s){T(o,e,s),e.innerHTML=t,T(o,i,s),T(o,l,s)},p(o,s){s[0]&512&&t!==(t=o[9].verified+"")&&(e.innerHTML=t),s[0]&8&&c(l,"name",o[3]),s[0]&16&&(l.value=o[4])},d(o){o&&(N(e),N(i),N(l))}}}function Ie(r){let e,t,i,l,o,s;return{c(){e=$("div"),t=$("a"),i=O("svg"),l=O("path"),o=O("path"),s=O("path"),c(l,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(l,"fill","currentColor"),c(o,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(o,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(i,"width","22"),c(i,"height","22"),c(i,"viewBox","0 0 20 20"),c(i,"fill","none"),c(i,"xmlns","http://www.w3.org/2000/svg"),c(t,"href",Ne),c(t,"target","_blank"),c(t,"class","altcha-logo svelte-14ngypa")},m(a,f){T(a,e,f),w(e,t),w(t,i),w(i,l),w(i,o),w(i,s)},p:S,d(a){a&&N(e)}}}function Re(r){let e,t,i,l;function o(f,u){return f[5]===y.EXPIRED?Rt:It}let s=o(r),a=s(r);return{c(){e=$("div"),t=O("svg"),i=O("path"),l=U(),a.c(),c(i,"stroke-linecap","round"),c(i,"stroke-linejoin","round"),c(i,"d","M6 18L18 6M6 6l12 12"),c(t,"width","14"),c(t,"height","14"),c(t,"xmlns","http://www.w3.org/2000/svg"),c(t,"fill","none"),c(t,"viewBox","0 0 24 24"),c(t,"stroke-width","1.5"),c(t,"stroke","currentColor"),c(e,"class","altcha-error svelte-14ngypa")},m(f,u){T(f,e,u),w(e,t),w(t,i),w(e,l),a.m(e,null)},p(f,u){s===(s=o(f))&&a?a.p(f,u):(a.d(1),a=s(f),a&&(a.c(),a.m(e,null)))},d(f){f&&N(e),a.d()}}}function It(r){let e,t=r[9].error+"";return{c(){e=$("div"),c(e,"title",r[8])},m(i,l){T(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].error+"")&&(e.innerHTML=t),l[0]&256&&c(e,"title",i[8])},d(i){i&&N(e)}}}function Rt(r){let e,t=r[9].expired+"";return{c(){e=$("div"),c(e,"title",r[8])},m(i,l){T(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].expired+"")&&(e.innerHTML=t),l[0]&256&&c(e,"title",i[8])},d(i){i&&N(e)}}}function Se(r){let e,t,i=r[9].footer+"";return{c(){e=$("div"),t=$("div"),c(t,"class","svelte-14ngypa"),c(e,"class","altcha-footer svelte-14ngypa")},m(l,o){T(l,e,o),w(e,t),t.innerHTML=i},p(l,o){o[0]&512&&i!==(i=l[9].footer+"")&&(t.innerHTML=i)},d(l){l&&N(e)}}}function St(r){let e,t,i,l,o,s,a,f,u,R,m,M,G,H,k=r[5]===y.VERIFYING&&Le();function Y(d,I){return d[5]===y.VERIFIED?Lt:d[5]===y.VERIFYING?Ct:$t}let P=Y(r),x=P(r),E=r[2]!==!0&&Ie(),g=(r[8]||r[5]===y.EXPIRED)&&Re(r),v=r[9].footer&&r[1]!==!0&&Se(r);return{c(){e=$("div"),t=$("div"),k&&k.c(),i=U(),l=$("div"),o=$("input"),f=U(),u=$("div"),x.c(),R=U(),E&&E.c(),m=U(),g&&g.c(),M=U(),v&&v.c(),c(o,"type","checkbox"),c(o,"id",s=r[3]+"_checkbox"),o.required=a=r[0]!=="onsubmit",c(o,"class","svelte-14ngypa"),c(l,"class","altcha-checkbox svelte-14ngypa"),ve(l,"altcha-hidden",r[5]===y.VERIFYING),c(u,"class","altcha-label svelte-14ngypa"),c(t,"class","altcha-main svelte-14ngypa"),c(e,"class","altcha svelte-14ngypa"),c(e,"data-state",r[5])},m(d,I){T(d,e,I),w(e,t),k&&k.m(t,null),w(t,i),w(t,l),w(l,o),o.checked=r[6],w(t,f),w(t,u),x.m(u,null),w(t,R),E&&E.m(t,null),w(e,m),g&&g.m(e,null),w(e,M),v&&v.m(e,null),r[30](e),G||(H=[ce(o,"change",r[29]),ce(o,"change",r[10]),ce(o,"invalid",r[11])],G=!0)},p(d,I){d[5]===y.VERIFYING?k||(k=Le(),k.c(),k.m(t,i)):k&&(k.d(1),k=null),I[0]&8&&s!==(s=d[3]+"_checkbox")&&c(o,"id",s),I[0]&1&&a!==(a=d[0]!=="onsubmit")&&(o.required=a),I[0]&64&&(o.checked=d[6]),I[0]&32&&ve(l,"altcha-hidden",d[5]===y.VERIFYING),P===(P=Y(d))&&x?x.p(d,I):(x.d(1),x=P(d),x&&(x.c(),x.m(u,null))),d[2]!==!0?E?E.p(d,I):(E=Ie(),E.c(),E.m(t,null)):E&&(E.d(1),E=null),d[8]||d[5]===y.EXPIRED?g?g.p(d,I):(g=Re(d),g.c(),g.m(e,M)):g&&(g.d(1),g=null),d[9].footer&&d[1]!==!0?v?v.p(d,I):(v=Se(d),v.c(),v.m(e,null)):v&&(v.d(1),v=null),I[0]&32&&c(e,"data-state",d[5])},i:S,o:S,d(d){d&&N(e),k&&k.d(),x.d(),E&&E.d(),g&&g.d(),v&&v.d(),r[30](null),G=!1,q(H)}}}const Ne="https://altcha.org/";function Te(r){return JSON.parse(r)}function Nt(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}function Tt(r,e,t){var Fe,We;let i,l,o,{auto:s=void 0}=e,{blockspam:a=void 0}=e,{challengeurl:f=void 0}=e,{challengejson:u=void 0}=e,{debug:R=!1}=e,{expire:m=void 0}=e,{hidefooter:M=!1}=e,{hidelogo:G=!1}=e,{name:H="altcha"}=e,{maxnumber:k=1e6}=e,{mockerror:Y=!1}=e,{refetchonexpire:P=!0}=e,{spamfilter:x=!1}=e,{strings:E=void 0}=e,{test:g=!1}=e,{verifyurl:v=void 0}=e,{workers:d=navigator.hardwareConcurrency||8}=e;const I=lt(),je=["SHA-256","SHA-384","SHA-512"],Me=(We=(Fe=document.documentElement.lang)==null?void 0:Fe.split("-"))==null?void 0:We[0];let B=!1,ne,b=null,ge=null,X=null,D=y.UNVERIFIED,me;it(()=>{b&&(b.removeEventListener("submit",Ge),b.removeEventListener("reset",Ve),b.removeEventListener("focusin",Ze),b=null)}),nt(()=>{C("mounted","0.3.2"),C("workers",d),g&&C("using test mode"),m&&be(m),s!==void 0&&C("auto",s),b=ne.closest("form"),b&&(b.addEventListener("submit",Ge),b.addEventListener("reset",Ve),s==="onfocus"&&b.addEventListener("focusin",Ze)),s==="onload"&&K()});function C(...n){(R||n.some(h=>h instanceof Error))&&console[n[0]instanceof Error?"error":"log"]("ALTCHA",...n)}function Ze(n){K()}function Ge(n){b&&s==="onsubmit"&&D===y.UNVERIFIED&&(n.preventDefault(),n.stopPropagation(),K().then(()=>{b==null||b.requestSubmit()}))}function Ve(){ie()}function Oe(n,h){return btoa(JSON.stringify({algorithm:n.algorithm,challenge:n.challenge,number:h.number,salt:n.salt,signature:n.signature,test:g?!0:void 0,took:h.took}))}function He(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(!je.includes(n.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${je.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 At(){if(Y)throw C("mocking error"),new Error("Mocked error.");if(i)return C("using provided json data"),i;if(g)return C("generating test challenge",{test:g}),kt(typeof g!="boolean"?+g:void 0);{if(!f)throw new Error("Attribute challengeurl not set.");C("fetching challenge from",f);const n=await fetch(f,{headers:{"x-altcha-spam-filter":x?"1":"0"}});if(n.status!==200)throw new Error(`Server responded with ${n.status}.`);const h=n.headers.get("Expires"),L=n.headers.get("X-Altcha-Config");if(L)try{const p=JSON.parse(L);p&&typeof p=="object"&&(p.verifyurl&&(p.verifyurl=new URL(p.verifyurl,new URL(f)).toString()),De(p))}catch(p){C("unable to configure from X-Altcha-Config",p)}if(!m&&(h!=null&&h.length)){const p=Date.parse(h);if(p){const A=p-Date.now();A>0&&be(A)}}return n.json()}}function Pe(){f&&P&&D===y.VERIFIED?K():ie(y.EXPIRED,o.expired)}async function jt(n){let h=null;if("Worker"in window){try{h=await Mt(n.challenge,n.salt,n.algorithm,n.maxnumber)}catch(L){C(L)}if((h==null?void 0:h.number)!==void 0)return{data:n,solution:h}}return{data:n,solution:await xt(n.challenge,n.salt,n.algorithm,n.maxnumber||k).promise}}async function Mt(n,h,L,p=k,A=Math.ceil(d)){const F=[];if(A<1)throw new Error("Wrong number of workers configured.");if(A>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let j=0;j{const Be=se*le;return new Promise(Ft=>{j.addEventListener("message",Ue=>{if(Ue.data)for(const Ye of F)Ye!==j&&Ye.postMessage({type:"abort"});Ft(Ue.data)}),j.postMessage({payload:{alg:L,challenge:n,max:Be+le,salt:h,start:Be},type:"work"})})}));for(const j of F)j.terminate();return oe.find(j=>!!j)||null}function Zt(){[y.UNVERIFIED,y.ERROR,y.EXPIRED].includes(D)?x&&(b==null?void 0:b.reportValidity())===!1?t(6,B=!1):K():t(6,B=!0)}function Gt(){D===y.VERIFYING&&alert(o.waitAlert)}function be(n){C("expire",n),clearTimeout(me),n<1?Pe():me=setTimeout(Pe,n)}function Vt(n){var L;const h=b==null?void 0:b.querySelector(typeof n=="string"?`input[name="${n}"]`:'input[type="email"]:not([data-no-spamfilter])');return((L=h==null?void 0:h.value)==null?void 0:L.slice(h.value.indexOf("@")))||void 0}function Ot(n){return[...(b==null?void 0:b.querySelectorAll(n!=null&&n.length?n.map(L=>`input[name="${L}"]`).join(", "):'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])'))||[]].reduce((L,p)=>{const A=p.name,F=p.value.trim();return A&&F&&(L[A]=F),L},{})}async function Ht(n){if(!v)throw new Error("Attribute verifyurl not set.");C("requesting server verification from",v);const h={payload:n};if(x){const{email:A,expectedLanguages:F,expectedCountries:le,fields:oe,ipAddress:j,timeZone:se}=typeof x=="object"?x:{email:void 0,expectedCountries:void 0,expectedLanguages:void 0,fields:void 0,ipAddress:void 0,timeZone:void 0};h.ipAddress=j===!1?void 0:j||"auto",h.email=A===!1?void 0:Vt(A),h.fields=oe===!1?void 0:Ot(oe),h.timeZone=se===!1?void 0:se||Nt(),h.expectedCountries=le,h.expectedLanguages=F||(Me?[Me]:void 0)}const L=await fetch(v,{body:JSON.stringify(h),headers:{"content-type":"application/json"},method:"POST"});if(L.status!==200)throw new Error(`Server responded with ${L.status}.`);const p=await L.json();if(p!=null&&p.payload&&t(4,X=p.payload),I("serververification",p),a&&p.classification==="BAD")throw new Error("SpamFilter returned negative classification.")}function De(n){n.auto!==void 0&&(t(0,s=n.auto),s==="onload"&&K()),n.expire!==void 0&&(be(n.expire),t(14,m=n.expire)),n.challenge&&(He(n.challenge),i=n.challenge),n.challengeurl!==void 0&&t(12,f=n.challengeurl),n.debug!==void 0&&t(13,R=!!n.debug),n.hidefooter!==void 0&&t(1,M=!!n.hidefooter),n.hidelogo!==void 0&&t(2,G=!!n.hidelogo),n.maxnumber!==void 0&&t(15,k=+n.maxnumber),n.mockerror!==void 0&&t(16,Y=!!n.mockerror),n.name!==void 0&&t(3,H=n.name),n.refetchonexpire!==void 0&&t(17,P=!!n.refetchonexpire),n.spamfilter!==void 0&&t(18,x=typeof n.spamfilter=="object"?n.spamfilter:!!n.spamfilter),n.strings&&t(28,l=n.strings),n.test!==void 0&&t(19,g=typeof n.test=="number"?n.test:!!n.test),n.verifyurl!==void 0&&t(20,v=n.verifyurl),n.workers!==void 0&&t(21,d=+n.workers)}function ie(n=y.UNVERIFIED,h=null){clearTimeout(me),t(6,B=!1),t(8,ge=h),t(4,X=null),t(5,D=n)}async function K(){return ie(y.VERIFYING),At().then(n=>(He(n),C("challenge",n),jt(n))).then(({data:n,solution:h})=>{if(C("solution",h),(h==null?void 0:h.number)!==void 0){if(v)return Ht(Oe(n,h));t(4,X=Oe(n,h)),C("payload",X)}else throw C("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."),new Error("Unexpected result returned.")}).then(()=>{ot().then(()=>{t(5,D=y.VERIFIED),t(6,B=!0),C("verified"),I("verified",{payload:X})})}).catch(n=>{C(n),t(5,D=y.ERROR),t(6,B=!1),t(8,ge=n.message)})}function Pt(){B=this.checked,t(6,B)}function Dt(n){fe[n?"unshift":"push"](()=>{ne=n,t(7,ne)})}return r.$$set=n=>{"auto"in n&&t(0,s=n.auto),"blockspam"in n&&t(22,a=n.blockspam),"challengeurl"in n&&t(12,f=n.challengeurl),"challengejson"in n&&t(23,u=n.challengejson),"debug"in n&&t(13,R=n.debug),"expire"in n&&t(14,m=n.expire),"hidefooter"in n&&t(1,M=n.hidefooter),"hidelogo"in n&&t(2,G=n.hidelogo),"name"in n&&t(3,H=n.name),"maxnumber"in n&&t(15,k=n.maxnumber),"mockerror"in n&&t(16,Y=n.mockerror),"refetchonexpire"in n&&t(17,P=n.refetchonexpire),"spamfilter"in n&&t(18,x=n.spamfilter),"strings"in n&&t(24,E=n.strings),"test"in n&&t(19,g=n.test),"verifyurl"in n&&t(20,v=n.verifyurl),"workers"in n&&t(21,d=n.workers)},r.$$.update=()=>{r.$$.dirty[0]&8388608&&(i=u?Te(u):void 0),r.$$.dirty[0]&16777216&&t(28,l=E?Te(E):{}),r.$$.dirty[0]&268435456&&t(9,o={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),r.$$.dirty[0]&48&&I("statechange",{payload:X,state:D})},[s,M,G,H,X,D,B,ne,ge,o,Zt,Gt,f,R,m,k,Y,P,x,g,v,d,a,u,E,De,ie,K,l,Pt,Dt]}class Ae extends bt{constructor(e){super(),gt(this,e,Tt,St,Xe,{auto:0,blockspam:22,challengeurl:12,challengejson:23,debug:13,expire:14,hidefooter:1,hidelogo:2,name:3,maxnumber:15,mockerror:16,refetchonexpire:17,spamfilter:18,strings:24,test:19,verifyurl:20,workers:21,configure:25,reset:26,verify:27},Et,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),_()}get blockspam(){return this.$$.ctx[22]}set blockspam(e){this.$$set({blockspam:e}),_()}get challengeurl(){return this.$$.ctx[12]}set challengeurl(e){this.$$set({challengeurl:e}),_()}get challengejson(){return this.$$.ctx[23]}set challengejson(e){this.$$set({challengejson:e}),_()}get debug(){return this.$$.ctx[13]}set debug(e){this.$$set({debug:e}),_()}get expire(){return this.$$.ctx[14]}set expire(e){this.$$set({expire:e}),_()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),_()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),_()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),_()}get maxnumber(){return this.$$.ctx[15]}set maxnumber(e){this.$$set({maxnumber:e}),_()}get mockerror(){return this.$$.ctx[16]}set mockerror(e){this.$$set({mockerror:e}),_()}get refetchonexpire(){return this.$$.ctx[17]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),_()}get spamfilter(){return this.$$.ctx[18]}set spamfilter(e){this.$$set({spamfilter:e}),_()}get strings(){return this.$$.ctx[24]}set strings(e){this.$$set({strings:e}),_()}get test(){return this.$$.ctx[19]}set test(e){this.$$set({test:e}),_()}get verifyurl(){return this.$$.ctx[20]}set verifyurl(e){this.$$set({verifyurl:e}),_()}get workers(){return this.$$.ctx[21]}set workers(e){this.$$set({workers:e}),_()}get configure(){return this.$$.ctx[25]}get reset(){return this.$$.ctx[26]}get verify(){return this.$$.ctx[27]}}return customElements.define("altcha-widget",mt(Ae,{auto:{},blockspam:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},spamfilter:{type:"Boolean"},strings:{},test:{type:"Boolean"},verifyurl:{},workers:{}},[],["configure","reset","verify"],!1)),V.Altcha=Ae,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"}),V}({}); +var altcha=function(O){"use strict";var Ht=Object.defineProperty;var Pt=(O,N,P)=>N in O?Ht(O,N,{enumerable:!0,configurable:!0,writable:!0,value:P}):O[N]=P;var V=(O,N,P)=>(Pt(O,typeof N!="symbol"?N+"":N,P),P);function N(){}function P(n){return n()}function ye(){return Object.create(null)}function te(n){n.forEach(P)}function pe(n){return typeof n=="function"}function Be(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function Ke(n){return Object.keys(n).length===0}function p(n,e){n.appendChild(e)}function Je(n,e,t){const i=ze(n);if(!i.getElementById(e)){const l=C("style");l.id=e,l.textContent=t,Qe(i,l)}}function ze(n){if(!n)return document;const e=n.getRootNode?n.getRootNode():n.ownerDocument;return e&&e.host?e:n.ownerDocument}function Qe(n,e){return p(n.head||n,e),e.sheet}function Z(n,e,t){n.insertBefore(e,t||null)}function S(n){n.parentNode&&n.parentNode.removeChild(n)}function C(n){return document.createElement(n)}function X(n){return document.createElementNS("http://www.w3.org/2000/svg",n)}function qe(n){return document.createTextNode(n)}function W(){return qe(" ")}function ae(n,e,t,i){return n.addEventListener(e,t,i),()=>n.removeEventListener(e,t,i)}function c(n,e,t){t==null?n.removeAttribute(e):n.getAttribute(e)!==t&&n.setAttribute(e,t)}function et(n){return Array.from(n.childNodes)}function ve(n,e,t){n.classList.toggle(e,!!t)}function tt(n,e,{bubbles:t=!1,cancelable:i=!1}={}){return new CustomEvent(n,{detail:e,bubbles:t,cancelable:i})}function nt(n){const e={};return n.childNodes.forEach(t=>{e[t.slot||"default"]=!0}),e}let ne;function re(n){ne=n}function fe(){if(!ne)throw new Error("Function called outside component initialization");return ne}function rt(n){fe().$$.on_mount.push(n)}function it(n){fe().$$.on_destroy.push(n)}function lt(){const n=fe();return(e,t,{cancelable:i=!1}={})=>{const l=n.$$.callbacks[e];if(l){const o=tt(e,t,{cancelable:i});return l.slice().forEach(s=>{s.call(n,o)}),!o.defaultPrevented}return!0}}const Q=[],ue=[];let q=[];const we=[],_e=Promise.resolve();let he=!1;function ke(){he||(he=!0,_e.then(w))}function ot(){return ke(),_e}function de(n){q.push(n)}const ge=new Set;let ee=0;function w(){if(ee!==0)return;const n=ne;do{try{for(;een.indexOf(i)===-1?e.push(i):t.push(i)),t.forEach(i=>i()),q=e}const at=new Set;function ft(n,e){n&&n.i&&(at.delete(n),n.i(e))}function ut(n,e,t){const{fragment:i,after_update:l}=n.$$;i&&i.m(e,t),de(()=>{const o=n.$$.on_mount.map(P).filter(pe);n.$$.on_destroy?n.$$.on_destroy.push(...o):te(o),n.$$.on_mount=[]}),l.forEach(de)}function ht(n,e){const t=n.$$;t.fragment!==null&&(ct(t.after_update),te(t.on_destroy),t.fragment&&t.fragment.d(e),t.on_destroy=t.fragment=null,t.ctx=[])}function dt(n,e){n.$$.dirty[0]===-1&&(Q.push(n),ke(),n.$$.dirty.fill(0)),n.$$.dirty[e/31|0]|=1<{const D=U.length?U[0]:G;return h.ctx&&l(h.ctx[L],h.ctx[L]=D)&&(!h.skip_bound&&h.bound[L]&&h.bound[L](D),T&&dt(n,L)),G}):[],h.update(),T=!0,te(h.before_update),h.fragment=i?i(h.ctx):!1,e.target){if(e.hydrate){const L=et(e.target);h.fragment&&h.fragment.l(L),L.forEach(S)}else h.fragment&&h.fragment.c();e.intro&&ft(n.$$.fragment),ut(n,e.target,e.anchor),w()}re(a)}let xe;typeof HTMLElement=="function"&&(xe=class extends HTMLElement{constructor(e,t,i){super();V(this,"$$ctor");V(this,"$$s");V(this,"$$c");V(this,"$$cn",!1);V(this,"$$d",{});V(this,"$$r",!1);V(this,"$$p_d",{});V(this,"$$l",{});V(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=t,i&&this.attachShadow({mode:"open"})}addEventListener(e,t,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(t),this.$$c){const l=this.$$c.$on(e,t);this.$$l_u.set(t,l)}super.addEventListener(e,t,i)}removeEventListener(e,t,i){if(super.removeEventListener(e,t,i),this.$$c){const l=this.$$l_u.get(t);l&&(l(),this.$$l_u.delete(t))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(o){return()=>{let s;return{c:function(){s=C("slot"),o!=="default"&&c(s,"name",o)},m:function(h,T){Z(h,s,T)},d:function(h){h&&S(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const t={},i=nt(this);for(const o of this.$$s)o in i&&(t[o]=[e(o)]);for(const o of this.attributes){const s=this.$$g_p(o.name);s in this.$$d||(this.$$d[s]=ie(s,o.value,this.$$p_d,"toProp"))}for(const o in this.$$p_d)!(o in this.$$d)&&this[o]!==void 0&&(this.$$d[o]=this[o],delete this[o]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:t,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const o in this.$$p_d)if(this.$$d[o]=this.$$c.$$.ctx[this.$$c.$$.props[o]],this.$$p_d[o].reflect){const s=ie(o,this.$$d[o],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[o].attribute||o):this.setAttribute(this.$$p_d[o].attribute||o,s)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const o in this.$$l)for(const s of this.$$l[o]){const f=this.$$c.$on(o,s);this.$$l_u.set(s,f)}this.$$l={}}}attributeChangedCallback(e,t,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=ie(e,i,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(t=>this.$$p_d[t].attribute===e||!this.$$p_d[t].attribute&&t.toLowerCase()===e)||e}});function ie(n,e,t,i){var o;const l=(o=t[n])==null?void 0:o.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!t[n])return e;if(i==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function mt(n,e,t,i,l,o){let s=class extends xe{constructor(){super(n,t,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(f=>(e[f].attribute||f).toLowerCase())}};return Object.keys(e).forEach(f=>{Object.defineProperty(s.prototype,f,{get(){return this.$$c&&f in this.$$c?this.$$c[f]:this.$$d[f]},set(a){var h;a=ie(f,a,e),this.$$d[f]=a,(h=this.$$c)==null||h.$set({[f]:a})}})}),i.forEach(f=>{Object.defineProperty(s.prototype,f,{get(){var a;return(a=this.$$c)==null?void 0:a[f]}})}),o&&(s=o(s)),n.element=s,s}class bt{constructor(){V(this,"$$");V(this,"$$set")}$destroy(){ht(this,1),this.$destroy=N}$on(e,t){if(!pe(t))return N;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(t),()=>{const l=i.indexOf(t);l!==-1&&i.splice(l,1)}}$set(e){this.$$set&&!Ke(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const yt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(yt);const Ee="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGQoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAodD0+dC50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBwKGUsdCxvKXtyZXR1cm4gZChhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUoZSt0KSkpfWZ1bmN0aW9uIGcoZSx0LG89IlNIQS0yNTYiLGw9MWU2LGM9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyLGk9RGF0ZS5ub3coKTtyZXR1cm57cHJvbWlzZTooYXN5bmMoKT0+e2ZvcihsZXQgbj1jO248PWw7bis9MSl7aWYoYS5zaWduYWwuYWJvcnRlZClyZXR1cm4gbnVsbDtpZihhd2FpdCBwKHQsbixvKT09PWUpcmV0dXJue251bWJlcjpuLHRvb2s6RGF0ZS5ub3coKS1pfX1yZXR1cm4gbnVsbH0pKCksY29udHJvbGxlcjphfX1sZXQgcjtvbm1lc3NhZ2U9YXN5bmMgZT0+e2NvbnN0e3R5cGU6dCxwYXlsb2FkOm99PWUuZGF0YTtpZih0PT09ImFib3J0IilyPT1udWxsfHxyLmFib3J0KCkscj12b2lkIDA7ZWxzZSBpZih0PT09IndvcmsiKXtjb25zdHthbGc6bCxjaGFsbGVuZ2U6YyxtYXg6YSxzYWx0Omksc3RhcnQ6dX09b3x8e30sbj1nKGMsaSxsLGEsdSk7cj1uLmNvbnRyb2xsZXIsbi5wcm9taXNlLnRoZW4ocz0+e3NlbGYucG9zdE1lc3NhZ2UocyYmey4uLnMsd29ya2VyOiEwfSl9KX19fSkoKTsK",pt=n=>Uint8Array.from(atob(n),e=>e.charCodeAt(0)),$e=typeof window<"u"&&window.Blob&&new Blob([pt(Ee)],{type:"text/javascript;charset=utf-8"});function vt(n){let e;try{if(e=$e&&(window.URL||window.webkitURL).createObjectURL($e),!e)throw"";const t=new Worker(e,{name:n==null?void 0:n.name});return t.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;base64,"+Ee,{name:n==null?void 0:n.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const wt=new TextEncoder;function _t(n){return[...new Uint8Array(n)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function kt(n,e="SHA-256",t=1e5){const i=Date.now().toString(16);n||(n=Math.round(Math.random()*t));const l=await Ce(i,n,e);return{algorithm:e,challenge:l,salt:i,signature:""}}async function Ce(n,e,t){return _t(await crypto.subtle.digest(t.toUpperCase(),wt.encode(n+e)))}function xt(n,e,t="SHA-256",i=1e6,l=0){const o=new AbortController,s=Date.now();return{promise:(async()=>{for(let a=l;a<=i;a+=1){if(o.signal.aborted)return null;if(await Ce(e,a,t)===n)return{number:a,took:Date.now()-s}}return null})(),controller:o}}var b=(n=>(n.ERROR="error",n.VERIFIED="verified",n.VERIFYING="verifying",n.UNVERIFIED="unverified",n.EXPIRED="expired",n))(b||{});function Et(n){Je(n,"svelte-14ngypa",`.altcha.svelte-14ngypa.svelte-14ngypa{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid + var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-14ngypa.svelte-14ngypa:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-14ngypa.svelte-14ngypa{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-14ngypa.svelte-14ngypa{flex-grow:1}.altcha-label.svelte-14ngypa label.svelte-14ngypa{cursor:pointer}.altcha-logo.svelte-14ngypa.svelte-14ngypa{color:currentColor;opacity:0.3}.altcha-logo.svelte-14ngypa.svelte-14ngypa:hover{opacity:1}.altcha-error.svelte-14ngypa.svelte-14ngypa{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-14ngypa.svelte-14ngypa{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-14ngypa.svelte-14ngypa:hover{opacity:1}.altcha-footer.svelte-14ngypa>.svelte-14ngypa:first-child{flex-grow:1}.altcha-footer.svelte-14ngypa a{color:currentColor}.altcha-checkbox.svelte-14ngypa.svelte-14ngypa{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-14ngypa input.svelte-14ngypa{width:18px;height:18px;margin:0}.altcha-hidden.svelte-14ngypa.svelte-14ngypa{display:none}.altcha-spinner.svelte-14ngypa.svelte-14ngypa{animation:svelte-14ngypa-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-14ngypa-altcha-spinner{100%{transform:rotate(360deg)}}`)}function Le(n){let e,t,i;return{c(){e=X("svg"),t=X("path"),i=X("path"),c(t,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(t,"fill","currentColor"),c(t,"opacity",".25"),c(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(i,"fill","currentColor"),c(i,"class","altcha-spinner svelte-14ngypa"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(l,o){Z(l,e,o),p(e,t),p(e,i)},d(l){l&&S(e)}}}function $t(n){let e,t=n[9].label+"",i;return{c(){e=C("label"),c(e,"for",i=n[3]+"_checkbox"),c(e,"class","svelte-14ngypa")},m(l,o){Z(l,e,o),e.innerHTML=t},p(l,o){o[0]&512&&t!==(t=l[9].label+"")&&(e.innerHTML=t),o[0]&8&&i!==(i=l[3]+"_checkbox")&&c(e,"for",i)},d(l){l&&S(e)}}}function Ct(n){let e,t=n[9].verifying+"";return{c(){e=C("span")},m(i,l){Z(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].verifying+"")&&(e.innerHTML=t)},d(i){i&&S(e)}}}function Lt(n){let e,t=n[9].verified+"",i,l;return{c(){e=C("span"),i=W(),l=C("input"),c(l,"type","hidden"),c(l,"name",n[3]),l.value=n[4]},m(o,s){Z(o,e,s),e.innerHTML=t,Z(o,i,s),Z(o,l,s)},p(o,s){s[0]&512&&t!==(t=o[9].verified+"")&&(e.innerHTML=t),s[0]&8&&c(l,"name",o[3]),s[0]&16&&(l.value=o[4])},d(o){o&&(S(e),S(i),S(l))}}}function Re(n){let e,t,i,l,o,s;return{c(){e=C("div"),t=C("a"),i=X("svg"),l=X("path"),o=X("path"),s=X("path"),c(l,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(l,"fill","currentColor"),c(o,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(o,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(i,"width","22"),c(i,"height","22"),c(i,"viewBox","0 0 20 20"),c(i,"fill","none"),c(i,"xmlns","http://www.w3.org/2000/svg"),c(t,"href",Se),c(t,"target","_blank"),c(t,"class","altcha-logo svelte-14ngypa")},m(f,a){Z(f,e,a),p(e,t),p(t,i),p(i,l),p(i,o),p(i,s)},p:N,d(f){f&&S(e)}}}function Ie(n){let e,t,i,l;function o(a,h){return a[5]===b.EXPIRED?It:Rt}let s=o(n),f=s(n);return{c(){e=C("div"),t=X("svg"),i=X("path"),l=W(),f.c(),c(i,"stroke-linecap","round"),c(i,"stroke-linejoin","round"),c(i,"d","M6 18L18 6M6 6l12 12"),c(t,"width","14"),c(t,"height","14"),c(t,"xmlns","http://www.w3.org/2000/svg"),c(t,"fill","none"),c(t,"viewBox","0 0 24 24"),c(t,"stroke-width","1.5"),c(t,"stroke","currentColor"),c(e,"class","altcha-error svelte-14ngypa")},m(a,h){Z(a,e,h),p(e,t),p(t,i),p(e,l),f.m(e,null)},p(a,h){s===(s=o(a))&&f?f.p(a,h):(f.d(1),f=s(a),f&&(f.c(),f.m(e,null)))},d(a){a&&S(e),f.d()}}}function Rt(n){let e,t=n[9].error+"";return{c(){e=C("div"),c(e,"title",n[8])},m(i,l){Z(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].error+"")&&(e.innerHTML=t),l[0]&256&&c(e,"title",i[8])},d(i){i&&S(e)}}}function It(n){let e,t=n[9].expired+"";return{c(){e=C("div"),c(e,"title",n[8])},m(i,l){Z(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].expired+"")&&(e.innerHTML=t),l[0]&256&&c(e,"title",i[8])},d(i){i&&S(e)}}}function Ne(n){let e,t,i=n[9].footer+"";return{c(){e=C("div"),t=C("div"),c(t,"class","svelte-14ngypa"),c(e,"class","altcha-footer svelte-14ngypa")},m(l,o){Z(l,e,o),p(e,t),t.innerHTML=i},p(l,o){o[0]&512&&i!==(i=l[9].footer+"")&&(t.innerHTML=i)},d(l){l&&S(e)}}}function Nt(n){let e,t,i,l,o,s,f,a,h,T,L,G,U,D,_=n[5]===b.VERIFYING&&Le();function B(d,I){return d[5]===b.VERIFIED?Lt:d[5]===b.VERIFYING?Ct:$t}let F=B(n),k=F(n),x=n[2]!==!0&&Re(),g=(n[8]||n[5]===b.EXPIRED)&&Ie(n),y=n[9].footer&&n[1]!==!0&&Ne(n);return{c(){e=C("div"),t=C("div"),_&&_.c(),i=W(),l=C("div"),o=C("input"),a=W(),h=C("div"),k.c(),T=W(),x&&x.c(),L=W(),g&&g.c(),G=W(),y&&y.c(),c(o,"type","checkbox"),c(o,"id",s=n[3]+"_checkbox"),o.required=f=n[0]!=="onsubmit",c(o,"class","svelte-14ngypa"),c(l,"class","altcha-checkbox svelte-14ngypa"),ve(l,"altcha-hidden",n[5]===b.VERIFYING),c(h,"class","altcha-label svelte-14ngypa"),c(t,"class","altcha-main svelte-14ngypa"),c(e,"class","altcha svelte-14ngypa"),c(e,"data-state",n[5])},m(d,I){Z(d,e,I),p(e,t),_&&_.m(t,null),p(t,i),p(t,l),p(l,o),o.checked=n[6],p(t,a),p(t,h),k.m(h,null),p(t,T),x&&x.m(t,null),p(e,L),g&&g.m(e,null),p(e,G),y&&y.m(e,null),n[30](e),U||(D=[ae(o,"change",n[29]),ae(o,"change",n[10]),ae(o,"invalid",n[11])],U=!0)},p(d,I){d[5]===b.VERIFYING?_||(_=Le(),_.c(),_.m(t,i)):_&&(_.d(1),_=null),I[0]&8&&s!==(s=d[3]+"_checkbox")&&c(o,"id",s),I[0]&1&&f!==(f=d[0]!=="onsubmit")&&(o.required=f),I[0]&64&&(o.checked=d[6]),I[0]&32&&ve(l,"altcha-hidden",d[5]===b.VERIFYING),F===(F=B(d))&&k?k.p(d,I):(k.d(1),k=F(d),k&&(k.c(),k.m(h,null))),d[2]!==!0?x?x.p(d,I):(x=Re(),x.c(),x.m(t,null)):x&&(x.d(1),x=null),d[8]||d[5]===b.EXPIRED?g?g.p(d,I):(g=Ie(d),g.c(),g.m(e,G)):g&&(g.d(1),g=null),d[9].footer&&d[1]!==!0?y?y.p(d,I):(y=Ne(d),y.c(),y.m(e,null)):y&&(y.d(1),y=null),I[0]&32&&c(e,"data-state",d[5])},i:N,o:N,d(d){d&&S(e),_&&_.d(),k.d(),x&&x.d(),g&&g.d(),y&&y.d(),n[30](null),U=!1,te(D)}}}const Se="https://altcha.org/";function je(n){return JSON.parse(n)}function St(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}function jt(n,e,t){var Fe,He;let i,l,o,{auto:s=void 0}=e,{blockspam:f=void 0}=e,{challengeurl:a=void 0}=e,{challengejson:h=void 0}=e,{debug:T=!1}=e,{expire:L=void 0}=e,{hidefooter:G=!1}=e,{hidelogo:U=!1}=e,{name:D="altcha"}=e,{maxnumber:_=1e6}=e,{mockerror:B=!1}=e,{refetchonexpire:F=!0}=e,{spamfilter:k=!1}=e,{strings:x=void 0}=e,{test:g=!1}=e,{verifyurl:y=void 0}=e,{workers:d=navigator.hardwareConcurrency||8}=e;const I=lt(),Ae=["SHA-256","SHA-384","SHA-512"],Te=(He=(Fe=document.documentElement.lang)==null?void 0:Fe.split("-"))==null?void 0:He[0];let Y=!1,le,m=null,me=null,K=null,H=b.UNVERIFIED,be;it(()=>{m&&(m.removeEventListener("submit",Ve),m.removeEventListener("reset",Ge),m.removeEventListener("focusin",Me),m=null)}),rt(()=>{R("mounted","0.4.0"),R("workers",d),g&&R("using test mode"),L&&oe(L),s!==void 0&&R("auto",s),m=le.closest("form"),m&&(m.addEventListener("submit",Ve),m.addEventListener("reset",Ge),s==="onfocus"&&m.addEventListener("focusin",Me)),s==="onload"&&J()});function R(...r){(T||r.some(u=>u instanceof Error))&&console[r[0]instanceof Error?"error":"log"]("ALTCHA",...r)}function Me(r){J()}function Ve(r){m&&s==="onsubmit"&&H===b.UNVERIFIED&&(r.preventDefault(),r.stopPropagation(),J().then(()=>{m==null||m.requestSubmit()}))}function Ge(){se()}function Ue(r,u){return btoa(JSON.stringify({algorithm:r.algorithm,challenge:r.challenge,number:u.number,salt:r.salt,signature:r.signature,test:g?!0:void 0,took:u.took}))}function Oe(r){if(!r.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(r.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!Ae.includes(r.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${Ae.join(", ")}`);if(!r.challenge||r.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!r.salt||r.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function Zt(){var r;if(B)throw R("mocking error"),new Error("Mocked error.");if(i)return R("using provided json data"),i;if(g)return R("generating test challenge",{test:g}),kt(typeof g!="boolean"?+g:void 0);{if(!a)throw new Error("Attribute challengeurl not set.");R("fetching challenge from",a);const u=await fetch(a,{headers:{"x-altcha-spam-filter":k?"1":"0"}});if(u.status!==200)throw new Error(`Server responded with ${u.status}.`);const v=u.headers.get("Expires"),j=u.headers.get("X-Altcha-Config"),A=await u.json(),M=new URLSearchParams((r=A.salt.split("?"))==null?void 0:r[1]),z=M.get("expires")||M.get("expire");if(z){const E=new Date(+z*1e3),$=isNaN(E.getTime())?0:E.getTime()-Date.now();$>0&&oe($)}if(j)try{const E=JSON.parse(j);E&&typeof E=="object"&&(E.verifyurl&&(E.verifyurl=new URL(E.verifyurl,new URL(a)).toString()),De(E))}catch(E){R("unable to configure from X-Altcha-Config",E)}if(!L&&(v!=null&&v.length)){const E=Date.parse(v);if(E){const $=E-Date.now();$>0&&oe($)}}return A}}function Xe(){a&&F&&H===b.VERIFIED?J():se(b.EXPIRED,o.expired)}async function At(r){let u=null;if("Worker"in window){try{u=await Tt(r.challenge,r.salt,r.algorithm,r.maxnumber)}catch(v){R(v)}if((u==null?void 0:u.number)!==void 0)return{data:r,solution:u}}return{data:r,solution:await xt(r.challenge,r.salt,r.algorithm,r.maxnumber||_).promise}}async function Tt(r,u,v,j=typeof g=="number"?g:_,A=Math.ceil(d)){const M=[];if(A<1)throw new Error("Wrong number of workers configured.");if(A>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let $=0;${const Pe=ce*z;return new Promise(Ft=>{$.addEventListener("message",Ye=>{if(Ye.data)for(const We of M)We!==$&&We.postMessage({type:"abort"});Ft(Ye.data)}),$.postMessage({payload:{alg:v,challenge:r,max:Pe+z,salt:u,start:Pe},type:"work"})})}));for(const $ of M)$.terminate();return E.find($=>!!$)||null}function Mt(){[b.UNVERIFIED,b.ERROR,b.EXPIRED].includes(H)?k&&(m==null?void 0:m.reportValidity())===!1?t(6,Y=!1):J():t(6,Y=!0)}function Vt(){H===b.VERIFYING&&alert(o.waitAlert)}function oe(r){R("expire",r),clearTimeout(be),r<1?Xe():be=setTimeout(Xe,r)}function Gt(r){var v;const u=m==null?void 0:m.querySelector(typeof r=="string"?`input[name="${r}"]`:'input[type="email"]:not([data-no-spamfilter])');return((v=u==null?void 0:u.value)==null?void 0:v.slice(u.value.indexOf("@")))||void 0}function Ut(r){return[...(m==null?void 0:m.querySelectorAll(r!=null&&r.length?r.map(v=>`input[name="${v}"]`).join(", "):'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])'))||[]].reduce((v,j)=>{const A=j.name,M=j.value.trim();return A&&M&&(v[A]=M),v},{})}async function Ot(r){if(!y)throw new Error("Attribute verifyurl not set.");R("requesting server verification from",y);const u={payload:r};if(k){const{email:A,expectedLanguages:M,expectedCountries:z,fields:E,ipAddress:$,timeZone:ce}=typeof k=="object"?k:{email:void 0,expectedCountries:void 0,expectedLanguages:void 0,fields:void 0,ipAddress:void 0,timeZone:void 0};u.ipAddress=$===!1?void 0:$||"auto",u.email=A===!1?void 0:Gt(A),u.fields=E===!1?void 0:Ut(E),u.timeZone=ce===!1?void 0:ce||St(),u.expectedCountries=z,u.expectedLanguages=M||(Te?[Te]:void 0)}const v=await fetch(y,{body:JSON.stringify(u),headers:{"content-type":"application/json"},method:"POST"});if(v.status!==200)throw new Error(`Server responded with ${v.status}.`);const j=await v.json();if(j!=null&&j.payload&&t(4,K=j.payload),I("serververification",j),f&&j.classification==="BAD")throw new Error("SpamFilter returned negative classification.")}function De(r){r.auto!==void 0&&(t(0,s=r.auto),s==="onload"&&J()),r.expire!==void 0&&(oe(r.expire),t(14,L=r.expire)),r.challenge&&(Oe(r.challenge),i=r.challenge),r.challengeurl!==void 0&&t(12,a=r.challengeurl),r.debug!==void 0&&t(13,T=!!r.debug),r.hidefooter!==void 0&&t(1,G=!!r.hidefooter),r.hidelogo!==void 0&&t(2,U=!!r.hidelogo),r.maxnumber!==void 0&&t(15,_=+r.maxnumber),r.mockerror!==void 0&&t(16,B=!!r.mockerror),r.name!==void 0&&t(3,D=r.name),r.refetchonexpire!==void 0&&t(17,F=!!r.refetchonexpire),r.spamfilter!==void 0&&t(18,k=typeof r.spamfilter=="object"?r.spamfilter:!!r.spamfilter),r.strings&&t(28,l=r.strings),r.test!==void 0&&t(19,g=typeof r.test=="number"?r.test:!!r.test),r.verifyurl!==void 0&&t(20,y=r.verifyurl),r.workers!==void 0&&t(21,d=+r.workers)}function se(r=b.UNVERIFIED,u=null){clearTimeout(be),t(6,Y=!1),t(8,me=u),t(4,K=null),t(5,H=r)}async function J(){return se(b.VERIFYING),Zt().then(r=>(Oe(r),R("challenge",r),At(r))).then(({data:r,solution:u})=>{if(R("solution",u),(u==null?void 0:u.number)!==void 0){if(y)return Ot(Ue(r,u));t(4,K=Ue(r,u)),R("payload",K)}else throw R("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."),new Error("Unexpected result returned.")}).then(()=>{ot().then(()=>{t(5,H=b.VERIFIED),t(6,Y=!0),R("verified"),I("verified",{payload:K})})}).catch(r=>{R(r),t(5,H=b.ERROR),t(6,Y=!1),t(8,me=r.message)})}function Xt(){Y=this.checked,t(6,Y)}function Dt(r){ue[r?"unshift":"push"](()=>{le=r,t(7,le)})}return n.$$set=r=>{"auto"in r&&t(0,s=r.auto),"blockspam"in r&&t(22,f=r.blockspam),"challengeurl"in r&&t(12,a=r.challengeurl),"challengejson"in r&&t(23,h=r.challengejson),"debug"in r&&t(13,T=r.debug),"expire"in r&&t(14,L=r.expire),"hidefooter"in r&&t(1,G=r.hidefooter),"hidelogo"in r&&t(2,U=r.hidelogo),"name"in r&&t(3,D=r.name),"maxnumber"in r&&t(15,_=r.maxnumber),"mockerror"in r&&t(16,B=r.mockerror),"refetchonexpire"in r&&t(17,F=r.refetchonexpire),"spamfilter"in r&&t(18,k=r.spamfilter),"strings"in r&&t(24,x=r.strings),"test"in r&&t(19,g=r.test),"verifyurl"in r&&t(20,y=r.verifyurl),"workers"in r&&t(21,d=r.workers)},n.$$.update=()=>{n.$$.dirty[0]&8388608&&(i=h?je(h):void 0),n.$$.dirty[0]&16777216&&t(28,l=x?je(x):{}),n.$$.dirty[0]&268435456&&t(9,o={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),n.$$.dirty[0]&48&&I("statechange",{payload:K,state:H})},[s,G,U,D,K,H,Y,le,me,o,Mt,Vt,a,T,L,_,B,F,k,g,y,d,f,h,x,De,se,J,l,Xt,Dt]}class Ze extends bt{constructor(e){super(),gt(this,e,jt,Nt,Be,{auto:0,blockspam:22,challengeurl:12,challengejson:23,debug:13,expire:14,hidefooter:1,hidelogo:2,name:3,maxnumber:15,mockerror:16,refetchonexpire:17,spamfilter:18,strings:24,test:19,verifyurl:20,workers:21,configure:25,reset:26,verify:27},Et,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),w()}get blockspam(){return this.$$.ctx[22]}set blockspam(e){this.$$set({blockspam:e}),w()}get challengeurl(){return this.$$.ctx[12]}set challengeurl(e){this.$$set({challengeurl:e}),w()}get challengejson(){return this.$$.ctx[23]}set challengejson(e){this.$$set({challengejson:e}),w()}get debug(){return this.$$.ctx[13]}set debug(e){this.$$set({debug:e}),w()}get expire(){return this.$$.ctx[14]}set expire(e){this.$$set({expire:e}),w()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),w()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),w()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),w()}get maxnumber(){return this.$$.ctx[15]}set maxnumber(e){this.$$set({maxnumber:e}),w()}get mockerror(){return this.$$.ctx[16]}set mockerror(e){this.$$set({mockerror:e}),w()}get refetchonexpire(){return this.$$.ctx[17]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),w()}get spamfilter(){return this.$$.ctx[18]}set spamfilter(e){this.$$set({spamfilter:e}),w()}get strings(){return this.$$.ctx[24]}set strings(e){this.$$set({strings:e}),w()}get test(){return this.$$.ctx[19]}set test(e){this.$$set({test:e}),w()}get verifyurl(){return this.$$.ctx[20]}set verifyurl(e){this.$$set({verifyurl:e}),w()}get workers(){return this.$$.ctx[21]}set workers(e){this.$$set({workers:e}),w()}get configure(){return this.$$.ctx[25]}get reset(){return this.$$.ctx[26]}get verify(){return this.$$.ctx[27]}}return customElements.define("altcha-widget",mt(Ze,{auto:{},blockspam:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},spamfilter:{type:"Boolean"},strings:{},test:{type:"Boolean"},verifyurl:{},workers:{}},[],["configure","reset","verify"],!1)),O.Altcha=Ze,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"}),O}({}); diff --git a/dist/altcha.js b/dist/altcha.js index 396f4bc..cdd1279 100644 --- a/dist/altcha.js +++ b/dist/altcha.js @@ -1,18 +1,18 @@ var nt = Object.defineProperty; var it = (r, e, t) => e in r ? nt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; var M = (r, e, t) => (it(r, typeof e != "symbol" ? e + "" : e, t), t); -function J() { +function Q() { } -function Ve(r) { +function Ge(r) { return r(); } -function Re() { +function Ie() { return /* @__PURE__ */ Object.create(null); } -function q(r) { - r.forEach(Ve); +function te(r) { + r.forEach(Ge); } -function Oe(r) { +function Ue(r) { return typeof r == "function"; } function lt(r, e) { @@ -21,13 +21,13 @@ function lt(r, e) { function ot(r) { return Object.keys(r).length === 0; } -function w(r, e) { +function y(r, e) { r.appendChild(e); } function st(r, e, t) { const i = ct(r); if (!i.getElementById(e)) { - const l = L("style"); + const l = R("style"); l.id = e, l.textContent = t, at(i, l); } } @@ -42,28 +42,28 @@ function ct(r) { ) : r.ownerDocument; } function at(r, e) { - return w( + return y( /** @type {Document} */ r.head || r, e ), e.sheet; } -function A(r, e, t) { +function Z(r, e, t) { r.insertBefore(e, t || null); } -function N(r) { +function S(r) { r.parentNode && r.parentNode.removeChild(r); } -function L(r) { +function R(r) { return document.createElement(r); } -function P(r) { +function O(r) { return document.createElementNS("http://www.w3.org/2000/svg", r); } function ft(r) { return document.createTextNode(r); } -function U() { +function B() { return ft(" "); } function ae(r, e, t, i) { @@ -90,14 +90,14 @@ function dt(r) { } ), e; } -let Q; -function z(r) { - Q = r; +let ee; +function q(r) { + ee = r; } function ge() { - if (!Q) + if (!ee) throw new Error("Function called outside component initialization"); - return Q; + return ee; } function gt(r) { ge().$$.on_mount.push(r); @@ -123,56 +123,56 @@ function bt() { return !0; }; } -const X = [], ue = []; -let K = []; -const Se = [], He = /* @__PURE__ */ Promise.resolve(); +const J = [], ue = []; +let z = []; +const Se = [], Xe = /* @__PURE__ */ Promise.resolve(); let he = !1; -function Pe() { - he || (he = !0, He.then(E)); +function De() { + he || (he = !0, Xe.then($)); } function pt() { - return Pe(), He; + return De(), Xe; } function de(r) { - K.push(r); + z.push(r); } const fe = /* @__PURE__ */ new Set(); -let Y = 0; -function E() { - if (Y !== 0) +let K = 0; +function $() { + if (K !== 0) return; - const r = Q; + const r = ee; do { try { - for (; Y < X.length; ) { - const e = X[Y]; - Y++, z(e), yt(e.$$); + for (; K < J.length; ) { + const e = J[K]; + K++, q(e), yt(e.$$); } } catch (e) { - throw X.length = 0, Y = 0, e; + throw J.length = 0, K = 0, e; } - for (z(null), X.length = 0, Y = 0; ue.length; ) + for (q(null), J.length = 0, K = 0; ue.length; ) ue.pop()(); - for (let e = 0; e < K.length; e += 1) { - const t = K[e]; + for (let e = 0; e < z.length; e += 1) { + const t = z[e]; fe.has(t) || (fe.add(t), t()); } - K.length = 0; - } while (X.length); + z.length = 0; + } while (J.length); for (; Se.length; ) Se.pop()(); - he = !1, fe.clear(), z(r); + he = !1, fe.clear(), q(r); } function yt(r) { if (r.fragment !== null) { - r.update(), q(r.before_update); + r.update(), te(r.before_update); const e = r.dirty; r.dirty = [-1], r.fragment && r.fragment.p(r.ctx, e), r.after_update.forEach(de); } } function vt(r) { const e = [], t = []; - K.forEach((i) => r.indexOf(i) === -1 ? e.push(i) : t.push(i)), t.forEach((i) => i()), K = e; + z.forEach((i) => r.indexOf(i) === -1 ? e.push(i) : t.push(i)), t.forEach((i) => i()), z = e; } const wt = /* @__PURE__ */ new Set(); function _t(r, e) { @@ -181,58 +181,58 @@ function _t(r, e) { function kt(r, e, t) { const { fragment: i, after_update: l } = r.$$; i && i.m(e, t), de(() => { - const o = r.$$.on_mount.map(Ve).filter(Oe); - r.$$.on_destroy ? r.$$.on_destroy.push(...o) : q(o), r.$$.on_mount = []; + const o = r.$$.on_mount.map(Ge).filter(Ue); + r.$$.on_destroy ? r.$$.on_destroy.push(...o) : te(o), r.$$.on_mount = []; }), l.forEach(de); } function xt(r, e) { const t = r.$$; - t.fragment !== null && (vt(t.after_update), q(t.on_destroy), t.fragment && t.fragment.d(e), t.on_destroy = t.fragment = null, t.ctx = []); + t.fragment !== null && (vt(t.after_update), te(t.on_destroy), t.fragment && t.fragment.d(e), t.on_destroy = t.fragment = null, t.ctx = []); } function Et(r, e) { - r.$$.dirty[0] === -1 && (X.push(r), Pe(), r.$$.dirty.fill(0)), r.$$.dirty[e / 31 | 0] |= 1 << e % 31; + r.$$.dirty[0] === -1 && (J.push(r), De(), r.$$.dirty.fill(0)), r.$$.dirty[e / 31 | 0] |= 1 << e % 31; } -function $t(r, e, t, i, l, o, s = null, a = [-1]) { - const f = Q; - z(r); - const u = r.$$ = { +function $t(r, e, t, i, l, o, s = null, f = [-1]) { + const a = ee; + q(r); + const h = r.$$ = { fragment: null, ctx: [], // state props: o, - update: J, + update: Q, not_equal: l, - bound: Re(), + bound: Ie(), // lifecycle on_mount: [], on_destroy: [], on_disconnect: [], before_update: [], after_update: [], - context: new Map(e.context || (f ? f.$$.context : [])), + context: new Map(e.context || (a ? a.$$.context : [])), // everything else - callbacks: Re(), - dirty: a, + callbacks: Ie(), + dirty: f, skip_bound: !1, - root: e.target || f.$$.root + root: e.target || a.$$.root }; - s && s(u.root); - let R = !1; - if (u.ctx = t ? t(r, e.props || {}, (m, j, ...Z) => { - const G = Z.length ? Z[0] : j; - return u.ctx && l(u.ctx[m], u.ctx[m] = G) && (!u.skip_bound && u.bound[m] && u.bound[m](G), R && Et(r, m)), j; - }) : [], u.update(), R = !0, q(u.before_update), u.fragment = i ? i(u.ctx) : !1, e.target) { + s && s(h.root); + let A = !1; + if (h.ctx = t ? t(r, e.props || {}, (C, V, ...G) => { + const U = G.length ? G[0] : V; + return h.ctx && l(h.ctx[C], h.ctx[C] = U) && (!h.skip_bound && h.bound[C] && h.bound[C](U), A && Et(r, C)), V; + }) : [], h.update(), A = !0, te(h.before_update), h.fragment = i ? i(h.ctx) : !1, e.target) { if (e.hydrate) { - const m = ut(e.target); - u.fragment && u.fragment.l(m), m.forEach(N); + const C = ut(e.target); + h.fragment && h.fragment.l(C), C.forEach(S); } else - u.fragment && u.fragment.c(); - e.intro && _t(r.$$.fragment), kt(r, e.target, e.anchor), E(); + h.fragment && h.fragment.c(); + e.intro && _t(r.$$.fragment), kt(r, e.target, e.anchor), $(); } - z(f); + q(a); } -let De; -typeof HTMLElement == "function" && (De = class extends HTMLElement { +let Oe; +typeof HTMLElement == "function" && (Oe = class extends HTMLElement { constructor(e, t, i) { super(); /** The Svelte component constructor */ @@ -275,17 +275,17 @@ typeof HTMLElement == "function" && (De = class extends HTMLElement { let s; return { c: function() { - s = L("slot"), o !== "default" && c(s, "name", o); + s = R("slot"), o !== "default" && c(s, "name", o); }, /** * @param {HTMLElement} target * @param {HTMLElement} [anchor] */ - m: function(u, R) { - A(u, s, R); + m: function(h, A) { + Z(h, s, A); }, - d: function(u) { - u && N(s); + d: function(h) { + h && S(s); } }; }; @@ -297,7 +297,7 @@ typeof HTMLElement == "function" && (De = class extends HTMLElement { o in i && (t[o] = [e(o)]); for (const o of this.attributes) { const s = this.$$g_p(o.name); - s in this.$$d || (this.$$d[s] = le(s, o.value, this.$$p_d, "toProp")); + s in this.$$d || (this.$$d[s] = oe(s, o.value, this.$$p_d, "toProp")); } for (const o in this.$$p_d) !(o in this.$$d) && this[o] !== void 0 && (this.$$d[o] = this[o], delete this[o]); @@ -315,7 +315,7 @@ typeof HTMLElement == "function" && (De = class extends HTMLElement { this.$$r = !0; for (const o in this.$$p_d) if (this.$$d[o] = this.$$c.$$.ctx[this.$$c.$$.props[o]], this.$$p_d[o].reflect) { - const s = le( + const s = oe( o, this.$$d[o], this.$$p_d, @@ -328,8 +328,8 @@ typeof HTMLElement == "function" && (De = class extends HTMLElement { this.$$c.$$.after_update.push(l), l(); for (const o in this.$$l) for (const s of this.$$l[o]) { - const a = this.$$c.$on(o, s); - this.$$l_u.set(s, a); + const f = this.$$c.$on(o, s); + this.$$l_u.set(s, f); } this.$$l = {}; } @@ -338,7 +338,7 @@ typeof HTMLElement == "function" && (De = class extends HTMLElement { // and setting attributes through setAttribute etc, this is helpful attributeChangedCallback(e, t, i) { var l; - this.$$r || (e = this.$$g_p(e), this.$$d[e] = le(e, i, this.$$p_d, "toProp"), (l = this.$$c) == null || l.$set({ [e]: this.$$d[e] })); + this.$$r || (e = this.$$g_p(e), this.$$d[e] = oe(e, i, this.$$p_d, "toProp"), (l = this.$$c) == null || l.$set({ [e]: this.$$d[e] })); } disconnectedCallback() { this.$$cn = !1, Promise.resolve().then(() => { @@ -351,7 +351,7 @@ typeof HTMLElement == "function" && (De = class extends HTMLElement { ) || e; } }); -function le(r, e, t, i) { +function oe(r, e, t, i) { var o; const l = (o = t[r]) == null ? void 0 : o.type; if (e = l === "Boolean" && typeof e != "boolean" ? e != null : e, !i || !t[r]) @@ -382,31 +382,31 @@ function le(r, e, t, i) { } } function Ct(r, e, t, i, l, o) { - let s = class extends De { + let s = class extends Oe { constructor() { super(r, t, l), this.$$p_d = e; } static get observedAttributes() { return Object.keys(e).map( - (a) => (e[a].attribute || a).toLowerCase() + (f) => (e[f].attribute || f).toLowerCase() ); } }; - return Object.keys(e).forEach((a) => { - Object.defineProperty(s.prototype, a, { + return Object.keys(e).forEach((f) => { + Object.defineProperty(s.prototype, f, { get() { - return this.$$c && a in this.$$c ? this.$$c[a] : this.$$d[a]; + return this.$$c && f in this.$$c ? this.$$c[f] : this.$$d[f]; }, - set(f) { - var u; - f = le(a, f, e), this.$$d[a] = f, (u = this.$$c) == null || u.$set({ [a]: f }); + set(a) { + var h; + a = oe(f, a, e), this.$$d[f] = a, (h = this.$$c) == null || h.$set({ [f]: a }); } }); - }), i.forEach((a) => { - Object.defineProperty(s.prototype, a, { + }), i.forEach((f) => { + Object.defineProperty(s.prototype, f, { get() { - var f; - return (f = this.$$c) == null ? void 0 : f[a]; + var a; + return (a = this.$$c) == null ? void 0 : a[f]; } }); }), o && (s = o(s)), r.element = /** @type {any} */ @@ -433,7 +433,7 @@ class Lt { } /** @returns {void} */ $destroy() { - xt(this, 1), this.$destroy = J; + xt(this, 1), this.$destroy = Q; } /** * @template {Extract} K @@ -442,8 +442,8 @@ class Lt { * @returns {() => void} */ $on(e, t) { - if (!Oe(t)) - return J; + if (!Ue(t)) + return Q; const i = this.$$.callbacks[e] || (this.$$.callbacks[e] = []); return i.push(t), () => { const l = i.indexOf(t); @@ -458,13 +458,13 @@ class Lt { this.$$set && !ot(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1); } } -const It = "4"; -typeof window < "u" && (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(It); -const Fe = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+aT9zKG51bGwpOmgoZSxsLG8pLnRoZW4odz0+e3c9PT10P3Moe251bWJlcjpsLHRvb2s6RGF0ZS5ub3coKS1yfSk6ZChsKzEpfSkuY2F0Y2goYyl9O2QocCl9KSxjb250cm9sbGVyOmF9fWxldCBuO29ubWVzc2FnZT1hc3luYyB0PT57Y29uc3R7dHlwZTplLHBheWxvYWQ6b309dC5kYXRhO2lmKGU9PT0iYWJvcnQiKW49PW51bGx8fG4uYWJvcnQoKSxuPXZvaWQgMDtlbHNlIGlmKGU9PT0id29yayIpe2NvbnN0e2FsZzppLGNoYWxsZW5nZTpwLG1heDphLHNhbHQ6dSxzdGFydDpzfT1vfHx7fSxjPW0ocCx1LGksYSxzKTtuPWMuY29udHJvbGxlcixjLnByb21pc2UudGhlbihyPT57c2VsZi5wb3N0TWVzc2FnZShyJiZ7Li4ucix3b3JrZXI6ITB9KX0pfX19KSgpOwo=", Rt = (r) => Uint8Array.from(atob(r), (e) => e.charCodeAt(0)), Te = typeof window < "u" && window.Blob && new Blob([Rt(Fe)], { type: "text/javascript;charset=utf-8" }); +const Rt = "4"; +typeof window < "u" && (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(Rt); +const Fe = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGQoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAodD0+dC50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBwKGUsdCxvKXtyZXR1cm4gZChhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUoZSt0KSkpfWZ1bmN0aW9uIGcoZSx0LG89IlNIQS0yNTYiLGw9MWU2LGM9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyLGk9RGF0ZS5ub3coKTtyZXR1cm57cHJvbWlzZTooYXN5bmMoKT0+e2ZvcihsZXQgbj1jO248PWw7bis9MSl7aWYoYS5zaWduYWwuYWJvcnRlZClyZXR1cm4gbnVsbDtpZihhd2FpdCBwKHQsbixvKT09PWUpcmV0dXJue251bWJlcjpuLHRvb2s6RGF0ZS5ub3coKS1pfX1yZXR1cm4gbnVsbH0pKCksY29udHJvbGxlcjphfX1sZXQgcjtvbm1lc3NhZ2U9YXN5bmMgZT0+e2NvbnN0e3R5cGU6dCxwYXlsb2FkOm99PWUuZGF0YTtpZih0PT09ImFib3J0IilyPT1udWxsfHxyLmFib3J0KCkscj12b2lkIDA7ZWxzZSBpZih0PT09IndvcmsiKXtjb25zdHthbGc6bCxjaGFsbGVuZ2U6YyxtYXg6YSxzYWx0Omksc3RhcnQ6dX09b3x8e30sbj1nKGMsaSxsLGEsdSk7cj1uLmNvbnRyb2xsZXIsbi5wcm9taXNlLnRoZW4ocz0+e3NlbGYucG9zdE1lc3NhZ2UocyYmey4uLnMsd29ya2VyOiEwfSl9KX19fSkoKTsK", It = (r) => Uint8Array.from(atob(r), (e) => e.charCodeAt(0)), je = typeof window < "u" && window.Blob && new Blob([It(Fe)], { type: "text/javascript;charset=utf-8" }); function Nt(r) { let e; try { - if (e = Te && (window.URL || window.webkitURL).createObjectURL(Te), !e) + if (e = je && (window.URL || window.webkitURL).createObjectURL(je), !e) throw ""; const t = new Worker(e, { name: r == null ? void 0 : r.name @@ -484,13 +484,13 @@ function Nt(r) { } } const St = new TextEncoder(); -function Tt(r) { +function jt(r) { return [...new Uint8Array(r)].map((e) => e.toString(16).padStart(2, "0")).join(""); } -async function At(r, e = "SHA-256", t = 1e5) { +async function Zt(r, e = "SHA-256", t = 1e5) { const i = Date.now().toString(16); r || (r = Math.round(Math.random() * t)); - const l = await We(i, r, e); + const l = await He(i, r, e); return { algorithm: e, challenge: l, @@ -498,62 +498,63 @@ async function At(r, e = "SHA-256", t = 1e5) { signature: "" }; } -async function We(r, e, t) { - return Tt( +async function He(r, e, t) { + return jt( await crypto.subtle.digest( t.toUpperCase(), St.encode(r + e) ) ); } -function jt(r, e, t = "SHA-256", i = 1e6, l = 0) { - const o = new AbortController(); +function At(r, e, t = "SHA-256", i = 1e6, l = 0) { + const o = new AbortController(), s = Date.now(); return { - promise: new Promise((a, f) => { - const u = Date.now(), R = (m) => { - o.signal.aborted || m > i ? a(null) : We(e, m, t).then((j) => { - j === r ? a({ - number: m, - took: Date.now() - u - }) : R(m + 1); - }).catch(f); - }; - R(l); - }), + promise: (async () => { + for (let a = l; a <= i; a += 1) { + if (o.signal.aborted) + return null; + if (await He(e, a, t) === r) + return { + number: a, + took: Date.now() - s + }; + } + return null; + })(), controller: o }; } -var v = /* @__PURE__ */ ((r) => (r.ERROR = "error", r.VERIFIED = "verified", r.VERIFYING = "verifying", r.UNVERIFIED = "unverified", r.EXPIRED = "expired", r))(v || {}); -function Mt(r) { +var p = /* @__PURE__ */ ((r) => (r.ERROR = "error", r.VERIFIED = "verified", r.VERIFYING = "verifying", r.UNVERIFIED = "unverified", r.EXPIRED = "expired", r))(p || {}); +function Tt(r) { st(r, "svelte-14ngypa", `.altcha.svelte-14ngypa.svelte-14ngypa{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-14ngypa.svelte-14ngypa:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-14ngypa.svelte-14ngypa{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-14ngypa.svelte-14ngypa{flex-grow:1}.altcha-label.svelte-14ngypa label.svelte-14ngypa{cursor:pointer}.altcha-logo.svelte-14ngypa.svelte-14ngypa{color:currentColor;opacity:0.3}.altcha-logo.svelte-14ngypa.svelte-14ngypa:hover{opacity:1}.altcha-error.svelte-14ngypa.svelte-14ngypa{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-14ngypa.svelte-14ngypa{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-14ngypa.svelte-14ngypa:hover{opacity:1}.altcha-footer.svelte-14ngypa>.svelte-14ngypa:first-child{flex-grow:1}.altcha-footer.svelte-14ngypa a{color:currentColor}.altcha-checkbox.svelte-14ngypa.svelte-14ngypa{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-14ngypa input.svelte-14ngypa{width:18px;height:18px;margin:0}.altcha-hidden.svelte-14ngypa.svelte-14ngypa{display:none}.altcha-spinner.svelte-14ngypa.svelte-14ngypa{animation:svelte-14ngypa-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-14ngypa-altcha-spinner{100%{transform:rotate(360deg)}}`); } -function Ae(r) { +function Ze(r) { let e, t, i; return { c() { - e = P("svg"), t = P("path"), i = P("path"), c(t, "d", "M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"), c(t, "fill", "currentColor"), c(t, "opacity", ".25"), c(i, "d", "M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"), c(i, "fill", "currentColor"), c(i, "class", "altcha-spinner svelte-14ngypa"), c(e, "width", "24"), c(e, "height", "24"), c(e, "viewBox", "0 0 24 24"), c(e, "xmlns", "http://www.w3.org/2000/svg"); + e = O("svg"), t = O("path"), i = O("path"), c(t, "d", "M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"), c(t, "fill", "currentColor"), c(t, "opacity", ".25"), c(i, "d", "M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"), c(i, "fill", "currentColor"), c(i, "class", "altcha-spinner svelte-14ngypa"), c(e, "width", "24"), c(e, "height", "24"), c(e, "viewBox", "0 0 24 24"), c(e, "xmlns", "http://www.w3.org/2000/svg"); }, m(l, o) { - A(l, e, o), w(e, t), w(e, i); + Z(l, e, o), y(e, t), y(e, i); }, d(l) { - l && N(e); + l && S(e); } }; } -function Zt(r) { +function Mt(r) { let e, t = ( /*_strings*/ r[9].label + "" ), i; return { c() { - e = L("label"), c(e, "for", i = /*name*/ + e = R("label"), c(e, "for", i = /*name*/ r[3] + "_checkbox"), c(e, "class", "svelte-14ngypa"); }, m(l, o) { - A(l, e, o), e.innerHTML = t; + Z(l, e, o), e.innerHTML = t; }, p(l, o) { o[0] & /*_strings*/ @@ -563,21 +564,21 @@ function Zt(r) { l[3] + "_checkbox") && c(e, "for", i); }, d(l) { - l && N(e); + l && S(e); } }; } -function Gt(r) { +function Vt(r) { let e, t = ( /*_strings*/ r[9].verifying + "" ); return { c() { - e = L("span"); + e = R("span"); }, m(i, l) { - A(i, e, l), e.innerHTML = t; + Z(i, e, l), e.innerHTML = t; }, p(i, l) { l[0] & /*_strings*/ @@ -585,18 +586,18 @@ function Gt(r) { i[9].verifying + "") && (e.innerHTML = t); }, d(i) { - i && N(e); + i && S(e); } }; } -function Vt(r) { +function Gt(r) { let e, t = ( /*_strings*/ r[9].verified + "" ), i, l; return { c() { - e = L("span"), i = U(), l = L("input"), c(l, "type", "hidden"), c( + e = R("span"), i = B(), l = R("input"), c(l, "type", "hidden"), c( l, "name", /*name*/ @@ -605,7 +606,7 @@ function Vt(r) { r[4]; }, m(o, s) { - A(o, e, s), e.innerHTML = t, A(o, i, s), A(o, l, s); + Z(o, e, s), e.innerHTML = t, Z(o, i, s), Z(o, l, s); }, p(o, s) { s[0] & /*_strings*/ @@ -621,57 +622,57 @@ function Vt(r) { o[4]); }, d(o) { - o && (N(e), N(i), N(l)); + o && (S(e), S(i), S(l)); } }; } -function je(r) { +function Ae(r) { let e, t, i, l, o, s; return { c() { - e = L("div"), t = L("a"), i = P("svg"), l = P("path"), o = P("path"), s = P("path"), c(l, "d", "M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"), c(l, "fill", "currentColor"), c(o, "d", "M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"), c(o, "fill", "currentColor"), c(s, "d", "M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"), c(s, "fill", "currentColor"), c(i, "width", "22"), c(i, "height", "22"), c(i, "viewBox", "0 0 20 20"), c(i, "fill", "none"), c(i, "xmlns", "http://www.w3.org/2000/svg"), c(t, "href", Be), c(t, "target", "_blank"), c(t, "class", "altcha-logo svelte-14ngypa"); + e = R("div"), t = R("a"), i = O("svg"), l = O("path"), o = O("path"), s = O("path"), c(l, "d", "M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"), c(l, "fill", "currentColor"), c(o, "d", "M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"), c(o, "fill", "currentColor"), c(s, "d", "M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"), c(s, "fill", "currentColor"), c(i, "width", "22"), c(i, "height", "22"), c(i, "viewBox", "0 0 20 20"), c(i, "fill", "none"), c(i, "xmlns", "http://www.w3.org/2000/svg"), c(t, "href", Ye), c(t, "target", "_blank"), c(t, "class", "altcha-logo svelte-14ngypa"); }, - m(a, f) { - A(a, e, f), w(e, t), w(t, i), w(i, l), w(i, o), w(i, s); + m(f, a) { + Z(f, e, a), y(e, t), y(t, i), y(i, l), y(i, o), y(i, s); }, - p: J, - d(a) { - a && N(e); + p: Q, + d(f) { + f && S(e); } }; } -function Me(r) { +function Te(r) { let e, t, i, l; - function o(f, u) { + function o(a, h) { return ( /*state*/ - f[5] === v.EXPIRED ? Ht : Ot + a[5] === p.EXPIRED ? Xt : Ut ); } - let s = o(r), a = s(r); + let s = o(r), f = s(r); return { c() { - e = L("div"), t = P("svg"), i = P("path"), l = U(), a.c(), c(i, "stroke-linecap", "round"), c(i, "stroke-linejoin", "round"), c(i, "d", "M6 18L18 6M6 6l12 12"), c(t, "width", "14"), c(t, "height", "14"), c(t, "xmlns", "http://www.w3.org/2000/svg"), c(t, "fill", "none"), c(t, "viewBox", "0 0 24 24"), c(t, "stroke-width", "1.5"), c(t, "stroke", "currentColor"), c(e, "class", "altcha-error svelte-14ngypa"); + e = R("div"), t = O("svg"), i = O("path"), l = B(), f.c(), c(i, "stroke-linecap", "round"), c(i, "stroke-linejoin", "round"), c(i, "d", "M6 18L18 6M6 6l12 12"), c(t, "width", "14"), c(t, "height", "14"), c(t, "xmlns", "http://www.w3.org/2000/svg"), c(t, "fill", "none"), c(t, "viewBox", "0 0 24 24"), c(t, "stroke-width", "1.5"), c(t, "stroke", "currentColor"), c(e, "class", "altcha-error svelte-14ngypa"); }, - m(f, u) { - A(f, e, u), w(e, t), w(t, i), w(e, l), a.m(e, null); + m(a, h) { + Z(a, e, h), y(e, t), y(t, i), y(e, l), f.m(e, null); }, - p(f, u) { - s === (s = o(f)) && a ? a.p(f, u) : (a.d(1), a = s(f), a && (a.c(), a.m(e, null))); + p(a, h) { + s === (s = o(a)) && f ? f.p(a, h) : (f.d(1), f = s(a), f && (f.c(), f.m(e, null))); }, - d(f) { - f && N(e), a.d(); + d(a) { + a && S(e), f.d(); } }; } -function Ot(r) { +function Ut(r) { let e, t = ( /*_strings*/ r[9].error + "" ); return { c() { - e = L("div"), c( + e = R("div"), c( e, "title", /*error*/ @@ -679,7 +680,7 @@ function Ot(r) { ); }, m(i, l) { - A(i, e, l), e.innerHTML = t; + Z(i, e, l), e.innerHTML = t; }, p(i, l) { l[0] & /*_strings*/ @@ -693,18 +694,18 @@ function Ot(r) { ); }, d(i) { - i && N(e); + i && S(e); } }; } -function Ht(r) { +function Xt(r) { let e, t = ( /*_strings*/ r[9].expired + "" ); return { c() { - e = L("div"), c( + e = R("div"), c( e, "title", /*error*/ @@ -712,7 +713,7 @@ function Ht(r) { ); }, m(i, l) { - A(i, e, l), e.innerHTML = t; + Z(i, e, l), e.innerHTML = t; }, p(i, l) { l[0] & /*_strings*/ @@ -726,21 +727,21 @@ function Ht(r) { ); }, d(i) { - i && N(e); + i && S(e); } }; } -function Ze(r) { +function Me(r) { let e, t, i = ( /*_strings*/ r[9].footer + "" ); return { c() { - e = L("div"), t = L("div"), c(t, "class", "svelte-14ngypa"), c(e, "class", "altcha-footer svelte-14ngypa"); + e = R("div"), t = R("div"), c(t, "class", "svelte-14ngypa"), c(e, "class", "altcha-footer svelte-14ngypa"); }, m(l, o) { - A(l, e, o), w(e, t), t.innerHTML = i; + Z(l, e, o), y(e, t), t.innerHTML = i; }, p(l, o) { o[0] & /*_strings*/ @@ -748,46 +749,46 @@ function Ze(r) { l[9].footer + "") && (t.innerHTML = i); }, d(l) { - l && N(e); + l && S(e); } }; } -function Pt(r) { - let e, t, i, l, o, s, a, f, u, R, m, j, Z, G, _ = ( +function Dt(r) { + let e, t, i, l, o, s, f, a, h, A, C, V, G, U, w = ( /*state*/ - r[5] === v.VERIFYING && Ae() + r[5] === p.VERIFYING && Ze() ); - function F(d, I) { + function H(d, I) { return ( /*state*/ - d[5] === v.VERIFIED ? Vt : ( + d[5] === p.VERIFIED ? Gt : ( /*state*/ - d[5] === v.VERIFYING ? Gt : Zt + d[5] === p.VERIFYING ? Vt : Mt ) ); } - let V = F(r), k = V(r), x = ( + let X = H(r), _ = X(r), k = ( /*hidelogo*/ - r[2] !== !0 && je() + r[2] !== !0 && Ae() ), g = ( /*error*/ (r[8] || /*state*/ - r[5] === v.EXPIRED) && Me(r) - ), y = ( + r[5] === p.EXPIRED) && Te(r) + ), b = ( /*_strings*/ r[9].footer && /*hidefooter*/ - r[1] !== !0 && Ze(r) + r[1] !== !0 && Me(r) ); return { c() { - e = L("div"), t = L("div"), _ && _.c(), i = U(), l = L("div"), o = L("input"), f = U(), u = L("div"), k.c(), R = U(), x && x.c(), m = U(), g && g.c(), j = U(), y && y.c(), c(o, "type", "checkbox"), c(o, "id", s = /*name*/ - r[3] + "_checkbox"), o.required = a = /*auto*/ + e = R("div"), t = R("div"), w && w.c(), i = B(), l = R("div"), o = R("input"), a = B(), h = R("div"), _.c(), A = B(), k && k.c(), C = B(), g && g.c(), V = B(), b && b.c(), c(o, "type", "checkbox"), c(o, "id", s = /*name*/ + r[3] + "_checkbox"), o.required = f = /*auto*/ r[0] !== "onsubmit", c(o, "class", "svelte-14ngypa"), c(l, "class", "altcha-checkbox svelte-14ngypa"), Ne( l, "altcha-hidden", /*state*/ - r[5] === v.VERIFYING - ), c(u, "class", "altcha-label svelte-14ngypa"), c(t, "class", "altcha-main svelte-14ngypa"), c(e, "class", "altcha svelte-14ngypa"), c( + r[5] === p.VERIFYING + ), c(h, "class", "altcha-label svelte-14ngypa"), c(t, "class", "altcha-main svelte-14ngypa"), c(e, "class", "altcha svelte-14ngypa"), c( e, "data-state", /*state*/ @@ -795,8 +796,8 @@ function Pt(r) { ); }, m(d, I) { - A(d, e, I), w(e, t), _ && _.m(t, null), w(t, i), w(t, l), w(l, o), o.checked = /*checked*/ - r[6], w(t, f), w(t, u), k.m(u, null), w(t, R), x && x.m(t, null), w(e, m), g && g.m(e, null), w(e, j), y && y.m(e, null), r[30](e), Z || (G = [ + Z(d, e, I), y(e, t), w && w.m(t, null), y(t, i), y(t, l), y(l, o), o.checked = /*checked*/ + r[6], y(t, a), y(t, h), _.m(h, null), y(t, A), k && k.m(t, null), y(e, C), g && g.m(e, null), y(e, V), b && b.m(e, null), r[30](e), G || (U = [ ae( o, "change", @@ -815,28 +816,28 @@ function Pt(r) { /*onInvalid*/ r[11] ) - ], Z = !0); + ], G = !0); }, p(d, I) { /*state*/ - d[5] === v.VERIFYING ? _ || (_ = Ae(), _.c(), _.m(t, i)) : _ && (_.d(1), _ = null), I[0] & /*name*/ + d[5] === p.VERIFYING ? w || (w = Ze(), w.c(), w.m(t, i)) : w && (w.d(1), w = null), I[0] & /*name*/ 8 && s !== (s = /*name*/ d[3] + "_checkbox") && c(o, "id", s), I[0] & /*auto*/ - 1 && a !== (a = /*auto*/ - d[0] !== "onsubmit") && (o.required = a), I[0] & /*checked*/ + 1 && f !== (f = /*auto*/ + d[0] !== "onsubmit") && (o.required = f), I[0] & /*checked*/ 64 && (o.checked = /*checked*/ d[6]), I[0] & /*state*/ 32 && Ne( l, "altcha-hidden", /*state*/ - d[5] === v.VERIFYING - ), V === (V = F(d)) && k ? k.p(d, I) : (k.d(1), k = V(d), k && (k.c(), k.m(u, null))), /*hidelogo*/ - d[2] !== !0 ? x ? x.p(d, I) : (x = je(), x.c(), x.m(t, null)) : x && (x.d(1), x = null), /*error*/ + d[5] === p.VERIFYING + ), X === (X = H(d)) && _ ? _.p(d, I) : (_.d(1), _ = X(d), _ && (_.c(), _.m(h, null))), /*hidelogo*/ + d[2] !== !0 ? k ? k.p(d, I) : (k = Ae(), k.c(), k.m(t, null)) : k && (k.d(1), k = null), /*error*/ d[8] || /*state*/ - d[5] === v.EXPIRED ? g ? g.p(d, I) : (g = Me(d), g.c(), g.m(e, j)) : g && (g.d(1), g = null), /*_strings*/ + d[5] === p.EXPIRED ? g ? g.p(d, I) : (g = Te(d), g.c(), g.m(e, V)) : g && (g.d(1), g = null), /*_strings*/ d[9].footer && /*hidefooter*/ - d[1] !== !0 ? y ? y.p(d, I) : (y = Ze(d), y.c(), y.m(e, null)) : y && (y.d(1), y = null), I[0] & /*state*/ + d[1] !== !0 ? b ? b.p(d, I) : (b = Me(d), b.c(), b.m(e, null)) : b && (b.d(1), b = null), I[0] & /*state*/ 32 && c( e, "data-state", @@ -844,18 +845,18 @@ function Pt(r) { d[5] ); }, - i: J, - o: J, + i: Q, + o: Q, d(d) { - d && N(e), _ && _.d(), k.d(), x && x.d(), g && g.d(), y && y.d(), r[30](null), Z = !1, q(G); + d && S(e), w && w.d(), _.d(), k && k.d(), g && g.d(), b && b.d(), r[30](null), G = !1, te(U); } }; } -const Be = "https://altcha.org/"; -function Ge(r) { +const Ye = "https://altcha.org/"; +function Ve(r) { return JSON.parse(r); } -function Dt() { +function Ot() { try { return Intl.DateTimeFormat().resolvedOptions().timeZone; } catch { @@ -863,37 +864,37 @@ function Dt() { } function Ft(r, e, t) { var Ee, $e; - let i, l, o, { auto: s = void 0 } = e, { blockspam: a = void 0 } = e, { challengeurl: f = void 0 } = e, { challengejson: u = void 0 } = e, { debug: R = !1 } = e, { expire: m = void 0 } = e, { hidefooter: j = !1 } = e, { hidelogo: Z = !1 } = e, { name: G = "altcha" } = e, { maxnumber: _ = 1e6 } = e, { mockerror: F = !1 } = e, { refetchonexpire: V = !0 } = e, { spamfilter: k = !1 } = e, { strings: x = void 0 } = e, { test: g = !1 } = e, { verifyurl: y = void 0 } = e, { workers: d = navigator.hardwareConcurrency || 8 } = e; + let i, l, o, { auto: s = void 0 } = e, { blockspam: f = void 0 } = e, { challengeurl: a = void 0 } = e, { challengejson: h = void 0 } = e, { debug: A = !1 } = e, { expire: C = void 0 } = e, { hidefooter: V = !1 } = e, { hidelogo: G = !1 } = e, { name: U = "altcha" } = e, { maxnumber: w = 1e6 } = e, { mockerror: H = !1 } = e, { refetchonexpire: X = !0 } = e, { spamfilter: _ = !1 } = e, { strings: k = void 0 } = e, { test: g = !1 } = e, { verifyurl: b = void 0 } = e, { workers: d = navigator.hardwareConcurrency || 8 } = e; const I = bt(), me = ["SHA-256", "SHA-384", "SHA-512"], be = ($e = (Ee = document.documentElement.lang) == null ? void 0 : Ee.split("-")) == null ? void 0 : $e[0]; - let D = !1, ee, b = null, oe = null, W = null, O = v.UNVERIFIED, se; + let F = !1, re, m = null, se = null, Y = null, D = p.UNVERIFIED, ce; mt(() => { - b && (b.removeEventListener("submit", ye), b.removeEventListener("reset", ve), b.removeEventListener("focusin", pe), b = null); + m && (m.removeEventListener("submit", ye), m.removeEventListener("reset", ve), m.removeEventListener("focusin", pe), m = null); }), gt(() => { - $("mounted", "0.3.2"), $("workers", d), g && $("using test mode"), m && ce(m), s !== void 0 && $("auto", s), b = ee.closest("form"), b && (b.addEventListener("submit", ye), b.addEventListener("reset", ve), s === "onfocus" && b.addEventListener("focusin", pe)), s === "onload" && B(); + L("mounted", "0.4.0"), L("workers", d), g && L("using test mode"), C && ne(C), s !== void 0 && L("auto", s), m = re.closest("form"), m && (m.addEventListener("submit", ye), m.addEventListener("reset", ve), s === "onfocus" && m.addEventListener("focusin", pe)), s === "onload" && P(); }); - function $(...n) { - (R || n.some((h) => h instanceof Error)) && console[n[0] instanceof Error ? "error" : "log"]("ALTCHA", ...n); + function L(...n) { + (A || n.some((u) => u instanceof Error)) && console[n[0] instanceof Error ? "error" : "log"]("ALTCHA", ...n); } function pe(n) { - B(); + P(); } function ye(n) { - b && s === "onsubmit" && O === v.UNVERIFIED && (n.preventDefault(), n.stopPropagation(), B().then(() => { - b == null || b.requestSubmit(); + m && s === "onsubmit" && D === p.UNVERIFIED && (n.preventDefault(), n.stopPropagation(), P().then(() => { + m == null || m.requestSubmit(); })); } function ve() { - te(); + ie(); } - function we(n, h) { + function we(n, u) { return btoa(JSON.stringify({ algorithm: n.algorithm, challenge: n.challenge, - number: h.number, + number: u.number, salt: n.salt, signature: n.signature, test: g ? !0 : void 0, - took: h.took + took: u.took })); } function _e(n) { @@ -908,125 +909,130 @@ function Ft(r, e, t) { if (!n.salt || n.salt.length < 10) throw new Error("Salt is too short. Min. 10 chars."); } - async function Ue() { - if (F) - throw $("mocking error"), new Error("Mocked error."); + async function Pe() { + var n; + if (H) + throw L("mocking error"), new Error("Mocked error."); if (i) - return $("using provided json data"), i; + return L("using provided json data"), i; if (g) - return $("generating test challenge", { test: g }), At(typeof g != "boolean" ? +g : void 0); + return L("generating test challenge", { test: g }), Zt(typeof g != "boolean" ? +g : void 0); { - if (!f) + if (!a) throw new Error("Attribute challengeurl not set."); - $("fetching challenge from", f); - const n = await fetch(f, { + L("fetching challenge from", a); + const u = await fetch(a, { headers: { - "x-altcha-spam-filter": k ? "1" : "0" + "x-altcha-spam-filter": _ ? "1" : "0" } }); - if (n.status !== 200) - throw new Error(`Server responded with ${n.status}.`); - const h = n.headers.get("Expires"), C = n.headers.get("X-Altcha-Config"); - if (C) + if (u.status !== 200) + throw new Error(`Server responded with ${u.status}.`); + const v = u.headers.get("Expires"), N = u.headers.get("X-Altcha-Config"), j = await u.json(), T = new URLSearchParams((n = j.salt.split("?")) == null ? void 0 : n[1]), W = T.get("expires") || T.get("expire"); + if (W) { + const x = new Date(+W * 1e3), E = isNaN(x.getTime()) ? 0 : x.getTime() - Date.now(); + E > 0 && ne(E); + } + if (N) try { - const p = JSON.parse(C); - p && typeof p == "object" && (p.verifyurl && (p.verifyurl = new URL(p.verifyurl, new URL(f)).toString()), xe(p)); - } catch (p) { - $("unable to configure from X-Altcha-Config", p); + const x = JSON.parse(N); + x && typeof x == "object" && (x.verifyurl && (x.verifyurl = new URL(x.verifyurl, new URL(a)).toString()), xe(x)); + } catch (x) { + L("unable to configure from X-Altcha-Config", x); } - if (!m && (h != null && h.length)) { - const p = Date.parse(h); - if (p) { - const S = p - Date.now(); - S > 0 && ce(S); + if (!C && (v != null && v.length)) { + const x = Date.parse(v); + if (x) { + const E = x - Date.now(); + E > 0 && ne(E); } } - return n.json(); + return j; } } function ke() { - f && V && O === v.VERIFIED ? B() : te(v.EXPIRED, o.expired); + a && X && D === p.VERIFIED ? P() : ie(p.EXPIRED, o.expired); } - async function Ye(n) { - let h = null; + async function We(n) { + let u = null; if ("Worker" in window) { try { - h = await Xe(n.challenge, n.salt, n.algorithm, n.maxnumber); - } catch (C) { - $(C); + u = await Be(n.challenge, n.salt, n.algorithm, n.maxnumber); + } catch (v) { + L(v); } - if ((h == null ? void 0 : h.number) !== void 0) - return { data: n, solution: h }; + if ((u == null ? void 0 : u.number) !== void 0) + return { data: n, solution: u }; } return { data: n, - solution: await jt(n.challenge, n.salt, n.algorithm, n.maxnumber || _).promise + solution: await At(n.challenge, n.salt, n.algorithm, n.maxnumber || w).promise }; } - async function Xe(n, h, C, p = _, S = Math.ceil(d)) { - const H = []; - if (S < 1) + async function Be(n, u, v, N = typeof g == "number" ? g : w, j = Math.ceil(d)) { + const T = []; + if (j < 1) throw new Error("Wrong number of workers configured."); - if (S > 16) + if (j > 16) throw new Error("Too many workers. Max. 16 allowed workers."); - for (let T = 0; T < S; T++) - H.push(new Nt()); - const re = Math.ceil(p / S), ne = await Promise.all(H.map((T, ie) => { - const Ce = ie * re; + for (let E = 0; E < j; E++) + T.push(new Nt()); + const W = Math.ceil(N / j), x = await Promise.all(T.map((E, le) => { + const Ce = le * W; return new Promise((rt) => { - T.addEventListener("message", (Le) => { + E.addEventListener("message", (Le) => { if (Le.data) - for (const Ie of H) - Ie !== T && Ie.postMessage({ type: "abort" }); + for (const Re of T) + Re !== E && Re.postMessage({ type: "abort" }); rt(Le.data); - }), T.postMessage({ + }), E.postMessage({ payload: { - alg: C, + alg: v, challenge: n, - max: Ce + re, - salt: h, + max: Ce + W, + salt: u, start: Ce }, type: "work" }); }); })); - for (const T of H) - T.terminate(); - return ne.find((T) => !!T) || null; + for (const E of T) + E.terminate(); + return x.find((E) => !!E) || null; } function Ke() { - [v.UNVERIFIED, v.ERROR, v.EXPIRED].includes(O) ? k && (b == null ? void 0 : b.reportValidity()) === !1 ? t(6, D = !1) : B() : t(6, D = !0); + [p.UNVERIFIED, p.ERROR, p.EXPIRED].includes(D) ? _ && (m == null ? void 0 : m.reportValidity()) === !1 ? t(6, F = !1) : P() : t(6, F = !0); } function Je() { - O === v.VERIFYING && alert(o.waitAlert); + D === p.VERIFYING && alert(o.waitAlert); } - function ce(n) { - $("expire", n), clearTimeout(se), n < 1 ? ke() : se = setTimeout(ke, n); + function ne(n) { + L("expire", n), clearTimeout(ce), n < 1 ? ke() : ce = setTimeout(ke, n); } function ze(n) { - var C; - const h = b == null ? void 0 : b.querySelector(typeof n == "string" ? `input[name="${n}"]` : 'input[type="email"]:not([data-no-spamfilter])'); - return ((C = h == null ? void 0 : h.value) == null ? void 0 : C.slice(h.value.indexOf("@"))) || void 0; + var v; + const u = m == null ? void 0 : m.querySelector(typeof n == "string" ? `input[name="${n}"]` : 'input[type="email"]:not([data-no-spamfilter])'); + return ((v = u == null ? void 0 : u.value) == null ? void 0 : v.slice(u.value.indexOf("@"))) || void 0; } function Qe(n) { return [ - ...(b == null ? void 0 : b.querySelectorAll(n != null && n.length ? n.map((C) => `input[name="${C}"]`).join(", ") : 'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])')) || [] + ...(m == null ? void 0 : m.querySelectorAll(n != null && n.length ? n.map((v) => `input[name="${v}"]`).join(", ") : 'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])')) || [] ].reduce( - (C, p) => { - const S = p.name, H = p.value.trim(); - return S && H && (C[S] = H), C; + (v, N) => { + const j = N.name, T = N.value.trim(); + return j && T && (v[j] = T), v; }, {} ); } async function qe(n) { - if (!y) + if (!b) throw new Error("Attribute verifyurl not set."); - $("requesting server verification from", y); - const h = { payload: n }; - if (k) { - const { email: S, expectedLanguages: H, expectedCountries: re, fields: ne, ipAddress: T, timeZone: ie } = typeof k == "object" ? k : { + L("requesting server verification from", b); + const u = { payload: n }; + if (_) { + const { email: j, expectedLanguages: T, expectedCountries: W, fields: x, ipAddress: E, timeZone: le } = typeof _ == "object" ? _ : { email: void 0, expectedCountries: void 0, expectedLanguages: void 0, @@ -1034,107 +1040,107 @@ function Ft(r, e, t) { ipAddress: void 0, timeZone: void 0 }; - h.ipAddress = T === !1 ? void 0 : T || "auto", h.email = S === !1 ? void 0 : ze(S), h.fields = ne === !1 ? void 0 : Qe(ne), h.timeZone = ie === !1 ? void 0 : ie || Dt(), h.expectedCountries = re, h.expectedLanguages = H || (be ? [be] : void 0); + u.ipAddress = E === !1 ? void 0 : E || "auto", u.email = j === !1 ? void 0 : ze(j), u.fields = x === !1 ? void 0 : Qe(x), u.timeZone = le === !1 ? void 0 : le || Ot(), u.expectedCountries = W, u.expectedLanguages = T || (be ? [be] : void 0); } - const C = await fetch(y, { - body: JSON.stringify(h), + const v = await fetch(b, { + body: JSON.stringify(u), headers: { "content-type": "application/json" }, method: "POST" }); - if (C.status !== 200) - throw new Error(`Server responded with ${C.status}.`); - const p = await C.json(); - if (p != null && p.payload && t(4, W = p.payload), I("serververification", p), a && p.classification === "BAD") + if (v.status !== 200) + throw new Error(`Server responded with ${v.status}.`); + const N = await v.json(); + if (N != null && N.payload && t(4, Y = N.payload), I("serververification", N), f && N.classification === "BAD") throw new Error("SpamFilter returned negative classification."); } function xe(n) { - n.auto !== void 0 && (t(0, s = n.auto), s === "onload" && B()), n.expire !== void 0 && (ce(n.expire), t(14, m = n.expire)), n.challenge && (_e(n.challenge), i = n.challenge), n.challengeurl !== void 0 && t(12, f = n.challengeurl), n.debug !== void 0 && t(13, R = !!n.debug), n.hidefooter !== void 0 && t(1, j = !!n.hidefooter), n.hidelogo !== void 0 && t(2, Z = !!n.hidelogo), n.maxnumber !== void 0 && t(15, _ = +n.maxnumber), n.mockerror !== void 0 && t(16, F = !!n.mockerror), n.name !== void 0 && t(3, G = n.name), n.refetchonexpire !== void 0 && t(17, V = !!n.refetchonexpire), n.spamfilter !== void 0 && t(18, k = typeof n.spamfilter == "object" ? n.spamfilter : !!n.spamfilter), n.strings && t(28, l = n.strings), n.test !== void 0 && t(19, g = typeof n.test == "number" ? n.test : !!n.test), n.verifyurl !== void 0 && t(20, y = n.verifyurl), n.workers !== void 0 && t(21, d = +n.workers); + n.auto !== void 0 && (t(0, s = n.auto), s === "onload" && P()), n.expire !== void 0 && (ne(n.expire), t(14, C = n.expire)), n.challenge && (_e(n.challenge), i = n.challenge), n.challengeurl !== void 0 && t(12, a = n.challengeurl), n.debug !== void 0 && t(13, A = !!n.debug), n.hidefooter !== void 0 && t(1, V = !!n.hidefooter), n.hidelogo !== void 0 && t(2, G = !!n.hidelogo), n.maxnumber !== void 0 && t(15, w = +n.maxnumber), n.mockerror !== void 0 && t(16, H = !!n.mockerror), n.name !== void 0 && t(3, U = n.name), n.refetchonexpire !== void 0 && t(17, X = !!n.refetchonexpire), n.spamfilter !== void 0 && t(18, _ = typeof n.spamfilter == "object" ? n.spamfilter : !!n.spamfilter), n.strings && t(28, l = n.strings), n.test !== void 0 && t(19, g = typeof n.test == "number" ? n.test : !!n.test), n.verifyurl !== void 0 && t(20, b = n.verifyurl), n.workers !== void 0 && t(21, d = +n.workers); } - function te(n = v.UNVERIFIED, h = null) { - clearTimeout(se), t(6, D = !1), t(8, oe = h), t(4, W = null), t(5, O = n); + function ie(n = p.UNVERIFIED, u = null) { + clearTimeout(ce), t(6, F = !1), t(8, se = u), t(4, Y = null), t(5, D = n); } - async function B() { - return te(v.VERIFYING), Ue().then((n) => (_e(n), $("challenge", n), Ye(n))).then(({ data: n, solution: h }) => { - if ($("solution", h), (h == null ? void 0 : h.number) !== void 0) { - if (y) - return qe(we(n, h)); - t(4, W = we(n, h)), $("payload", W); + async function P() { + return ie(p.VERIFYING), Pe().then((n) => (_e(n), L("challenge", n), We(n))).then(({ data: n, solution: u }) => { + if (L("solution", u), (u == null ? void 0 : u.number) !== void 0) { + if (b) + return qe(we(n, u)); + t(4, Y = we(n, u)), L("payload", Y); } else - throw $("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."), new Error("Unexpected result returned."); + throw L("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."), new Error("Unexpected result returned."); }).then(() => { pt().then(() => { - t(5, O = v.VERIFIED), t(6, D = !0), $("verified"), I("verified", { payload: W }); + t(5, D = p.VERIFIED), t(6, F = !0), L("verified"), I("verified", { payload: Y }); }); }).catch((n) => { - $(n), t(5, O = v.ERROR), t(6, D = !1), t(8, oe = n.message); + L(n), t(5, D = p.ERROR), t(6, F = !1), t(8, se = n.message); }); } function et() { - D = this.checked, t(6, D); + F = this.checked, t(6, F); } function tt(n) { ue[n ? "unshift" : "push"](() => { - ee = n, t(7, ee); + re = n, t(7, re); }); } return r.$$set = (n) => { - "auto" in n && t(0, s = n.auto), "blockspam" in n && t(22, a = n.blockspam), "challengeurl" in n && t(12, f = n.challengeurl), "challengejson" in n && t(23, u = n.challengejson), "debug" in n && t(13, R = n.debug), "expire" in n && t(14, m = n.expire), "hidefooter" in n && t(1, j = n.hidefooter), "hidelogo" in n && t(2, Z = n.hidelogo), "name" in n && t(3, G = n.name), "maxnumber" in n && t(15, _ = n.maxnumber), "mockerror" in n && t(16, F = n.mockerror), "refetchonexpire" in n && t(17, V = n.refetchonexpire), "spamfilter" in n && t(18, k = n.spamfilter), "strings" in n && t(24, x = n.strings), "test" in n && t(19, g = n.test), "verifyurl" in n && t(20, y = n.verifyurl), "workers" in n && t(21, d = n.workers); + "auto" in n && t(0, s = n.auto), "blockspam" in n && t(22, f = n.blockspam), "challengeurl" in n && t(12, a = n.challengeurl), "challengejson" in n && t(23, h = n.challengejson), "debug" in n && t(13, A = n.debug), "expire" in n && t(14, C = n.expire), "hidefooter" in n && t(1, V = n.hidefooter), "hidelogo" in n && t(2, G = n.hidelogo), "name" in n && t(3, U = n.name), "maxnumber" in n && t(15, w = n.maxnumber), "mockerror" in n && t(16, H = n.mockerror), "refetchonexpire" in n && t(17, X = n.refetchonexpire), "spamfilter" in n && t(18, _ = n.spamfilter), "strings" in n && t(24, k = n.strings), "test" in n && t(19, g = n.test), "verifyurl" in n && t(20, b = n.verifyurl), "workers" in n && t(21, d = n.workers); }, r.$$.update = () => { r.$$.dirty[0] & /*challengejson*/ - 8388608 && (i = u ? Ge(u) : void 0), r.$$.dirty[0] & /*strings*/ - 16777216 && t(28, l = x ? Ge(x) : {}), r.$$.dirty[0] & /*parsedStrings*/ + 8388608 && (i = h ? Ve(h) : void 0), r.$$.dirty[0] & /*strings*/ + 16777216 && t(28, l = k ? Ve(k) : {}), r.$$.dirty[0] & /*parsedStrings*/ 268435456 && t(9, o = { error: "Verification failed. Try again later.", expired: "Verification expired. Try again.", - footer: `Protected by ALTCHA`, + footer: `Protected by ALTCHA`, label: "I'm not a robot", verified: "Verified", verifying: "Verifying...", waitAlert: "Verifying... please wait.", ...l }), r.$$.dirty[0] & /*payload, state*/ - 48 && I("statechange", { payload: W, state: O }); + 48 && I("statechange", { payload: Y, state: D }); }, [ s, - j, - Z, + V, G, - W, - O, + U, + Y, D, - ee, - oe, + F, + re, + se, o, Ke, Je, - f, - R, - m, + a, + A, + C, + w, + H, + X, _, - F, - V, - k, g, - y, + b, d, - a, - u, - x, + f, + h, + k, xe, - te, - B, + ie, + P, l, et, tt ]; } -class Wt extends Lt { +class Ht extends Lt { constructor(e) { super(), $t( this, e, Ft, - Pt, + Dt, lt, { auto: 0, @@ -1158,7 +1164,7 @@ class Wt extends Lt { reset: 26, verify: 27 }, - Mt, + Tt, [-1, -1] ); } @@ -1166,103 +1172,103 @@ class Wt extends Lt { return this.$$.ctx[0]; } set auto(e) { - this.$$set({ auto: e }), E(); + this.$$set({ auto: e }), $(); } get blockspam() { return this.$$.ctx[22]; } set blockspam(e) { - this.$$set({ blockspam: e }), E(); + this.$$set({ blockspam: e }), $(); } get challengeurl() { return this.$$.ctx[12]; } set challengeurl(e) { - this.$$set({ challengeurl: e }), E(); + this.$$set({ challengeurl: e }), $(); } get challengejson() { return this.$$.ctx[23]; } set challengejson(e) { - this.$$set({ challengejson: e }), E(); + this.$$set({ challengejson: e }), $(); } get debug() { return this.$$.ctx[13]; } set debug(e) { - this.$$set({ debug: e }), E(); + this.$$set({ debug: e }), $(); } get expire() { return this.$$.ctx[14]; } set expire(e) { - this.$$set({ expire: e }), E(); + this.$$set({ expire: e }), $(); } get hidefooter() { return this.$$.ctx[1]; } set hidefooter(e) { - this.$$set({ hidefooter: e }), E(); + this.$$set({ hidefooter: e }), $(); } get hidelogo() { return this.$$.ctx[2]; } set hidelogo(e) { - this.$$set({ hidelogo: e }), E(); + this.$$set({ hidelogo: e }), $(); } get name() { return this.$$.ctx[3]; } set name(e) { - this.$$set({ name: e }), E(); + this.$$set({ name: e }), $(); } get maxnumber() { return this.$$.ctx[15]; } set maxnumber(e) { - this.$$set({ maxnumber: e }), E(); + this.$$set({ maxnumber: e }), $(); } get mockerror() { return this.$$.ctx[16]; } set mockerror(e) { - this.$$set({ mockerror: e }), E(); + this.$$set({ mockerror: e }), $(); } get refetchonexpire() { return this.$$.ctx[17]; } set refetchonexpire(e) { - this.$$set({ refetchonexpire: e }), E(); + this.$$set({ refetchonexpire: e }), $(); } get spamfilter() { return this.$$.ctx[18]; } set spamfilter(e) { - this.$$set({ spamfilter: e }), E(); + this.$$set({ spamfilter: e }), $(); } get strings() { return this.$$.ctx[24]; } set strings(e) { - this.$$set({ strings: e }), E(); + this.$$set({ strings: e }), $(); } get test() { return this.$$.ctx[19]; } set test(e) { - this.$$set({ test: e }), E(); + this.$$set({ test: e }), $(); } get verifyurl() { return this.$$.ctx[20]; } set verifyurl(e) { - this.$$set({ verifyurl: e }), E(); + this.$$set({ verifyurl: e }), $(); } get workers() { return this.$$.ctx[21]; } set workers(e) { - this.$$set({ workers: e }), E(); + this.$$set({ workers: e }), $(); } get configure() { return this.$$.ctx[25]; @@ -1274,7 +1280,7 @@ class Wt extends Lt { return this.$$.ctx[27]; } } -customElements.define("altcha-widget", Ct(Wt, { auto: {}, blockspam: {}, challengeurl: {}, challengejson: {}, debug: { type: "Boolean" }, expire: {}, hidefooter: { type: "Boolean" }, hidelogo: { type: "Boolean" }, name: {}, maxnumber: {}, mockerror: { type: "Boolean" }, refetchonexpire: { type: "Boolean" }, spamfilter: { type: "Boolean" }, strings: {}, test: { type: "Boolean" }, verifyurl: {}, workers: {} }, [], ["configure", "reset", "verify"], !1)); +customElements.define("altcha-widget", Ct(Ht, { auto: {}, blockspam: {}, challengeurl: {}, challengejson: {}, debug: { type: "Boolean" }, expire: {}, hidefooter: { type: "Boolean" }, hidelogo: { type: "Boolean" }, name: {}, maxnumber: {}, mockerror: { type: "Boolean" }, refetchonexpire: { type: "Boolean" }, spamfilter: { type: "Boolean" }, strings: {}, test: { type: "Boolean" }, verifyurl: {}, workers: {} }, [], ["configure", "reset", "verify"], !1)); export { - Wt as Altcha + Ht as Altcha }; diff --git a/dist/altcha.umd.cjs b/dist/altcha.umd.cjs index f1c1a40..e386f54 100644 --- a/dist/altcha.umd.cjs +++ b/dist/altcha.umd.cjs @@ -1,2 +1,2 @@ -(function(M,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(M=typeof globalThis<"u"?globalThis:M||self,$(M.altcha={}))})(this,function(M){"use strict";var Wt=Object.defineProperty;var Bt=(M,$,W)=>$ in M?Wt(M,$,{enumerable:!0,configurable:!0,writable:!0,value:W}):M[$]=W;var G=(M,$,W)=>(Bt(M,typeof $!="symbol"?$+"":$,W),W);function $(){}function W(n){return n()}function pe(){return Object.create(null)}function q(n){n.forEach(W)}function ye(n){return typeof n=="function"}function Xe(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function Ke(n){return Object.keys(n).length===0}function w(n,e){n.appendChild(e)}function Je(n,e,t){const i=ze(n);if(!i.getElementById(e)){const l=C("style");l.id=e,l.textContent=t,Qe(i,l)}}function ze(n){if(!n)return document;const e=n.getRootNode?n.getRootNode():n.ownerDocument;return e&&e.host?e:n.ownerDocument}function Qe(n,e){return w(n.head||n,e),e.sheet}function N(n,e,t){n.insertBefore(e,t||null)}function T(n){n.parentNode&&n.parentNode.removeChild(n)}function C(n){return document.createElement(n)}function O(n){return document.createElementNS("http://www.w3.org/2000/svg",n)}function qe(n){return document.createTextNode(n)}function U(){return qe(" ")}function ce(n,e,t,i){return n.addEventListener(e,t,i),()=>n.removeEventListener(e,t,i)}function c(n,e,t){t==null?n.removeAttribute(e):n.getAttribute(e)!==t&&n.setAttribute(e,t)}function et(n){return Array.from(n.childNodes)}function ve(n,e,t){n.classList.toggle(e,!!t)}function tt(n,e,{bubbles:t=!1,cancelable:i=!1}={}){return new CustomEvent(n,{detail:e,bubbles:t,cancelable:i})}function nt(n){const e={};return n.childNodes.forEach(t=>{e[t.slot||"default"]=!0}),e}let ee;function te(n){ee=n}function ae(){if(!ee)throw new Error("Function called outside component initialization");return ee}function rt(n){ae().$$.on_mount.push(n)}function it(n){ae().$$.on_destroy.push(n)}function lt(){const n=ae();return(e,t,{cancelable:i=!1}={})=>{const l=n.$$.callbacks[e];if(l){const o=tt(e,t,{cancelable:i});return l.slice().forEach(s=>{s.call(n,o)}),!o.defaultPrevented}return!0}}const J=[],fe=[];let z=[];const we=[],_e=Promise.resolve();let ue=!1;function ke(){ue||(ue=!0,_e.then(_))}function ot(){return ke(),_e}function he(n){z.push(n)}const de=new Set;let Q=0;function _(){if(Q!==0)return;const n=ee;do{try{for(;Qn.indexOf(i)===-1?e.push(i):t.push(i)),t.forEach(i=>i()),z=e}const at=new Set;function ft(n,e){n&&n.i&&(at.delete(n),n.i(e))}function ut(n,e,t){const{fragment:i,after_update:l}=n.$$;i&&i.m(e,t),he(()=>{const o=n.$$.on_mount.map(W).filter(ye);n.$$.on_destroy?n.$$.on_destroy.push(...o):q(o),n.$$.on_mount=[]}),l.forEach(he)}function ht(n,e){const t=n.$$;t.fragment!==null&&(ct(t.after_update),q(t.on_destroy),t.fragment&&t.fragment.d(e),t.on_destroy=t.fragment=null,t.ctx=[])}function dt(n,e){n.$$.dirty[0]===-1&&(J.push(n),ke(),n.$$.dirty.fill(0)),n.$$.dirty[e/31|0]|=1<{const H=V.length?V[0]:Z;return u.ctx&&l(u.ctx[m],u.ctx[m]=H)&&(!u.skip_bound&&u.bound[m]&&u.bound[m](H),S&&dt(n,m)),Z}):[],u.update(),S=!0,q(u.before_update),u.fragment=i?i(u.ctx):!1,e.target){if(e.hydrate){const m=et(e.target);u.fragment&&u.fragment.l(m),m.forEach(T)}else u.fragment&&u.fragment.c();e.intro&&ft(n.$$.fragment),ut(n,e.target,e.anchor),_()}te(f)}let xe;typeof HTMLElement=="function"&&(xe=class extends HTMLElement{constructor(e,t,i){super();G(this,"$$ctor");G(this,"$$s");G(this,"$$c");G(this,"$$cn",!1);G(this,"$$d",{});G(this,"$$r",!1);G(this,"$$p_d",{});G(this,"$$l",{});G(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=t,i&&this.attachShadow({mode:"open"})}addEventListener(e,t,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(t),this.$$c){const l=this.$$c.$on(e,t);this.$$l_u.set(t,l)}super.addEventListener(e,t,i)}removeEventListener(e,t,i){if(super.removeEventListener(e,t,i),this.$$c){const l=this.$$l_u.get(t);l&&(l(),this.$$l_u.delete(t))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(o){return()=>{let s;return{c:function(){s=C("slot"),o!=="default"&&c(s,"name",o)},m:function(u,S){N(u,s,S)},d:function(u){u&&T(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const t={},i=nt(this);for(const o of this.$$s)o in i&&(t[o]=[e(o)]);for(const o of this.attributes){const s=this.$$g_p(o.name);s in this.$$d||(this.$$d[s]=ne(s,o.value,this.$$p_d,"toProp"))}for(const o in this.$$p_d)!(o in this.$$d)&&this[o]!==void 0&&(this.$$d[o]=this[o],delete this[o]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:t,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const o in this.$$p_d)if(this.$$d[o]=this.$$c.$$.ctx[this.$$c.$$.props[o]],this.$$p_d[o].reflect){const s=ne(o,this.$$d[o],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[o].attribute||o):this.setAttribute(this.$$p_d[o].attribute||o,s)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const o in this.$$l)for(const s of this.$$l[o]){const a=this.$$c.$on(o,s);this.$$l_u.set(s,a)}this.$$l={}}}attributeChangedCallback(e,t,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=ne(e,i,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(t=>this.$$p_d[t].attribute===e||!this.$$p_d[t].attribute&&t.toLowerCase()===e)||e}});function ne(n,e,t,i){var o;const l=(o=t[n])==null?void 0:o.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!t[n])return e;if(i==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function mt(n,e,t,i,l,o){let s=class extends xe{constructor(){super(n,t,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(s.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(f){var u;f=ne(a,f,e),this.$$d[a]=f,(u=this.$$c)==null||u.$set({[a]:f})}})}),i.forEach(a=>{Object.defineProperty(s.prototype,a,{get(){var f;return(f=this.$$c)==null?void 0:f[a]}})}),o&&(s=o(s)),n.element=s,s}class bt{constructor(){G(this,"$$");G(this,"$$set")}$destroy(){ht(this,1),this.$destroy=$}$on(e,t){if(!ye(t))return $;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(t),()=>{const l=i.indexOf(t);l!==-1&&i.splice(l,1)}}$set(e){this.$$set&&!Ke(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const pt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(pt);const Ee="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+aT9zKG51bGwpOmgoZSxsLG8pLnRoZW4odz0+e3c9PT10P3Moe251bWJlcjpsLHRvb2s6RGF0ZS5ub3coKS1yfSk6ZChsKzEpfSkuY2F0Y2goYyl9O2QocCl9KSxjb250cm9sbGVyOmF9fWxldCBuO29ubWVzc2FnZT1hc3luYyB0PT57Y29uc3R7dHlwZTplLHBheWxvYWQ6b309dC5kYXRhO2lmKGU9PT0iYWJvcnQiKW49PW51bGx8fG4uYWJvcnQoKSxuPXZvaWQgMDtlbHNlIGlmKGU9PT0id29yayIpe2NvbnN0e2FsZzppLGNoYWxsZW5nZTpwLG1heDphLHNhbHQ6dSxzdGFydDpzfT1vfHx7fSxjPW0ocCx1LGksYSxzKTtuPWMuY29udHJvbGxlcixjLnByb21pc2UudGhlbihyPT57c2VsZi5wb3N0TWVzc2FnZShyJiZ7Li4ucix3b3JrZXI6ITB9KX0pfX19KSgpOwo=",yt=n=>Uint8Array.from(atob(n),e=>e.charCodeAt(0)),$e=typeof window<"u"&&window.Blob&&new Blob([yt(Ee)],{type:"text/javascript;charset=utf-8"});function vt(n){let e;try{if(e=$e&&(window.URL||window.webkitURL).createObjectURL($e),!e)throw"";const t=new Worker(e,{name:n==null?void 0:n.name});return t.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;base64,"+Ee,{name:n==null?void 0:n.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const wt=new TextEncoder;function _t(n){return[...new Uint8Array(n)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function kt(n,e="SHA-256",t=1e5){const i=Date.now().toString(16);n||(n=Math.round(Math.random()*t));const l=await Ce(i,n,e);return{algorithm:e,challenge:l,salt:i,signature:""}}async function Ce(n,e,t){return _t(await crypto.subtle.digest(t.toUpperCase(),wt.encode(n+e)))}function xt(n,e,t="SHA-256",i=1e6,l=0){const o=new AbortController;return{promise:new Promise((a,f)=>{const u=Date.now(),S=m=>{o.signal.aborted||m>i?a(null):Ce(e,m,t).then(Z=>{Z===n?a({number:m,took:Date.now()-u}):S(m+1)}).catch(f)};S(l)}),controller:o}}var y=(n=>(n.ERROR="error",n.VERIFIED="verified",n.VERIFYING="verifying",n.UNVERIFIED="unverified",n.EXPIRED="expired",n))(y||{});function Et(n){Je(n,"svelte-14ngypa",`.altcha.svelte-14ngypa.svelte-14ngypa{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid - var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-14ngypa.svelte-14ngypa:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-14ngypa.svelte-14ngypa{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-14ngypa.svelte-14ngypa{flex-grow:1}.altcha-label.svelte-14ngypa label.svelte-14ngypa{cursor:pointer}.altcha-logo.svelte-14ngypa.svelte-14ngypa{color:currentColor;opacity:0.3}.altcha-logo.svelte-14ngypa.svelte-14ngypa:hover{opacity:1}.altcha-error.svelte-14ngypa.svelte-14ngypa{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-14ngypa.svelte-14ngypa{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-14ngypa.svelte-14ngypa:hover{opacity:1}.altcha-footer.svelte-14ngypa>.svelte-14ngypa:first-child{flex-grow:1}.altcha-footer.svelte-14ngypa a{color:currentColor}.altcha-checkbox.svelte-14ngypa.svelte-14ngypa{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-14ngypa input.svelte-14ngypa{width:18px;height:18px;margin:0}.altcha-hidden.svelte-14ngypa.svelte-14ngypa{display:none}.altcha-spinner.svelte-14ngypa.svelte-14ngypa{animation:svelte-14ngypa-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-14ngypa-altcha-spinner{100%{transform:rotate(360deg)}}`)}function Le(n){let e,t,i;return{c(){e=O("svg"),t=O("path"),i=O("path"),c(t,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(t,"fill","currentColor"),c(t,"opacity",".25"),c(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(i,"fill","currentColor"),c(i,"class","altcha-spinner svelte-14ngypa"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(l,o){N(l,e,o),w(e,t),w(e,i)},d(l){l&&T(e)}}}function $t(n){let e,t=n[9].label+"",i;return{c(){e=C("label"),c(e,"for",i=n[3]+"_checkbox"),c(e,"class","svelte-14ngypa")},m(l,o){N(l,e,o),e.innerHTML=t},p(l,o){o[0]&512&&t!==(t=l[9].label+"")&&(e.innerHTML=t),o[0]&8&&i!==(i=l[3]+"_checkbox")&&c(e,"for",i)},d(l){l&&T(e)}}}function Ct(n){let e,t=n[9].verifying+"";return{c(){e=C("span")},m(i,l){N(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].verifying+"")&&(e.innerHTML=t)},d(i){i&&T(e)}}}function Lt(n){let e,t=n[9].verified+"",i,l;return{c(){e=C("span"),i=U(),l=C("input"),c(l,"type","hidden"),c(l,"name",n[3]),l.value=n[4]},m(o,s){N(o,e,s),e.innerHTML=t,N(o,i,s),N(o,l,s)},p(o,s){s[0]&512&&t!==(t=o[9].verified+"")&&(e.innerHTML=t),s[0]&8&&c(l,"name",o[3]),s[0]&16&&(l.value=o[4])},d(o){o&&(T(e),T(i),T(l))}}}function Ie(n){let e,t,i,l,o,s;return{c(){e=C("div"),t=C("a"),i=O("svg"),l=O("path"),o=O("path"),s=O("path"),c(l,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(l,"fill","currentColor"),c(o,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(o,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(i,"width","22"),c(i,"height","22"),c(i,"viewBox","0 0 20 20"),c(i,"fill","none"),c(i,"xmlns","http://www.w3.org/2000/svg"),c(t,"href",Te),c(t,"target","_blank"),c(t,"class","altcha-logo svelte-14ngypa")},m(a,f){N(a,e,f),w(e,t),w(t,i),w(i,l),w(i,o),w(i,s)},p:$,d(a){a&&T(e)}}}function Re(n){let e,t,i,l;function o(f,u){return f[5]===y.EXPIRED?Rt:It}let s=o(n),a=s(n);return{c(){e=C("div"),t=O("svg"),i=O("path"),l=U(),a.c(),c(i,"stroke-linecap","round"),c(i,"stroke-linejoin","round"),c(i,"d","M6 18L18 6M6 6l12 12"),c(t,"width","14"),c(t,"height","14"),c(t,"xmlns","http://www.w3.org/2000/svg"),c(t,"fill","none"),c(t,"viewBox","0 0 24 24"),c(t,"stroke-width","1.5"),c(t,"stroke","currentColor"),c(e,"class","altcha-error svelte-14ngypa")},m(f,u){N(f,e,u),w(e,t),w(t,i),w(e,l),a.m(e,null)},p(f,u){s===(s=o(f))&&a?a.p(f,u):(a.d(1),a=s(f),a&&(a.c(),a.m(e,null)))},d(f){f&&T(e),a.d()}}}function It(n){let e,t=n[9].error+"";return{c(){e=C("div"),c(e,"title",n[8])},m(i,l){N(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].error+"")&&(e.innerHTML=t),l[0]&256&&c(e,"title",i[8])},d(i){i&&T(e)}}}function Rt(n){let e,t=n[9].expired+"";return{c(){e=C("div"),c(e,"title",n[8])},m(i,l){N(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].expired+"")&&(e.innerHTML=t),l[0]&256&&c(e,"title",i[8])},d(i){i&&T(e)}}}function Se(n){let e,t,i=n[9].footer+"";return{c(){e=C("div"),t=C("div"),c(t,"class","svelte-14ngypa"),c(e,"class","altcha-footer svelte-14ngypa")},m(l,o){N(l,e,o),w(e,t),t.innerHTML=i},p(l,o){o[0]&512&&i!==(i=l[9].footer+"")&&(t.innerHTML=i)},d(l){l&&T(e)}}}function St(n){let e,t,i,l,o,s,a,f,u,S,m,Z,V,H,k=n[5]===y.VERIFYING&&Le();function Y(d,R){return d[5]===y.VERIFIED?Lt:d[5]===y.VERIFYING?Ct:$t}let P=Y(n),x=P(n),E=n[2]!==!0&&Ie(),g=(n[8]||n[5]===y.EXPIRED)&&Re(n),v=n[9].footer&&n[1]!==!0&&Se(n);return{c(){e=C("div"),t=C("div"),k&&k.c(),i=U(),l=C("div"),o=C("input"),f=U(),u=C("div"),x.c(),S=U(),E&&E.c(),m=U(),g&&g.c(),Z=U(),v&&v.c(),c(o,"type","checkbox"),c(o,"id",s=n[3]+"_checkbox"),o.required=a=n[0]!=="onsubmit",c(o,"class","svelte-14ngypa"),c(l,"class","altcha-checkbox svelte-14ngypa"),ve(l,"altcha-hidden",n[5]===y.VERIFYING),c(u,"class","altcha-label svelte-14ngypa"),c(t,"class","altcha-main svelte-14ngypa"),c(e,"class","altcha svelte-14ngypa"),c(e,"data-state",n[5])},m(d,R){N(d,e,R),w(e,t),k&&k.m(t,null),w(t,i),w(t,l),w(l,o),o.checked=n[6],w(t,f),w(t,u),x.m(u,null),w(t,S),E&&E.m(t,null),w(e,m),g&&g.m(e,null),w(e,Z),v&&v.m(e,null),n[30](e),V||(H=[ce(o,"change",n[29]),ce(o,"change",n[10]),ce(o,"invalid",n[11])],V=!0)},p(d,R){d[5]===y.VERIFYING?k||(k=Le(),k.c(),k.m(t,i)):k&&(k.d(1),k=null),R[0]&8&&s!==(s=d[3]+"_checkbox")&&c(o,"id",s),R[0]&1&&a!==(a=d[0]!=="onsubmit")&&(o.required=a),R[0]&64&&(o.checked=d[6]),R[0]&32&&ve(l,"altcha-hidden",d[5]===y.VERIFYING),P===(P=Y(d))&&x?x.p(d,R):(x.d(1),x=P(d),x&&(x.c(),x.m(u,null))),d[2]!==!0?E?E.p(d,R):(E=Ie(),E.c(),E.m(t,null)):E&&(E.d(1),E=null),d[8]||d[5]===y.EXPIRED?g?g.p(d,R):(g=Re(d),g.c(),g.m(e,Z)):g&&(g.d(1),g=null),d[9].footer&&d[1]!==!0?v?v.p(d,R):(v=Se(d),v.c(),v.m(e,null)):v&&(v.d(1),v=null),R[0]&32&&c(e,"data-state",d[5])},i:$,o:$,d(d){d&&T(e),k&&k.d(),x.d(),E&&E.d(),g&&g.d(),v&&v.d(),n[30](null),V=!1,q(H)}}}const Te="https://altcha.org/";function Ne(n){return JSON.parse(n)}function Tt(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}function Nt(n,e,t){var Fe,We;let i,l,o,{auto:s=void 0}=e,{blockspam:a=void 0}=e,{challengeurl:f=void 0}=e,{challengejson:u=void 0}=e,{debug:S=!1}=e,{expire:m=void 0}=e,{hidefooter:Z=!1}=e,{hidelogo:V=!1}=e,{name:H="altcha"}=e,{maxnumber:k=1e6}=e,{mockerror:Y=!1}=e,{refetchonexpire:P=!0}=e,{spamfilter:x=!1}=e,{strings:E=void 0}=e,{test:g=!1}=e,{verifyurl:v=void 0}=e,{workers:d=navigator.hardwareConcurrency||8}=e;const R=lt(),je=["SHA-256","SHA-384","SHA-512"],Me=(We=(Fe=document.documentElement.lang)==null?void 0:Fe.split("-"))==null?void 0:We[0];let B=!1,re,b=null,ge=null,X=null,D=y.UNVERIFIED,me;it(()=>{b&&(b.removeEventListener("submit",Ge),b.removeEventListener("reset",Ve),b.removeEventListener("focusin",Ze),b=null)}),rt(()=>{L("mounted","0.3.2"),L("workers",d),g&&L("using test mode"),m&&be(m),s!==void 0&&L("auto",s),b=re.closest("form"),b&&(b.addEventListener("submit",Ge),b.addEventListener("reset",Ve),s==="onfocus"&&b.addEventListener("focusin",Ze)),s==="onload"&&K()});function L(...r){(S||r.some(h=>h instanceof Error))&&console[r[0]instanceof Error?"error":"log"]("ALTCHA",...r)}function Ze(r){K()}function Ge(r){b&&s==="onsubmit"&&D===y.UNVERIFIED&&(r.preventDefault(),r.stopPropagation(),K().then(()=>{b==null||b.requestSubmit()}))}function Ve(){ie()}function Oe(r,h){return btoa(JSON.stringify({algorithm:r.algorithm,challenge:r.challenge,number:h.number,salt:r.salt,signature:r.signature,test:g?!0:void 0,took:h.took}))}function He(r){if(!r.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(r.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!je.includes(r.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${je.join(", ")}`);if(!r.challenge||r.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!r.salt||r.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function At(){if(Y)throw L("mocking error"),new Error("Mocked error.");if(i)return L("using provided json data"),i;if(g)return L("generating test challenge",{test:g}),kt(typeof g!="boolean"?+g:void 0);{if(!f)throw new Error("Attribute challengeurl not set.");L("fetching challenge from",f);const r=await fetch(f,{headers:{"x-altcha-spam-filter":x?"1":"0"}});if(r.status!==200)throw new Error(`Server responded with ${r.status}.`);const h=r.headers.get("Expires"),I=r.headers.get("X-Altcha-Config");if(I)try{const p=JSON.parse(I);p&&typeof p=="object"&&(p.verifyurl&&(p.verifyurl=new URL(p.verifyurl,new URL(f)).toString()),De(p))}catch(p){L("unable to configure from X-Altcha-Config",p)}if(!m&&(h!=null&&h.length)){const p=Date.parse(h);if(p){const A=p-Date.now();A>0&&be(A)}}return r.json()}}function Pe(){f&&P&&D===y.VERIFIED?K():ie(y.EXPIRED,o.expired)}async function jt(r){let h=null;if("Worker"in window){try{h=await Mt(r.challenge,r.salt,r.algorithm,r.maxnumber)}catch(I){L(I)}if((h==null?void 0:h.number)!==void 0)return{data:r,solution:h}}return{data:r,solution:await xt(r.challenge,r.salt,r.algorithm,r.maxnumber||k).promise}}async function Mt(r,h,I,p=k,A=Math.ceil(d)){const F=[];if(A<1)throw new Error("Wrong number of workers configured.");if(A>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let j=0;j{const Be=se*le;return new Promise(Ft=>{j.addEventListener("message",Ue=>{if(Ue.data)for(const Ye of F)Ye!==j&&Ye.postMessage({type:"abort"});Ft(Ue.data)}),j.postMessage({payload:{alg:I,challenge:r,max:Be+le,salt:h,start:Be},type:"work"})})}));for(const j of F)j.terminate();return oe.find(j=>!!j)||null}function Zt(){[y.UNVERIFIED,y.ERROR,y.EXPIRED].includes(D)?x&&(b==null?void 0:b.reportValidity())===!1?t(6,B=!1):K():t(6,B=!0)}function Gt(){D===y.VERIFYING&&alert(o.waitAlert)}function be(r){L("expire",r),clearTimeout(me),r<1?Pe():me=setTimeout(Pe,r)}function Vt(r){var I;const h=b==null?void 0:b.querySelector(typeof r=="string"?`input[name="${r}"]`:'input[type="email"]:not([data-no-spamfilter])');return((I=h==null?void 0:h.value)==null?void 0:I.slice(h.value.indexOf("@")))||void 0}function Ot(r){return[...(b==null?void 0:b.querySelectorAll(r!=null&&r.length?r.map(I=>`input[name="${I}"]`).join(", "):'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])'))||[]].reduce((I,p)=>{const A=p.name,F=p.value.trim();return A&&F&&(I[A]=F),I},{})}async function Ht(r){if(!v)throw new Error("Attribute verifyurl not set.");L("requesting server verification from",v);const h={payload:r};if(x){const{email:A,expectedLanguages:F,expectedCountries:le,fields:oe,ipAddress:j,timeZone:se}=typeof x=="object"?x:{email:void 0,expectedCountries:void 0,expectedLanguages:void 0,fields:void 0,ipAddress:void 0,timeZone:void 0};h.ipAddress=j===!1?void 0:j||"auto",h.email=A===!1?void 0:Vt(A),h.fields=oe===!1?void 0:Ot(oe),h.timeZone=se===!1?void 0:se||Tt(),h.expectedCountries=le,h.expectedLanguages=F||(Me?[Me]:void 0)}const I=await fetch(v,{body:JSON.stringify(h),headers:{"content-type":"application/json"},method:"POST"});if(I.status!==200)throw new Error(`Server responded with ${I.status}.`);const p=await I.json();if(p!=null&&p.payload&&t(4,X=p.payload),R("serververification",p),a&&p.classification==="BAD")throw new Error("SpamFilter returned negative classification.")}function De(r){r.auto!==void 0&&(t(0,s=r.auto),s==="onload"&&K()),r.expire!==void 0&&(be(r.expire),t(14,m=r.expire)),r.challenge&&(He(r.challenge),i=r.challenge),r.challengeurl!==void 0&&t(12,f=r.challengeurl),r.debug!==void 0&&t(13,S=!!r.debug),r.hidefooter!==void 0&&t(1,Z=!!r.hidefooter),r.hidelogo!==void 0&&t(2,V=!!r.hidelogo),r.maxnumber!==void 0&&t(15,k=+r.maxnumber),r.mockerror!==void 0&&t(16,Y=!!r.mockerror),r.name!==void 0&&t(3,H=r.name),r.refetchonexpire!==void 0&&t(17,P=!!r.refetchonexpire),r.spamfilter!==void 0&&t(18,x=typeof r.spamfilter=="object"?r.spamfilter:!!r.spamfilter),r.strings&&t(28,l=r.strings),r.test!==void 0&&t(19,g=typeof r.test=="number"?r.test:!!r.test),r.verifyurl!==void 0&&t(20,v=r.verifyurl),r.workers!==void 0&&t(21,d=+r.workers)}function ie(r=y.UNVERIFIED,h=null){clearTimeout(me),t(6,B=!1),t(8,ge=h),t(4,X=null),t(5,D=r)}async function K(){return ie(y.VERIFYING),At().then(r=>(He(r),L("challenge",r),jt(r))).then(({data:r,solution:h})=>{if(L("solution",h),(h==null?void 0:h.number)!==void 0){if(v)return Ht(Oe(r,h));t(4,X=Oe(r,h)),L("payload",X)}else throw L("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."),new Error("Unexpected result returned.")}).then(()=>{ot().then(()=>{t(5,D=y.VERIFIED),t(6,B=!0),L("verified"),R("verified",{payload:X})})}).catch(r=>{L(r),t(5,D=y.ERROR),t(6,B=!1),t(8,ge=r.message)})}function Pt(){B=this.checked,t(6,B)}function Dt(r){fe[r?"unshift":"push"](()=>{re=r,t(7,re)})}return n.$$set=r=>{"auto"in r&&t(0,s=r.auto),"blockspam"in r&&t(22,a=r.blockspam),"challengeurl"in r&&t(12,f=r.challengeurl),"challengejson"in r&&t(23,u=r.challengejson),"debug"in r&&t(13,S=r.debug),"expire"in r&&t(14,m=r.expire),"hidefooter"in r&&t(1,Z=r.hidefooter),"hidelogo"in r&&t(2,V=r.hidelogo),"name"in r&&t(3,H=r.name),"maxnumber"in r&&t(15,k=r.maxnumber),"mockerror"in r&&t(16,Y=r.mockerror),"refetchonexpire"in r&&t(17,P=r.refetchonexpire),"spamfilter"in r&&t(18,x=r.spamfilter),"strings"in r&&t(24,E=r.strings),"test"in r&&t(19,g=r.test),"verifyurl"in r&&t(20,v=r.verifyurl),"workers"in r&&t(21,d=r.workers)},n.$$.update=()=>{n.$$.dirty[0]&8388608&&(i=u?Ne(u):void 0),n.$$.dirty[0]&16777216&&t(28,l=E?Ne(E):{}),n.$$.dirty[0]&268435456&&t(9,o={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),n.$$.dirty[0]&48&&R("statechange",{payload:X,state:D})},[s,Z,V,H,X,D,B,re,ge,o,Zt,Gt,f,S,m,k,Y,P,x,g,v,d,a,u,E,De,ie,K,l,Pt,Dt]}class Ae extends bt{constructor(e){super(),gt(this,e,Nt,St,Xe,{auto:0,blockspam:22,challengeurl:12,challengejson:23,debug:13,expire:14,hidefooter:1,hidelogo:2,name:3,maxnumber:15,mockerror:16,refetchonexpire:17,spamfilter:18,strings:24,test:19,verifyurl:20,workers:21,configure:25,reset:26,verify:27},Et,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),_()}get blockspam(){return this.$$.ctx[22]}set blockspam(e){this.$$set({blockspam:e}),_()}get challengeurl(){return this.$$.ctx[12]}set challengeurl(e){this.$$set({challengeurl:e}),_()}get challengejson(){return this.$$.ctx[23]}set challengejson(e){this.$$set({challengejson:e}),_()}get debug(){return this.$$.ctx[13]}set debug(e){this.$$set({debug:e}),_()}get expire(){return this.$$.ctx[14]}set expire(e){this.$$set({expire:e}),_()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),_()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),_()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),_()}get maxnumber(){return this.$$.ctx[15]}set maxnumber(e){this.$$set({maxnumber:e}),_()}get mockerror(){return this.$$.ctx[16]}set mockerror(e){this.$$set({mockerror:e}),_()}get refetchonexpire(){return this.$$.ctx[17]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),_()}get spamfilter(){return this.$$.ctx[18]}set spamfilter(e){this.$$set({spamfilter:e}),_()}get strings(){return this.$$.ctx[24]}set strings(e){this.$$set({strings:e}),_()}get test(){return this.$$.ctx[19]}set test(e){this.$$set({test:e}),_()}get verifyurl(){return this.$$.ctx[20]}set verifyurl(e){this.$$set({verifyurl:e}),_()}get workers(){return this.$$.ctx[21]}set workers(e){this.$$set({workers:e}),_()}get configure(){return this.$$.ctx[25]}get reset(){return this.$$.ctx[26]}get verify(){return this.$$.ctx[27]}}customElements.define("altcha-widget",mt(Ae,{auto:{},blockspam:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},spamfilter:{type:"Boolean"},strings:{},test:{type:"Boolean"},verifyurl:{},workers:{}},[],["configure","reset","verify"],!1)),M.Altcha=Ae,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})}); +(function(T,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(T=typeof globalThis<"u"?globalThis:T||self,C(T.altcha={}))})(this,function(T){"use strict";var Ht=Object.defineProperty;var Pt=(T,C,P)=>C in T?Ht(T,C,{enumerable:!0,configurable:!0,writable:!0,value:P}):T[C]=P;var G=(T,C,P)=>(Pt(T,typeof C!="symbol"?C+"":C,P),P);function C(){}function P(n){return n()}function pe(){return Object.create(null)}function te(n){n.forEach(P)}function ye(n){return typeof n=="function"}function Be(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function Ke(n){return Object.keys(n).length===0}function y(n,e){n.appendChild(e)}function Je(n,e,t){const i=ze(n);if(!i.getElementById(e)){const l=L("style");l.id=e,l.textContent=t,Qe(i,l)}}function ze(n){if(!n)return document;const e=n.getRootNode?n.getRootNode():n.ownerDocument;return e&&e.host?e:n.ownerDocument}function Qe(n,e){return y(n.head||n,e),e.sheet}function Z(n,e,t){n.insertBefore(e,t||null)}function S(n){n.parentNode&&n.parentNode.removeChild(n)}function L(n){return document.createElement(n)}function X(n){return document.createElementNS("http://www.w3.org/2000/svg",n)}function qe(n){return document.createTextNode(n)}function W(){return qe(" ")}function ae(n,e,t,i){return n.addEventListener(e,t,i),()=>n.removeEventListener(e,t,i)}function c(n,e,t){t==null?n.removeAttribute(e):n.getAttribute(e)!==t&&n.setAttribute(e,t)}function et(n){return Array.from(n.childNodes)}function ve(n,e,t){n.classList.toggle(e,!!t)}function tt(n,e,{bubbles:t=!1,cancelable:i=!1}={}){return new CustomEvent(n,{detail:e,bubbles:t,cancelable:i})}function nt(n){const e={};return n.childNodes.forEach(t=>{e[t.slot||"default"]=!0}),e}let ne;function re(n){ne=n}function fe(){if(!ne)throw new Error("Function called outside component initialization");return ne}function rt(n){fe().$$.on_mount.push(n)}function it(n){fe().$$.on_destroy.push(n)}function lt(){const n=fe();return(e,t,{cancelable:i=!1}={})=>{const l=n.$$.callbacks[e];if(l){const o=tt(e,t,{cancelable:i});return l.slice().forEach(s=>{s.call(n,o)}),!o.defaultPrevented}return!0}}const Q=[],ue=[];let q=[];const we=[],_e=Promise.resolve();let he=!1;function ke(){he||(he=!0,_e.then(w))}function ot(){return ke(),_e}function de(n){q.push(n)}const ge=new Set;let ee=0;function w(){if(ee!==0)return;const n=ne;do{try{for(;een.indexOf(i)===-1?e.push(i):t.push(i)),t.forEach(i=>i()),q=e}const at=new Set;function ft(n,e){n&&n.i&&(at.delete(n),n.i(e))}function ut(n,e,t){const{fragment:i,after_update:l}=n.$$;i&&i.m(e,t),de(()=>{const o=n.$$.on_mount.map(P).filter(ye);n.$$.on_destroy?n.$$.on_destroy.push(...o):te(o),n.$$.on_mount=[]}),l.forEach(de)}function ht(n,e){const t=n.$$;t.fragment!==null&&(ct(t.after_update),te(t.on_destroy),t.fragment&&t.fragment.d(e),t.on_destroy=t.fragment=null,t.ctx=[])}function dt(n,e){n.$$.dirty[0]===-1&&(Q.push(n),ke(),n.$$.dirty.fill(0)),n.$$.dirty[e/31|0]|=1<{const D=O.length?O[0]:U;return h.ctx&&l(h.ctx[R],h.ctx[R]=D)&&(!h.skip_bound&&h.bound[R]&&h.bound[R](D),M&&dt(n,R)),U}):[],h.update(),M=!0,te(h.before_update),h.fragment=i?i(h.ctx):!1,e.target){if(e.hydrate){const R=et(e.target);h.fragment&&h.fragment.l(R),R.forEach(S)}else h.fragment&&h.fragment.c();e.intro&&ft(n.$$.fragment),ut(n,e.target,e.anchor),w()}re(a)}let xe;typeof HTMLElement=="function"&&(xe=class extends HTMLElement{constructor(e,t,i){super();G(this,"$$ctor");G(this,"$$s");G(this,"$$c");G(this,"$$cn",!1);G(this,"$$d",{});G(this,"$$r",!1);G(this,"$$p_d",{});G(this,"$$l",{});G(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=t,i&&this.attachShadow({mode:"open"})}addEventListener(e,t,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(t),this.$$c){const l=this.$$c.$on(e,t);this.$$l_u.set(t,l)}super.addEventListener(e,t,i)}removeEventListener(e,t,i){if(super.removeEventListener(e,t,i),this.$$c){const l=this.$$l_u.get(t);l&&(l(),this.$$l_u.delete(t))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(o){return()=>{let s;return{c:function(){s=L("slot"),o!=="default"&&c(s,"name",o)},m:function(h,M){Z(h,s,M)},d:function(h){h&&S(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const t={},i=nt(this);for(const o of this.$$s)o in i&&(t[o]=[e(o)]);for(const o of this.attributes){const s=this.$$g_p(o.name);s in this.$$d||(this.$$d[s]=ie(s,o.value,this.$$p_d,"toProp"))}for(const o in this.$$p_d)!(o in this.$$d)&&this[o]!==void 0&&(this.$$d[o]=this[o],delete this[o]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:t,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const o in this.$$p_d)if(this.$$d[o]=this.$$c.$$.ctx[this.$$c.$$.props[o]],this.$$p_d[o].reflect){const s=ie(o,this.$$d[o],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[o].attribute||o):this.setAttribute(this.$$p_d[o].attribute||o,s)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const o in this.$$l)for(const s of this.$$l[o]){const f=this.$$c.$on(o,s);this.$$l_u.set(s,f)}this.$$l={}}}attributeChangedCallback(e,t,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=ie(e,i,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(t=>this.$$p_d[t].attribute===e||!this.$$p_d[t].attribute&&t.toLowerCase()===e)||e}});function ie(n,e,t,i){var o;const l=(o=t[n])==null?void 0:o.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!t[n])return e;if(i==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function mt(n,e,t,i,l,o){let s=class extends xe{constructor(){super(n,t,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(f=>(e[f].attribute||f).toLowerCase())}};return Object.keys(e).forEach(f=>{Object.defineProperty(s.prototype,f,{get(){return this.$$c&&f in this.$$c?this.$$c[f]:this.$$d[f]},set(a){var h;a=ie(f,a,e),this.$$d[f]=a,(h=this.$$c)==null||h.$set({[f]:a})}})}),i.forEach(f=>{Object.defineProperty(s.prototype,f,{get(){var a;return(a=this.$$c)==null?void 0:a[f]}})}),o&&(s=o(s)),n.element=s,s}class bt{constructor(){G(this,"$$");G(this,"$$set")}$destroy(){ht(this,1),this.$destroy=C}$on(e,t){if(!ye(t))return C;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(t),()=>{const l=i.indexOf(t);l!==-1&&i.splice(l,1)}}$set(e){this.$$set&&!Ke(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const pt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(pt);const Ee="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGQoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAodD0+dC50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBwKGUsdCxvKXtyZXR1cm4gZChhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUoZSt0KSkpfWZ1bmN0aW9uIGcoZSx0LG89IlNIQS0yNTYiLGw9MWU2LGM9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyLGk9RGF0ZS5ub3coKTtyZXR1cm57cHJvbWlzZTooYXN5bmMoKT0+e2ZvcihsZXQgbj1jO248PWw7bis9MSl7aWYoYS5zaWduYWwuYWJvcnRlZClyZXR1cm4gbnVsbDtpZihhd2FpdCBwKHQsbixvKT09PWUpcmV0dXJue251bWJlcjpuLHRvb2s6RGF0ZS5ub3coKS1pfX1yZXR1cm4gbnVsbH0pKCksY29udHJvbGxlcjphfX1sZXQgcjtvbm1lc3NhZ2U9YXN5bmMgZT0+e2NvbnN0e3R5cGU6dCxwYXlsb2FkOm99PWUuZGF0YTtpZih0PT09ImFib3J0IilyPT1udWxsfHxyLmFib3J0KCkscj12b2lkIDA7ZWxzZSBpZih0PT09IndvcmsiKXtjb25zdHthbGc6bCxjaGFsbGVuZ2U6YyxtYXg6YSxzYWx0Omksc3RhcnQ6dX09b3x8e30sbj1nKGMsaSxsLGEsdSk7cj1uLmNvbnRyb2xsZXIsbi5wcm9taXNlLnRoZW4ocz0+e3NlbGYucG9zdE1lc3NhZ2UocyYmey4uLnMsd29ya2VyOiEwfSl9KX19fSkoKTsK",yt=n=>Uint8Array.from(atob(n),e=>e.charCodeAt(0)),$e=typeof window<"u"&&window.Blob&&new Blob([yt(Ee)],{type:"text/javascript;charset=utf-8"});function vt(n){let e;try{if(e=$e&&(window.URL||window.webkitURL).createObjectURL($e),!e)throw"";const t=new Worker(e,{name:n==null?void 0:n.name});return t.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;base64,"+Ee,{name:n==null?void 0:n.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const wt=new TextEncoder;function _t(n){return[...new Uint8Array(n)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function kt(n,e="SHA-256",t=1e5){const i=Date.now().toString(16);n||(n=Math.round(Math.random()*t));const l=await Ce(i,n,e);return{algorithm:e,challenge:l,salt:i,signature:""}}async function Ce(n,e,t){return _t(await crypto.subtle.digest(t.toUpperCase(),wt.encode(n+e)))}function xt(n,e,t="SHA-256",i=1e6,l=0){const o=new AbortController,s=Date.now();return{promise:(async()=>{for(let a=l;a<=i;a+=1){if(o.signal.aborted)return null;if(await Ce(e,a,t)===n)return{number:a,took:Date.now()-s}}return null})(),controller:o}}var b=(n=>(n.ERROR="error",n.VERIFIED="verified",n.VERIFYING="verifying",n.UNVERIFIED="unverified",n.EXPIRED="expired",n))(b||{});function Et(n){Je(n,"svelte-14ngypa",`.altcha.svelte-14ngypa.svelte-14ngypa{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid + var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-14ngypa.svelte-14ngypa:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-14ngypa.svelte-14ngypa{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-14ngypa.svelte-14ngypa{flex-grow:1}.altcha-label.svelte-14ngypa label.svelte-14ngypa{cursor:pointer}.altcha-logo.svelte-14ngypa.svelte-14ngypa{color:currentColor;opacity:0.3}.altcha-logo.svelte-14ngypa.svelte-14ngypa:hover{opacity:1}.altcha-error.svelte-14ngypa.svelte-14ngypa{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-14ngypa.svelte-14ngypa{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-14ngypa.svelte-14ngypa:hover{opacity:1}.altcha-footer.svelte-14ngypa>.svelte-14ngypa:first-child{flex-grow:1}.altcha-footer.svelte-14ngypa a{color:currentColor}.altcha-checkbox.svelte-14ngypa.svelte-14ngypa{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-14ngypa input.svelte-14ngypa{width:18px;height:18px;margin:0}.altcha-hidden.svelte-14ngypa.svelte-14ngypa{display:none}.altcha-spinner.svelte-14ngypa.svelte-14ngypa{animation:svelte-14ngypa-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-14ngypa-altcha-spinner{100%{transform:rotate(360deg)}}`)}function Le(n){let e,t,i;return{c(){e=X("svg"),t=X("path"),i=X("path"),c(t,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(t,"fill","currentColor"),c(t,"opacity",".25"),c(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(i,"fill","currentColor"),c(i,"class","altcha-spinner svelte-14ngypa"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(l,o){Z(l,e,o),y(e,t),y(e,i)},d(l){l&&S(e)}}}function $t(n){let e,t=n[9].label+"",i;return{c(){e=L("label"),c(e,"for",i=n[3]+"_checkbox"),c(e,"class","svelte-14ngypa")},m(l,o){Z(l,e,o),e.innerHTML=t},p(l,o){o[0]&512&&t!==(t=l[9].label+"")&&(e.innerHTML=t),o[0]&8&&i!==(i=l[3]+"_checkbox")&&c(e,"for",i)},d(l){l&&S(e)}}}function Ct(n){let e,t=n[9].verifying+"";return{c(){e=L("span")},m(i,l){Z(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].verifying+"")&&(e.innerHTML=t)},d(i){i&&S(e)}}}function Lt(n){let e,t=n[9].verified+"",i,l;return{c(){e=L("span"),i=W(),l=L("input"),c(l,"type","hidden"),c(l,"name",n[3]),l.value=n[4]},m(o,s){Z(o,e,s),e.innerHTML=t,Z(o,i,s),Z(o,l,s)},p(o,s){s[0]&512&&t!==(t=o[9].verified+"")&&(e.innerHTML=t),s[0]&8&&c(l,"name",o[3]),s[0]&16&&(l.value=o[4])},d(o){o&&(S(e),S(i),S(l))}}}function Re(n){let e,t,i,l,o,s;return{c(){e=L("div"),t=L("a"),i=X("svg"),l=X("path"),o=X("path"),s=X("path"),c(l,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(l,"fill","currentColor"),c(o,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(o,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(i,"width","22"),c(i,"height","22"),c(i,"viewBox","0 0 20 20"),c(i,"fill","none"),c(i,"xmlns","http://www.w3.org/2000/svg"),c(t,"href",Se),c(t,"target","_blank"),c(t,"class","altcha-logo svelte-14ngypa")},m(f,a){Z(f,e,a),y(e,t),y(t,i),y(i,l),y(i,o),y(i,s)},p:C,d(f){f&&S(e)}}}function Ie(n){let e,t,i,l;function o(a,h){return a[5]===b.EXPIRED?It:Rt}let s=o(n),f=s(n);return{c(){e=L("div"),t=X("svg"),i=X("path"),l=W(),f.c(),c(i,"stroke-linecap","round"),c(i,"stroke-linejoin","round"),c(i,"d","M6 18L18 6M6 6l12 12"),c(t,"width","14"),c(t,"height","14"),c(t,"xmlns","http://www.w3.org/2000/svg"),c(t,"fill","none"),c(t,"viewBox","0 0 24 24"),c(t,"stroke-width","1.5"),c(t,"stroke","currentColor"),c(e,"class","altcha-error svelte-14ngypa")},m(a,h){Z(a,e,h),y(e,t),y(t,i),y(e,l),f.m(e,null)},p(a,h){s===(s=o(a))&&f?f.p(a,h):(f.d(1),f=s(a),f&&(f.c(),f.m(e,null)))},d(a){a&&S(e),f.d()}}}function Rt(n){let e,t=n[9].error+"";return{c(){e=L("div"),c(e,"title",n[8])},m(i,l){Z(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].error+"")&&(e.innerHTML=t),l[0]&256&&c(e,"title",i[8])},d(i){i&&S(e)}}}function It(n){let e,t=n[9].expired+"";return{c(){e=L("div"),c(e,"title",n[8])},m(i,l){Z(i,e,l),e.innerHTML=t},p(i,l){l[0]&512&&t!==(t=i[9].expired+"")&&(e.innerHTML=t),l[0]&256&&c(e,"title",i[8])},d(i){i&&S(e)}}}function Ne(n){let e,t,i=n[9].footer+"";return{c(){e=L("div"),t=L("div"),c(t,"class","svelte-14ngypa"),c(e,"class","altcha-footer svelte-14ngypa")},m(l,o){Z(l,e,o),y(e,t),t.innerHTML=i},p(l,o){o[0]&512&&i!==(i=l[9].footer+"")&&(t.innerHTML=i)},d(l){l&&S(e)}}}function Nt(n){let e,t,i,l,o,s,f,a,h,M,R,U,O,D,_=n[5]===b.VERIFYING&&Le();function B(d,N){return d[5]===b.VERIFIED?Lt:d[5]===b.VERIFYING?Ct:$t}let F=B(n),k=F(n),x=n[2]!==!0&&Re(),g=(n[8]||n[5]===b.EXPIRED)&&Ie(n),p=n[9].footer&&n[1]!==!0&&Ne(n);return{c(){e=L("div"),t=L("div"),_&&_.c(),i=W(),l=L("div"),o=L("input"),a=W(),h=L("div"),k.c(),M=W(),x&&x.c(),R=W(),g&&g.c(),U=W(),p&&p.c(),c(o,"type","checkbox"),c(o,"id",s=n[3]+"_checkbox"),o.required=f=n[0]!=="onsubmit",c(o,"class","svelte-14ngypa"),c(l,"class","altcha-checkbox svelte-14ngypa"),ve(l,"altcha-hidden",n[5]===b.VERIFYING),c(h,"class","altcha-label svelte-14ngypa"),c(t,"class","altcha-main svelte-14ngypa"),c(e,"class","altcha svelte-14ngypa"),c(e,"data-state",n[5])},m(d,N){Z(d,e,N),y(e,t),_&&_.m(t,null),y(t,i),y(t,l),y(l,o),o.checked=n[6],y(t,a),y(t,h),k.m(h,null),y(t,M),x&&x.m(t,null),y(e,R),g&&g.m(e,null),y(e,U),p&&p.m(e,null),n[30](e),O||(D=[ae(o,"change",n[29]),ae(o,"change",n[10]),ae(o,"invalid",n[11])],O=!0)},p(d,N){d[5]===b.VERIFYING?_||(_=Le(),_.c(),_.m(t,i)):_&&(_.d(1),_=null),N[0]&8&&s!==(s=d[3]+"_checkbox")&&c(o,"id",s),N[0]&1&&f!==(f=d[0]!=="onsubmit")&&(o.required=f),N[0]&64&&(o.checked=d[6]),N[0]&32&&ve(l,"altcha-hidden",d[5]===b.VERIFYING),F===(F=B(d))&&k?k.p(d,N):(k.d(1),k=F(d),k&&(k.c(),k.m(h,null))),d[2]!==!0?x?x.p(d,N):(x=Re(),x.c(),x.m(t,null)):x&&(x.d(1),x=null),d[8]||d[5]===b.EXPIRED?g?g.p(d,N):(g=Ie(d),g.c(),g.m(e,U)):g&&(g.d(1),g=null),d[9].footer&&d[1]!==!0?p?p.p(d,N):(p=Ne(d),p.c(),p.m(e,null)):p&&(p.d(1),p=null),N[0]&32&&c(e,"data-state",d[5])},i:C,o:C,d(d){d&&S(e),_&&_.d(),k.d(),x&&x.d(),g&&g.d(),p&&p.d(),n[30](null),O=!1,te(D)}}}const Se="https://altcha.org/";function je(n){return JSON.parse(n)}function St(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}function jt(n,e,t){var Fe,He;let i,l,o,{auto:s=void 0}=e,{blockspam:f=void 0}=e,{challengeurl:a=void 0}=e,{challengejson:h=void 0}=e,{debug:M=!1}=e,{expire:R=void 0}=e,{hidefooter:U=!1}=e,{hidelogo:O=!1}=e,{name:D="altcha"}=e,{maxnumber:_=1e6}=e,{mockerror:B=!1}=e,{refetchonexpire:F=!0}=e,{spamfilter:k=!1}=e,{strings:x=void 0}=e,{test:g=!1}=e,{verifyurl:p=void 0}=e,{workers:d=navigator.hardwareConcurrency||8}=e;const N=lt(),Ae=["SHA-256","SHA-384","SHA-512"],Te=(He=(Fe=document.documentElement.lang)==null?void 0:Fe.split("-"))==null?void 0:He[0];let Y=!1,le,m=null,me=null,K=null,H=b.UNVERIFIED,be;it(()=>{m&&(m.removeEventListener("submit",Ve),m.removeEventListener("reset",Ge),m.removeEventListener("focusin",Me),m=null)}),rt(()=>{I("mounted","0.4.0"),I("workers",d),g&&I("using test mode"),R&&oe(R),s!==void 0&&I("auto",s),m=le.closest("form"),m&&(m.addEventListener("submit",Ve),m.addEventListener("reset",Ge),s==="onfocus"&&m.addEventListener("focusin",Me)),s==="onload"&&J()});function I(...r){(M||r.some(u=>u instanceof Error))&&console[r[0]instanceof Error?"error":"log"]("ALTCHA",...r)}function Me(r){J()}function Ve(r){m&&s==="onsubmit"&&H===b.UNVERIFIED&&(r.preventDefault(),r.stopPropagation(),J().then(()=>{m==null||m.requestSubmit()}))}function Ge(){se()}function Ue(r,u){return btoa(JSON.stringify({algorithm:r.algorithm,challenge:r.challenge,number:u.number,salt:r.salt,signature:r.signature,test:g?!0:void 0,took:u.took}))}function Oe(r){if(!r.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(r.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!Ae.includes(r.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${Ae.join(", ")}`);if(!r.challenge||r.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!r.salt||r.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function Zt(){var r;if(B)throw I("mocking error"),new Error("Mocked error.");if(i)return I("using provided json data"),i;if(g)return I("generating test challenge",{test:g}),kt(typeof g!="boolean"?+g:void 0);{if(!a)throw new Error("Attribute challengeurl not set.");I("fetching challenge from",a);const u=await fetch(a,{headers:{"x-altcha-spam-filter":k?"1":"0"}});if(u.status!==200)throw new Error(`Server responded with ${u.status}.`);const v=u.headers.get("Expires"),j=u.headers.get("X-Altcha-Config"),A=await u.json(),V=new URLSearchParams((r=A.salt.split("?"))==null?void 0:r[1]),z=V.get("expires")||V.get("expire");if(z){const E=new Date(+z*1e3),$=isNaN(E.getTime())?0:E.getTime()-Date.now();$>0&&oe($)}if(j)try{const E=JSON.parse(j);E&&typeof E=="object"&&(E.verifyurl&&(E.verifyurl=new URL(E.verifyurl,new URL(a)).toString()),De(E))}catch(E){I("unable to configure from X-Altcha-Config",E)}if(!R&&(v!=null&&v.length)){const E=Date.parse(v);if(E){const $=E-Date.now();$>0&&oe($)}}return A}}function Xe(){a&&F&&H===b.VERIFIED?J():se(b.EXPIRED,o.expired)}async function At(r){let u=null;if("Worker"in window){try{u=await Tt(r.challenge,r.salt,r.algorithm,r.maxnumber)}catch(v){I(v)}if((u==null?void 0:u.number)!==void 0)return{data:r,solution:u}}return{data:r,solution:await xt(r.challenge,r.salt,r.algorithm,r.maxnumber||_).promise}}async function Tt(r,u,v,j=typeof g=="number"?g:_,A=Math.ceil(d)){const V=[];if(A<1)throw new Error("Wrong number of workers configured.");if(A>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let $=0;${const Pe=ce*z;return new Promise(Ft=>{$.addEventListener("message",Ye=>{if(Ye.data)for(const We of V)We!==$&&We.postMessage({type:"abort"});Ft(Ye.data)}),$.postMessage({payload:{alg:v,challenge:r,max:Pe+z,salt:u,start:Pe},type:"work"})})}));for(const $ of V)$.terminate();return E.find($=>!!$)||null}function Mt(){[b.UNVERIFIED,b.ERROR,b.EXPIRED].includes(H)?k&&(m==null?void 0:m.reportValidity())===!1?t(6,Y=!1):J():t(6,Y=!0)}function Vt(){H===b.VERIFYING&&alert(o.waitAlert)}function oe(r){I("expire",r),clearTimeout(be),r<1?Xe():be=setTimeout(Xe,r)}function Gt(r){var v;const u=m==null?void 0:m.querySelector(typeof r=="string"?`input[name="${r}"]`:'input[type="email"]:not([data-no-spamfilter])');return((v=u==null?void 0:u.value)==null?void 0:v.slice(u.value.indexOf("@")))||void 0}function Ut(r){return[...(m==null?void 0:m.querySelectorAll(r!=null&&r.length?r.map(v=>`input[name="${v}"]`).join(", "):'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])'))||[]].reduce((v,j)=>{const A=j.name,V=j.value.trim();return A&&V&&(v[A]=V),v},{})}async function Ot(r){if(!p)throw new Error("Attribute verifyurl not set.");I("requesting server verification from",p);const u={payload:r};if(k){const{email:A,expectedLanguages:V,expectedCountries:z,fields:E,ipAddress:$,timeZone:ce}=typeof k=="object"?k:{email:void 0,expectedCountries:void 0,expectedLanguages:void 0,fields:void 0,ipAddress:void 0,timeZone:void 0};u.ipAddress=$===!1?void 0:$||"auto",u.email=A===!1?void 0:Gt(A),u.fields=E===!1?void 0:Ut(E),u.timeZone=ce===!1?void 0:ce||St(),u.expectedCountries=z,u.expectedLanguages=V||(Te?[Te]:void 0)}const v=await fetch(p,{body:JSON.stringify(u),headers:{"content-type":"application/json"},method:"POST"});if(v.status!==200)throw new Error(`Server responded with ${v.status}.`);const j=await v.json();if(j!=null&&j.payload&&t(4,K=j.payload),N("serververification",j),f&&j.classification==="BAD")throw new Error("SpamFilter returned negative classification.")}function De(r){r.auto!==void 0&&(t(0,s=r.auto),s==="onload"&&J()),r.expire!==void 0&&(oe(r.expire),t(14,R=r.expire)),r.challenge&&(Oe(r.challenge),i=r.challenge),r.challengeurl!==void 0&&t(12,a=r.challengeurl),r.debug!==void 0&&t(13,M=!!r.debug),r.hidefooter!==void 0&&t(1,U=!!r.hidefooter),r.hidelogo!==void 0&&t(2,O=!!r.hidelogo),r.maxnumber!==void 0&&t(15,_=+r.maxnumber),r.mockerror!==void 0&&t(16,B=!!r.mockerror),r.name!==void 0&&t(3,D=r.name),r.refetchonexpire!==void 0&&t(17,F=!!r.refetchonexpire),r.spamfilter!==void 0&&t(18,k=typeof r.spamfilter=="object"?r.spamfilter:!!r.spamfilter),r.strings&&t(28,l=r.strings),r.test!==void 0&&t(19,g=typeof r.test=="number"?r.test:!!r.test),r.verifyurl!==void 0&&t(20,p=r.verifyurl),r.workers!==void 0&&t(21,d=+r.workers)}function se(r=b.UNVERIFIED,u=null){clearTimeout(be),t(6,Y=!1),t(8,me=u),t(4,K=null),t(5,H=r)}async function J(){return se(b.VERIFYING),Zt().then(r=>(Oe(r),I("challenge",r),At(r))).then(({data:r,solution:u})=>{if(I("solution",u),(u==null?void 0:u.number)!==void 0){if(p)return Ot(Ue(r,u));t(4,K=Ue(r,u)),I("payload",K)}else throw I("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."),new Error("Unexpected result returned.")}).then(()=>{ot().then(()=>{t(5,H=b.VERIFIED),t(6,Y=!0),I("verified"),N("verified",{payload:K})})}).catch(r=>{I(r),t(5,H=b.ERROR),t(6,Y=!1),t(8,me=r.message)})}function Xt(){Y=this.checked,t(6,Y)}function Dt(r){ue[r?"unshift":"push"](()=>{le=r,t(7,le)})}return n.$$set=r=>{"auto"in r&&t(0,s=r.auto),"blockspam"in r&&t(22,f=r.blockspam),"challengeurl"in r&&t(12,a=r.challengeurl),"challengejson"in r&&t(23,h=r.challengejson),"debug"in r&&t(13,M=r.debug),"expire"in r&&t(14,R=r.expire),"hidefooter"in r&&t(1,U=r.hidefooter),"hidelogo"in r&&t(2,O=r.hidelogo),"name"in r&&t(3,D=r.name),"maxnumber"in r&&t(15,_=r.maxnumber),"mockerror"in r&&t(16,B=r.mockerror),"refetchonexpire"in r&&t(17,F=r.refetchonexpire),"spamfilter"in r&&t(18,k=r.spamfilter),"strings"in r&&t(24,x=r.strings),"test"in r&&t(19,g=r.test),"verifyurl"in r&&t(20,p=r.verifyurl),"workers"in r&&t(21,d=r.workers)},n.$$.update=()=>{n.$$.dirty[0]&8388608&&(i=h?je(h):void 0),n.$$.dirty[0]&16777216&&t(28,l=x?je(x):{}),n.$$.dirty[0]&268435456&&t(9,o={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),n.$$.dirty[0]&48&&N("statechange",{payload:K,state:H})},[s,U,O,D,K,H,Y,le,me,o,Mt,Vt,a,M,R,_,B,F,k,g,p,d,f,h,x,De,se,J,l,Xt,Dt]}class Ze extends bt{constructor(e){super(),gt(this,e,jt,Nt,Be,{auto:0,blockspam:22,challengeurl:12,challengejson:23,debug:13,expire:14,hidefooter:1,hidelogo:2,name:3,maxnumber:15,mockerror:16,refetchonexpire:17,spamfilter:18,strings:24,test:19,verifyurl:20,workers:21,configure:25,reset:26,verify:27},Et,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),w()}get blockspam(){return this.$$.ctx[22]}set blockspam(e){this.$$set({blockspam:e}),w()}get challengeurl(){return this.$$.ctx[12]}set challengeurl(e){this.$$set({challengeurl:e}),w()}get challengejson(){return this.$$.ctx[23]}set challengejson(e){this.$$set({challengejson:e}),w()}get debug(){return this.$$.ctx[13]}set debug(e){this.$$set({debug:e}),w()}get expire(){return this.$$.ctx[14]}set expire(e){this.$$set({expire:e}),w()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),w()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),w()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),w()}get maxnumber(){return this.$$.ctx[15]}set maxnumber(e){this.$$set({maxnumber:e}),w()}get mockerror(){return this.$$.ctx[16]}set mockerror(e){this.$$set({mockerror:e}),w()}get refetchonexpire(){return this.$$.ctx[17]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),w()}get spamfilter(){return this.$$.ctx[18]}set spamfilter(e){this.$$set({spamfilter:e}),w()}get strings(){return this.$$.ctx[24]}set strings(e){this.$$set({strings:e}),w()}get test(){return this.$$.ctx[19]}set test(e){this.$$set({test:e}),w()}get verifyurl(){return this.$$.ctx[20]}set verifyurl(e){this.$$set({verifyurl:e}),w()}get workers(){return this.$$.ctx[21]}set workers(e){this.$$set({workers:e}),w()}get configure(){return this.$$.ctx[25]}get reset(){return this.$$.ctx[26]}get verify(){return this.$$.ctx[27]}}customElements.define("altcha-widget",mt(Ze,{auto:{},blockspam:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},spamfilter:{type:"Boolean"},strings:{},test:{type:"Boolean"},verifyurl:{},workers:{}},[],["configure","reset","verify"],!1)),T.Altcha=Ze,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}); diff --git a/package.json b/package.json index dc99d41..5e44292 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "altcha", "description": "GDPR compliant, self-hosted CAPTCHA alternative.", - "version": "0.3.2", + "version": "0.4.0", "license": "MIT", "author": { "name": "Daniel Regeci" diff --git a/server/server-deno.ts b/server/server-deno.ts index 3c6ea55..b6e354e 100644 --- a/server/server-deno.ts +++ b/server/server-deno.ts @@ -9,7 +9,7 @@ import { cors } from 'https://deno.land/x/hono/middleware/cors/index.ts'; import { createChallenge, verifySolution, -} from 'https://deno.land/x/altcha/mod.ts'; +} from 'https://deno.land/x/altcha@0.3.0/mod.ts'; // Configure your secret HMAC key const HMAC_KEY = 'secret.hmac.key'; @@ -28,10 +28,11 @@ app.use('/*', cors()); app.get('/altcha', async (c) => c.json( await createChallenge({ + expires: new Date(Date.now() + 3600000), hmacKey: HMAC_KEY, - }) + } ) -); +)); // Form submission endpoint app.post('/submit', async (c) => { diff --git a/src/Altcha.svelte b/src/Altcha.svelte index 8fe3665..740d21b 100644 --- a/src/Altcha.svelte +++ b/src/Altcha.svelte @@ -185,8 +185,19 @@ if (resp.status !== 200) { throw new Error(`Server responded with ${resp.status}.`); } + // The use of Expires header is deprecated, use salt params instead const expHeader = resp.headers.get('Expires'); const configHeader = resp.headers.get('X-Altcha-Config'); + const json = await resp.json(); + const params = new URLSearchParams(json.salt.split('?')?.[1]); + const expires = params.get('expires') || params.get('expire'); + if (expires) { + const date = new Date(+expires * 1000); + const diff = !isNaN(date.getTime()) ? date.getTime() - Date.now() : 0; + if (diff > 0) { + setExpire(diff); + } + } if (configHeader) { try { const config = JSON.parse(configHeader); @@ -212,7 +223,7 @@ } } } - return resp.json(); + return json; } } @@ -262,7 +273,7 @@ challenge: string, salt: string, alg?: string, - max: number = maxnumber, + max: number = typeof test === 'number' ? test : maxnumber, concurrency: number = Math.ceil(workers) ): Promise { const workers: Worker[] = []; diff --git a/src/helpers.ts b/src/helpers.ts index 433b8b8..90504ad 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -47,30 +47,24 @@ export function solveChallenge( start: number = 0 ): { promise: Promise; controller: AbortController } { const controller = new AbortController(); - const promise = new Promise((resolve, reject) => { - const startTime = Date.now(); - const next = (n: number) => { - if (controller.signal.aborted || n > max) { - resolve(null); - } else { - hashChallenge(salt, n, algorithm) - .then((t) => { - if (t === challenge) { - resolve({ - number: n, - took: Date.now() - startTime, - }); - } else { - next(n + 1); - } - }) - .catch(reject); + const startTime = Date.now(); + const fn = async () => { + for (let n = start; n <= max; n += 1) { + if (controller.signal.aborted) { + return null; } - }; - next(start); - }) as Promise; + const t = await hashChallenge(salt, n, algorithm); + if (t === challenge) { + return { + number: n, + took: Date.now() - startTime, + }; + } + } + return null; + } return { - promise, + promise: fn(), controller, }; }