diff --git a/dist/altcha.iife.js b/dist/altcha.iife.js index c712e71..a52f02c 100644 --- a/dist/altcha.iife.js +++ b/dist/altcha.iife.js @@ -1 +1 @@ -var altcha=function(j){"use strict";var Mt=Object.defineProperty;var St=(j,L,P)=>L in j?Mt(j,L,{enumerable:!0,configurable:!0,writable:!0,value:P}):j[L]=P;var M=(j,L,P)=>(St(j,typeof L!="symbol"?L+"":L,P),P);function L(){}function P(t){return t()}function ae(){return Object.create(null)}function K(t){t.forEach(P)}function he(t){return typeof t=="function"}function je(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ve(t){return Object.keys(t).length===0}function b(t,e){t.appendChild(e)}function Ze(t,e,r){const n=He(t);if(!n.getElementById(e)){const o=w("style");o.id=e,o.textContent=r,Pe(n,o)}}function He(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Pe(t,e){return b(t.head||t,e),e.sheet}function I(t,e,r){t.insertBefore(e,r||null)}function R(t){t.parentNode&&t.parentNode.removeChild(t)}function w(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Fe(t){return document.createTextNode(t)}function F(){return Fe(" ")}function re(t,e,r,n){return t.addEventListener(e,r,n),()=>t.removeEventListener(e,r,n)}function c(t,e,r){r==null?t.removeAttribute(e):t.getAttribute(e)!==r&&t.setAttribute(e,r)}function Oe(t){return Array.from(t.childNodes)}function de(t,e,r){t.classList.toggle(e,!!r)}function We(t,e,{bubbles:r=!1,cancelable:n=!1}={}){return new CustomEvent(t,{detail:e,bubbles:r,cancelable:n})}function De(t){const e={};return t.childNodes.forEach(r=>{e[r.slot||"default"]=!0}),e}let J;function z(t){J=t}function ne(){if(!J)throw new Error("Function called outside component initialization");return J}function Be(t){ne().$$.on_mount.push(t)}function Ye(t){ne().$$.on_destroy.push(t)}function Ue(){const t=ne();return(e,r,{cancelable:n=!1}={})=>{const o=t.$$.callbacks[e];if(o){const l=We(e,r,{cancelable:n});return o.slice().forEach(s=>{s.call(t,l)}),!l.defaultPrevented}return!0}}const W=[],ie=[];let D=[];const ge=[],be=Promise.resolve();let oe=!1;function me(){oe||(oe=!0,be.then(E))}function Xe(){return me(),be}function le(t){D.push(t)}const se=new Set;let B=0;function E(){if(B!==0)return;const t=J;do{try{for(;Bt.indexOf(n)===-1?e.push(n):r.push(n)),r.forEach(n=>n()),D=e}const ze=new Set;function Qe(t,e){t&&t.i&&(ze.delete(t),t.i(e))}function qe(t,e,r){const{fragment:n,after_update:o}=t.$$;n&&n.m(e,r),le(()=>{const l=t.$$.on_mount.map(P).filter(he);t.$$.on_destroy?t.$$.on_destroy.push(...l):K(l),t.$$.on_mount=[]}),o.forEach(le)}function et(t,e){const r=t.$$;r.fragment!==null&&(Je(r.after_update),K(r.on_destroy),r.fragment&&r.fragment.d(e),r.on_destroy=r.fragment=null,r.ctx=[])}function tt(t,e){t.$$.dirty[0]===-1&&(W.push(t),me(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const S=A.length?A[0]:N;return f.ctx&&o(f.ctx[m],f.ctx[m]=S)&&(!f.skip_bound&&f.bound[m]&&f.bound[m](S),x&&tt(t,m)),N}):[],f.update(),x=!0,K(f.before_update),f.fragment=n?n(f.ctx):!1,e.target){if(e.hydrate){const m=Oe(e.target);f.fragment&&f.fragment.l(m),m.forEach(R)}else f.fragment&&f.fragment.c();e.intro&&Qe(t.$$.fragment),qe(t,e.target,e.anchor),E()}z(a)}let ve;typeof HTMLElement=="function"&&(ve=class extends HTMLElement{constructor(e,r,n){super();M(this,"$$ctor");M(this,"$$s");M(this,"$$c");M(this,"$$cn",!1);M(this,"$$d",{});M(this,"$$r",!1);M(this,"$$p_d",{});M(this,"$$l",{});M(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=r,n&&this.attachShadow({mode:"open"})}addEventListener(e,r,n){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(r),this.$$c){const o=this.$$c.$on(e,r);this.$$l_u.set(r,o)}super.addEventListener(e,r,n)}removeEventListener(e,r,n){if(super.removeEventListener(e,r,n),this.$$c){const o=this.$$l_u.get(r);o&&(o(),this.$$l_u.delete(r))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(l){return()=>{let s;return{c:function(){s=w("slot"),l!=="default"&&c(s,"name",l)},m:function(f,x){I(f,s,x)},d:function(f){f&&R(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const r={},n=De(this);for(const l of this.$$s)l in n&&(r[l]=[e(l)]);for(const l of this.attributes){const s=this.$$g_p(l.name);s in this.$$d||(this.$$d[s]=Q(s,l.value,this.$$p_d,"toProp"))}for(const l in this.$$p_d)!(l in this.$$d)&&this[l]!==void 0&&(this.$$d[l]=this[l],delete this[l]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:r,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const l in this.$$p_d)if(this.$$d[l]=this.$$c.$$.ctx[this.$$c.$$.props[l]],this.$$p_d[l].reflect){const s=Q(l,this.$$d[l],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[l].attribute||l):this.setAttribute(this.$$p_d[l].attribute||l,s)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const l in this.$$l)for(const s of this.$$l[l]){const u=this.$$c.$on(l,s);this.$$l_u.set(s,u)}this.$$l={}}}attributeChangedCallback(e,r,n){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Q(e,n,this.$$p_d,"toProp"),(o=this.$$c)==null||o.$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(r=>this.$$p_d[r].attribute===e||!this.$$p_d[r].attribute&&r.toLowerCase()===e)||e}});function Q(t,e,r,n){var l;const o=(l=r[t])==null?void 0:l.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!n||!r[t])return e;if(n==="toAttribute")switch(o){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(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function nt(t,e,r,n,o,l){let s=class extends ve{constructor(){super(t,r,o),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(u=>(e[u].attribute||u).toLowerCase())}};return Object.keys(e).forEach(u=>{Object.defineProperty(s.prototype,u,{get(){return this.$$c&&u in this.$$c?this.$$c[u]:this.$$d[u]},set(a){var f;a=Q(u,a,e),this.$$d[u]=a,(f=this.$$c)==null||f.$set({[u]:a})}})}),n.forEach(u=>{Object.defineProperty(s.prototype,u,{get(){var a;return(a=this.$$c)==null?void 0:a[u]}})}),l&&(s=l(s)),t.element=s,s}class it{constructor(){M(this,"$$");M(this,"$$set")}$destroy(){et(this,1),this.$destroy=L}$on(e,r){if(!he(r))return L;const n=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return n.push(r),()=>{const o=n.indexOf(r);o!==-1&&n.splice(o,1)}}$set(e){this.$$set&&!Ve(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const ot="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ot);const we="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+aT9zKG51bGwpOmgoZSxsLG8pLnRoZW4odz0+e3c9PT10P3Moe251bWJlcjpsLHRvb2s6RGF0ZS5ub3coKS1yfSk6ZChsKzEpfSkuY2F0Y2goYyl9O2QocCl9KSxjb250cm9sbGVyOmF9fWxldCBuO29ubWVzc2FnZT1hc3luYyB0PT57Y29uc3R7dHlwZTplLHBheWxvYWQ6b309dC5kYXRhO2lmKGU9PT0iYWJvcnQiKW49PW51bGx8fG4uYWJvcnQoKSxuPXZvaWQgMDtlbHNlIGlmKGU9PT0id29yayIpe2NvbnN0e2FsZzppLGNoYWxsZW5nZTpwLG1heDphLHNhbHQ6dSxzdGFydDpzfT1vfHx7fSxjPW0ocCx1LGksYSxzKTtuPWMuY29udHJvbGxlcixjLnByb21pc2UudGhlbihyPT57c2VsZi5wb3N0TWVzc2FnZShyJiZ7Li4ucix3b3JrZXI6ITB9KX0pfX19KSgpOwo=",lt=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),_e=typeof window<"u"&&window.Blob&&new Blob([lt(we)],{type:"text/javascript;charset=utf-8"});function st(t){let e;try{if(e=_e&&(window.URL||window.webkitURL).createObjectURL(_e),!e)throw"";const r=new Worker(e,{name:t==null?void 0:t.name});return r.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),r}catch{return new Worker("data:text/javascript;base64,"+we,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const ct=new TextEncoder;function ut(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ft(t,e="SHA-256",r=1e5){const n=Date.now().toString(16);t||(t=Math.round(Math.random()*r));const o=await pe(n,t,e);return{algorithm:e,challenge:o,salt:n,signature:""}}async function pe(t,e,r){return ut(await crypto.subtle.digest(r.toUpperCase(),ct.encode(t+e)))}function at(t,e,r="SHA-256",n=1e6,o=0){const l=new AbortController;return{promise:new Promise((u,a)=>{const f=Date.now(),x=m=>{l.signal.aborted||m>n?u(null):pe(e,m,r).then(N=>{N===t?u({number:m,took:Date.now()-f}):x(m+1)}).catch(a)};x(o)}),controller:l}}var g=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(g||{});function ht(t){Ze(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function ye(t){let e,r,n;return{c(){e=V("svg"),r=V("path"),n=V("path"),c(r,"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(r,"fill","currentColor"),c(r,"opacity",".25"),c(n,"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(n,"fill","currentColor"),c(n,"class","altcha-spinner svelte-vuofbg"),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(o,l){I(o,e,l),b(e,r),b(e,n)},d(o){o&&R(e)}}}function dt(t){let e,r=t[9].label+"",n;return{c(){e=w("label"),c(e,"for",n=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(o,l){I(o,e,l),e.innerHTML=r},p(o,l){l[0]&512&&r!==(r=o[9].label+"")&&(e.innerHTML=r),l[0]&8&&n!==(n=o[3]+"_checkbox")&&c(e,"for",n)},d(o){o&&R(e)}}}function gt(t){let e,r=t[9].verifying+"";return{c(){e=w("span")},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].verifying+"")&&(e.innerHTML=r)},d(n){n&&R(e)}}}function bt(t){let e,r=t[9].verified+"",n,o;return{c(){e=w("span"),n=F(),o=w("input"),c(o,"type","hidden"),c(o,"name",t[3]),o.value=t[4]},m(l,s){I(l,e,s),e.innerHTML=r,I(l,n,s),I(l,o,s)},p(l,s){s[0]&512&&r!==(r=l[9].verified+"")&&(e.innerHTML=r),s[0]&8&&c(o,"name",l[3]),s[0]&16&&(o.value=l[4])},d(l){l&&(R(e),R(n),R(o))}}}function ke(t){let e,r,n,o,l,s;return{c(){e=w("div"),r=w("a"),n=V("svg"),o=V("path"),l=V("path"),s=V("path"),c(o,"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(o,"fill","currentColor"),c(l,"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(l,"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(n,"width","22"),c(n,"height","22"),c(n,"viewBox","0 0 20 20"),c(n,"fill","none"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(r,"href",xe),c(r,"target","_blank"),c(r,"class","altcha-logo svelte-vuofbg")},m(u,a){I(u,e,a),b(e,r),b(r,n),b(n,o),b(n,l),b(n,s)},p:L,d(u){u&&R(e)}}}function $e(t){let e,r,n,o;function l(a,f){return a[5]===g.EXPIRED?vt:mt}let s=l(t),u=s(t);return{c(){e=w("div"),r=V("svg"),n=V("path"),o=F(),u.c(),c(n,"stroke-linecap","round"),c(n,"stroke-linejoin","round"),c(n,"d","M6 18L18 6M6 6l12 12"),c(r,"width","14"),c(r,"height","14"),c(r,"xmlns","http://www.w3.org/2000/svg"),c(r,"fill","none"),c(r,"viewBox","0 0 24 24"),c(r,"stroke-width","1.5"),c(r,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(a,f){I(a,e,f),b(e,r),b(r,n),b(e,o),u.m(e,null)},p(a,f){s===(s=l(a))&&u?u.p(a,f):(u.d(1),u=s(a),u&&(u.c(),u.m(e,null)))},d(a){a&&R(e),u.d()}}}function mt(t){let e,r=t[9].error+"";return{c(){e=w("div"),c(e,"title",t[8])},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].error+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&R(e)}}}function vt(t){let e,r=t[9].expired+"";return{c(){e=w("div"),c(e,"title",t[8])},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].expired+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&R(e)}}}function Ee(t){let e,r,n=t[9].footer+"";return{c(){e=w("div"),r=w("div"),c(r,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(o,l){I(o,e,l),b(e,r),r.innerHTML=n},p(o,l){l[0]&512&&n!==(n=o[9].footer+"")&&(r.innerHTML=n)},d(o){o&&R(e)}}}function wt(t){let e,r,n,o,l,s,u,a,f,x,m,N,A,S,_=t[5]===g.VERIFYING&&ye();function O(h,$){return h[5]===g.VERIFIED?bt:h[5]===g.VERIFYING?gt:dt}let Z=O(t),p=Z(t),v=t[2]!==!0&&ke(),y=(t[8]||t[5]===g.EXPIRED)&&$e(t),k=t[9].footer&&t[1]!==!0&&Ee(t);return{c(){e=w("div"),r=w("div"),_&&_.c(),n=F(),o=w("div"),l=w("input"),a=F(),f=w("div"),p.c(),x=F(),v&&v.c(),m=F(),y&&y.c(),N=F(),k&&k.c(),c(l,"type","checkbox"),c(l,"id",s=t[3]+"_checkbox"),l.required=u=t[0]!=="onsubmit",c(l,"class","svelte-vuofbg"),c(o,"class","altcha-checkbox svelte-vuofbg"),de(o,"altcha-hidden",t[5]===g.VERIFYING),c(f,"class","altcha-label svelte-vuofbg"),c(r,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,$){I(h,e,$),b(e,r),_&&_.m(r,null),b(r,n),b(r,o),b(o,l),l.checked=t[6],b(r,a),b(r,f),p.m(f,null),b(r,x),v&&v.m(r,null),b(e,m),y&&y.m(e,null),b(e,N),k&&k.m(e,null),t[27](e),A||(S=[re(l,"change",t[26]),re(l,"change",t[10]),re(l,"invalid",t[11])],A=!0)},p(h,$){h[5]===g.VERIFYING?_||(_=ye(),_.c(),_.m(r,n)):_&&(_.d(1),_=null),$[0]&8&&s!==(s=h[3]+"_checkbox")&&c(l,"id",s),$[0]&1&&u!==(u=h[0]!=="onsubmit")&&(l.required=u),$[0]&64&&(l.checked=h[6]),$[0]&32&&de(o,"altcha-hidden",h[5]===g.VERIFYING),Z===(Z=O(h))&&p?p.p(h,$):(p.d(1),p=Z(h),p&&(p.c(),p.m(f,null))),h[2]!==!0?v?v.p(h,$):(v=ke(),v.c(),v.m(r,null)):v&&(v.d(1),v=null),h[8]||h[5]===g.EXPIRED?y?y.p(h,$):(y=$e(h),y.c(),y.m(e,N)):y&&(y.d(1),y=null),h[9].footer&&h[1]!==!0?k?k.p(h,$):(k=Ee(h),k.c(),k.m(e,null)):k&&(k.d(1),k=null),$[0]&32&&c(e,"data-state",h[5])},i:L,o:L,d(h){h&&R(e),_&&_.d(),p.d(),v&&v.d(),y&&y.d(),k&&k.d(),t[27](null),A=!1,K(S)}}}const xe="https://altcha.org/";function Ce(t){return JSON.parse(t)}function _t(t,e,r){let n,o,l,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:a=void 0}=e,{debug:f=!1}=e,{expire:x=void 0}=e,{hidefooter:m=!1}=e,{hidelogo:N=!1}=e,{name:A="altcha"}=e,{maxnumber:S=1e6}=e,{mockerror:_=!1}=e,{refetchonexpire:O=!0}=e,{strings:Z=void 0}=e,{test:p=!1}=e,{workers:v=navigator.hardwareConcurrency||8}=e;const y=Ue(),k=["SHA-256","SHA-384","SHA-512"];let h=!1,$,T=null,ce=null,Y=null,H=g.UNVERIFIED,ue;Ye(()=>{T&&(T.removeEventListener("submit",Re),T.removeEventListener("reset",Ie),T=null)}),Be(()=>{C("mounted","0.2.1"),C("workers",v),p&&C("using test mode"),x&&fe(x),s!==void 0&&C("auto",s),T=$.closest("form"),T&&(T.addEventListener("submit",Re),T.addEventListener("reset",Ie)),s==="onload"&&U()});function C(...i){(f||i.some(d=>d instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function Re(i){T&&s==="onsubmit"&&H===g.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),U().then(()=>{T==null||T.requestSubmit()}))}function Ie(){q()}function pt(i,d){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:d.number,salt:i.salt,signature:i.signature,test:p?!0:void 0,took:d.took}))}function Ne(i){if(!i.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(i.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!k.includes(i.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${k.join(", ")}`);if(!i.challenge||i.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!i.salt||i.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function yt(){if(_)throw C("mocking error"),new Error("Mocked error.");if(n)return C("using provided json data"),n;if(p)return C("generating test challenge"),ft();{if(!u)throw new Error("Attribute challengeurl not set.");C("fetching challenge from",u);const i=await fetch(u);if(i.status!==200)throw new Error(`Server responded with ${i.status}.`);const d=i.headers.get("Expires");if(d!=null&&d.length){const X=Date.parse(d);isNaN(X)||fe(X-Date.now())}return i.json()}}function Te(){u&&O&&H===g.VERIFIED?U():q(g.EXPIRED,l.expired)}async function kt(i){let d=null;if("Worker"in window){try{d=await $t(i.challenge,i.salt,i.algorithm)}catch(X){C(X)}if((d==null?void 0:d.number)!==void 0)return{data:i,solution:d}}return{data:i,solution:await at(i.challenge,i.salt,i.algorithm,S).promise}}async function $t(i,d,X,ee=Math.ceil(v)){const te=[];if(ee<1)throw new Error("Wrong number of workers configured.");if(ee>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let G=0;G{const Se=Nt*Me;return new Promise(Tt=>{G.addEventListener("message",Ae=>{if(Ae.data)for(const Ge of te)Ge!==G&&Ge.postMessage({type:"abort"});Tt(Ae.data)}),G.postMessage({payload:{alg:X,challenge:i,max:Se+Me,salt:d,start:Se},type:"work"})})}));for(const G of te)G.terminate();return It.find(G=>!!G)||null}function Et(){[g.UNVERIFIED,g.ERROR,g.EXPIRED].includes(H)?U():r(6,h=!0)}function xt(){H===g.VERIFYING&&alert(l.waitAlert)}function fe(i){C("expire",i),clearTimeout(ue),i<1?Te():ue=setTimeout(Te,i)}function Ct(i){i.auto!==void 0&&(r(0,s=i.auto),s==="onload"&&U()),i.expire!==void 0&&(fe(i.expire),r(13,x=i.expire)),i.challenge&&(Ne(i.challenge),n=i.challenge),i.debug!==void 0&&r(12,f=!!i.debug),i.hidefooter!==void 0&&r(1,m=!!i.hidefooter),i.hidelogo!==void 0&&r(2,N=!!i.hidelogo),i.maxnumber!==void 0&&r(14,S=+i.maxnumber),i.mockerror!==void 0&&r(15,_=!!i.mockerror),i.name!==void 0&&r(3,A=i.name),i.refetchonexpire!==void 0&&r(16,O=!!i.refetchonexpire),i.strings&&r(25,o=i.strings),i.test!==void 0&&r(17,p=!!i.test),i.workers!==void 0&&r(18,v=+i.workers)}function q(i=g.UNVERIFIED,d=null){clearTimeout(ue),r(6,h=!1),r(8,ce=d),r(4,Y=null),r(5,H=i)}async function U(){return q(g.VERIFYING),yt().then(i=>(Ne(i),C("challenge",i),kt(i))).then(({data:i,solution:d})=>{if(C("solution",d),(d==null?void 0:d.number)!==void 0)C("verified"),r(5,H=g.VERIFIED),r(6,h=!0),r(4,Y=pt(i,d)),C("payload",Y),Xe().then(()=>{y("verified",{payload:Y})});else throw new Error("Unexpected result returned.")}).catch(i=>{C(i),r(5,H=g.ERROR),r(6,h=!1),r(8,ce=i.message)})}function Lt(){h=this.checked,r(6,h)}function Rt(i){ie[i?"unshift":"push"](()=>{$=i,r(7,$)})}return t.$$set=i=>{"auto"in i&&r(0,s=i.auto),"challengeurl"in i&&r(19,u=i.challengeurl),"challengejson"in i&&r(20,a=i.challengejson),"debug"in i&&r(12,f=i.debug),"expire"in i&&r(13,x=i.expire),"hidefooter"in i&&r(1,m=i.hidefooter),"hidelogo"in i&&r(2,N=i.hidelogo),"name"in i&&r(3,A=i.name),"maxnumber"in i&&r(14,S=i.maxnumber),"mockerror"in i&&r(15,_=i.mockerror),"refetchonexpire"in i&&r(16,O=i.refetchonexpire),"strings"in i&&r(21,Z=i.strings),"test"in i&&r(17,p=i.test),"workers"in i&&r(18,v=i.workers)},t.$$.update=()=>{t.$$.dirty[0]&1048576&&(n=a?Ce(a):void 0),t.$$.dirty[0]&2097152&&r(25,o=Z?Ce(Z):{}),t.$$.dirty[0]&33554432&&r(9,l={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.",...o}),t.$$.dirty[0]&48&&y("statechange",{payload:Y,state:H})},[s,m,N,A,Y,H,h,$,ce,l,Et,xt,f,x,S,_,O,p,v,u,a,Z,Ct,q,U,o,Lt,Rt]}class Le extends it{constructor(e){super(),rt(this,e,_t,wt,je,{auto:0,challengeurl:19,challengejson:20,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,refetchonexpire:16,strings:21,test:17,workers:18,configure:22,reset:23,verify:24},ht,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),E()}get challengeurl(){return this.$$.ctx[19]}set challengeurl(e){this.$$set({challengeurl:e}),E()}get challengejson(){return this.$$.ctx[20]}set challengejson(e){this.$$set({challengejson:e}),E()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),E()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),E()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),E()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),E()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),E()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),E()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),E()}get refetchonexpire(){return this.$$.ctx[16]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),E()}get strings(){return this.$$.ctx[21]}set strings(e){this.$$set({strings:e}),E()}get test(){return this.$$.ctx[17]}set test(e){this.$$set({test:e}),E()}get workers(){return this.$$.ctx[18]}set workers(e){this.$$set({workers:e}),E()}get configure(){return this.$$.ctx[22]}get reset(){return this.$$.ctx[23]}get verify(){return this.$$.ctx[24]}}return customElements.define("altcha-widget",nt(Le,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),j.Altcha=Le,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"}),j}({}); +var altcha=function(j){"use strict";var Mt=Object.defineProperty;var St=(j,L,P)=>L in j?Mt(j,L,{enumerable:!0,configurable:!0,writable:!0,value:P}):j[L]=P;var M=(j,L,P)=>(St(j,typeof L!="symbol"?L+"":L,P),P);function L(){}function P(t){return t()}function ae(){return Object.create(null)}function K(t){t.forEach(P)}function he(t){return typeof t=="function"}function je(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ve(t){return Object.keys(t).length===0}function b(t,e){t.appendChild(e)}function Ze(t,e,r){const n=He(t);if(!n.getElementById(e)){const o=w("style");o.id=e,o.textContent=r,Pe(n,o)}}function He(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Pe(t,e){return b(t.head||t,e),e.sheet}function I(t,e,r){t.insertBefore(e,r||null)}function R(t){t.parentNode&&t.parentNode.removeChild(t)}function w(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Fe(t){return document.createTextNode(t)}function F(){return Fe(" ")}function re(t,e,r,n){return t.addEventListener(e,r,n),()=>t.removeEventListener(e,r,n)}function c(t,e,r){r==null?t.removeAttribute(e):t.getAttribute(e)!==r&&t.setAttribute(e,r)}function Oe(t){return Array.from(t.childNodes)}function de(t,e,r){t.classList.toggle(e,!!r)}function We(t,e,{bubbles:r=!1,cancelable:n=!1}={}){return new CustomEvent(t,{detail:e,bubbles:r,cancelable:n})}function De(t){const e={};return t.childNodes.forEach(r=>{e[r.slot||"default"]=!0}),e}let J;function z(t){J=t}function ne(){if(!J)throw new Error("Function called outside component initialization");return J}function Be(t){ne().$$.on_mount.push(t)}function Ye(t){ne().$$.on_destroy.push(t)}function Ue(){const t=ne();return(e,r,{cancelable:n=!1}={})=>{const o=t.$$.callbacks[e];if(o){const l=We(e,r,{cancelable:n});return o.slice().forEach(s=>{s.call(t,l)}),!l.defaultPrevented}return!0}}const W=[],ie=[];let D=[];const ge=[],be=Promise.resolve();let oe=!1;function me(){oe||(oe=!0,be.then(E))}function Xe(){return me(),be}function le(t){D.push(t)}const se=new Set;let B=0;function E(){if(B!==0)return;const t=J;do{try{for(;Bt.indexOf(n)===-1?e.push(n):r.push(n)),r.forEach(n=>n()),D=e}const ze=new Set;function Qe(t,e){t&&t.i&&(ze.delete(t),t.i(e))}function qe(t,e,r){const{fragment:n,after_update:o}=t.$$;n&&n.m(e,r),le(()=>{const l=t.$$.on_mount.map(P).filter(he);t.$$.on_destroy?t.$$.on_destroy.push(...l):K(l),t.$$.on_mount=[]}),o.forEach(le)}function et(t,e){const r=t.$$;r.fragment!==null&&(Je(r.after_update),K(r.on_destroy),r.fragment&&r.fragment.d(e),r.on_destroy=r.fragment=null,r.ctx=[])}function tt(t,e){t.$$.dirty[0]===-1&&(W.push(t),me(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const S=A.length?A[0]:N;return f.ctx&&o(f.ctx[m],f.ctx[m]=S)&&(!f.skip_bound&&f.bound[m]&&f.bound[m](S),x&&tt(t,m)),N}):[],f.update(),x=!0,K(f.before_update),f.fragment=n?n(f.ctx):!1,e.target){if(e.hydrate){const m=Oe(e.target);f.fragment&&f.fragment.l(m),m.forEach(R)}else f.fragment&&f.fragment.c();e.intro&&Qe(t.$$.fragment),qe(t,e.target,e.anchor),E()}z(a)}let ve;typeof HTMLElement=="function"&&(ve=class extends HTMLElement{constructor(e,r,n){super();M(this,"$$ctor");M(this,"$$s");M(this,"$$c");M(this,"$$cn",!1);M(this,"$$d",{});M(this,"$$r",!1);M(this,"$$p_d",{});M(this,"$$l",{});M(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=r,n&&this.attachShadow({mode:"open"})}addEventListener(e,r,n){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(r),this.$$c){const o=this.$$c.$on(e,r);this.$$l_u.set(r,o)}super.addEventListener(e,r,n)}removeEventListener(e,r,n){if(super.removeEventListener(e,r,n),this.$$c){const o=this.$$l_u.get(r);o&&(o(),this.$$l_u.delete(r))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(l){return()=>{let s;return{c:function(){s=w("slot"),l!=="default"&&c(s,"name",l)},m:function(f,x){I(f,s,x)},d:function(f){f&&R(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const r={},n=De(this);for(const l of this.$$s)l in n&&(r[l]=[e(l)]);for(const l of this.attributes){const s=this.$$g_p(l.name);s in this.$$d||(this.$$d[s]=Q(s,l.value,this.$$p_d,"toProp"))}for(const l in this.$$p_d)!(l in this.$$d)&&this[l]!==void 0&&(this.$$d[l]=this[l],delete this[l]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:r,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const l in this.$$p_d)if(this.$$d[l]=this.$$c.$$.ctx[this.$$c.$$.props[l]],this.$$p_d[l].reflect){const s=Q(l,this.$$d[l],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[l].attribute||l):this.setAttribute(this.$$p_d[l].attribute||l,s)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const l in this.$$l)for(const s of this.$$l[l]){const u=this.$$c.$on(l,s);this.$$l_u.set(s,u)}this.$$l={}}}attributeChangedCallback(e,r,n){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Q(e,n,this.$$p_d,"toProp"),(o=this.$$c)==null||o.$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(r=>this.$$p_d[r].attribute===e||!this.$$p_d[r].attribute&&r.toLowerCase()===e)||e}});function Q(t,e,r,n){var l;const o=(l=r[t])==null?void 0:l.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!n||!r[t])return e;if(n==="toAttribute")switch(o){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(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function nt(t,e,r,n,o,l){let s=class extends ve{constructor(){super(t,r,o),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(u=>(e[u].attribute||u).toLowerCase())}};return Object.keys(e).forEach(u=>{Object.defineProperty(s.prototype,u,{get(){return this.$$c&&u in this.$$c?this.$$c[u]:this.$$d[u]},set(a){var f;a=Q(u,a,e),this.$$d[u]=a,(f=this.$$c)==null||f.$set({[u]:a})}})}),n.forEach(u=>{Object.defineProperty(s.prototype,u,{get(){var a;return(a=this.$$c)==null?void 0:a[u]}})}),l&&(s=l(s)),t.element=s,s}class it{constructor(){M(this,"$$");M(this,"$$set")}$destroy(){et(this,1),this.$destroy=L}$on(e,r){if(!he(r))return L;const n=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return n.push(r),()=>{const o=n.indexOf(r);o!==-1&&n.splice(o,1)}}$set(e){this.$$set&&!Ve(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const ot="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ot);const we="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+aT9zKG51bGwpOmgoZSxsLG8pLnRoZW4odz0+e3c9PT10P3Moe251bWJlcjpsLHRvb2s6RGF0ZS5ub3coKS1yfSk6ZChsKzEpfSkuY2F0Y2goYyl9O2QocCl9KSxjb250cm9sbGVyOmF9fWxldCBuO29ubWVzc2FnZT1hc3luYyB0PT57Y29uc3R7dHlwZTplLHBheWxvYWQ6b309dC5kYXRhO2lmKGU9PT0iYWJvcnQiKW49PW51bGx8fG4uYWJvcnQoKSxuPXZvaWQgMDtlbHNlIGlmKGU9PT0id29yayIpe2NvbnN0e2FsZzppLGNoYWxsZW5nZTpwLG1heDphLHNhbHQ6dSxzdGFydDpzfT1vfHx7fSxjPW0ocCx1LGksYSxzKTtuPWMuY29udHJvbGxlcixjLnByb21pc2UudGhlbihyPT57c2VsZi5wb3N0TWVzc2FnZShyJiZ7Li4ucix3b3JrZXI6ITB9KX0pfX19KSgpOwo=",lt=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),_e=typeof window<"u"&&window.Blob&&new Blob([lt(we)],{type:"text/javascript;charset=utf-8"});function st(t){let e;try{if(e=_e&&(window.URL||window.webkitURL).createObjectURL(_e),!e)throw"";const r=new Worker(e,{name:t==null?void 0:t.name});return r.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),r}catch{return new Worker("data:text/javascript;base64,"+we,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const ct=new TextEncoder;function ut(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ft(t,e="SHA-256",r=1e5){const n=Date.now().toString(16);t||(t=Math.round(Math.random()*r));const o=await pe(n,t,e);return{algorithm:e,challenge:o,salt:n,signature:""}}async function pe(t,e,r){return ut(await crypto.subtle.digest(r.toUpperCase(),ct.encode(t+e)))}function at(t,e,r="SHA-256",n=1e6,o=0){const l=new AbortController;return{promise:new Promise((u,a)=>{const f=Date.now(),x=m=>{l.signal.aborted||m>n?u(null):pe(e,m,r).then(N=>{N===t?u({number:m,took:Date.now()-f}):x(m+1)}).catch(a)};x(o)}),controller:l}}var g=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(g||{});function ht(t){Ze(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function ye(t){let e,r,n;return{c(){e=V("svg"),r=V("path"),n=V("path"),c(r,"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(r,"fill","currentColor"),c(r,"opacity",".25"),c(n,"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(n,"fill","currentColor"),c(n,"class","altcha-spinner svelte-vuofbg"),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(o,l){I(o,e,l),b(e,r),b(e,n)},d(o){o&&R(e)}}}function dt(t){let e,r=t[9].label+"",n;return{c(){e=w("label"),c(e,"for",n=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(o,l){I(o,e,l),e.innerHTML=r},p(o,l){l[0]&512&&r!==(r=o[9].label+"")&&(e.innerHTML=r),l[0]&8&&n!==(n=o[3]+"_checkbox")&&c(e,"for",n)},d(o){o&&R(e)}}}function gt(t){let e,r=t[9].verifying+"";return{c(){e=w("span")},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].verifying+"")&&(e.innerHTML=r)},d(n){n&&R(e)}}}function bt(t){let e,r=t[9].verified+"",n,o;return{c(){e=w("span"),n=F(),o=w("input"),c(o,"type","hidden"),c(o,"name",t[3]),o.value=t[4]},m(l,s){I(l,e,s),e.innerHTML=r,I(l,n,s),I(l,o,s)},p(l,s){s[0]&512&&r!==(r=l[9].verified+"")&&(e.innerHTML=r),s[0]&8&&c(o,"name",l[3]),s[0]&16&&(o.value=l[4])},d(l){l&&(R(e),R(n),R(o))}}}function ke(t){let e,r,n,o,l,s;return{c(){e=w("div"),r=w("a"),n=V("svg"),o=V("path"),l=V("path"),s=V("path"),c(o,"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(o,"fill","currentColor"),c(l,"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(l,"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(n,"width","22"),c(n,"height","22"),c(n,"viewBox","0 0 20 20"),c(n,"fill","none"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(r,"href",xe),c(r,"target","_blank"),c(r,"class","altcha-logo svelte-vuofbg")},m(u,a){I(u,e,a),b(e,r),b(r,n),b(n,o),b(n,l),b(n,s)},p:L,d(u){u&&R(e)}}}function $e(t){let e,r,n,o;function l(a,f){return a[5]===g.EXPIRED?vt:mt}let s=l(t),u=s(t);return{c(){e=w("div"),r=V("svg"),n=V("path"),o=F(),u.c(),c(n,"stroke-linecap","round"),c(n,"stroke-linejoin","round"),c(n,"d","M6 18L18 6M6 6l12 12"),c(r,"width","14"),c(r,"height","14"),c(r,"xmlns","http://www.w3.org/2000/svg"),c(r,"fill","none"),c(r,"viewBox","0 0 24 24"),c(r,"stroke-width","1.5"),c(r,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(a,f){I(a,e,f),b(e,r),b(r,n),b(e,o),u.m(e,null)},p(a,f){s===(s=l(a))&&u?u.p(a,f):(u.d(1),u=s(a),u&&(u.c(),u.m(e,null)))},d(a){a&&R(e),u.d()}}}function mt(t){let e,r=t[9].error+"";return{c(){e=w("div"),c(e,"title",t[8])},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].error+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&R(e)}}}function vt(t){let e,r=t[9].expired+"";return{c(){e=w("div"),c(e,"title",t[8])},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].expired+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&R(e)}}}function Ee(t){let e,r,n=t[9].footer+"";return{c(){e=w("div"),r=w("div"),c(r,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(o,l){I(o,e,l),b(e,r),r.innerHTML=n},p(o,l){l[0]&512&&n!==(n=o[9].footer+"")&&(r.innerHTML=n)},d(o){o&&R(e)}}}function wt(t){let e,r,n,o,l,s,u,a,f,x,m,N,A,S,_=t[5]===g.VERIFYING&&ye();function O(h,$){return h[5]===g.VERIFIED?bt:h[5]===g.VERIFYING?gt:dt}let Z=O(t),p=Z(t),v=t[2]!==!0&&ke(),y=(t[8]||t[5]===g.EXPIRED)&&$e(t),k=t[9].footer&&t[1]!==!0&&Ee(t);return{c(){e=w("div"),r=w("div"),_&&_.c(),n=F(),o=w("div"),l=w("input"),a=F(),f=w("div"),p.c(),x=F(),v&&v.c(),m=F(),y&&y.c(),N=F(),k&&k.c(),c(l,"type","checkbox"),c(l,"id",s=t[3]+"_checkbox"),l.required=u=t[0]!=="onsubmit",c(l,"class","svelte-vuofbg"),c(o,"class","altcha-checkbox svelte-vuofbg"),de(o,"altcha-hidden",t[5]===g.VERIFYING),c(f,"class","altcha-label svelte-vuofbg"),c(r,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,$){I(h,e,$),b(e,r),_&&_.m(r,null),b(r,n),b(r,o),b(o,l),l.checked=t[6],b(r,a),b(r,f),p.m(f,null),b(r,x),v&&v.m(r,null),b(e,m),y&&y.m(e,null),b(e,N),k&&k.m(e,null),t[27](e),A||(S=[re(l,"change",t[26]),re(l,"change",t[10]),re(l,"invalid",t[11])],A=!0)},p(h,$){h[5]===g.VERIFYING?_||(_=ye(),_.c(),_.m(r,n)):_&&(_.d(1),_=null),$[0]&8&&s!==(s=h[3]+"_checkbox")&&c(l,"id",s),$[0]&1&&u!==(u=h[0]!=="onsubmit")&&(l.required=u),$[0]&64&&(l.checked=h[6]),$[0]&32&&de(o,"altcha-hidden",h[5]===g.VERIFYING),Z===(Z=O(h))&&p?p.p(h,$):(p.d(1),p=Z(h),p&&(p.c(),p.m(f,null))),h[2]!==!0?v?v.p(h,$):(v=ke(),v.c(),v.m(r,null)):v&&(v.d(1),v=null),h[8]||h[5]===g.EXPIRED?y?y.p(h,$):(y=$e(h),y.c(),y.m(e,N)):y&&(y.d(1),y=null),h[9].footer&&h[1]!==!0?k?k.p(h,$):(k=Ee(h),k.c(),k.m(e,null)):k&&(k.d(1),k=null),$[0]&32&&c(e,"data-state",h[5])},i:L,o:L,d(h){h&&R(e),_&&_.d(),p.d(),v&&v.d(),y&&y.d(),k&&k.d(),t[27](null),A=!1,K(S)}}}const xe="https://altcha.org/";function Ce(t){return JSON.parse(t)}function _t(t,e,r){let n,o,l,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:a=void 0}=e,{debug:f=!1}=e,{expire:x=void 0}=e,{hidefooter:m=!1}=e,{hidelogo:N=!1}=e,{name:A="altcha"}=e,{maxnumber:S=1e6}=e,{mockerror:_=!1}=e,{refetchonexpire:O=!0}=e,{strings:Z=void 0}=e,{test:p=!1}=e,{workers:v=navigator.hardwareConcurrency||8}=e;const y=Ue(),k=["SHA-256","SHA-384","SHA-512"];let h=!1,$,T=null,ce=null,Y=null,H=g.UNVERIFIED,ue;Ye(()=>{T&&(T.removeEventListener("submit",Re),T.removeEventListener("reset",Ie),T=null)}),Be(()=>{C("mounted","0.2.2"),C("workers",v),p&&C("using test mode"),x&&fe(x),s!==void 0&&C("auto",s),T=$.closest("form"),T&&(T.addEventListener("submit",Re),T.addEventListener("reset",Ie)),s==="onload"&&U()});function C(...i){(f||i.some(d=>d instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function Re(i){T&&s==="onsubmit"&&H===g.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),U().then(()=>{T==null||T.requestSubmit()}))}function Ie(){q()}function pt(i,d){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:d.number,salt:i.salt,signature:i.signature,test:p?!0:void 0,took:d.took}))}function Ne(i){if(!i.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(i.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!k.includes(i.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${k.join(", ")}`);if(!i.challenge||i.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!i.salt||i.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function yt(){if(_)throw C("mocking error"),new Error("Mocked error.");if(n)return C("using provided json data"),n;if(p)return C("generating test challenge"),ft();{if(!u)throw new Error("Attribute challengeurl not set.");C("fetching challenge from",u);const i=await fetch(u);if(i.status!==200)throw new Error(`Server responded with ${i.status}.`);const d=i.headers.get("Expires");if(d!=null&&d.length){const X=Date.parse(d);isNaN(X)||fe(X-Date.now())}return i.json()}}function Te(){u&&O&&H===g.VERIFIED?U():q(g.EXPIRED,l.expired)}async function kt(i){let d=null;if("Worker"in window){try{d=await $t(i.challenge,i.salt,i.algorithm)}catch(X){C(X)}if((d==null?void 0:d.number)!==void 0)return{data:i,solution:d}}return{data:i,solution:await at(i.challenge,i.salt,i.algorithm,S).promise}}async function $t(i,d,X,ee=Math.ceil(v)){const te=[];if(ee<1)throw new Error("Wrong number of workers configured.");if(ee>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let G=0;G{const Se=Nt*Me;return new Promise(Tt=>{G.addEventListener("message",Ae=>{if(Ae.data)for(const Ge of te)Ge!==G&&Ge.postMessage({type:"abort"});Tt(Ae.data)}),G.postMessage({payload:{alg:X,challenge:i,max:Se+Me,salt:d,start:Se},type:"work"})})}));for(const G of te)G.terminate();return It.find(G=>!!G)||null}function Et(){[g.UNVERIFIED,g.ERROR,g.EXPIRED].includes(H)?U():r(6,h=!0)}function xt(){H===g.VERIFYING&&alert(l.waitAlert)}function fe(i){C("expire",i),clearTimeout(ue),i<1?Te():ue=setTimeout(Te,i)}function Ct(i){i.auto!==void 0&&(r(0,s=i.auto),s==="onload"&&U()),i.expire!==void 0&&(fe(i.expire),r(13,x=i.expire)),i.challenge&&(Ne(i.challenge),n=i.challenge),i.debug!==void 0&&r(12,f=!!i.debug),i.hidefooter!==void 0&&r(1,m=!!i.hidefooter),i.hidelogo!==void 0&&r(2,N=!!i.hidelogo),i.maxnumber!==void 0&&r(14,S=+i.maxnumber),i.mockerror!==void 0&&r(15,_=!!i.mockerror),i.name!==void 0&&r(3,A=i.name),i.refetchonexpire!==void 0&&r(16,O=!!i.refetchonexpire),i.strings&&r(25,o=i.strings),i.test!==void 0&&r(17,p=!!i.test),i.workers!==void 0&&r(18,v=+i.workers)}function q(i=g.UNVERIFIED,d=null){clearTimeout(ue),r(6,h=!1),r(8,ce=d),r(4,Y=null),r(5,H=i)}async function U(){return q(g.VERIFYING),yt().then(i=>(Ne(i),C("challenge",i),kt(i))).then(({data:i,solution:d})=>{if(C("solution",d),(d==null?void 0:d.number)!==void 0)C("verified"),r(5,H=g.VERIFIED),r(6,h=!0),r(4,Y=pt(i,d)),C("payload",Y),Xe().then(()=>{y("verified",{payload:Y})});else throw new Error("Unexpected result returned.")}).catch(i=>{C(i),r(5,H=g.ERROR),r(6,h=!1),r(8,ce=i.message)})}function Lt(){h=this.checked,r(6,h)}function Rt(i){ie[i?"unshift":"push"](()=>{$=i,r(7,$)})}return t.$$set=i=>{"auto"in i&&r(0,s=i.auto),"challengeurl"in i&&r(19,u=i.challengeurl),"challengejson"in i&&r(20,a=i.challengejson),"debug"in i&&r(12,f=i.debug),"expire"in i&&r(13,x=i.expire),"hidefooter"in i&&r(1,m=i.hidefooter),"hidelogo"in i&&r(2,N=i.hidelogo),"name"in i&&r(3,A=i.name),"maxnumber"in i&&r(14,S=i.maxnumber),"mockerror"in i&&r(15,_=i.mockerror),"refetchonexpire"in i&&r(16,O=i.refetchonexpire),"strings"in i&&r(21,Z=i.strings),"test"in i&&r(17,p=i.test),"workers"in i&&r(18,v=i.workers)},t.$$.update=()=>{t.$$.dirty[0]&1048576&&(n=a?Ce(a):void 0),t.$$.dirty[0]&2097152&&r(25,o=Z?Ce(Z):{}),t.$$.dirty[0]&33554432&&r(9,l={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.",...o}),t.$$.dirty[0]&48&&y("statechange",{payload:Y,state:H})},[s,m,N,A,Y,H,h,$,ce,l,Et,xt,f,x,S,_,O,p,v,u,a,Z,Ct,q,U,o,Lt,Rt]}class Le extends it{constructor(e){super(),rt(this,e,_t,wt,je,{auto:0,challengeurl:19,challengejson:20,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,refetchonexpire:16,strings:21,test:17,workers:18,configure:22,reset:23,verify:24},ht,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),E()}get challengeurl(){return this.$$.ctx[19]}set challengeurl(e){this.$$set({challengeurl:e}),E()}get challengejson(){return this.$$.ctx[20]}set challengejson(e){this.$$set({challengejson:e}),E()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),E()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),E()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),E()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),E()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),E()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),E()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),E()}get refetchonexpire(){return this.$$.ctx[16]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),E()}get strings(){return this.$$.ctx[21]}set strings(e){this.$$set({strings:e}),E()}get test(){return this.$$.ctx[17]}set test(e){this.$$set({test:e}),E()}get workers(){return this.$$.ctx[18]}set workers(e){this.$$set({workers:e}),E()}get configure(){return this.$$.ctx[22]}get reset(){return this.$$.ctx[23]}get verify(){return this.$$.ctx[24]}}return customElements.define("altcha-widget",nt(Le,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),j.Altcha=Le,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"}),j}({}); diff --git a/dist/altcha.js b/dist/altcha.js index ea3814e..c7a3d33 100644 --- a/dist/altcha.js +++ b/dist/altcha.js @@ -856,7 +856,7 @@ function Tt(t, e, r) { it(() => { N && (N.removeEventListener("submit", ue), N.removeEventListener("reset", fe), N = null); }), nt(() => { - C("mounted", "0.2.1"), C("workers", v), p && C("using test mode"), E && re(E), s !== void 0 && C("auto", s), N = $.closest("form"), N && (N.addEventListener("submit", ue), N.addEventListener("reset", fe)), s === "onload" && P(); + C("mounted", "0.2.2"), C("workers", v), p && C("using test mode"), E && re(E), s !== void 0 && C("auto", s), N = $.closest("form"), N && (N.addEventListener("submit", ue), N.addEventListener("reset", fe)), s === "onload" && P(); }); function C(...i) { (f || i.some((d) => d instanceof Error)) && console[i[0] instanceof Error ? "error" : "log"]("ALTCHA", ...i); diff --git a/dist/altcha.umd.cjs b/dist/altcha.umd.cjs index a0c74a2..d7b29b9 100644 --- a/dist/altcha.umd.cjs +++ b/dist/altcha.umd.cjs @@ -1 +1 @@ -(function(N,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(N=typeof globalThis<"u"?globalThis:N||self,w(N.altcha={}))})(this,function(N){"use strict";var Mt=Object.defineProperty;var St=(N,w,P)=>w in N?Mt(N,w,{enumerable:!0,configurable:!0,writable:!0,value:P}):N[w]=P;var S=(N,w,P)=>(St(N,typeof w!="symbol"?w+"":w,P),P);function w(){}function P(t){return t()}function ae(){return Object.create(null)}function K(t){t.forEach(P)}function he(t){return typeof t=="function"}function Ge(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ve(t){return Object.keys(t).length===0}function b(t,e){t.appendChild(e)}function Ze(t,e,r){const n=He(t);if(!n.getElementById(e)){const o=_("style");o.id=e,o.textContent=r,Pe(n,o)}}function He(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Pe(t,e){return b(t.head||t,e),e.sheet}function I(t,e,r){t.insertBefore(e,r||null)}function R(t){t.parentNode&&t.parentNode.removeChild(t)}function _(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Fe(t){return document.createTextNode(t)}function F(){return Fe(" ")}function re(t,e,r,n){return t.addEventListener(e,r,n),()=>t.removeEventListener(e,r,n)}function c(t,e,r){r==null?t.removeAttribute(e):t.getAttribute(e)!==r&&t.setAttribute(e,r)}function Oe(t){return Array.from(t.childNodes)}function de(t,e,r){t.classList.toggle(e,!!r)}function We(t,e,{bubbles:r=!1,cancelable:n=!1}={}){return new CustomEvent(t,{detail:e,bubbles:r,cancelable:n})}function De(t){const e={};return t.childNodes.forEach(r=>{e[r.slot||"default"]=!0}),e}let J;function z(t){J=t}function ne(){if(!J)throw new Error("Function called outside component initialization");return J}function Be(t){ne().$$.on_mount.push(t)}function Ye(t){ne().$$.on_destroy.push(t)}function Ue(){const t=ne();return(e,r,{cancelable:n=!1}={})=>{const o=t.$$.callbacks[e];if(o){const l=We(e,r,{cancelable:n});return o.slice().forEach(s=>{s.call(t,l)}),!l.defaultPrevented}return!0}}const W=[],ie=[];let D=[];const ge=[],be=Promise.resolve();let oe=!1;function me(){oe||(oe=!0,be.then(x))}function Xe(){return me(),be}function le(t){D.push(t)}const se=new Set;let B=0;function x(){if(B!==0)return;const t=J;do{try{for(;Bt.indexOf(n)===-1?e.push(n):r.push(n)),r.forEach(n=>n()),D=e}const ze=new Set;function Qe(t,e){t&&t.i&&(ze.delete(t),t.i(e))}function qe(t,e,r){const{fragment:n,after_update:o}=t.$$;n&&n.m(e,r),le(()=>{const l=t.$$.on_mount.map(P).filter(he);t.$$.on_destroy?t.$$.on_destroy.push(...l):K(l),t.$$.on_mount=[]}),o.forEach(le)}function et(t,e){const r=t.$$;r.fragment!==null&&(Je(r.after_update),K(r.on_destroy),r.fragment&&r.fragment.d(e),r.on_destroy=r.fragment=null,r.ctx=[])}function tt(t,e){t.$$.dirty[0]===-1&&(W.push(t),me(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const j=A.length?A[0]:T;return u.ctx&&o(u.ctx[m],u.ctx[m]=j)&&(!u.skip_bound&&u.bound[m]&&u.bound[m](j),C&&tt(t,m)),T}):[],u.update(),C=!0,K(u.before_update),u.fragment=n?n(u.ctx):!1,e.target){if(e.hydrate){const m=Oe(e.target);u.fragment&&u.fragment.l(m),m.forEach(R)}else u.fragment&&u.fragment.c();e.intro&&Qe(t.$$.fragment),qe(t,e.target,e.anchor),x()}z(a)}let ve;typeof HTMLElement=="function"&&(ve=class extends HTMLElement{constructor(e,r,n){super();S(this,"$$ctor");S(this,"$$s");S(this,"$$c");S(this,"$$cn",!1);S(this,"$$d",{});S(this,"$$r",!1);S(this,"$$p_d",{});S(this,"$$l",{});S(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=r,n&&this.attachShadow({mode:"open"})}addEventListener(e,r,n){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(r),this.$$c){const o=this.$$c.$on(e,r);this.$$l_u.set(r,o)}super.addEventListener(e,r,n)}removeEventListener(e,r,n){if(super.removeEventListener(e,r,n),this.$$c){const o=this.$$l_u.get(r);o&&(o(),this.$$l_u.delete(r))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(l){return()=>{let s;return{c:function(){s=_("slot"),l!=="default"&&c(s,"name",l)},m:function(u,C){I(u,s,C)},d:function(u){u&&R(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const r={},n=De(this);for(const l of this.$$s)l in n&&(r[l]=[e(l)]);for(const l of this.attributes){const s=this.$$g_p(l.name);s in this.$$d||(this.$$d[s]=Q(s,l.value,this.$$p_d,"toProp"))}for(const l in this.$$p_d)!(l in this.$$d)&&this[l]!==void 0&&(this.$$d[l]=this[l],delete this[l]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:r,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const l in this.$$p_d)if(this.$$d[l]=this.$$c.$$.ctx[this.$$c.$$.props[l]],this.$$p_d[l].reflect){const s=Q(l,this.$$d[l],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[l].attribute||l):this.setAttribute(this.$$p_d[l].attribute||l,s)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const l in this.$$l)for(const s of this.$$l[l]){const f=this.$$c.$on(l,s);this.$$l_u.set(s,f)}this.$$l={}}}attributeChangedCallback(e,r,n){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Q(e,n,this.$$p_d,"toProp"),(o=this.$$c)==null||o.$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(r=>this.$$p_d[r].attribute===e||!this.$$p_d[r].attribute&&r.toLowerCase()===e)||e}});function Q(t,e,r,n){var l;const o=(l=r[t])==null?void 0:l.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!n||!r[t])return e;if(n==="toAttribute")switch(o){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(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function nt(t,e,r,n,o,l){let s=class extends ve{constructor(){super(t,r,o),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 u;a=Q(f,a,e),this.$$d[f]=a,(u=this.$$c)==null||u.$set({[f]:a})}})}),n.forEach(f=>{Object.defineProperty(s.prototype,f,{get(){var a;return(a=this.$$c)==null?void 0:a[f]}})}),l&&(s=l(s)),t.element=s,s}class it{constructor(){S(this,"$$");S(this,"$$set")}$destroy(){et(this,1),this.$destroy=w}$on(e,r){if(!he(r))return w;const n=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return n.push(r),()=>{const o=n.indexOf(r);o!==-1&&n.splice(o,1)}}$set(e){this.$$set&&!Ve(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const ot="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ot);const we="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+aT9zKG51bGwpOmgoZSxsLG8pLnRoZW4odz0+e3c9PT10P3Moe251bWJlcjpsLHRvb2s6RGF0ZS5ub3coKS1yfSk6ZChsKzEpfSkuY2F0Y2goYyl9O2QocCl9KSxjb250cm9sbGVyOmF9fWxldCBuO29ubWVzc2FnZT1hc3luYyB0PT57Y29uc3R7dHlwZTplLHBheWxvYWQ6b309dC5kYXRhO2lmKGU9PT0iYWJvcnQiKW49PW51bGx8fG4uYWJvcnQoKSxuPXZvaWQgMDtlbHNlIGlmKGU9PT0id29yayIpe2NvbnN0e2FsZzppLGNoYWxsZW5nZTpwLG1heDphLHNhbHQ6dSxzdGFydDpzfT1vfHx7fSxjPW0ocCx1LGksYSxzKTtuPWMuY29udHJvbGxlcixjLnByb21pc2UudGhlbihyPT57c2VsZi5wb3N0TWVzc2FnZShyJiZ7Li4ucix3b3JrZXI6ITB9KX0pfX19KSgpOwo=",lt=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),_e=typeof window<"u"&&window.Blob&&new Blob([lt(we)],{type:"text/javascript;charset=utf-8"});function st(t){let e;try{if(e=_e&&(window.URL||window.webkitURL).createObjectURL(_e),!e)throw"";const r=new Worker(e,{name:t==null?void 0:t.name});return r.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),r}catch{return new Worker("data:text/javascript;base64,"+we,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const ct=new TextEncoder;function ft(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ut(t,e="SHA-256",r=1e5){const n=Date.now().toString(16);t||(t=Math.round(Math.random()*r));const o=await pe(n,t,e);return{algorithm:e,challenge:o,salt:n,signature:""}}async function pe(t,e,r){return ft(await crypto.subtle.digest(r.toUpperCase(),ct.encode(t+e)))}function at(t,e,r="SHA-256",n=1e6,o=0){const l=new AbortController;return{promise:new Promise((f,a)=>{const u=Date.now(),C=m=>{l.signal.aborted||m>n?f(null):pe(e,m,r).then(T=>{T===t?f({number:m,took:Date.now()-u}):C(m+1)}).catch(a)};C(o)}),controller:l}}var g=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(g||{});function ht(t){Ze(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function ye(t){let e,r,n;return{c(){e=V("svg"),r=V("path"),n=V("path"),c(r,"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(r,"fill","currentColor"),c(r,"opacity",".25"),c(n,"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(n,"fill","currentColor"),c(n,"class","altcha-spinner svelte-vuofbg"),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(o,l){I(o,e,l),b(e,r),b(e,n)},d(o){o&&R(e)}}}function dt(t){let e,r=t[9].label+"",n;return{c(){e=_("label"),c(e,"for",n=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(o,l){I(o,e,l),e.innerHTML=r},p(o,l){l[0]&512&&r!==(r=o[9].label+"")&&(e.innerHTML=r),l[0]&8&&n!==(n=o[3]+"_checkbox")&&c(e,"for",n)},d(o){o&&R(e)}}}function gt(t){let e,r=t[9].verifying+"";return{c(){e=_("span")},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].verifying+"")&&(e.innerHTML=r)},d(n){n&&R(e)}}}function bt(t){let e,r=t[9].verified+"",n,o;return{c(){e=_("span"),n=F(),o=_("input"),c(o,"type","hidden"),c(o,"name",t[3]),o.value=t[4]},m(l,s){I(l,e,s),e.innerHTML=r,I(l,n,s),I(l,o,s)},p(l,s){s[0]&512&&r!==(r=l[9].verified+"")&&(e.innerHTML=r),s[0]&8&&c(o,"name",l[3]),s[0]&16&&(o.value=l[4])},d(l){l&&(R(e),R(n),R(o))}}}function ke(t){let e,r,n,o,l,s;return{c(){e=_("div"),r=_("a"),n=V("svg"),o=V("path"),l=V("path"),s=V("path"),c(o,"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(o,"fill","currentColor"),c(l,"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(l,"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(n,"width","22"),c(n,"height","22"),c(n,"viewBox","0 0 20 20"),c(n,"fill","none"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(r,"href",xe),c(r,"target","_blank"),c(r,"class","altcha-logo svelte-vuofbg")},m(f,a){I(f,e,a),b(e,r),b(r,n),b(n,o),b(n,l),b(n,s)},p:w,d(f){f&&R(e)}}}function $e(t){let e,r,n,o;function l(a,u){return a[5]===g.EXPIRED?vt:mt}let s=l(t),f=s(t);return{c(){e=_("div"),r=V("svg"),n=V("path"),o=F(),f.c(),c(n,"stroke-linecap","round"),c(n,"stroke-linejoin","round"),c(n,"d","M6 18L18 6M6 6l12 12"),c(r,"width","14"),c(r,"height","14"),c(r,"xmlns","http://www.w3.org/2000/svg"),c(r,"fill","none"),c(r,"viewBox","0 0 24 24"),c(r,"stroke-width","1.5"),c(r,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(a,u){I(a,e,u),b(e,r),b(r,n),b(e,o),f.m(e,null)},p(a,u){s===(s=l(a))&&f?f.p(a,u):(f.d(1),f=s(a),f&&(f.c(),f.m(e,null)))},d(a){a&&R(e),f.d()}}}function mt(t){let e,r=t[9].error+"";return{c(){e=_("div"),c(e,"title",t[8])},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].error+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&R(e)}}}function vt(t){let e,r=t[9].expired+"";return{c(){e=_("div"),c(e,"title",t[8])},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].expired+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&R(e)}}}function Ee(t){let e,r,n=t[9].footer+"";return{c(){e=_("div"),r=_("div"),c(r,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(o,l){I(o,e,l),b(e,r),r.innerHTML=n},p(o,l){l[0]&512&&n!==(n=o[9].footer+"")&&(r.innerHTML=n)},d(o){o&&R(e)}}}function wt(t){let e,r,n,o,l,s,f,a,u,C,m,T,A,j,p=t[5]===g.VERIFYING&&ye();function O(h,E){return h[5]===g.VERIFIED?bt:h[5]===g.VERIFYING?gt:dt}let Z=O(t),y=Z(t),v=t[2]!==!0&&ke(),k=(t[8]||t[5]===g.EXPIRED)&&$e(t),$=t[9].footer&&t[1]!==!0&&Ee(t);return{c(){e=_("div"),r=_("div"),p&&p.c(),n=F(),o=_("div"),l=_("input"),a=F(),u=_("div"),y.c(),C=F(),v&&v.c(),m=F(),k&&k.c(),T=F(),$&&$.c(),c(l,"type","checkbox"),c(l,"id",s=t[3]+"_checkbox"),l.required=f=t[0]!=="onsubmit",c(l,"class","svelte-vuofbg"),c(o,"class","altcha-checkbox svelte-vuofbg"),de(o,"altcha-hidden",t[5]===g.VERIFYING),c(u,"class","altcha-label svelte-vuofbg"),c(r,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,E){I(h,e,E),b(e,r),p&&p.m(r,null),b(r,n),b(r,o),b(o,l),l.checked=t[6],b(r,a),b(r,u),y.m(u,null),b(r,C),v&&v.m(r,null),b(e,m),k&&k.m(e,null),b(e,T),$&&$.m(e,null),t[27](e),A||(j=[re(l,"change",t[26]),re(l,"change",t[10]),re(l,"invalid",t[11])],A=!0)},p(h,E){h[5]===g.VERIFYING?p||(p=ye(),p.c(),p.m(r,n)):p&&(p.d(1),p=null),E[0]&8&&s!==(s=h[3]+"_checkbox")&&c(l,"id",s),E[0]&1&&f!==(f=h[0]!=="onsubmit")&&(l.required=f),E[0]&64&&(l.checked=h[6]),E[0]&32&&de(o,"altcha-hidden",h[5]===g.VERIFYING),Z===(Z=O(h))&&y?y.p(h,E):(y.d(1),y=Z(h),y&&(y.c(),y.m(u,null))),h[2]!==!0?v?v.p(h,E):(v=ke(),v.c(),v.m(r,null)):v&&(v.d(1),v=null),h[8]||h[5]===g.EXPIRED?k?k.p(h,E):(k=$e(h),k.c(),k.m(e,T)):k&&(k.d(1),k=null),h[9].footer&&h[1]!==!0?$?$.p(h,E):($=Ee(h),$.c(),$.m(e,null)):$&&($.d(1),$=null),E[0]&32&&c(e,"data-state",h[5])},i:w,o:w,d(h){h&&R(e),p&&p.d(),y.d(),v&&v.d(),k&&k.d(),$&&$.d(),t[27](null),A=!1,K(j)}}}const xe="https://altcha.org/";function Ce(t){return JSON.parse(t)}function _t(t,e,r){let n,o,l,{auto:s=void 0}=e,{challengeurl:f=void 0}=e,{challengejson:a=void 0}=e,{debug:u=!1}=e,{expire:C=void 0}=e,{hidefooter:m=!1}=e,{hidelogo:T=!1}=e,{name:A="altcha"}=e,{maxnumber:j=1e6}=e,{mockerror:p=!1}=e,{refetchonexpire:O=!0}=e,{strings:Z=void 0}=e,{test:y=!1}=e,{workers:v=navigator.hardwareConcurrency||8}=e;const k=Ue(),$=["SHA-256","SHA-384","SHA-512"];let h=!1,E,M=null,ce=null,Y=null,H=g.UNVERIFIED,fe;Ye(()=>{M&&(M.removeEventListener("submit",Re),M.removeEventListener("reset",Ie),M=null)}),Be(()=>{L("mounted","0.2.1"),L("workers",v),y&&L("using test mode"),C&&ue(C),s!==void 0&&L("auto",s),M=E.closest("form"),M&&(M.addEventListener("submit",Re),M.addEventListener("reset",Ie)),s==="onload"&&U()});function L(...i){(u||i.some(d=>d instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function Re(i){M&&s==="onsubmit"&&H===g.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),U().then(()=>{M==null||M.requestSubmit()}))}function Ie(){q()}function pt(i,d){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:d.number,salt:i.salt,signature:i.signature,test:y?!0:void 0,took:d.took}))}function Ne(i){if(!i.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(i.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!$.includes(i.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${$.join(", ")}`);if(!i.challenge||i.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!i.salt||i.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function yt(){if(p)throw L("mocking error"),new Error("Mocked error.");if(n)return L("using provided json data"),n;if(y)return L("generating test challenge"),ut();{if(!f)throw new Error("Attribute challengeurl not set.");L("fetching challenge from",f);const i=await fetch(f);if(i.status!==200)throw new Error(`Server responded with ${i.status}.`);const d=i.headers.get("Expires");if(d!=null&&d.length){const X=Date.parse(d);isNaN(X)||ue(X-Date.now())}return i.json()}}function Te(){f&&O&&H===g.VERIFIED?U():q(g.EXPIRED,l.expired)}async function kt(i){let d=null;if("Worker"in window){try{d=await $t(i.challenge,i.salt,i.algorithm)}catch(X){L(X)}if((d==null?void 0:d.number)!==void 0)return{data:i,solution:d}}return{data:i,solution:await at(i.challenge,i.salt,i.algorithm,j).promise}}async function $t(i,d,X,ee=Math.ceil(v)){const te=[];if(ee<1)throw new Error("Wrong number of workers configured.");if(ee>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let G=0;G{const Se=Nt*Me;return new Promise(Tt=>{G.addEventListener("message",je=>{if(je.data)for(const Ae of te)Ae!==G&&Ae.postMessage({type:"abort"});Tt(je.data)}),G.postMessage({payload:{alg:X,challenge:i,max:Se+Me,salt:d,start:Se},type:"work"})})}));for(const G of te)G.terminate();return It.find(G=>!!G)||null}function Et(){[g.UNVERIFIED,g.ERROR,g.EXPIRED].includes(H)?U():r(6,h=!0)}function xt(){H===g.VERIFYING&&alert(l.waitAlert)}function ue(i){L("expire",i),clearTimeout(fe),i<1?Te():fe=setTimeout(Te,i)}function Ct(i){i.auto!==void 0&&(r(0,s=i.auto),s==="onload"&&U()),i.expire!==void 0&&(ue(i.expire),r(13,C=i.expire)),i.challenge&&(Ne(i.challenge),n=i.challenge),i.debug!==void 0&&r(12,u=!!i.debug),i.hidefooter!==void 0&&r(1,m=!!i.hidefooter),i.hidelogo!==void 0&&r(2,T=!!i.hidelogo),i.maxnumber!==void 0&&r(14,j=+i.maxnumber),i.mockerror!==void 0&&r(15,p=!!i.mockerror),i.name!==void 0&&r(3,A=i.name),i.refetchonexpire!==void 0&&r(16,O=!!i.refetchonexpire),i.strings&&r(25,o=i.strings),i.test!==void 0&&r(17,y=!!i.test),i.workers!==void 0&&r(18,v=+i.workers)}function q(i=g.UNVERIFIED,d=null){clearTimeout(fe),r(6,h=!1),r(8,ce=d),r(4,Y=null),r(5,H=i)}async function U(){return q(g.VERIFYING),yt().then(i=>(Ne(i),L("challenge",i),kt(i))).then(({data:i,solution:d})=>{if(L("solution",d),(d==null?void 0:d.number)!==void 0)L("verified"),r(5,H=g.VERIFIED),r(6,h=!0),r(4,Y=pt(i,d)),L("payload",Y),Xe().then(()=>{k("verified",{payload:Y})});else throw new Error("Unexpected result returned.")}).catch(i=>{L(i),r(5,H=g.ERROR),r(6,h=!1),r(8,ce=i.message)})}function Lt(){h=this.checked,r(6,h)}function Rt(i){ie[i?"unshift":"push"](()=>{E=i,r(7,E)})}return t.$$set=i=>{"auto"in i&&r(0,s=i.auto),"challengeurl"in i&&r(19,f=i.challengeurl),"challengejson"in i&&r(20,a=i.challengejson),"debug"in i&&r(12,u=i.debug),"expire"in i&&r(13,C=i.expire),"hidefooter"in i&&r(1,m=i.hidefooter),"hidelogo"in i&&r(2,T=i.hidelogo),"name"in i&&r(3,A=i.name),"maxnumber"in i&&r(14,j=i.maxnumber),"mockerror"in i&&r(15,p=i.mockerror),"refetchonexpire"in i&&r(16,O=i.refetchonexpire),"strings"in i&&r(21,Z=i.strings),"test"in i&&r(17,y=i.test),"workers"in i&&r(18,v=i.workers)},t.$$.update=()=>{t.$$.dirty[0]&1048576&&(n=a?Ce(a):void 0),t.$$.dirty[0]&2097152&&r(25,o=Z?Ce(Z):{}),t.$$.dirty[0]&33554432&&r(9,l={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.",...o}),t.$$.dirty[0]&48&&k("statechange",{payload:Y,state:H})},[s,m,T,A,Y,H,h,E,ce,l,Et,xt,u,C,j,p,O,y,v,f,a,Z,Ct,q,U,o,Lt,Rt]}class Le extends it{constructor(e){super(),rt(this,e,_t,wt,Ge,{auto:0,challengeurl:19,challengejson:20,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,refetchonexpire:16,strings:21,test:17,workers:18,configure:22,reset:23,verify:24},ht,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),x()}get challengeurl(){return this.$$.ctx[19]}set challengeurl(e){this.$$set({challengeurl:e}),x()}get challengejson(){return this.$$.ctx[20]}set challengejson(e){this.$$set({challengejson:e}),x()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),x()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),x()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),x()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),x()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),x()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),x()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),x()}get refetchonexpire(){return this.$$.ctx[16]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),x()}get strings(){return this.$$.ctx[21]}set strings(e){this.$$set({strings:e}),x()}get test(){return this.$$.ctx[17]}set test(e){this.$$set({test:e}),x()}get workers(){return this.$$.ctx[18]}set workers(e){this.$$set({workers:e}),x()}get configure(){return this.$$.ctx[22]}get reset(){return this.$$.ctx[23]}get verify(){return this.$$.ctx[24]}}customElements.define("altcha-widget",nt(Le,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),N.Altcha=Le,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})}); +(function(N,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(N=typeof globalThis<"u"?globalThis:N||self,w(N.altcha={}))})(this,function(N){"use strict";var Mt=Object.defineProperty;var St=(N,w,P)=>w in N?Mt(N,w,{enumerable:!0,configurable:!0,writable:!0,value:P}):N[w]=P;var S=(N,w,P)=>(St(N,typeof w!="symbol"?w+"":w,P),P);function w(){}function P(t){return t()}function ae(){return Object.create(null)}function K(t){t.forEach(P)}function he(t){return typeof t=="function"}function Ge(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ve(t){return Object.keys(t).length===0}function b(t,e){t.appendChild(e)}function Ze(t,e,r){const n=He(t);if(!n.getElementById(e)){const o=_("style");o.id=e,o.textContent=r,Pe(n,o)}}function He(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Pe(t,e){return b(t.head||t,e),e.sheet}function I(t,e,r){t.insertBefore(e,r||null)}function R(t){t.parentNode&&t.parentNode.removeChild(t)}function _(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Fe(t){return document.createTextNode(t)}function F(){return Fe(" ")}function re(t,e,r,n){return t.addEventListener(e,r,n),()=>t.removeEventListener(e,r,n)}function c(t,e,r){r==null?t.removeAttribute(e):t.getAttribute(e)!==r&&t.setAttribute(e,r)}function Oe(t){return Array.from(t.childNodes)}function de(t,e,r){t.classList.toggle(e,!!r)}function We(t,e,{bubbles:r=!1,cancelable:n=!1}={}){return new CustomEvent(t,{detail:e,bubbles:r,cancelable:n})}function De(t){const e={};return t.childNodes.forEach(r=>{e[r.slot||"default"]=!0}),e}let J;function z(t){J=t}function ne(){if(!J)throw new Error("Function called outside component initialization");return J}function Be(t){ne().$$.on_mount.push(t)}function Ye(t){ne().$$.on_destroy.push(t)}function Ue(){const t=ne();return(e,r,{cancelable:n=!1}={})=>{const o=t.$$.callbacks[e];if(o){const l=We(e,r,{cancelable:n});return o.slice().forEach(s=>{s.call(t,l)}),!l.defaultPrevented}return!0}}const W=[],ie=[];let D=[];const ge=[],be=Promise.resolve();let oe=!1;function me(){oe||(oe=!0,be.then(x))}function Xe(){return me(),be}function le(t){D.push(t)}const se=new Set;let B=0;function x(){if(B!==0)return;const t=J;do{try{for(;Bt.indexOf(n)===-1?e.push(n):r.push(n)),r.forEach(n=>n()),D=e}const ze=new Set;function Qe(t,e){t&&t.i&&(ze.delete(t),t.i(e))}function qe(t,e,r){const{fragment:n,after_update:o}=t.$$;n&&n.m(e,r),le(()=>{const l=t.$$.on_mount.map(P).filter(he);t.$$.on_destroy?t.$$.on_destroy.push(...l):K(l),t.$$.on_mount=[]}),o.forEach(le)}function et(t,e){const r=t.$$;r.fragment!==null&&(Je(r.after_update),K(r.on_destroy),r.fragment&&r.fragment.d(e),r.on_destroy=r.fragment=null,r.ctx=[])}function tt(t,e){t.$$.dirty[0]===-1&&(W.push(t),me(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const j=A.length?A[0]:T;return u.ctx&&o(u.ctx[m],u.ctx[m]=j)&&(!u.skip_bound&&u.bound[m]&&u.bound[m](j),C&&tt(t,m)),T}):[],u.update(),C=!0,K(u.before_update),u.fragment=n?n(u.ctx):!1,e.target){if(e.hydrate){const m=Oe(e.target);u.fragment&&u.fragment.l(m),m.forEach(R)}else u.fragment&&u.fragment.c();e.intro&&Qe(t.$$.fragment),qe(t,e.target,e.anchor),x()}z(a)}let ve;typeof HTMLElement=="function"&&(ve=class extends HTMLElement{constructor(e,r,n){super();S(this,"$$ctor");S(this,"$$s");S(this,"$$c");S(this,"$$cn",!1);S(this,"$$d",{});S(this,"$$r",!1);S(this,"$$p_d",{});S(this,"$$l",{});S(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=r,n&&this.attachShadow({mode:"open"})}addEventListener(e,r,n){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(r),this.$$c){const o=this.$$c.$on(e,r);this.$$l_u.set(r,o)}super.addEventListener(e,r,n)}removeEventListener(e,r,n){if(super.removeEventListener(e,r,n),this.$$c){const o=this.$$l_u.get(r);o&&(o(),this.$$l_u.delete(r))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(l){return()=>{let s;return{c:function(){s=_("slot"),l!=="default"&&c(s,"name",l)},m:function(u,C){I(u,s,C)},d:function(u){u&&R(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const r={},n=De(this);for(const l of this.$$s)l in n&&(r[l]=[e(l)]);for(const l of this.attributes){const s=this.$$g_p(l.name);s in this.$$d||(this.$$d[s]=Q(s,l.value,this.$$p_d,"toProp"))}for(const l in this.$$p_d)!(l in this.$$d)&&this[l]!==void 0&&(this.$$d[l]=this[l],delete this[l]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:r,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const l in this.$$p_d)if(this.$$d[l]=this.$$c.$$.ctx[this.$$c.$$.props[l]],this.$$p_d[l].reflect){const s=Q(l,this.$$d[l],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[l].attribute||l):this.setAttribute(this.$$p_d[l].attribute||l,s)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const l in this.$$l)for(const s of this.$$l[l]){const f=this.$$c.$on(l,s);this.$$l_u.set(s,f)}this.$$l={}}}attributeChangedCallback(e,r,n){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Q(e,n,this.$$p_d,"toProp"),(o=this.$$c)==null||o.$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(r=>this.$$p_d[r].attribute===e||!this.$$p_d[r].attribute&&r.toLowerCase()===e)||e}});function Q(t,e,r,n){var l;const o=(l=r[t])==null?void 0:l.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!n||!r[t])return e;if(n==="toAttribute")switch(o){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(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function nt(t,e,r,n,o,l){let s=class extends ve{constructor(){super(t,r,o),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 u;a=Q(f,a,e),this.$$d[f]=a,(u=this.$$c)==null||u.$set({[f]:a})}})}),n.forEach(f=>{Object.defineProperty(s.prototype,f,{get(){var a;return(a=this.$$c)==null?void 0:a[f]}})}),l&&(s=l(s)),t.element=s,s}class it{constructor(){S(this,"$$");S(this,"$$set")}$destroy(){et(this,1),this.$destroy=w}$on(e,r){if(!he(r))return w;const n=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return n.push(r),()=>{const o=n.indexOf(r);o!==-1&&n.splice(o,1)}}$set(e){this.$$set&&!Ve(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const ot="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ot);const we="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+aT9zKG51bGwpOmgoZSxsLG8pLnRoZW4odz0+e3c9PT10P3Moe251bWJlcjpsLHRvb2s6RGF0ZS5ub3coKS1yfSk6ZChsKzEpfSkuY2F0Y2goYyl9O2QocCl9KSxjb250cm9sbGVyOmF9fWxldCBuO29ubWVzc2FnZT1hc3luYyB0PT57Y29uc3R7dHlwZTplLHBheWxvYWQ6b309dC5kYXRhO2lmKGU9PT0iYWJvcnQiKW49PW51bGx8fG4uYWJvcnQoKSxuPXZvaWQgMDtlbHNlIGlmKGU9PT0id29yayIpe2NvbnN0e2FsZzppLGNoYWxsZW5nZTpwLG1heDphLHNhbHQ6dSxzdGFydDpzfT1vfHx7fSxjPW0ocCx1LGksYSxzKTtuPWMuY29udHJvbGxlcixjLnByb21pc2UudGhlbihyPT57c2VsZi5wb3N0TWVzc2FnZShyJiZ7Li4ucix3b3JrZXI6ITB9KX0pfX19KSgpOwo=",lt=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),_e=typeof window<"u"&&window.Blob&&new Blob([lt(we)],{type:"text/javascript;charset=utf-8"});function st(t){let e;try{if(e=_e&&(window.URL||window.webkitURL).createObjectURL(_e),!e)throw"";const r=new Worker(e,{name:t==null?void 0:t.name});return r.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),r}catch{return new Worker("data:text/javascript;base64,"+we,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const ct=new TextEncoder;function ft(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ut(t,e="SHA-256",r=1e5){const n=Date.now().toString(16);t||(t=Math.round(Math.random()*r));const o=await pe(n,t,e);return{algorithm:e,challenge:o,salt:n,signature:""}}async function pe(t,e,r){return ft(await crypto.subtle.digest(r.toUpperCase(),ct.encode(t+e)))}function at(t,e,r="SHA-256",n=1e6,o=0){const l=new AbortController;return{promise:new Promise((f,a)=>{const u=Date.now(),C=m=>{l.signal.aborted||m>n?f(null):pe(e,m,r).then(T=>{T===t?f({number:m,took:Date.now()-u}):C(m+1)}).catch(a)};C(o)}),controller:l}}var g=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(g||{});function ht(t){Ze(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg{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-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function ye(t){let e,r,n;return{c(){e=V("svg"),r=V("path"),n=V("path"),c(r,"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(r,"fill","currentColor"),c(r,"opacity",".25"),c(n,"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(n,"fill","currentColor"),c(n,"class","altcha-spinner svelte-vuofbg"),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(o,l){I(o,e,l),b(e,r),b(e,n)},d(o){o&&R(e)}}}function dt(t){let e,r=t[9].label+"",n;return{c(){e=_("label"),c(e,"for",n=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(o,l){I(o,e,l),e.innerHTML=r},p(o,l){l[0]&512&&r!==(r=o[9].label+"")&&(e.innerHTML=r),l[0]&8&&n!==(n=o[3]+"_checkbox")&&c(e,"for",n)},d(o){o&&R(e)}}}function gt(t){let e,r=t[9].verifying+"";return{c(){e=_("span")},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].verifying+"")&&(e.innerHTML=r)},d(n){n&&R(e)}}}function bt(t){let e,r=t[9].verified+"",n,o;return{c(){e=_("span"),n=F(),o=_("input"),c(o,"type","hidden"),c(o,"name",t[3]),o.value=t[4]},m(l,s){I(l,e,s),e.innerHTML=r,I(l,n,s),I(l,o,s)},p(l,s){s[0]&512&&r!==(r=l[9].verified+"")&&(e.innerHTML=r),s[0]&8&&c(o,"name",l[3]),s[0]&16&&(o.value=l[4])},d(l){l&&(R(e),R(n),R(o))}}}function ke(t){let e,r,n,o,l,s;return{c(){e=_("div"),r=_("a"),n=V("svg"),o=V("path"),l=V("path"),s=V("path"),c(o,"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(o,"fill","currentColor"),c(l,"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(l,"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(n,"width","22"),c(n,"height","22"),c(n,"viewBox","0 0 20 20"),c(n,"fill","none"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(r,"href",xe),c(r,"target","_blank"),c(r,"class","altcha-logo svelte-vuofbg")},m(f,a){I(f,e,a),b(e,r),b(r,n),b(n,o),b(n,l),b(n,s)},p:w,d(f){f&&R(e)}}}function $e(t){let e,r,n,o;function l(a,u){return a[5]===g.EXPIRED?vt:mt}let s=l(t),f=s(t);return{c(){e=_("div"),r=V("svg"),n=V("path"),o=F(),f.c(),c(n,"stroke-linecap","round"),c(n,"stroke-linejoin","round"),c(n,"d","M6 18L18 6M6 6l12 12"),c(r,"width","14"),c(r,"height","14"),c(r,"xmlns","http://www.w3.org/2000/svg"),c(r,"fill","none"),c(r,"viewBox","0 0 24 24"),c(r,"stroke-width","1.5"),c(r,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(a,u){I(a,e,u),b(e,r),b(r,n),b(e,o),f.m(e,null)},p(a,u){s===(s=l(a))&&f?f.p(a,u):(f.d(1),f=s(a),f&&(f.c(),f.m(e,null)))},d(a){a&&R(e),f.d()}}}function mt(t){let e,r=t[9].error+"";return{c(){e=_("div"),c(e,"title",t[8])},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].error+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&R(e)}}}function vt(t){let e,r=t[9].expired+"";return{c(){e=_("div"),c(e,"title",t[8])},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].expired+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&R(e)}}}function Ee(t){let e,r,n=t[9].footer+"";return{c(){e=_("div"),r=_("div"),c(r,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(o,l){I(o,e,l),b(e,r),r.innerHTML=n},p(o,l){l[0]&512&&n!==(n=o[9].footer+"")&&(r.innerHTML=n)},d(o){o&&R(e)}}}function wt(t){let e,r,n,o,l,s,f,a,u,C,m,T,A,j,p=t[5]===g.VERIFYING&&ye();function O(h,E){return h[5]===g.VERIFIED?bt:h[5]===g.VERIFYING?gt:dt}let Z=O(t),y=Z(t),v=t[2]!==!0&&ke(),k=(t[8]||t[5]===g.EXPIRED)&&$e(t),$=t[9].footer&&t[1]!==!0&&Ee(t);return{c(){e=_("div"),r=_("div"),p&&p.c(),n=F(),o=_("div"),l=_("input"),a=F(),u=_("div"),y.c(),C=F(),v&&v.c(),m=F(),k&&k.c(),T=F(),$&&$.c(),c(l,"type","checkbox"),c(l,"id",s=t[3]+"_checkbox"),l.required=f=t[0]!=="onsubmit",c(l,"class","svelte-vuofbg"),c(o,"class","altcha-checkbox svelte-vuofbg"),de(o,"altcha-hidden",t[5]===g.VERIFYING),c(u,"class","altcha-label svelte-vuofbg"),c(r,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,E){I(h,e,E),b(e,r),p&&p.m(r,null),b(r,n),b(r,o),b(o,l),l.checked=t[6],b(r,a),b(r,u),y.m(u,null),b(r,C),v&&v.m(r,null),b(e,m),k&&k.m(e,null),b(e,T),$&&$.m(e,null),t[27](e),A||(j=[re(l,"change",t[26]),re(l,"change",t[10]),re(l,"invalid",t[11])],A=!0)},p(h,E){h[5]===g.VERIFYING?p||(p=ye(),p.c(),p.m(r,n)):p&&(p.d(1),p=null),E[0]&8&&s!==(s=h[3]+"_checkbox")&&c(l,"id",s),E[0]&1&&f!==(f=h[0]!=="onsubmit")&&(l.required=f),E[0]&64&&(l.checked=h[6]),E[0]&32&&de(o,"altcha-hidden",h[5]===g.VERIFYING),Z===(Z=O(h))&&y?y.p(h,E):(y.d(1),y=Z(h),y&&(y.c(),y.m(u,null))),h[2]!==!0?v?v.p(h,E):(v=ke(),v.c(),v.m(r,null)):v&&(v.d(1),v=null),h[8]||h[5]===g.EXPIRED?k?k.p(h,E):(k=$e(h),k.c(),k.m(e,T)):k&&(k.d(1),k=null),h[9].footer&&h[1]!==!0?$?$.p(h,E):($=Ee(h),$.c(),$.m(e,null)):$&&($.d(1),$=null),E[0]&32&&c(e,"data-state",h[5])},i:w,o:w,d(h){h&&R(e),p&&p.d(),y.d(),v&&v.d(),k&&k.d(),$&&$.d(),t[27](null),A=!1,K(j)}}}const xe="https://altcha.org/";function Ce(t){return JSON.parse(t)}function _t(t,e,r){let n,o,l,{auto:s=void 0}=e,{challengeurl:f=void 0}=e,{challengejson:a=void 0}=e,{debug:u=!1}=e,{expire:C=void 0}=e,{hidefooter:m=!1}=e,{hidelogo:T=!1}=e,{name:A="altcha"}=e,{maxnumber:j=1e6}=e,{mockerror:p=!1}=e,{refetchonexpire:O=!0}=e,{strings:Z=void 0}=e,{test:y=!1}=e,{workers:v=navigator.hardwareConcurrency||8}=e;const k=Ue(),$=["SHA-256","SHA-384","SHA-512"];let h=!1,E,M=null,ce=null,Y=null,H=g.UNVERIFIED,fe;Ye(()=>{M&&(M.removeEventListener("submit",Re),M.removeEventListener("reset",Ie),M=null)}),Be(()=>{L("mounted","0.2.2"),L("workers",v),y&&L("using test mode"),C&&ue(C),s!==void 0&&L("auto",s),M=E.closest("form"),M&&(M.addEventListener("submit",Re),M.addEventListener("reset",Ie)),s==="onload"&&U()});function L(...i){(u||i.some(d=>d instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function Re(i){M&&s==="onsubmit"&&H===g.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),U().then(()=>{M==null||M.requestSubmit()}))}function Ie(){q()}function pt(i,d){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:d.number,salt:i.salt,signature:i.signature,test:y?!0:void 0,took:d.took}))}function Ne(i){if(!i.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(i.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!$.includes(i.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${$.join(", ")}`);if(!i.challenge||i.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!i.salt||i.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function yt(){if(p)throw L("mocking error"),new Error("Mocked error.");if(n)return L("using provided json data"),n;if(y)return L("generating test challenge"),ut();{if(!f)throw new Error("Attribute challengeurl not set.");L("fetching challenge from",f);const i=await fetch(f);if(i.status!==200)throw new Error(`Server responded with ${i.status}.`);const d=i.headers.get("Expires");if(d!=null&&d.length){const X=Date.parse(d);isNaN(X)||ue(X-Date.now())}return i.json()}}function Te(){f&&O&&H===g.VERIFIED?U():q(g.EXPIRED,l.expired)}async function kt(i){let d=null;if("Worker"in window){try{d=await $t(i.challenge,i.salt,i.algorithm)}catch(X){L(X)}if((d==null?void 0:d.number)!==void 0)return{data:i,solution:d}}return{data:i,solution:await at(i.challenge,i.salt,i.algorithm,j).promise}}async function $t(i,d,X,ee=Math.ceil(v)){const te=[];if(ee<1)throw new Error("Wrong number of workers configured.");if(ee>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let G=0;G{const Se=Nt*Me;return new Promise(Tt=>{G.addEventListener("message",je=>{if(je.data)for(const Ae of te)Ae!==G&&Ae.postMessage({type:"abort"});Tt(je.data)}),G.postMessage({payload:{alg:X,challenge:i,max:Se+Me,salt:d,start:Se},type:"work"})})}));for(const G of te)G.terminate();return It.find(G=>!!G)||null}function Et(){[g.UNVERIFIED,g.ERROR,g.EXPIRED].includes(H)?U():r(6,h=!0)}function xt(){H===g.VERIFYING&&alert(l.waitAlert)}function ue(i){L("expire",i),clearTimeout(fe),i<1?Te():fe=setTimeout(Te,i)}function Ct(i){i.auto!==void 0&&(r(0,s=i.auto),s==="onload"&&U()),i.expire!==void 0&&(ue(i.expire),r(13,C=i.expire)),i.challenge&&(Ne(i.challenge),n=i.challenge),i.debug!==void 0&&r(12,u=!!i.debug),i.hidefooter!==void 0&&r(1,m=!!i.hidefooter),i.hidelogo!==void 0&&r(2,T=!!i.hidelogo),i.maxnumber!==void 0&&r(14,j=+i.maxnumber),i.mockerror!==void 0&&r(15,p=!!i.mockerror),i.name!==void 0&&r(3,A=i.name),i.refetchonexpire!==void 0&&r(16,O=!!i.refetchonexpire),i.strings&&r(25,o=i.strings),i.test!==void 0&&r(17,y=!!i.test),i.workers!==void 0&&r(18,v=+i.workers)}function q(i=g.UNVERIFIED,d=null){clearTimeout(fe),r(6,h=!1),r(8,ce=d),r(4,Y=null),r(5,H=i)}async function U(){return q(g.VERIFYING),yt().then(i=>(Ne(i),L("challenge",i),kt(i))).then(({data:i,solution:d})=>{if(L("solution",d),(d==null?void 0:d.number)!==void 0)L("verified"),r(5,H=g.VERIFIED),r(6,h=!0),r(4,Y=pt(i,d)),L("payload",Y),Xe().then(()=>{k("verified",{payload:Y})});else throw new Error("Unexpected result returned.")}).catch(i=>{L(i),r(5,H=g.ERROR),r(6,h=!1),r(8,ce=i.message)})}function Lt(){h=this.checked,r(6,h)}function Rt(i){ie[i?"unshift":"push"](()=>{E=i,r(7,E)})}return t.$$set=i=>{"auto"in i&&r(0,s=i.auto),"challengeurl"in i&&r(19,f=i.challengeurl),"challengejson"in i&&r(20,a=i.challengejson),"debug"in i&&r(12,u=i.debug),"expire"in i&&r(13,C=i.expire),"hidefooter"in i&&r(1,m=i.hidefooter),"hidelogo"in i&&r(2,T=i.hidelogo),"name"in i&&r(3,A=i.name),"maxnumber"in i&&r(14,j=i.maxnumber),"mockerror"in i&&r(15,p=i.mockerror),"refetchonexpire"in i&&r(16,O=i.refetchonexpire),"strings"in i&&r(21,Z=i.strings),"test"in i&&r(17,y=i.test),"workers"in i&&r(18,v=i.workers)},t.$$.update=()=>{t.$$.dirty[0]&1048576&&(n=a?Ce(a):void 0),t.$$.dirty[0]&2097152&&r(25,o=Z?Ce(Z):{}),t.$$.dirty[0]&33554432&&r(9,l={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.",...o}),t.$$.dirty[0]&48&&k("statechange",{payload:Y,state:H})},[s,m,T,A,Y,H,h,E,ce,l,Et,xt,u,C,j,p,O,y,v,f,a,Z,Ct,q,U,o,Lt,Rt]}class Le extends it{constructor(e){super(),rt(this,e,_t,wt,Ge,{auto:0,challengeurl:19,challengejson:20,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,refetchonexpire:16,strings:21,test:17,workers:18,configure:22,reset:23,verify:24},ht,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),x()}get challengeurl(){return this.$$.ctx[19]}set challengeurl(e){this.$$set({challengeurl:e}),x()}get challengejson(){return this.$$.ctx[20]}set challengejson(e){this.$$set({challengejson:e}),x()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),x()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),x()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),x()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),x()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),x()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),x()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),x()}get refetchonexpire(){return this.$$.ctx[16]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),x()}get strings(){return this.$$.ctx[21]}set strings(e){this.$$set({strings:e}),x()}get test(){return this.$$.ctx[17]}set test(e){this.$$set({test:e}),x()}get workers(){return this.$$.ctx[18]}set workers(e){this.$$set({workers:e}),x()}get configure(){return this.$$.ctx[22]}get reset(){return this.$$.ctx[23]}get verify(){return this.$$.ctx[24]}}customElements.define("altcha-widget",nt(Le,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),N.Altcha=Le,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})}); diff --git a/package.json b/package.json index 88f9a9e..b2ab4d1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "altcha", "description": "GDPR compliant, self-hosted CAPTCHA alternative.", - "version": "0.2.1", + "version": "0.2.2", "license": "MIT", "author": { "name": "Daniel Regeci"