diff --git a/README.md b/README.md index f429289..239f7fb 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,54 @@ Development / testing options: - __mockerror__ - Causes the verification to always fail with a "mock" error. - __test__ - Generates a "mock" challenge within the widget, bypassing the request to `challengeurl`. -Events: +## Programmatic Configuration + +To configure the widget programmatically, use the `configure()` method: + +```ts +document.querySelector('#altcha').configure({ + challenge: { + algorithm: 'SHA-256', + challenge: '...', + salt: '...', + signature: '...', + }, + strings: { + label: 'Verify', + }, +}); +``` + +Available configuration options: + +```ts +export interface Configure { + auto?: 'onload' | 'onsubmit'; + challenge?: { + algorithm: string; + challenge: string; + salt: string; + signature: string; + }; + debug?: boolean; + hidefooter?: boolean; + hidelogo?: boolean; + maxnumber?: number; + mockerror?: boolean; + name?: string; + strings?: { + error?: string; + footer?: string; + label?: string; + verified?: string; + verifying?: string; + waitAlert?: string; + }; + test?: boolean; +} +``` + +## Events - __statechange__ - Triggers whenever an internal `state` changes. - __verified__ - Triggers when the challenge is verified. @@ -87,7 +134,7 @@ document.querySelector('#altcha').addEventListener('statechange', (ev) => { ``` > [!IMPORTANT] -> Ensure that you attach event listeners after the ALTCHA script loads, such as within window.addEventListener('load', ...), to ensure the events trigger correctly. +> Both programmatic configuration and event listeners have to called/attached after the ALTCHA script loads, such as within window.addEventListener('load', ...). ## Contributing See [Contributing Guide](https://github.com/altcha-org/altcha/blob/main/CONTRIBUTING.md) and please follow our [Code of Conduct](https://github.com/altcha-org/altcha/blob/main/CODE_OF_CONDUCT.md). diff --git a/dist/altcha.iife.js b/dist/altcha.iife.js index b29fc6b..06bbd28 100644 --- a/dist/altcha.iife.js +++ b/dist/altcha.iife.js @@ -1 +1 @@ -var altcha=function(A){"use strict";var vt=Object.defineProperty;var $t=(A,y,U)=>y in A?vt(A,y,{enumerable:!0,configurable:!0,writable:!0,value:U}):A[y]=U;var I=(A,y,U)=>($t(A,typeof y!="symbol"?y+"":y,U),U);function y(){}function U(t){return t()}function re(){return Object.create(null)}function W(t){t.forEach(U)}function oe(t){return typeof t=="function"}function ke(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ee(t){return Object.keys(t).length===0}function g(t,e){t.appendChild(e)}function Ce(t,e,n){const o=xe(t);if(!o.getElementById(e)){const i=w("style");i.id=e,i.textContent=n,Le(o,i)}}function xe(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Le(t,e){return g(t.head||t,e),e.sheet}function R(t,e,n){t.insertBefore(e,n||null)}function L(t){t.parentNode&&t.parentNode.removeChild(t)}function w(t){return document.createElement(t)}function G(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Ie(t){return document.createTextNode(t)}function F(){return Ie(" ")}function K(t,e,n,o){return t.addEventListener(e,n,o),()=>t.removeEventListener(e,n,o)}function c(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Re(t){return Array.from(t.childNodes)}function ie(t,e,n){t.classList.toggle(e,!!n)}function Ne(t,e,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:o})}function je(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let P;function T(t){P=t}function z(){if(!P)throw new Error("Function called outside component initialization");return P}function Ae(t){z().$$.on_mount.push(t)}function Ge(t){z().$$.on_destroy.push(t)}function Se(){const t=z();return(e,n,{cancelable:o=!1}={})=>{const i=t.$$.callbacks[e];if(i){const r=Ne(e,n,{cancelable:o});return i.slice().forEach(s=>{s.call(t,r)}),!r.defaultPrevented}return!0}}const Z=[],J=[];let B=[];const le=[],se=Promise.resolve();let Q=!1;function ce(){Q||(Q=!0,se.then(E))}function Me(){return ce(),se}function q(t){B.push(t)}const ee=new Set;let H=0;function E(){if(H!==0)return;const t=P;do{try{for(;Ht.indexOf(o)===-1?e.push(o):n.push(o)),n.forEach(o=>o()),B=e}const Oe=new Set;function Fe(t,e){t&&t.i&&(Oe.delete(t),t.i(e))}function Ye(t,e,n){const{fragment:o,after_update:i}=t.$$;o&&o.m(e,n),q(()=>{const r=t.$$.on_mount.map(U).filter(oe);t.$$.on_destroy?t.$$.on_destroy.push(...r):W(r),t.$$.on_mount=[]}),i.forEach(q)}function Ze(t,e){const n=t.$$;n.fragment!==null&&(Ve(n.after_update),W(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Be(t,e){t.$$.dirty[0]===-1&&(Z.push(t),ce(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const M=N.length?N[0]:S;return u.ctx&&i(u.ctx[k],u.ctx[k]=M)&&(!u.skip_bound&&u.bound[k]&&u.bound[k](M),j&&Be(t,k)),S}):[],u.update(),j=!0,W(u.before_update),u.fragment=o?o(u.ctx):!1,e.target){if(e.hydrate){const k=Re(e.target);u.fragment&&u.fragment.l(k),k.forEach(L)}else u.fragment&&u.fragment.c();e.intro&&Fe(t.$$.fragment),Ye(t,e.target,e.anchor),E()}T(f)}let ae;typeof HTMLElement=="function"&&(ae=class extends HTMLElement{constructor(e,n,o){super();I(this,"$$ctor");I(this,"$$s");I(this,"$$c");I(this,"$$cn",!1);I(this,"$$d",{});I(this,"$$r",!1);I(this,"$$p_d",{});I(this,"$$l",{});I(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,o&&this.attachShadow({mode:"open"})}addEventListener(e,n,o){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const i=this.$$c.$on(e,n);this.$$l_u.set(n,i)}super.addEventListener(e,n,o)}removeEventListener(e,n,o){if(super.removeEventListener(e,n,o),this.$$c){const i=this.$$l_u.get(n);i&&(i(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let s;return{c:function(){s=w("slot"),r!=="default"&&c(s,"name",r)},m:function(u,j){R(u,s,j)},d:function(u){u&&L(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},o=je(this);for(const r of this.$$s)r in o&&(n[r]=[e(r)]);for(const r of this.attributes){const s=this.$$g_p(r.name);s in this.$$d||(this.$$d[s]=X(s,r.value,this.$$p_d,"toProp"))}for(const r in this.$$p_d)!(r in this.$$d)&&this[r]!==void 0&&(this.$$d[r]=this[r],delete this[r]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const i=()=>{this.$$r=!0;for(const r in this.$$p_d)if(this.$$d[r]=this.$$c.$$.ctx[this.$$c.$$.props[r]],this.$$p_d[r].reflect){const s=X(r,this.$$d[r],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,s)}this.$$r=!1};this.$$c.$$.after_update.push(i),i();for(const r in this.$$l)for(const s of this.$$l[r]){const a=this.$$c.$on(r,s);this.$$l_u.set(s,a)}this.$$l={}}}attributeChangedCallback(e,n,o){var i;this.$$r||(e=this.$$g_p(e),this.$$d[e]=X(e,o,this.$$p_d,"toProp"),(i=this.$$c)==null||i.$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(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function X(t,e,n,o){var r;const i=(r=n[t])==null?void 0:r.type;if(e=i==="Boolean"&&typeof e!="boolean"?e!=null:e,!o||!n[t])return e;if(o==="toAttribute")switch(i){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(i){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function We(t,e,n,o,i,r){let s=class extends ae{constructor(){super(t,n,i),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(s.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(f){var u;f=X(a,f,e),this.$$d[a]=f,(u=this.$$c)==null||u.$set({[a]:f})}})}),o.forEach(a=>{Object.defineProperty(s.prototype,a,{get(){var f;return(f=this.$$c)==null?void 0:f[a]}})}),r&&(s=r(s)),t.element=s,s}class Pe{constructor(){I(this,"$$");I(this,"$$set")}$destroy(){Ze(this,1),this.$destroy=y}$on(e,n){if(!oe(n))return y;const o=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(e){this.$$set&&!Ee(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Te="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Te);const ue="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",Xe=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),fe=typeof window<"u"&&window.Blob&&new Blob([Xe(ue)],{type:"text/javascript;charset=utf-8"});function De(t){let e;try{if(e=fe&&(window.URL||window.webkitURL).createObjectURL(fe),!e)throw"";const n=new Worker(e,{name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;base64,"+ue,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const Ke=1e7,ze=new TextEncoder;function Je(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function Qe(t=1e5,e="SHA-256"){const n=Date.now().toString(16),o=Math.round(Math.random()*t),i=await he(n,o,e);return{algorithm:e,challenge:i,salt:n,signature:""}}async function he(t,e,n){return Je(await crypto.subtle.digest(n.toUpperCase(),ze.encode(t+e)))}async function qe(t,e,n="SHA-256",o=Ke){const i=Date.now();for(let r=0;r<=o;r++)if(await he(e,r,n)===t)return{number:r,took:Date.now()-i};return null}var p=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t))(p||{});function et(t){Ce(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 de(t){let e,n,o;return{c(){e=G("svg"),n=G("path"),o=G("path"),c(n,"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(n,"fill","currentColor"),c(n,"opacity",".25"),c(o,"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(o,"fill","currentColor"),c(o,"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(i,r){R(i,e,r),g(e,n),g(e,o)},d(i){i&&L(e)}}}function tt(t){let e,n=t[9].label+"",o;return{c(){e=w("label"),c(e,"for",o=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(i,r){R(i,e,r),e.innerHTML=n},p(i,r){r[0]&512&&n!==(n=i[9].label+"")&&(e.innerHTML=n),r[0]&8&&o!==(o=i[3]+"_checkbox")&&c(e,"for",o)},d(i){i&&L(e)}}}function nt(t){let e,n=t[9].verifying+"";return{c(){e=w("span")},m(o,i){R(o,e,i),e.innerHTML=n},p(o,i){i[0]&512&&n!==(n=o[9].verifying+"")&&(e.innerHTML=n)},d(o){o&&L(e)}}}function rt(t){let e,n=t[9].verified+"",o,i;return{c(){e=w("span"),o=F(),i=w("input"),c(i,"type","hidden"),c(i,"name",t[3]),i.value=t[4]},m(r,s){R(r,e,s),e.innerHTML=n,R(r,o,s),R(r,i,s)},p(r,s){s[0]&512&&n!==(n=r[9].verified+"")&&(e.innerHTML=n),s[0]&8&&c(i,"name",r[3]),s[0]&16&&(i.value=r[4])},d(r){r&&(L(e),L(o),L(i))}}}function ge(t){let e,n,o,i,r,s;return{c(){e=w("div"),n=w("a"),o=G("svg"),i=G("path"),r=G("path"),s=G("path"),c(i,"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(i,"fill","currentColor"),c(r,"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(r,"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(o,"width","22"),c(o,"height","22"),c(o,"viewBox","0 0 20 20"),c(o,"fill","none"),c(o,"xmlns","http://www.w3.org/2000/svg"),c(n,"href",ve),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-vuofbg")},m(a,f){R(a,e,f),g(e,n),g(n,o),g(o,i),g(o,r),g(o,s)},p:y,d(a){a&&L(e)}}}function be(t){let e,n,o,i,r,s=t[9].error+"";return{c(){e=w("div"),n=G("svg"),o=G("path"),i=F(),r=w("div"),c(o,"stroke-linecap","round"),c(o,"stroke-linejoin","round"),c(o,"d","M6 18L18 6M6 6l12 12"),c(n,"width","14"),c(n,"height","14"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(n,"fill","none"),c(n,"viewBox","0 0 24 24"),c(n,"stroke-width","1.5"),c(n,"stroke","currentColor"),c(r,"title",t[8]),c(e,"class","altcha-error svelte-vuofbg")},m(a,f){R(a,e,f),g(e,n),g(n,o),g(e,i),g(e,r),r.innerHTML=s},p(a,f){f[0]&512&&s!==(s=a[9].error+"")&&(r.innerHTML=s),f[0]&256&&c(r,"title",a[8])},d(a){a&&L(e)}}}function me(t){let e,n,o=t[9].footer+"";return{c(){e=w("div"),n=w("div"),c(n,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(i,r){R(i,e,r),g(e,n),n.innerHTML=o},p(i,r){r[0]&512&&o!==(o=i[9].footer+"")&&(n.innerHTML=o)},d(i){i&&L(e)}}}function ot(t){let e,n,o,i,r,s,a,f,u,j,k,S,N,M,$=t[5]===p.VERIFYING&&de();function V(h,v){return h[5]===p.VERIFIED?rt:h[5]===p.VERIFYING?nt:tt}let Y=V(t),C=Y(t),b=t[2]!==!0&&ge(),m=t[8]&&be(t),d=t[9].footer&&t[1]!==!0&&me(t);return{c(){e=w("div"),n=w("div"),$&&$.c(),o=F(),i=w("div"),r=w("input"),f=F(),u=w("div"),C.c(),j=F(),b&&b.c(),k=F(),m&&m.c(),S=F(),d&&d.c(),c(r,"type","checkbox"),c(r,"id",s=t[3]+"_checkbox"),r.required=a=t[0]!=="onsubmit",c(r,"class","svelte-vuofbg"),c(i,"class","altcha-checkbox svelte-vuofbg"),ie(i,"altcha-hidden",t[5]===p.VERIFYING),c(u,"class","altcha-label svelte-vuofbg"),c(n,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,v){R(h,e,v),g(e,n),$&&$.m(n,null),g(n,o),g(n,i),g(i,r),r.checked=t[6],g(n,f),g(n,u),C.m(u,null),g(n,j),b&&b.m(n,null),g(e,k),m&&m.m(e,null),g(e,S),d&&d.m(e,null),t[23](e),N||(M=[K(r,"change",t[22]),K(r,"change",t[10]),K(r,"invalid",t[11])],N=!0)},p(h,v){h[5]===p.VERIFYING?$||($=de(),$.c(),$.m(n,o)):$&&($.d(1),$=null),v[0]&8&&s!==(s=h[3]+"_checkbox")&&c(r,"id",s),v[0]&1&&a!==(a=h[0]!=="onsubmit")&&(r.required=a),v[0]&64&&(r.checked=h[6]),v[0]&32&&ie(i,"altcha-hidden",h[5]===p.VERIFYING),Y===(Y=V(h))&&C?C.p(h,v):(C.d(1),C=Y(h),C&&(C.c(),C.m(u,null))),h[2]!==!0?b?b.p(h,v):(b=ge(),b.c(),b.m(n,null)):b&&(b.d(1),b=null),h[8]?m?m.p(h,v):(m=be(h),m.c(),m.m(e,S)):m&&(m.d(1),m=null),h[9].footer&&h[1]!==!0?d?d.p(h,v):(d=me(h),d.c(),d.m(e,null)):d&&(d.d(1),d=null),v[0]&32&&c(e,"data-state",h[5])},i:y,o:y,d(h){h&&L(e),$&&$.d(),C.d(),b&&b.d(),m&&m.d(),d&&d.d(),t[23](null),N=!1,W(M)}}}const ve="https://altcha.org/";function $e(t){return JSON.parse(t)}function it(t,e,n){let o,i,r,{auto:s=void 0}=e,{challengeurl:a=void 0}=e,{challengejson:f=void 0}=e,{debug:u=!1}=e,{hidefooter:j=!1}=e,{hidelogo:k=!1}=e,{name:S="altcha"}=e,{maxnumber:N=void 0}=e,{mockerror:M=!1}=e,{strings:$=void 0}=e,{test:V=!1}=e;const Y=Se(),C=["SHA-256","SHA-384","SHA-512"];let b=!1,m,d=null,h=null,v=null,O=p.UNVERIFIED;Ge(()=>{d&&(d.removeEventListener("submit",we),d.removeEventListener("reset",pe),d=null)}),Ae(()=>{x("mounted","0.1.8"),V&&x("using test mode"),s!==void 0&&x("auto",s),d=m.closest("form"),d&&(d.addEventListener("submit",we),d.addEventListener("reset",pe)),s==="onload"&&D()});function x(...l){(u||l.some(_=>_ instanceof Error))&&console[l[0]instanceof Error?"error":"log"]("ALTCHA",...l)}function we(l){d&&s==="onsubmit"&&O===p.UNVERIFIED&&(l.preventDefault(),l.stopPropagation(),D().then(()=>{d==null||d.requestSubmit()}))}function pe(){te()}function lt(l,_){return btoa(JSON.stringify({algorithm:l.algorithm,challenge:l.challenge,number:_.number,salt:l.salt,signature:l.signature,test:V?!0:void 0,took:_.took}))}function st(l){if(!l.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(l.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!C.includes(l.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${C.join(", ")}`);if(!l.challenge||l.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!l.salt||l.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function ct(){if(M)throw x("mocking error"),new Error("Mocked error.");if(o)return x("using provided json data"),o;if(V)return x("generating test challenge"),Qe();{if(!a)throw new Error("Attribute challengeurl not set.");x("fetching challenge from",a);const l=await fetch(a);if(l.status!==200)throw new Error(`Server responded with ${l.status}.`);return l.json()}}async function at(l){let _=null;if("Worker"in window){try{_=await ut(l.challenge,l.salt,l.algorithm)}catch(ne){x(ne)}if((_==null?void 0:_.number)!==void 0)return{data:l,solution:_}}return{data:l,solution:await qe(l.challenge,l.salt,l.algorithm,N)}}async function ut(l,_,ne){const ye=new De;return new Promise(bt=>{ye.addEventListener("message",mt=>{bt(mt.data)}),ye.postMessage({alg:ne,challenge:l,max:N,salt:_})})}function ft(){[p.UNVERIFIED,p.ERROR].includes(O)?D():n(6,b=!0)}function ht(){O===p.VERIFYING&&alert(r.waitAlert)}function te(l=p.UNVERIFIED){n(6,b=!1),n(8,h=null),n(4,v=null),n(5,O=l)}async function D(){return te(p.VERIFYING),ct().then(l=>(st(l),x("challenge",l),at(l))).then(({data:l,solution:_})=>{if(x("solution",_),(_==null?void 0:_.number)!==void 0)x("verified"),n(5,O=p.VERIFIED),n(6,b=!0),n(4,v=lt(l,_)),x("payload",v),Me().then(()=>{Y("verified",{payload:v})});else throw new Error("Unexpected result returned.")}).catch(l=>{x(l),n(5,O=p.ERROR),n(6,b=!1),n(8,h=l)})}function dt(){b=this.checked,n(6,b)}function gt(l){J[l?"unshift":"push"](()=>{m=l,n(7,m)})}return t.$$set=l=>{"auto"in l&&n(0,s=l.auto),"challengeurl"in l&&n(12,a=l.challengeurl),"challengejson"in l&&n(13,f=l.challengejson),"debug"in l&&n(14,u=l.debug),"hidefooter"in l&&n(1,j=l.hidefooter),"hidelogo"in l&&n(2,k=l.hidelogo),"name"in l&&n(3,S=l.name),"maxnumber"in l&&n(15,N=l.maxnumber),"mockerror"in l&&n(16,M=l.mockerror),"strings"in l&&n(17,$=l.strings),"test"in l&&n(18,V=l.test)},t.$$.update=()=>{t.$$.dirty[0]&8192&&(o=f?$e(f):void 0),t.$$.dirty[0]&131072&&n(21,i=$?$e($):{}),t.$$.dirty[0]&2097152&&n(9,r={error:"Verification failed. Try again later.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...i}),t.$$.dirty[0]&48&&Y("statechange",{payload:v,state:O})},[s,j,k,S,v,O,b,m,h,r,ft,ht,a,f,u,N,M,$,V,te,D,i,dt,gt]}class _e extends Pe{constructor(e){super(),He(this,e,it,ot,ke,{auto:0,challengeurl:12,challengejson:13,debug:14,hidefooter:1,hidelogo:2,name:3,maxnumber:15,mockerror:16,strings:17,test:18,reset:19,verify:20},et,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),E()}get challengeurl(){return this.$$.ctx[12]}set challengeurl(e){this.$$set({challengeurl:e}),E()}get challengejson(){return this.$$.ctx[13]}set challengejson(e){this.$$set({challengejson:e}),E()}get debug(){return this.$$.ctx[14]}set debug(e){this.$$set({debug: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[15]}set maxnumber(e){this.$$set({maxnumber:e}),E()}get mockerror(){return this.$$.ctx[16]}set mockerror(e){this.$$set({mockerror:e}),E()}get strings(){return this.$$.ctx[17]}set strings(e){this.$$set({strings:e}),E()}get test(){return this.$$.ctx[18]}set test(e){this.$$set({test:e}),E()}get reset(){return this.$$.ctx[19]}get verify(){return this.$$.ctx[20]}}return customElements.define("altcha-widget",We(_e,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset","verify"],!1)),A.Altcha=_e,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"}),A}({}); +var altcha=function(S){"use strict";var _t=Object.defineProperty;var wt=(S,p,V)=>p in S?_t(S,p,{enumerable:!0,configurable:!0,writable:!0,value:V}):S[p]=V;var R=(S,p,V)=>(wt(S,typeof p!="symbol"?p+"":p,V),V);function p(){}function V(t){return t()}function re(){return Object.create(null)}function W(t){t.forEach(V)}function ie(t){return typeof t=="function"}function Ee(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ce(t){return Object.keys(t).length===0}function g(t,e){t.appendChild(e)}function xe(t,e,n){const i=Le(t);if(!i.getElementById(e)){const o=$("style");o.id=e,o.textContent=n,Ie(i,o)}}function Le(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Ie(t,e){return g(t.head||t,e),e.sheet}function N(t,e,n){t.insertBefore(e,n||null)}function L(t){t.parentNode&&t.parentNode.removeChild(t)}function $(t){return document.createElement(t)}function M(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Re(t){return document.createTextNode(t)}function F(){return Re(" ")}function K(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}function c(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ne(t){return Array.from(t.childNodes)}function le(t,e,n){t.classList.toggle(e,!!n)}function je(t,e,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:i})}function Ae(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let P;function T(t){P=t}function z(){if(!P)throw new Error("Function called outside component initialization");return P}function Ge(t){z().$$.on_mount.push(t)}function Se(t){z().$$.on_destroy.push(t)}function Me(){const t=z();return(e,n,{cancelable:i=!1}={})=>{const o=t.$$.callbacks[e];if(o){const r=je(e,n,{cancelable:i});return o.slice().forEach(s=>{s.call(t,r)}),!r.defaultPrevented}return!0}}const Z=[],J=[];let B=[];const oe=[],se=Promise.resolve();let Q=!1;function ce(){Q||(Q=!0,se.then(E))}function Ue(){return ce(),se}function q(t){B.push(t)}const ee=new Set;let H=0;function E(){if(H!==0)return;const t=P;do{try{for(;Ht.indexOf(i)===-1?e.push(i):n.push(i)),n.forEach(i=>i()),B=e}const Fe=new Set;function Ye(t,e){t&&t.i&&(Fe.delete(t),t.i(e))}function Ze(t,e,n){const{fragment:i,after_update:o}=t.$$;i&&i.m(e,n),q(()=>{const r=t.$$.on_mount.map(V).filter(ie);t.$$.on_destroy?t.$$.on_destroy.push(...r):W(r),t.$$.on_mount=[]}),o.forEach(q)}function Be(t,e){const n=t.$$;n.fragment!==null&&(Oe(n.after_update),W(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function He(t,e){t.$$.dirty[0]===-1&&(Z.push(t),ce(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const G=I.length?I[0]:A;return a.ctx&&o(a.ctx[k],a.ctx[k]=G)&&(!a.skip_bound&&a.bound[k]&&a.bound[k](G),j&&He(t,k)),A}):[],a.update(),j=!0,W(a.before_update),a.fragment=i?i(a.ctx):!1,e.target){if(e.hydrate){const k=Ne(e.target);a.fragment&&a.fragment.l(k),k.forEach(L)}else a.fragment&&a.fragment.c();e.intro&&Ye(t.$$.fragment),Ze(t,e.target,e.anchor),E()}T(f)}let ue;typeof HTMLElement=="function"&&(ue=class extends HTMLElement{constructor(e,n,i){super();R(this,"$$ctor");R(this,"$$s");R(this,"$$c");R(this,"$$cn",!1);R(this,"$$d",{});R(this,"$$r",!1);R(this,"$$p_d",{});R(this,"$$l",{});R(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,i&&this.attachShadow({mode:"open"})}addEventListener(e,n,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const o=this.$$c.$on(e,n);this.$$l_u.set(n,o)}super.addEventListener(e,n,i)}removeEventListener(e,n,i){if(super.removeEventListener(e,n,i),this.$$c){const o=this.$$l_u.get(n);o&&(o(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let s;return{c:function(){s=$("slot"),r!=="default"&&c(s,"name",r)},m:function(a,j){N(a,s,j)},d:function(a){a&&L(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},i=Ae(this);for(const r of this.$$s)r in i&&(n[r]=[e(r)]);for(const r of this.attributes){const s=this.$$g_p(r.name);s in this.$$d||(this.$$d[s]=D(s,r.value,this.$$p_d,"toProp"))}for(const r in this.$$p_d)!(r in this.$$d)&&this[r]!==void 0&&(this.$$d[r]=this[r],delete this[r]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const r in this.$$p_d)if(this.$$d[r]=this.$$c.$$.ctx[this.$$c.$$.props[r]],this.$$p_d[r].reflect){const s=D(r,this.$$d[r],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,s)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const r in this.$$l)for(const s of this.$$l[r]){const u=this.$$c.$on(r,s);this.$$l_u.set(s,u)}this.$$l={}}}attributeChangedCallback(e,n,i){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=D(e,i,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(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function D(t,e,n,i){var r;const o=(r=n[t])==null?void 0:r.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!n[t])return e;if(i==="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 Pe(t,e,n,i,o,r){let s=class extends ue{constructor(){super(t,n,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(f){var a;f=D(u,f,e),this.$$d[u]=f,(a=this.$$c)==null||a.$set({[u]:f})}})}),i.forEach(u=>{Object.defineProperty(s.prototype,u,{get(){var f;return(f=this.$$c)==null?void 0:f[u]}})}),r&&(s=r(s)),t.element=s,s}class Te{constructor(){R(this,"$$");R(this,"$$set")}$destroy(){Be(this,1),this.$destroy=p}$on(e,n){if(!ie(n))return p;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(n),()=>{const o=i.indexOf(n);o!==-1&&i.splice(o,1)}}$set(e){this.$$set&&!Ce(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Xe="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Xe);const ae="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",De=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),fe=typeof window<"u"&&window.Blob&&new Blob([De(ae)],{type:"text/javascript;charset=utf-8"});function Ke(t){let e;try{if(e=fe&&(window.URL||window.webkitURL).createObjectURL(fe),!e)throw"";const n=new Worker(e,{name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;base64,"+ae,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const ze=1e7,Je=new TextEncoder;function Qe(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function qe(t=1e5,e="SHA-256"){const n=Date.now().toString(16),i=Math.round(Math.random()*t),o=await he(n,i,e);return{algorithm:e,challenge:o,salt:n,signature:""}}async function he(t,e,n){return Qe(await crypto.subtle.digest(n.toUpperCase(),Je.encode(t+e)))}async function et(t,e,n="SHA-256",i=ze){const o=Date.now();for(let r=0;r<=i;r++)if(await he(e,r,n)===t)return{number:r,took:Date.now()-o};return null}var y=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t))(y||{});function tt(t){xe(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 de(t){let e,n,i;return{c(){e=M("svg"),n=M("path"),i=M("path"),c(n,"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(n,"fill","currentColor"),c(n,"opacity",".25"),c(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(i,"fill","currentColor"),c(i,"class","altcha-spinner svelte-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,r){N(o,e,r),g(e,n),g(e,i)},d(o){o&&L(e)}}}function nt(t){let e,n=t[9].label+"",i;return{c(){e=$("label"),c(e,"for",i=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(o,r){N(o,e,r),e.innerHTML=n},p(o,r){r[0]&512&&n!==(n=o[9].label+"")&&(e.innerHTML=n),r[0]&8&&i!==(i=o[3]+"_checkbox")&&c(e,"for",i)},d(o){o&&L(e)}}}function rt(t){let e,n=t[9].verifying+"";return{c(){e=$("span")},m(i,o){N(i,e,o),e.innerHTML=n},p(i,o){o[0]&512&&n!==(n=i[9].verifying+"")&&(e.innerHTML=n)},d(i){i&&L(e)}}}function it(t){let e,n=t[9].verified+"",i,o;return{c(){e=$("span"),i=F(),o=$("input"),c(o,"type","hidden"),c(o,"name",t[3]),o.value=t[4]},m(r,s){N(r,e,s),e.innerHTML=n,N(r,i,s),N(r,o,s)},p(r,s){s[0]&512&&n!==(n=r[9].verified+"")&&(e.innerHTML=n),s[0]&8&&c(o,"name",r[3]),s[0]&16&&(o.value=r[4])},d(r){r&&(L(e),L(i),L(o))}}}function ge(t){let e,n,i,o,r,s;return{c(){e=$("div"),n=$("a"),i=M("svg"),o=M("path"),r=M("path"),s=M("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(r,"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(r,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(i,"width","22"),c(i,"height","22"),c(i,"viewBox","0 0 20 20"),c(i,"fill","none"),c(i,"xmlns","http://www.w3.org/2000/svg"),c(n,"href",ve),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-vuofbg")},m(u,f){N(u,e,f),g(e,n),g(n,i),g(i,o),g(i,r),g(i,s)},p,d(u){u&&L(e)}}}function be(t){let e,n,i,o,r,s=t[9].error+"";return{c(){e=$("div"),n=M("svg"),i=M("path"),o=F(),r=$("div"),c(i,"stroke-linecap","round"),c(i,"stroke-linejoin","round"),c(i,"d","M6 18L18 6M6 6l12 12"),c(n,"width","14"),c(n,"height","14"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(n,"fill","none"),c(n,"viewBox","0 0 24 24"),c(n,"stroke-width","1.5"),c(n,"stroke","currentColor"),c(r,"title",t[8]),c(e,"class","altcha-error svelte-vuofbg")},m(u,f){N(u,e,f),g(e,n),g(n,i),g(e,o),g(e,r),r.innerHTML=s},p(u,f){f[0]&512&&s!==(s=u[9].error+"")&&(r.innerHTML=s),f[0]&256&&c(r,"title",u[8])},d(u){u&&L(e)}}}function me(t){let e,n,i=t[9].footer+"";return{c(){e=$("div"),n=$("div"),c(n,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(o,r){N(o,e,r),g(e,n),n.innerHTML=i},p(o,r){r[0]&512&&i!==(i=o[9].footer+"")&&(n.innerHTML=i)},d(o){o&&L(e)}}}function lt(t){let e,n,i,o,r,s,u,f,a,j,k,A,I,G,_=t[5]===y.VERIFYING&&de();function U(h,v){return h[5]===y.VERIFIED?it:h[5]===y.VERIFYING?rt:nt}let Y=U(t),C=Y(t),b=t[2]!==!0&&ge(),m=t[8]&&be(t),d=t[9].footer&&t[1]!==!0&&me(t);return{c(){e=$("div"),n=$("div"),_&&_.c(),i=F(),o=$("div"),r=$("input"),f=F(),a=$("div"),C.c(),j=F(),b&&b.c(),k=F(),m&&m.c(),A=F(),d&&d.c(),c(r,"type","checkbox"),c(r,"id",s=t[3]+"_checkbox"),r.required=u=t[0]!=="onsubmit",c(r,"class","svelte-vuofbg"),c(o,"class","altcha-checkbox svelte-vuofbg"),le(o,"altcha-hidden",t[5]===y.VERIFYING),c(a,"class","altcha-label svelte-vuofbg"),c(n,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,v){N(h,e,v),g(e,n),_&&_.m(n,null),g(n,i),g(n,o),g(o,r),r.checked=t[6],g(n,f),g(n,a),C.m(a,null),g(n,j),b&&b.m(n,null),g(e,k),m&&m.m(e,null),g(e,A),d&&d.m(e,null),t[24](e),I||(G=[K(r,"change",t[23]),K(r,"change",t[10]),K(r,"invalid",t[11])],I=!0)},p(h,v){h[5]===y.VERIFYING?_||(_=de(),_.c(),_.m(n,i)):_&&(_.d(1),_=null),v[0]&8&&s!==(s=h[3]+"_checkbox")&&c(r,"id",s),v[0]&1&&u!==(u=h[0]!=="onsubmit")&&(r.required=u),v[0]&64&&(r.checked=h[6]),v[0]&32&&le(o,"altcha-hidden",h[5]===y.VERIFYING),Y===(Y=U(h))&&C?C.p(h,v):(C.d(1),C=Y(h),C&&(C.c(),C.m(a,null))),h[2]!==!0?b?b.p(h,v):(b=ge(),b.c(),b.m(n,null)):b&&(b.d(1),b=null),h[8]?m?m.p(h,v):(m=be(h),m.c(),m.m(e,A)):m&&(m.d(1),m=null),h[9].footer&&h[1]!==!0?d?d.p(h,v):(d=me(h),d.c(),d.m(e,null)):d&&(d.d(1),d=null),v[0]&32&&c(e,"data-state",h[5])},i:p,o:p,d(h){h&&L(e),_&&_.d(),C.d(),b&&b.d(),m&&m.d(),d&&d.d(),t[24](null),I=!1,W(G)}}}const ve="https://altcha.org/";function _e(t){return JSON.parse(t)}function ot(t,e,n){let i,o,r,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:f=void 0}=e,{debug:a=!1}=e,{hidefooter:j=!1}=e,{hidelogo:k=!1}=e,{name:A="altcha"}=e,{maxnumber:I=void 0}=e,{mockerror:G=!1}=e,{strings:_=void 0}=e,{test:U=!1}=e;const Y=Me(),C=["SHA-256","SHA-384","SHA-512"];let b=!1,m,d=null,h=null,v=null,O=y.UNVERIFIED;Se(()=>{d&&(d.removeEventListener("submit",$e),d.removeEventListener("reset",ye),d=null)}),Ge(()=>{x("mounted","0.1.9"),U&&x("using test mode"),s!==void 0&&x("auto",s),d=m.closest("form"),d&&(d.addEventListener("submit",$e),d.addEventListener("reset",ye)),s==="onload"&&X()});function x(...l){(a||l.some(w=>w instanceof Error))&&console[l[0]instanceof Error?"error":"log"]("ALTCHA",...l)}function $e(l){d&&s==="onsubmit"&&O===y.UNVERIFIED&&(l.preventDefault(),l.stopPropagation(),X().then(()=>{d==null||d.requestSubmit()}))}function ye(){te()}function st(l,w){return btoa(JSON.stringify({algorithm:l.algorithm,challenge:l.challenge,number:w.number,salt:l.salt,signature:l.signature,test:U?!0:void 0,took:w.took}))}function ke(l){if(!l.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(l.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!C.includes(l.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${C.join(", ")}`);if(!l.challenge||l.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!l.salt||l.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function ct(){if(G)throw x("mocking error"),new Error("Mocked error.");if(i)return x("using provided json data"),i;if(U)return x("generating test challenge"),qe();{if(!u)throw new Error("Attribute challengeurl not set.");x("fetching challenge from",u);const l=await fetch(u);if(l.status!==200)throw new Error(`Server responded with ${l.status}.`);return l.json()}}async function ut(l){let w=null;if("Worker"in window){try{w=await at(l.challenge,l.salt,l.algorithm)}catch(ne){x(ne)}if((w==null?void 0:w.number)!==void 0)return{data:l,solution:w}}return{data:l,solution:await et(l.challenge,l.salt,l.algorithm,I)}}async function at(l,w,ne){const pe=new Ke;return new Promise(mt=>{pe.addEventListener("message",vt=>{mt(vt.data)}),pe.postMessage({alg:ne,challenge:l,max:I,salt:w})})}function ft(){[y.UNVERIFIED,y.ERROR].includes(O)?X():n(6,b=!0)}function ht(){O===y.VERIFYING&&alert(r.waitAlert)}function dt(l){l.auto!==void 0&&(n(0,s=l.auto),s==="onload"&&X()),l.challenge&&(ke(l.challenge),i=l.challenge),l.debug!==void 0&&n(12,a=!!l.debug),l.hidefooter!==void 0&&n(1,j=!!l.hidefooter),l.hidelogo!==void 0&&n(2,k=!!l.hidelogo),l.maxnumber!==void 0&&n(13,I=+l.maxnumber),l.mockerror!==void 0&&n(14,G=!!l.mockerror),l.name!==void 0&&n(3,A=l.name),l.test!==void 0&&n(15,U=!!l.test),l.strings&&n(22,o=l.strings)}function te(l=y.UNVERIFIED){n(6,b=!1),n(8,h=null),n(4,v=null),n(5,O=l)}async function X(){return te(y.VERIFYING),ct().then(l=>(ke(l),x("challenge",l),ut(l))).then(({data:l,solution:w})=>{if(x("solution",w),(w==null?void 0:w.number)!==void 0)x("verified"),n(5,O=y.VERIFIED),n(6,b=!0),n(4,v=st(l,w)),x("payload",v),Ue().then(()=>{Y("verified",{payload:v})});else throw new Error("Unexpected result returned.")}).catch(l=>{x(l),n(5,O=y.ERROR),n(6,b=!1),n(8,h=l)})}function gt(){b=this.checked,n(6,b)}function bt(l){J[l?"unshift":"push"](()=>{m=l,n(7,m)})}return t.$$set=l=>{"auto"in l&&n(0,s=l.auto),"challengeurl"in l&&n(16,u=l.challengeurl),"challengejson"in l&&n(17,f=l.challengejson),"debug"in l&&n(12,a=l.debug),"hidefooter"in l&&n(1,j=l.hidefooter),"hidelogo"in l&&n(2,k=l.hidelogo),"name"in l&&n(3,A=l.name),"maxnumber"in l&&n(13,I=l.maxnumber),"mockerror"in l&&n(14,G=l.mockerror),"strings"in l&&n(18,_=l.strings),"test"in l&&n(15,U=l.test)},t.$$.update=()=>{t.$$.dirty[0]&131072&&(i=f?_e(f):void 0),t.$$.dirty[0]&262144&&n(22,o=_?_e(_):{}),t.$$.dirty[0]&4194304&&n(9,r={error:"Verification failed. Try again later.",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:v,state:O})},[s,j,k,A,v,O,b,m,h,r,ft,ht,a,I,G,U,u,f,_,dt,te,X,o,gt,bt]}class we extends Te{constructor(e){super(),We(this,e,ot,lt,Ee,{auto:0,challengeurl:16,challengejson:17,debug:12,hidefooter:1,hidelogo:2,name:3,maxnumber:13,mockerror:14,strings:18,test:15,configure:19,reset:20,verify:21},tt,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),E()}get challengeurl(){return this.$$.ctx[16]}set challengeurl(e){this.$$set({challengeurl:e}),E()}get challengejson(){return this.$$.ctx[17]}set challengejson(e){this.$$set({challengejson:e}),E()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug: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[13]}set maxnumber(e){this.$$set({maxnumber:e}),E()}get mockerror(){return this.$$.ctx[14]}set mockerror(e){this.$$set({mockerror:e}),E()}get strings(){return this.$$.ctx[18]}set strings(e){this.$$set({strings:e}),E()}get test(){return this.$$.ctx[15]}set test(e){this.$$set({test:e}),E()}get configure(){return this.$$.ctx[19]}get reset(){return this.$$.ctx[20]}get verify(){return this.$$.ctx[21]}}return customElements.define("altcha-widget",Pe(we,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["configure","reset","verify"],!1)),S.Altcha=we,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"}),S}({}); diff --git a/dist/altcha.js b/dist/altcha.js index badeb3f..0b0e49c 100644 --- a/dist/altcha.js +++ b/dist/altcha.js @@ -1,37 +1,37 @@ -var Ae = Object.defineProperty; -var Ge = (t, e, n) => e in t ? Ae(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; -var x = (t, e, n) => (Ge(t, typeof e != "symbol" ? e + "" : e, n), n); +var Ge = Object.defineProperty; +var Se = (t, e, n) => e in t ? Ge(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; +var L = (t, e, n) => (Se(t, typeof e != "symbol" ? e + "" : e, n), n); function Z() { } -function de(t) { +function ge(t) { return t(); } -function oe() { +function ie() { return /* @__PURE__ */ Object.create(null); } -function W(t) { - t.forEach(de); +function P(t) { + t.forEach(ge); } -function ge(t) { +function be(t) { return typeof t == "function"; } -function Se(t, e) { +function Ue(t, e) { return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function"; } -function Ue(t) { +function Ve(t) { return Object.keys(t).length === 0; } function b(t, e) { t.appendChild(e); } -function Ve(t, e, n) { - const o = Me(t); +function Me(t, e, n) { + const o = Fe(t); if (!o.getElementById(e)) { - const i = w("style"); - i.id = e, i.textContent = n, Fe(o, i); + const l = $("style"); + l.id = e, l.textContent = n, Oe(o, l); } } -function Me(t) { +function Fe(t) { if (!t) return document; const e = t.getRootNode ? t.getRootNode() : t.ownerDocument; @@ -41,30 +41,30 @@ function Me(t) { e ) : t.ownerDocument; } -function Fe(t, e) { +function Oe(t, e) { return b( /** @type {Document} */ t.head || t, e ), e.sheet; } -function R(t, e, n) { +function N(t, e, n) { t.insertBefore(e, n || null); } -function L(t) { +function I(t) { t.parentNode && t.parentNode.removeChild(t); } -function w(t) { +function $(t) { return document.createElement(t); } -function G(t) { +function S(t) { return document.createElementNS("http://www.w3.org/2000/svg", t); } -function Oe(t) { +function Ye(t) { return document.createTextNode(t); } function M() { - return Oe(" "); + return Ye(" "); } function K(t, e, n, o) { return t.addEventListener(e, n, o), () => t.removeEventListener(e, n, o); @@ -72,16 +72,16 @@ function K(t, e, n, o) { function c(t, e, n) { n == null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n); } -function Ye(t) { +function Ze(t) { return Array.from(t.childNodes); } -function ie(t, e, n) { +function le(t, e, n) { t.classList.toggle(e, !!n); } -function Ze(t, e, { bubbles: n = !1, cancelable: o = !1 } = {}) { +function Be(t, e, { bubbles: n = !1, cancelable: o = !1 } = {}) { return new CustomEvent(t, { detail: e, bubbles: n, cancelable: o }); } -function Be(t) { +function He(t) { const e = {}; return t.childNodes.forEach( /** @param {Element} node */ @@ -90,33 +90,33 @@ function Be(t) { } ), e; } -let H; -function B(t) { - H = t; +let W; +function H(t) { + W = t; } function ee() { - if (!H) + if (!W) throw new Error("Function called outside component initialization"); - return H; + return W; } -function He(t) { +function We(t) { ee().$$.on_mount.push(t); } -function We(t) { +function Pe(t) { ee().$$.on_destroy.push(t); } -function Pe() { +function Te() { const t = ee(); return (e, n, { cancelable: o = !1 } = {}) => { - const i = t.$$.callbacks[e]; - if (i) { - const r = Ze( + const l = t.$$.callbacks[e]; + if (l) { + const r = Be( /** @type {string} */ e, n, { cancelable: o } ); - return i.slice().forEach((s) => { + return l.slice().forEach((s) => { s.call(t, r); }), !r.defaultPrevented; } @@ -125,13 +125,13 @@ function Pe() { } const O = [], J = []; let Y = []; -const le = [], be = /* @__PURE__ */ Promise.resolve(); +const se = [], me = /* @__PURE__ */ Promise.resolve(); let Q = !1; -function me() { - Q || (Q = !0, be.then(C)); +function ve() { + Q || (Q = !0, me.then(C)); } -function Te() { - return me(), be; +function Xe() { + return ve(), me; } function q(t) { Y.push(t); @@ -141,17 +141,17 @@ let F = 0; function C() { if (F !== 0) return; - const t = H; + const t = W; do { try { for (; F < O.length; ) { const e = O[F]; - F++, B(e), Xe(e.$$); + F++, H(e), De(e.$$); } } catch (e) { throw O.length = 0, F = 0, e; } - for (B(null), O.length = 0, F = 0; J.length; ) + for (H(null), O.length = 0, F = 0; J.length; ) J.pop()(); for (let e = 0; e < Y.length; e += 1) { const n = Y[e]; @@ -159,50 +159,50 @@ function C() { } Y.length = 0; } while (O.length); - for (; le.length; ) - le.pop()(); - Q = !1, z.clear(), B(t); + for (; se.length; ) + se.pop()(); + Q = !1, z.clear(), H(t); } -function Xe(t) { +function De(t) { if (t.fragment !== null) { - t.update(), W(t.before_update); + t.update(), P(t.before_update); const e = t.dirty; t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(q); } } -function De(t) { +function Ke(t) { const e = [], n = []; Y.forEach((o) => t.indexOf(o) === -1 ? e.push(o) : n.push(o)), n.forEach((o) => o()), Y = e; } -const Ke = /* @__PURE__ */ new Set(); -function ze(t, e) { - t && t.i && (Ke.delete(t), t.i(e)); +const ze = /* @__PURE__ */ new Set(); +function Je(t, e) { + t && t.i && (ze.delete(t), t.i(e)); } -function Je(t, e, n) { - const { fragment: o, after_update: i } = t.$$; +function Qe(t, e, n) { + const { fragment: o, after_update: l } = t.$$; o && o.m(e, n), q(() => { - const r = t.$$.on_mount.map(de).filter(ge); - t.$$.on_destroy ? t.$$.on_destroy.push(...r) : W(r), t.$$.on_mount = []; - }), i.forEach(q); + const r = t.$$.on_mount.map(ge).filter(be); + t.$$.on_destroy ? t.$$.on_destroy.push(...r) : P(r), t.$$.on_mount = []; + }), l.forEach(q); } -function Qe(t, e) { +function qe(t, e) { const n = t.$$; - n.fragment !== null && (De(n.after_update), W(n.on_destroy), n.fragment && n.fragment.d(e), n.on_destroy = n.fragment = null, n.ctx = []); + n.fragment !== null && (Ke(n.after_update), P(n.on_destroy), n.fragment && n.fragment.d(e), n.on_destroy = n.fragment = null, n.ctx = []); } -function qe(t, e) { - t.$$.dirty[0] === -1 && (O.push(t), me(), t.$$.dirty.fill(0)), t.$$.dirty[e / 31 | 0] |= 1 << e % 31; +function et(t, e) { + t.$$.dirty[0] === -1 && (O.push(t), ve(), t.$$.dirty.fill(0)), t.$$.dirty[e / 31 | 0] |= 1 << e % 31; } -function et(t, e, n, o, i, r, s = null, a = [-1]) { - const f = H; - B(t); - const u = t.$$ = { +function tt(t, e, n, o, l, r, s = null, u = [-1]) { + const f = W; + H(t); + const a = t.$$ = { fragment: null, ctx: [], // state props: r, update: Z, - not_equal: i, - bound: oe(), + not_equal: l, + bound: ie(), // lifecycle on_mount: [], on_destroy: [], @@ -211,61 +211,61 @@ function et(t, e, n, o, i, r, s = null, a = [-1]) { after_update: [], context: new Map(e.context || (f ? f.$$.context : [])), // everything else - callbacks: oe(), - dirty: a, + callbacks: ie(), + dirty: u, skip_bound: !1, root: e.target || f.$$.root }; - s && s(u.root); - let N = !1; - if (u.ctx = n ? n(t, e.props || {}, (y, j, ...I) => { - const A = I.length ? I[0] : j; - return u.ctx && i(u.ctx[y], u.ctx[y] = A) && (!u.skip_bound && u.bound[y] && u.bound[y](A), N && qe(t, y)), j; - }) : [], u.update(), N = !0, W(u.before_update), u.fragment = o ? o(u.ctx) : !1, e.target) { + s && s(a.root); + let R = !1; + if (a.ctx = n ? n(t, e.props || {}, (p, j, ...x) => { + const A = x.length ? x[0] : j; + return a.ctx && l(a.ctx[p], a.ctx[p] = A) && (!a.skip_bound && a.bound[p] && a.bound[p](A), R && et(t, p)), j; + }) : [], a.update(), R = !0, P(a.before_update), a.fragment = o ? o(a.ctx) : !1, e.target) { if (e.hydrate) { - const y = Ye(e.target); - u.fragment && u.fragment.l(y), y.forEach(L); + const p = Ze(e.target); + a.fragment && a.fragment.l(p), p.forEach(I); } else - u.fragment && u.fragment.c(); - e.intro && ze(t.$$.fragment), Je(t, e.target, e.anchor), C(); + a.fragment && a.fragment.c(); + e.intro && Je(t.$$.fragment), Qe(t, e.target, e.anchor), C(); } - B(f); + H(f); } -let ve; -typeof HTMLElement == "function" && (ve = class extends HTMLElement { +let _e; +typeof HTMLElement == "function" && (_e = class extends HTMLElement { constructor(e, n, o) { super(); /** The Svelte component constructor */ - x(this, "$$ctor"); + L(this, "$$ctor"); /** Slots */ - x(this, "$$s"); + L(this, "$$s"); /** The Svelte component instance */ - x(this, "$$c"); + L(this, "$$c"); /** Whether or not the custom element is connected */ - x(this, "$$cn", !1); + L(this, "$$cn", !1); /** Component props data */ - x(this, "$$d", {}); + L(this, "$$d", {}); /** `true` if currently in the process of reflecting component props back to attributes */ - x(this, "$$r", !1); + L(this, "$$r", !1); /** @type {Record} Props definition (name, reflected, type etc) */ - x(this, "$$p_d", {}); + L(this, "$$p_d", {}); /** @type {Record} Event listeners */ - x(this, "$$l", {}); + L(this, "$$l", {}); /** @type {Map} Event listener unsubscribe functions */ - x(this, "$$l_u", /* @__PURE__ */ new Map()); + L(this, "$$l_u", /* @__PURE__ */ new Map()); this.$$ctor = e, this.$$s = n, o && this.attachShadow({ mode: "open" }); } addEventListener(e, n, o) { if (this.$$l[e] = this.$$l[e] || [], this.$$l[e].push(n), this.$$c) { - const i = this.$$c.$on(e, n); - this.$$l_u.set(n, i); + const l = this.$$c.$on(e, n); + this.$$l_u.set(n, l); } super.addEventListener(e, n, o); } removeEventListener(e, n, o) { if (super.removeEventListener(e, n, o), this.$$c) { - const i = this.$$l_u.get(n); - i && (i(), this.$$l_u.delete(n)); + const l = this.$$l_u.get(n); + l && (l(), this.$$l_u.delete(n)); } } async connectedCallback() { @@ -275,24 +275,24 @@ typeof HTMLElement == "function" && (ve = class extends HTMLElement { let s; return { c: function() { - s = w("slot"), r !== "default" && c(s, "name", r); + s = $("slot"), r !== "default" && c(s, "name", r); }, /** * @param {HTMLElement} target * @param {HTMLElement} [anchor] */ - m: function(u, N) { - R(u, s, N); + m: function(a, R) { + N(a, s, R); }, - d: function(u) { - u && L(s); + d: function(a) { + a && I(s); } }; }; }; if (await Promise.resolve(), !this.$$cn || this.$$c) return; - const n = {}, o = Be(this); + const n = {}, o = He(this); for (const r of this.$$s) r in o && (n[r] = [e(r)]); for (const r of this.attributes) { @@ -311,7 +311,7 @@ typeof HTMLElement == "function" && (ve = class extends HTMLElement { } } }); - const i = () => { + const l = () => { this.$$r = !0; for (const r in this.$$p_d) if (this.$$d[r] = this.$$c.$$.ctx[this.$$c.$$.props[r]], this.$$p_d[r].reflect) { @@ -325,11 +325,11 @@ typeof HTMLElement == "function" && (ve = class extends HTMLElement { } this.$$r = !1; }; - this.$$c.$$.after_update.push(i), i(); + this.$$c.$$.after_update.push(l), l(); for (const r in this.$$l) for (const s of this.$$l[r]) { - const a = this.$$c.$on(r, s); - this.$$l_u.set(s, a); + const u = this.$$c.$on(r, s); + this.$$l_u.set(s, u); } this.$$l = {}; } @@ -337,8 +337,8 @@ typeof HTMLElement == "function" && (ve = class extends HTMLElement { // We don't need this when working within Svelte code, but for compatibility of people using this outside of Svelte // and setting attributes through setAttribute etc, this is helpful attributeChangedCallback(e, n, o) { - var i; - this.$$r || (e = this.$$g_p(e), this.$$d[e] = T(e, o, this.$$p_d, "toProp"), (i = this.$$c) == null || i.$set({ [e]: this.$$d[e] })); + var l; + this.$$r || (e = this.$$g_p(e), this.$$d[e] = T(e, o, this.$$p_d, "toProp"), (l = this.$$c) == null || l.$set({ [e]: this.$$d[e] })); } disconnectedCallback() { this.$$cn = !1, Promise.resolve().then(() => { @@ -353,11 +353,11 @@ typeof HTMLElement == "function" && (ve = class extends HTMLElement { }); function T(t, e, n, o) { var r; - const i = (r = n[t]) == null ? void 0 : r.type; - if (e = i === "Boolean" && typeof e != "boolean" ? e != null : e, !o || !n[t]) + const l = (r = n[t]) == null ? void 0 : r.type; + if (e = l === "Boolean" && typeof e != "boolean" ? e != null : e, !o || !n[t]) return e; if (o === "toAttribute") - switch (i) { + switch (l) { case "Object": case "Array": return e == null ? null : JSON.stringify(e); @@ -369,7 +369,7 @@ function T(t, e, n, o) { return e; } else - switch (i) { + switch (l) { case "Object": case "Array": return e && JSON.parse(e); @@ -381,38 +381,38 @@ function T(t, e, n, o) { return e; } } -function tt(t, e, n, o, i, r) { - let s = class extends ve { +function nt(t, e, n, o, l, r) { + let s = class extends _e { constructor() { - super(t, n, i), this.$$p_d = e; + super(t, n, l), this.$$p_d = e; } static get observedAttributes() { return Object.keys(e).map( - (a) => (e[a].attribute || a).toLowerCase() + (u) => (e[u].attribute || u).toLowerCase() ); } }; - return Object.keys(e).forEach((a) => { - Object.defineProperty(s.prototype, a, { + return Object.keys(e).forEach((u) => { + Object.defineProperty(s.prototype, u, { get() { - return this.$$c && a in this.$$c ? this.$$c[a] : this.$$d[a]; + return this.$$c && u in this.$$c ? this.$$c[u] : this.$$d[u]; }, set(f) { - var u; - f = T(a, f, e), this.$$d[a] = f, (u = this.$$c) == null || u.$set({ [a]: f }); + var a; + f = T(u, f, e), this.$$d[u] = f, (a = this.$$c) == null || a.$set({ [u]: f }); } }); - }), o.forEach((a) => { - Object.defineProperty(s.prototype, a, { + }), o.forEach((u) => { + Object.defineProperty(s.prototype, u, { get() { var f; - return (f = this.$$c) == null ? void 0 : f[a]; + return (f = this.$$c) == null ? void 0 : f[u]; } }); }), r && (s = r(s)), t.element = /** @type {any} */ s, s; } -class nt { +class rt { constructor() { /** * ### PRIVATE API @@ -421,7 +421,7 @@ class nt { * * @type {any} */ - x(this, "$$"); + L(this, "$$"); /** * ### PRIVATE API * @@ -429,11 +429,11 @@ class nt { * * @type {any} */ - x(this, "$$set"); + L(this, "$$set"); } /** @returns {void} */ $destroy() { - Qe(this, 1), this.$destroy = Z; + qe(this, 1), this.$destroy = Z; } /** * @template {Extract} K @@ -442,12 +442,12 @@ class nt { * @returns {() => void} */ $on(e, n) { - if (!ge(n)) + if (!be(n)) return Z; const o = this.$$.callbacks[e] || (this.$$.callbacks[e] = []); return o.push(n), () => { - const i = o.indexOf(n); - i !== -1 && o.splice(i, 1); + const l = o.indexOf(n); + l !== -1 && o.splice(l, 1); }; } /** @@ -455,16 +455,16 @@ class nt { * @returns {void} */ $set(e) { - this.$$set && !Ue(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1); + this.$$set && !Ve(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1); } } -const rt = "4"; -typeof window < "u" && (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(rt); -const $e = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==", ot = (t) => Uint8Array.from(atob(t), (e) => e.charCodeAt(0)), se = typeof window < "u" && window.Blob && new Blob([ot($e)], { type: "text/javascript;charset=utf-8" }); -function it(t) { +const ot = "4"; +typeof window < "u" && (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(ot); +const we = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==", it = (t) => Uint8Array.from(atob(t), (e) => e.charCodeAt(0)), ce = typeof window < "u" && window.Blob && new Blob([it(we)], { type: "text/javascript;charset=utf-8" }); +function lt(t) { let e; try { - if (e = se && (window.URL || window.webkitURL).createObjectURL(se), !e) + if (e = ce && (window.URL || window.webkitURL).createObjectURL(ce), !e) throw ""; const n = new Worker(e, { name: t == null ? void 0 : t.name @@ -474,7 +474,7 @@ function it(t) { }), n; } catch { return new Worker( - "data:text/javascript;base64," + $e, + "data:text/javascript;base64," + we, { name: t == null ? void 0 : t.name } @@ -483,238 +483,238 @@ function it(t) { e && (window.URL || window.webkitURL).revokeObjectURL(e); } } -const lt = 1e7, st = new TextEncoder(); -function ct(t) { +const st = 1e7, ct = new TextEncoder(); +function ut(t) { return [...new Uint8Array(t)].map((e) => e.toString(16).padStart(2, "0")).join(""); } async function at(t = 1e5, e = "SHA-256") { - const n = Date.now().toString(16), o = Math.round(Math.random() * t), i = await _e(n, o, e); + const n = Date.now().toString(16), o = Math.round(Math.random() * t), l = await $e(n, o, e); return { algorithm: e, - challenge: i, + challenge: l, salt: n, signature: "" }; } -async function _e(t, e, n) { - return ct(await crypto.subtle.digest(n.toUpperCase(), st.encode(t + e))); +async function $e(t, e, n) { + return ut(await crypto.subtle.digest(n.toUpperCase(), ct.encode(t + e))); } -async function ut(t, e, n = "SHA-256", o = lt) { - const i = Date.now(); +async function ft(t, e, n = "SHA-256", o = st) { + const l = Date.now(); for (let r = 0; r <= o; r++) - if (await _e(e, r, n) === t) + if (await $e(e, r, n) === t) return { number: r, - took: Date.now() - i + took: Date.now() - l }; return null; } -var p = /* @__PURE__ */ ((t) => (t.ERROR = "error", t.VERIFIED = "verified", t.VERIFYING = "verifying", t.UNVERIFIED = "unverified", t))(p || {}); -function ft(t) { - Ve(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)}}"); +var y = /* @__PURE__ */ ((t) => (t.ERROR = "error", t.VERIFIED = "verified", t.VERIFYING = "verifying", t.UNVERIFIED = "unverified", t))(y || {}); +function ht(t) { + Me(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 ce(t) { +function ue(t) { let e, n, o; return { c() { - e = G("svg"), n = G("path"), o = G("path"), c(n, "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(n, "fill", "currentColor"), c(n, "opacity", ".25"), c(o, "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(o, "fill", "currentColor"), c(o, "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"); + e = S("svg"), n = S("path"), o = S("path"), c(n, "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(n, "fill", "currentColor"), c(n, "opacity", ".25"), c(o, "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(o, "fill", "currentColor"), c(o, "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(i, r) { - R(i, e, r), b(e, n), b(e, o); + m(l, r) { + N(l, e, r), b(e, n), b(e, o); }, - d(i) { - i && L(e); + d(l) { + l && I(e); } }; } -function ht(t) { +function dt(t) { let e, n = ( /*_strings*/ t[9].label + "" ), o; return { c() { - e = w("label"), c(e, "for", o = /*name*/ + e = $("label"), c(e, "for", o = /*name*/ t[3] + "_checkbox"), c(e, "class", "svelte-vuofbg"); }, - m(i, r) { - R(i, e, r), e.innerHTML = n; + m(l, r) { + N(l, e, r), e.innerHTML = n; }, - p(i, r) { + p(l, r) { r[0] & /*_strings*/ 512 && n !== (n = /*_strings*/ - i[9].label + "") && (e.innerHTML = n), r[0] & /*name*/ + l[9].label + "") && (e.innerHTML = n), r[0] & /*name*/ 8 && o !== (o = /*name*/ - i[3] + "_checkbox") && c(e, "for", o); + l[3] + "_checkbox") && c(e, "for", o); }, - d(i) { - i && L(e); + d(l) { + l && I(e); } }; } -function dt(t) { +function gt(t) { let e, n = ( /*_strings*/ t[9].verifying + "" ); return { c() { - e = w("span"); + e = $("span"); }, - m(o, i) { - R(o, e, i), e.innerHTML = n; + m(o, l) { + N(o, e, l), e.innerHTML = n; }, - p(o, i) { - i[0] & /*_strings*/ + p(o, l) { + l[0] & /*_strings*/ 512 && n !== (n = /*_strings*/ o[9].verifying + "") && (e.innerHTML = n); }, d(o) { - o && L(e); + o && I(e); } }; } -function gt(t) { +function bt(t) { let e, n = ( /*_strings*/ t[9].verified + "" - ), o, i; + ), o, l; return { c() { - e = w("span"), o = M(), i = w("input"), c(i, "type", "hidden"), c( - i, + e = $("span"), o = M(), l = $("input"), c(l, "type", "hidden"), c( + l, "name", /*name*/ t[3] - ), i.value = /*payload*/ + ), l.value = /*payload*/ t[4]; }, m(r, s) { - R(r, e, s), e.innerHTML = n, R(r, o, s), R(r, i, s); + N(r, e, s), e.innerHTML = n, N(r, o, s), N(r, l, s); }, p(r, s) { s[0] & /*_strings*/ 512 && n !== (n = /*_strings*/ r[9].verified + "") && (e.innerHTML = n), s[0] & /*name*/ 8 && c( - i, + l, "name", /*name*/ r[3] ), s[0] & /*payload*/ - 16 && (i.value = /*payload*/ + 16 && (l.value = /*payload*/ r[4]); }, d(r) { - r && (L(e), L(o), L(i)); + r && (I(e), I(o), I(l)); } }; } function ae(t) { - let e, n, o, i, r, s; + let e, n, o, l, r, s; return { c() { - e = w("div"), n = w("a"), o = G("svg"), i = G("path"), r = G("path"), s = G("path"), c(i, "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(i, "fill", "currentColor"), c(r, "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(r, "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(o, "width", "22"), c(o, "height", "22"), c(o, "viewBox", "0 0 20 20"), c(o, "fill", "none"), c(o, "xmlns", "http://www.w3.org/2000/svg"), c(n, "href", we), c(n, "target", "_blank"), c(n, "class", "altcha-logo svelte-vuofbg"); + e = $("div"), n = $("a"), o = S("svg"), l = S("path"), r = S("path"), s = S("path"), c(l, "d", "M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"), c(l, "fill", "currentColor"), c(r, "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(r, "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(o, "width", "22"), c(o, "height", "22"), c(o, "viewBox", "0 0 20 20"), c(o, "fill", "none"), c(o, "xmlns", "http://www.w3.org/2000/svg"), c(n, "href", ye), c(n, "target", "_blank"), c(n, "class", "altcha-logo svelte-vuofbg"); }, - m(a, f) { - R(a, e, f), b(e, n), b(n, o), b(o, i), b(o, r), b(o, s); + m(u, f) { + N(u, e, f), b(e, n), b(n, o), b(o, l), b(o, r), b(o, s); }, p: Z, - d(a) { - a && L(e); + d(u) { + u && I(e); } }; } -function ue(t) { - let e, n, o, i, r, s = ( +function fe(t) { + let e, n, o, l, r, s = ( /*_strings*/ t[9].error + "" ); return { c() { - e = w("div"), n = G("svg"), o = G("path"), i = M(), r = w("div"), c(o, "stroke-linecap", "round"), c(o, "stroke-linejoin", "round"), c(o, "d", "M6 18L18 6M6 6l12 12"), c(n, "width", "14"), c(n, "height", "14"), c(n, "xmlns", "http://www.w3.org/2000/svg"), c(n, "fill", "none"), c(n, "viewBox", "0 0 24 24"), c(n, "stroke-width", "1.5"), c(n, "stroke", "currentColor"), c( + e = $("div"), n = S("svg"), o = S("path"), l = M(), r = $("div"), c(o, "stroke-linecap", "round"), c(o, "stroke-linejoin", "round"), c(o, "d", "M6 18L18 6M6 6l12 12"), c(n, "width", "14"), c(n, "height", "14"), c(n, "xmlns", "http://www.w3.org/2000/svg"), c(n, "fill", "none"), c(n, "viewBox", "0 0 24 24"), c(n, "stroke-width", "1.5"), c(n, "stroke", "currentColor"), c( r, "title", /*error*/ t[8] ), c(e, "class", "altcha-error svelte-vuofbg"); }, - m(a, f) { - R(a, e, f), b(e, n), b(n, o), b(e, i), b(e, r), r.innerHTML = s; + m(u, f) { + N(u, e, f), b(e, n), b(n, o), b(e, l), b(e, r), r.innerHTML = s; }, - p(a, f) { + p(u, f) { f[0] & /*_strings*/ 512 && s !== (s = /*_strings*/ - a[9].error + "") && (r.innerHTML = s), f[0] & /*error*/ + u[9].error + "") && (r.innerHTML = s), f[0] & /*error*/ 256 && c( r, "title", /*error*/ - a[8] + u[8] ); }, - d(a) { - a && L(e); + d(u) { + u && I(e); } }; } -function fe(t) { +function he(t) { let e, n, o = ( /*_strings*/ t[9].footer + "" ); return { c() { - e = w("div"), n = w("div"), c(n, "class", "svelte-vuofbg"), c(e, "class", "altcha-footer svelte-vuofbg"); + e = $("div"), n = $("div"), c(n, "class", "svelte-vuofbg"), c(e, "class", "altcha-footer svelte-vuofbg"); }, - m(i, r) { - R(i, e, r), b(e, n), n.innerHTML = o; + m(l, r) { + N(l, e, r), b(e, n), n.innerHTML = o; }, - p(i, r) { + p(l, r) { r[0] & /*_strings*/ 512 && o !== (o = /*_strings*/ - i[9].footer + "") && (n.innerHTML = o); + l[9].footer + "") && (n.innerHTML = o); }, - d(i) { - i && L(e); + d(l) { + l && I(e); } }; } -function bt(t) { - let e, n, o, i, r, s, a, f, u, N, y, j, I, A, $ = ( +function mt(t) { + let e, n, o, l, r, s, u, f, a, R, p, j, x, A, _ = ( /*state*/ - t[5] === p.VERIFYING && ce() + t[5] === y.VERIFYING && ue() ); - function S(h, v) { + function G(h, v) { return ( /*state*/ - h[5] === p.VERIFIED ? gt : ( + h[5] === y.VERIFIED ? bt : ( /*state*/ - h[5] === p.VERIFYING ? dt : ht + h[5] === y.VERIFYING ? gt : dt ) ); } - let V = S(t), k = V(t), g = ( + let V = G(t), k = V(t), g = ( /*hidelogo*/ t[2] !== !0 && ae() ), m = ( /*error*/ - t[8] && ue(t) + t[8] && fe(t) ), d = ( /*_strings*/ t[9].footer && /*hidefooter*/ - t[1] !== !0 && fe(t) + t[1] !== !0 && he(t) ); return { c() { - e = w("div"), n = w("div"), $ && $.c(), o = M(), i = w("div"), r = w("input"), f = M(), u = w("div"), k.c(), N = M(), g && g.c(), y = M(), m && m.c(), j = M(), d && d.c(), c(r, "type", "checkbox"), c(r, "id", s = /*name*/ - t[3] + "_checkbox"), r.required = a = /*auto*/ - t[0] !== "onsubmit", c(r, "class", "svelte-vuofbg"), c(i, "class", "altcha-checkbox svelte-vuofbg"), ie( - i, + e = $("div"), n = $("div"), _ && _.c(), o = M(), l = $("div"), r = $("input"), f = M(), a = $("div"), k.c(), R = M(), g && g.c(), p = M(), m && m.c(), j = M(), d && d.c(), c(r, "type", "checkbox"), c(r, "id", s = /*name*/ + t[3] + "_checkbox"), r.required = u = /*auto*/ + t[0] !== "onsubmit", c(r, "class", "svelte-vuofbg"), c(l, "class", "altcha-checkbox svelte-vuofbg"), le( + l, "altcha-hidden", /*state*/ - t[5] === p.VERIFYING - ), c(u, "class", "altcha-label svelte-vuofbg"), c(n, "class", "altcha-main svelte-vuofbg"), c(e, "class", "altcha svelte-vuofbg"), c( + t[5] === y.VERIFYING + ), c(a, "class", "altcha-label svelte-vuofbg"), c(n, "class", "altcha-main svelte-vuofbg"), c(e, "class", "altcha svelte-vuofbg"), c( e, "data-state", /*state*/ @@ -722,13 +722,13 @@ function bt(t) { ); }, m(h, v) { - R(h, e, v), b(e, n), $ && $.m(n, null), b(n, o), b(n, i), b(i, r), r.checked = /*checked*/ - t[6], b(n, f), b(n, u), k.m(u, null), b(n, N), g && g.m(n, null), b(e, y), m && m.m(e, null), b(e, j), d && d.m(e, null), t[23](e), I || (A = [ + N(h, e, v), b(e, n), _ && _.m(n, null), b(n, o), b(n, l), b(l, r), r.checked = /*checked*/ + t[6], b(n, f), b(n, a), k.m(a, null), b(n, R), g && g.m(n, null), b(e, p), m && m.m(e, null), b(e, j), d && d.m(e, null), t[24](e), x || (A = [ K( r, "change", /*input_change_handler*/ - t[22] + t[23] ), K( r, @@ -742,27 +742,27 @@ function bt(t) { /*onInvalid*/ t[11] ) - ], I = !0); + ], x = !0); }, p(h, v) { /*state*/ - h[5] === p.VERIFYING ? $ || ($ = ce(), $.c(), $.m(n, o)) : $ && ($.d(1), $ = null), v[0] & /*name*/ + h[5] === y.VERIFYING ? _ || (_ = ue(), _.c(), _.m(n, o)) : _ && (_.d(1), _ = null), v[0] & /*name*/ 8 && s !== (s = /*name*/ h[3] + "_checkbox") && c(r, "id", s), v[0] & /*auto*/ - 1 && a !== (a = /*auto*/ - h[0] !== "onsubmit") && (r.required = a), v[0] & /*checked*/ + 1 && u !== (u = /*auto*/ + h[0] !== "onsubmit") && (r.required = u), v[0] & /*checked*/ 64 && (r.checked = /*checked*/ h[6]), v[0] & /*state*/ - 32 && ie( - i, + 32 && le( + l, "altcha-hidden", /*state*/ - h[5] === p.VERIFYING - ), V === (V = S(h)) && k ? k.p(h, v) : (k.d(1), k = V(h), k && (k.c(), k.m(u, null))), /*hidelogo*/ + h[5] === y.VERIFYING + ), V === (V = G(h)) && k ? k.p(h, v) : (k.d(1), k = V(h), k && (k.c(), k.m(a, null))), /*hidelogo*/ h[2] !== !0 ? g ? g.p(h, v) : (g = ae(), g.c(), g.m(n, null)) : g && (g.d(1), g = null), /*error*/ - h[8] ? m ? m.p(h, v) : (m = ue(h), m.c(), m.m(e, j)) : m && (m.d(1), m = null), /*_strings*/ + h[8] ? m ? m.p(h, v) : (m = fe(h), m.c(), m.m(e, j)) : m && (m.d(1), m = null), /*_strings*/ h[9].footer && /*hidefooter*/ - h[1] !== !0 ? d ? d.p(h, v) : (d = fe(h), d.c(), d.m(e, null)) : d && (d.d(1), d = null), v[0] & /*state*/ + h[1] !== !0 ? d ? d.p(h, v) : (d = he(h), d.c(), d.m(e, null)) : d && (d.d(1), d = null), v[0] & /*state*/ 32 && c( e, "data-state", @@ -773,55 +773,55 @@ function bt(t) { i: Z, o: Z, d(h) { - h && L(e), $ && $.d(), k.d(), g && g.d(), m && m.d(), d && d.d(), t[23](null), I = !1, W(A); + h && I(e), _ && _.d(), k.d(), g && g.d(), m && m.d(), d && d.d(), t[24](null), x = !1, P(A); } }; } -const we = "https://altcha.org/"; -function he(t) { +const ye = "https://altcha.org/"; +function de(t) { return JSON.parse(t); } -function mt(t, e, n) { - let o, i, r, { auto: s = void 0 } = e, { challengeurl: a = void 0 } = e, { challengejson: f = void 0 } = e, { debug: u = !1 } = e, { hidefooter: N = !1 } = e, { hidelogo: y = !1 } = e, { name: j = "altcha" } = e, { maxnumber: I = void 0 } = e, { mockerror: A = !1 } = e, { strings: $ = void 0 } = e, { test: S = !1 } = e; - const V = Pe(), k = ["SHA-256", "SHA-384", "SHA-512"]; - let g = !1, m, d = null, h = null, v = null, U = p.UNVERIFIED; - We(() => { +function vt(t, e, n) { + let o, l, r, { auto: s = void 0 } = e, { challengeurl: u = void 0 } = e, { challengejson: f = void 0 } = e, { debug: a = !1 } = e, { hidefooter: R = !1 } = e, { hidelogo: p = !1 } = e, { name: j = "altcha" } = e, { maxnumber: x = void 0 } = e, { mockerror: A = !1 } = e, { strings: _ = void 0 } = e, { test: G = !1 } = e; + const V = Te(), k = ["SHA-256", "SHA-384", "SHA-512"]; + let g = !1, m, d = null, h = null, v = null, U = y.UNVERIFIED; + Pe(() => { d && (d.removeEventListener("submit", te), d.removeEventListener("reset", ne), d = null); - }), He(() => { - E("mounted", "0.1.8"), S && E("using test mode"), s !== void 0 && E("auto", s), d = m.closest("form"), d && (d.addEventListener("submit", te), d.addEventListener("reset", ne)), s === "onload" && P(); + }), We(() => { + E("mounted", "0.1.9"), G && E("using test mode"), s !== void 0 && E("auto", s), d = m.closest("form"), d && (d.addEventListener("submit", te), d.addEventListener("reset", ne)), s === "onload" && B(); }); - function E(...l) { - (u || l.some((_) => _ instanceof Error)) && console[l[0] instanceof Error ? "error" : "log"]("ALTCHA", ...l); + function E(...i) { + (a || i.some((w) => w instanceof Error)) && console[i[0] instanceof Error ? "error" : "log"]("ALTCHA", ...i); } - function te(l) { - d && s === "onsubmit" && U === p.UNVERIFIED && (l.preventDefault(), l.stopPropagation(), P().then(() => { + function te(i) { + d && s === "onsubmit" && U === y.UNVERIFIED && (i.preventDefault(), i.stopPropagation(), B().then(() => { d == null || d.requestSubmit(); })); } function ne() { X(); } - function pe(l, _) { + function pe(i, w) { return btoa(JSON.stringify({ - algorithm: l.algorithm, - challenge: l.challenge, - number: _.number, - salt: l.salt, - signature: l.signature, - test: S ? !0 : void 0, - took: _.took + algorithm: i.algorithm, + challenge: i.challenge, + number: w.number, + salt: i.salt, + signature: i.signature, + test: G ? !0 : void 0, + took: w.took })); } - function ye(l) { - if (!l.algorithm) + function re(i) { + if (!i.algorithm) throw new Error("Invalid challenge. Property algorithm is missing."); - if (l.signature === void 0) + if (i.signature === void 0) throw new Error("Invalid challenge. Property signature is missing."); - if (!k.includes(l.algorithm.toUpperCase())) + if (!k.includes(i.algorithm.toUpperCase())) throw new Error(`Unknown algorithm value. Allowed values: ${k.join(", ")}`); - if (!l.challenge || l.challenge.length < 40) + if (!i.challenge || i.challenge.length < 40) throw new Error("Challenge is too short. Min. 40 chars."); - if (!l.salt || l.salt.length < 10) + if (!i.salt || i.salt.length < 10) throw new Error("Salt is too short. Min. 10 chars."); } async function ke() { @@ -829,91 +829,94 @@ function mt(t, e, n) { throw E("mocking error"), new Error("Mocked error."); if (o) return E("using provided json data"), o; - if (S) + if (G) return E("generating test challenge"), at(); { - if (!a) + if (!u) throw new Error("Attribute challengeurl not set."); - E("fetching challenge from", a); - const l = await fetch(a); - if (l.status !== 200) - throw new Error(`Server responded with ${l.status}.`); - return l.json(); + E("fetching challenge from", u); + const i = await fetch(u); + if (i.status !== 200) + throw new Error(`Server responded with ${i.status}.`); + return i.json(); } } - async function Ee(l) { - let _ = null; + async function Ee(i) { + let w = null; if ("Worker" in window) { try { - _ = await Ce(l.challenge, l.salt, l.algorithm); + w = await Ce(i.challenge, i.salt, i.algorithm); } catch (D) { E(D); } - if ((_ == null ? void 0 : _.number) !== void 0) - return { data: l, solution: _ }; + if ((w == null ? void 0 : w.number) !== void 0) + return { data: i, solution: w }; } return { - data: l, - solution: await ut(l.challenge, l.salt, l.algorithm, I) + data: i, + solution: await ft(i.challenge, i.salt, i.algorithm, x) }; } - async function Ce(l, _, D) { - const re = new it(); - return new Promise((Ne) => { - re.addEventListener("message", (je) => { - Ne(je.data); - }), re.postMessage({ alg: D, challenge: l, max: I, salt: _ }); + async function Ce(i, w, D) { + const oe = new lt(); + return new Promise((je) => { + oe.addEventListener("message", (Ae) => { + je(Ae.data); + }), oe.postMessage({ alg: D, challenge: i, max: x, salt: w }); }); } function xe() { - [p.UNVERIFIED, p.ERROR].includes(U) ? P() : n(6, g = !0); + [y.UNVERIFIED, y.ERROR].includes(U) ? B() : n(6, g = !0); } function Le() { - U === p.VERIFYING && alert(r.waitAlert); + U === y.VERIFYING && alert(r.waitAlert); } - function X(l = p.UNVERIFIED) { - n(6, g = !1), n(8, h = null), n(4, v = null), n(5, U = l); + function Ie(i) { + i.auto !== void 0 && (n(0, s = i.auto), s === "onload" && B()), i.challenge && (re(i.challenge), o = i.challenge), i.debug !== void 0 && n(12, a = !!i.debug), i.hidefooter !== void 0 && n(1, R = !!i.hidefooter), i.hidelogo !== void 0 && n(2, p = !!i.hidelogo), i.maxnumber !== void 0 && n(13, x = +i.maxnumber), i.mockerror !== void 0 && n(14, A = !!i.mockerror), i.name !== void 0 && n(3, j = i.name), i.test !== void 0 && n(15, G = !!i.test), i.strings && n(22, l = i.strings); } - async function P() { - return X(p.VERIFYING), ke().then((l) => (ye(l), E("challenge", l), Ee(l))).then(({ data: l, solution: _ }) => { - if (E("solution", _), (_ == null ? void 0 : _.number) !== void 0) - E("verified"), n(5, U = p.VERIFIED), n(6, g = !0), n(4, v = pe(l, _)), E("payload", v), Te().then(() => { + function X(i = y.UNVERIFIED) { + n(6, g = !1), n(8, h = null), n(4, v = null), n(5, U = i); + } + async function B() { + return X(y.VERIFYING), ke().then((i) => (re(i), E("challenge", i), Ee(i))).then(({ data: i, solution: w }) => { + if (E("solution", w), (w == null ? void 0 : w.number) !== void 0) + E("verified"), n(5, U = y.VERIFIED), n(6, g = !0), n(4, v = pe(i, w)), E("payload", v), Xe().then(() => { V("verified", { payload: v }); }); else throw new Error("Unexpected result returned."); - }).catch((l) => { - E(l), n(5, U = p.ERROR), n(6, g = !1), n(8, h = l); + }).catch((i) => { + E(i), n(5, U = y.ERROR), n(6, g = !1), n(8, h = i); }); } - function Ie() { + function Re() { g = this.checked, n(6, g); } - function Re(l) { - J[l ? "unshift" : "push"](() => { - m = l, n(7, m); + function Ne(i) { + J[i ? "unshift" : "push"](() => { + m = i, n(7, m); }); } - return t.$$set = (l) => { - "auto" in l && n(0, s = l.auto), "challengeurl" in l && n(12, a = l.challengeurl), "challengejson" in l && n(13, f = l.challengejson), "debug" in l && n(14, u = l.debug), "hidefooter" in l && n(1, N = l.hidefooter), "hidelogo" in l && n(2, y = l.hidelogo), "name" in l && n(3, j = l.name), "maxnumber" in l && n(15, I = l.maxnumber), "mockerror" in l && n(16, A = l.mockerror), "strings" in l && n(17, $ = l.strings), "test" in l && n(18, S = l.test); + return t.$$set = (i) => { + "auto" in i && n(0, s = i.auto), "challengeurl" in i && n(16, u = i.challengeurl), "challengejson" in i && n(17, f = i.challengejson), "debug" in i && n(12, a = i.debug), "hidefooter" in i && n(1, R = i.hidefooter), "hidelogo" in i && n(2, p = i.hidelogo), "name" in i && n(3, j = i.name), "maxnumber" in i && n(13, x = i.maxnumber), "mockerror" in i && n(14, A = i.mockerror), "strings" in i && n(18, _ = i.strings), "test" in i && n(15, G = i.test); }, t.$$.update = () => { t.$$.dirty[0] & /*challengejson*/ - 8192 && (o = f ? he(f) : void 0), t.$$.dirty[0] & /*strings*/ - 131072 && n(21, i = $ ? he($) : {}), t.$$.dirty[0] & /*parsedStrings*/ - 2097152 && n(9, r = { + 131072 && (o = f ? de(f) : void 0), t.$$.dirty[0] & /*strings*/ + 262144 && n(22, l = _ ? de(_) : {}), t.$$.dirty[0] & /*parsedStrings*/ + 4194304 && n(9, r = { error: "Verification failed. Try again later.", - footer: `Protected by ALTCHA`, + footer: `Protected by ALTCHA`, label: "I'm not a robot", verified: "Verified", verifying: "Verifying...", waitAlert: "Verifying... please wait.", - ...i + ...l }), t.$$.dirty[0] & /*payload, state*/ 48 && V("statechange", { payload: v, state: U }); }, [ s, - N, - y, + R, + p, j, v, U, @@ -924,43 +927,45 @@ function mt(t, e, n) { xe, Le, a, - f, - u, - I, + x, A, - $, - S, - X, - P, - i, + G, + u, + f, + _, Ie, - Re + X, + B, + l, + Re, + Ne ]; } -class vt extends nt { +class _t extends rt { constructor(e) { - super(), et( + super(), tt( this, e, + vt, mt, - bt, - Se, + Ue, { auto: 0, - challengeurl: 12, - challengejson: 13, - debug: 14, + challengeurl: 16, + challengejson: 17, + debug: 12, hidefooter: 1, hidelogo: 2, name: 3, - maxnumber: 15, - mockerror: 16, - strings: 17, - test: 18, - reset: 19, - verify: 20 + maxnumber: 13, + mockerror: 14, + strings: 18, + test: 15, + configure: 19, + reset: 20, + verify: 21 }, - ft, + ht, [-1, -1] ); } @@ -971,19 +976,19 @@ class vt extends nt { this.$$set({ auto: e }), C(); } get challengeurl() { - return this.$$.ctx[12]; + return this.$$.ctx[16]; } set challengeurl(e) { this.$$set({ challengeurl: e }), C(); } get challengejson() { - return this.$$.ctx[13]; + return this.$$.ctx[17]; } set challengejson(e) { this.$$set({ challengejson: e }), C(); } get debug() { - return this.$$.ctx[14]; + return this.$$.ctx[12]; } set debug(e) { this.$$set({ debug: e }), C(); @@ -1007,37 +1012,40 @@ class vt extends nt { this.$$set({ name: e }), C(); } get maxnumber() { - return this.$$.ctx[15]; + return this.$$.ctx[13]; } set maxnumber(e) { this.$$set({ maxnumber: e }), C(); } get mockerror() { - return this.$$.ctx[16]; + return this.$$.ctx[14]; } set mockerror(e) { this.$$set({ mockerror: e }), C(); } get strings() { - return this.$$.ctx[17]; + return this.$$.ctx[18]; } set strings(e) { this.$$set({ strings: e }), C(); } get test() { - return this.$$.ctx[18]; + return this.$$.ctx[15]; } set test(e) { this.$$set({ test: e }), C(); } - get reset() { + get configure() { return this.$$.ctx[19]; } - get verify() { + get reset() { return this.$$.ctx[20]; } + get verify() { + return this.$$.ctx[21]; + } } -customElements.define("altcha-widget", tt(vt, { auto: {}, challengeurl: {}, challengejson: {}, debug: { type: "Boolean" }, hidefooter: { type: "Boolean" }, hidelogo: { type: "Boolean" }, name: {}, maxnumber: {}, mockerror: { type: "Boolean" }, strings: {}, test: { type: "Boolean" } }, [], ["reset", "verify"], !1)); +customElements.define("altcha-widget", nt(_t, { auto: {}, challengeurl: {}, challengejson: {}, debug: { type: "Boolean" }, hidefooter: { type: "Boolean" }, hidelogo: { type: "Boolean" }, name: {}, maxnumber: {}, mockerror: { type: "Boolean" }, strings: {}, test: { type: "Boolean" } }, [], ["configure", "reset", "verify"], !1)); export { - vt as Altcha + _t as Altcha }; diff --git a/dist/altcha.umd.cjs b/dist/altcha.umd.cjs index 9ab650e..7e0ef28 100644 --- a/dist/altcha.umd.cjs +++ b/dist/altcha.umd.cjs @@ -1 +1 @@ -(function(L,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(L=typeof globalThis<"u"?globalThis:L||self,$(L.altcha={}))})(this,function(L){"use strict";var vt=Object.defineProperty;var $t=(L,$,U)=>$ in L?vt(L,$,{enumerable:!0,configurable:!0,writable:!0,value:U}):L[$]=U;var R=(L,$,U)=>($t(L,typeof $!="symbol"?$+"":$,U),U);function $(){}function U(t){return t()}function re(){return Object.create(null)}function W(t){t.forEach(U)}function oe(t){return typeof t=="function"}function ke(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ee(t){return Object.keys(t).length===0}function g(t,e){t.appendChild(e)}function Ce(t,e,n){const o=xe(t);if(!o.getElementById(e)){const i=p("style");i.id=e,i.textContent=n,Le(o,i)}}function xe(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Le(t,e){return g(t.head||t,e),e.sheet}function N(t,e,n){t.insertBefore(e,n||null)}function I(t){t.parentNode&&t.parentNode.removeChild(t)}function p(t){return document.createElement(t)}function G(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Ie(t){return document.createTextNode(t)}function F(){return Ie(" ")}function K(t,e,n,o){return t.addEventListener(e,n,o),()=>t.removeEventListener(e,n,o)}function c(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Re(t){return Array.from(t.childNodes)}function ie(t,e,n){t.classList.toggle(e,!!n)}function Ne(t,e,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:o})}function je(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let T;function P(t){T=t}function z(){if(!T)throw new Error("Function called outside component initialization");return T}function Ae(t){z().$$.on_mount.push(t)}function Ge(t){z().$$.on_destroy.push(t)}function Se(){const t=z();return(e,n,{cancelable:o=!1}={})=>{const i=t.$$.callbacks[e];if(i){const r=Ne(e,n,{cancelable:o});return i.slice().forEach(s=>{s.call(t,r)}),!r.defaultPrevented}return!0}}const Z=[],J=[];let B=[];const le=[],se=Promise.resolve();let Q=!1;function ce(){Q||(Q=!0,se.then(E))}function Me(){return ce(),se}function q(t){B.push(t)}const ee=new Set;let H=0;function E(){if(H!==0)return;const t=T;do{try{for(;Ht.indexOf(o)===-1?e.push(o):n.push(o)),n.forEach(o=>o()),B=e}const Oe=new Set;function Fe(t,e){t&&t.i&&(Oe.delete(t),t.i(e))}function Ye(t,e,n){const{fragment:o,after_update:i}=t.$$;o&&o.m(e,n),q(()=>{const r=t.$$.on_mount.map(U).filter(oe);t.$$.on_destroy?t.$$.on_destroy.push(...r):W(r),t.$$.on_mount=[]}),i.forEach(q)}function Ze(t,e){const n=t.$$;n.fragment!==null&&(Ve(n.after_update),W(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Be(t,e){t.$$.dirty[0]===-1&&(Z.push(t),ce(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const M=j.length?j[0]:S;return u.ctx&&i(u.ctx[k],u.ctx[k]=M)&&(!u.skip_bound&&u.bound[k]&&u.bound[k](M),A&&Be(t,k)),S}):[],u.update(),A=!0,W(u.before_update),u.fragment=o?o(u.ctx):!1,e.target){if(e.hydrate){const k=Re(e.target);u.fragment&&u.fragment.l(k),k.forEach(I)}else u.fragment&&u.fragment.c();e.intro&&Fe(t.$$.fragment),Ye(t,e.target,e.anchor),E()}P(f)}let ae;typeof HTMLElement=="function"&&(ae=class extends HTMLElement{constructor(e,n,o){super();R(this,"$$ctor");R(this,"$$s");R(this,"$$c");R(this,"$$cn",!1);R(this,"$$d",{});R(this,"$$r",!1);R(this,"$$p_d",{});R(this,"$$l",{});R(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,o&&this.attachShadow({mode:"open"})}addEventListener(e,n,o){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const i=this.$$c.$on(e,n);this.$$l_u.set(n,i)}super.addEventListener(e,n,o)}removeEventListener(e,n,o){if(super.removeEventListener(e,n,o),this.$$c){const i=this.$$l_u.get(n);i&&(i(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let s;return{c:function(){s=p("slot"),r!=="default"&&c(s,"name",r)},m:function(u,A){N(u,s,A)},d:function(u){u&&I(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},o=je(this);for(const r of this.$$s)r in o&&(n[r]=[e(r)]);for(const r of this.attributes){const s=this.$$g_p(r.name);s in this.$$d||(this.$$d[s]=X(s,r.value,this.$$p_d,"toProp"))}for(const r in this.$$p_d)!(r in this.$$d)&&this[r]!==void 0&&(this.$$d[r]=this[r],delete this[r]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const i=()=>{this.$$r=!0;for(const r in this.$$p_d)if(this.$$d[r]=this.$$c.$$.ctx[this.$$c.$$.props[r]],this.$$p_d[r].reflect){const s=X(r,this.$$d[r],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,s)}this.$$r=!1};this.$$c.$$.after_update.push(i),i();for(const r in this.$$l)for(const s of this.$$l[r]){const a=this.$$c.$on(r,s);this.$$l_u.set(s,a)}this.$$l={}}}attributeChangedCallback(e,n,o){var i;this.$$r||(e=this.$$g_p(e),this.$$d[e]=X(e,o,this.$$p_d,"toProp"),(i=this.$$c)==null||i.$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(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function X(t,e,n,o){var r;const i=(r=n[t])==null?void 0:r.type;if(e=i==="Boolean"&&typeof e!="boolean"?e!=null:e,!o||!n[t])return e;if(o==="toAttribute")switch(i){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(i){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function We(t,e,n,o,i,r){let s=class extends ae{constructor(){super(t,n,i),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(s.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(f){var u;f=X(a,f,e),this.$$d[a]=f,(u=this.$$c)==null||u.$set({[a]:f})}})}),o.forEach(a=>{Object.defineProperty(s.prototype,a,{get(){var f;return(f=this.$$c)==null?void 0:f[a]}})}),r&&(s=r(s)),t.element=s,s}class Te{constructor(){R(this,"$$");R(this,"$$set")}$destroy(){Ze(this,1),this.$destroy=$}$on(e,n){if(!oe(n))return $;const o=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(e){this.$$set&&!Ee(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Pe="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Pe);const ue="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",Xe=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),fe=typeof window<"u"&&window.Blob&&new Blob([Xe(ue)],{type:"text/javascript;charset=utf-8"});function De(t){let e;try{if(e=fe&&(window.URL||window.webkitURL).createObjectURL(fe),!e)throw"";const n=new Worker(e,{name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;base64,"+ue,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const Ke=1e7,ze=new TextEncoder;function Je(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function Qe(t=1e5,e="SHA-256"){const n=Date.now().toString(16),o=Math.round(Math.random()*t),i=await he(n,o,e);return{algorithm:e,challenge:i,salt:n,signature:""}}async function he(t,e,n){return Je(await crypto.subtle.digest(n.toUpperCase(),ze.encode(t+e)))}async function qe(t,e,n="SHA-256",o=Ke){const i=Date.now();for(let r=0;r<=o;r++)if(await he(e,r,n)===t)return{number:r,took:Date.now()-i};return null}var y=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t))(y||{});function et(t){Ce(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 de(t){let e,n,o;return{c(){e=G("svg"),n=G("path"),o=G("path"),c(n,"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(n,"fill","currentColor"),c(n,"opacity",".25"),c(o,"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(o,"fill","currentColor"),c(o,"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(i,r){N(i,e,r),g(e,n),g(e,o)},d(i){i&&I(e)}}}function tt(t){let e,n=t[9].label+"",o;return{c(){e=p("label"),c(e,"for",o=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(i,r){N(i,e,r),e.innerHTML=n},p(i,r){r[0]&512&&n!==(n=i[9].label+"")&&(e.innerHTML=n),r[0]&8&&o!==(o=i[3]+"_checkbox")&&c(e,"for",o)},d(i){i&&I(e)}}}function nt(t){let e,n=t[9].verifying+"";return{c(){e=p("span")},m(o,i){N(o,e,i),e.innerHTML=n},p(o,i){i[0]&512&&n!==(n=o[9].verifying+"")&&(e.innerHTML=n)},d(o){o&&I(e)}}}function rt(t){let e,n=t[9].verified+"",o,i;return{c(){e=p("span"),o=F(),i=p("input"),c(i,"type","hidden"),c(i,"name",t[3]),i.value=t[4]},m(r,s){N(r,e,s),e.innerHTML=n,N(r,o,s),N(r,i,s)},p(r,s){s[0]&512&&n!==(n=r[9].verified+"")&&(e.innerHTML=n),s[0]&8&&c(i,"name",r[3]),s[0]&16&&(i.value=r[4])},d(r){r&&(I(e),I(o),I(i))}}}function ge(t){let e,n,o,i,r,s;return{c(){e=p("div"),n=p("a"),o=G("svg"),i=G("path"),r=G("path"),s=G("path"),c(i,"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(i,"fill","currentColor"),c(r,"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(r,"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(o,"width","22"),c(o,"height","22"),c(o,"viewBox","0 0 20 20"),c(o,"fill","none"),c(o,"xmlns","http://www.w3.org/2000/svg"),c(n,"href",ve),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-vuofbg")},m(a,f){N(a,e,f),g(e,n),g(n,o),g(o,i),g(o,r),g(o,s)},p:$,d(a){a&&I(e)}}}function be(t){let e,n,o,i,r,s=t[9].error+"";return{c(){e=p("div"),n=G("svg"),o=G("path"),i=F(),r=p("div"),c(o,"stroke-linecap","round"),c(o,"stroke-linejoin","round"),c(o,"d","M6 18L18 6M6 6l12 12"),c(n,"width","14"),c(n,"height","14"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(n,"fill","none"),c(n,"viewBox","0 0 24 24"),c(n,"stroke-width","1.5"),c(n,"stroke","currentColor"),c(r,"title",t[8]),c(e,"class","altcha-error svelte-vuofbg")},m(a,f){N(a,e,f),g(e,n),g(n,o),g(e,i),g(e,r),r.innerHTML=s},p(a,f){f[0]&512&&s!==(s=a[9].error+"")&&(r.innerHTML=s),f[0]&256&&c(r,"title",a[8])},d(a){a&&I(e)}}}function me(t){let e,n,o=t[9].footer+"";return{c(){e=p("div"),n=p("div"),c(n,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(i,r){N(i,e,r),g(e,n),n.innerHTML=o},p(i,r){r[0]&512&&o!==(o=i[9].footer+"")&&(n.innerHTML=o)},d(i){i&&I(e)}}}function ot(t){let e,n,o,i,r,s,a,f,u,A,k,S,j,M,_=t[5]===y.VERIFYING&&de();function V(h,v){return h[5]===y.VERIFIED?rt:h[5]===y.VERIFYING?nt:tt}let Y=V(t),C=Y(t),b=t[2]!==!0&&ge(),m=t[8]&&be(t),d=t[9].footer&&t[1]!==!0&&me(t);return{c(){e=p("div"),n=p("div"),_&&_.c(),o=F(),i=p("div"),r=p("input"),f=F(),u=p("div"),C.c(),A=F(),b&&b.c(),k=F(),m&&m.c(),S=F(),d&&d.c(),c(r,"type","checkbox"),c(r,"id",s=t[3]+"_checkbox"),r.required=a=t[0]!=="onsubmit",c(r,"class","svelte-vuofbg"),c(i,"class","altcha-checkbox svelte-vuofbg"),ie(i,"altcha-hidden",t[5]===y.VERIFYING),c(u,"class","altcha-label svelte-vuofbg"),c(n,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,v){N(h,e,v),g(e,n),_&&_.m(n,null),g(n,o),g(n,i),g(i,r),r.checked=t[6],g(n,f),g(n,u),C.m(u,null),g(n,A),b&&b.m(n,null),g(e,k),m&&m.m(e,null),g(e,S),d&&d.m(e,null),t[23](e),j||(M=[K(r,"change",t[22]),K(r,"change",t[10]),K(r,"invalid",t[11])],j=!0)},p(h,v){h[5]===y.VERIFYING?_||(_=de(),_.c(),_.m(n,o)):_&&(_.d(1),_=null),v[0]&8&&s!==(s=h[3]+"_checkbox")&&c(r,"id",s),v[0]&1&&a!==(a=h[0]!=="onsubmit")&&(r.required=a),v[0]&64&&(r.checked=h[6]),v[0]&32&&ie(i,"altcha-hidden",h[5]===y.VERIFYING),Y===(Y=V(h))&&C?C.p(h,v):(C.d(1),C=Y(h),C&&(C.c(),C.m(u,null))),h[2]!==!0?b?b.p(h,v):(b=ge(),b.c(),b.m(n,null)):b&&(b.d(1),b=null),h[8]?m?m.p(h,v):(m=be(h),m.c(),m.m(e,S)):m&&(m.d(1),m=null),h[9].footer&&h[1]!==!0?d?d.p(h,v):(d=me(h),d.c(),d.m(e,null)):d&&(d.d(1),d=null),v[0]&32&&c(e,"data-state",h[5])},i:$,o:$,d(h){h&&I(e),_&&_.d(),C.d(),b&&b.d(),m&&m.d(),d&&d.d(),t[23](null),j=!1,W(M)}}}const ve="https://altcha.org/";function $e(t){return JSON.parse(t)}function it(t,e,n){let o,i,r,{auto:s=void 0}=e,{challengeurl:a=void 0}=e,{challengejson:f=void 0}=e,{debug:u=!1}=e,{hidefooter:A=!1}=e,{hidelogo:k=!1}=e,{name:S="altcha"}=e,{maxnumber:j=void 0}=e,{mockerror:M=!1}=e,{strings:_=void 0}=e,{test:V=!1}=e;const Y=Se(),C=["SHA-256","SHA-384","SHA-512"];let b=!1,m,d=null,h=null,v=null,O=y.UNVERIFIED;Ge(()=>{d&&(d.removeEventListener("submit",we),d.removeEventListener("reset",pe),d=null)}),Ae(()=>{x("mounted","0.1.8"),V&&x("using test mode"),s!==void 0&&x("auto",s),d=m.closest("form"),d&&(d.addEventListener("submit",we),d.addEventListener("reset",pe)),s==="onload"&&D()});function x(...l){(u||l.some(w=>w instanceof Error))&&console[l[0]instanceof Error?"error":"log"]("ALTCHA",...l)}function we(l){d&&s==="onsubmit"&&O===y.UNVERIFIED&&(l.preventDefault(),l.stopPropagation(),D().then(()=>{d==null||d.requestSubmit()}))}function pe(){te()}function lt(l,w){return btoa(JSON.stringify({algorithm:l.algorithm,challenge:l.challenge,number:w.number,salt:l.salt,signature:l.signature,test:V?!0:void 0,took:w.took}))}function st(l){if(!l.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(l.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!C.includes(l.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${C.join(", ")}`);if(!l.challenge||l.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!l.salt||l.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function ct(){if(M)throw x("mocking error"),new Error("Mocked error.");if(o)return x("using provided json data"),o;if(V)return x("generating test challenge"),Qe();{if(!a)throw new Error("Attribute challengeurl not set.");x("fetching challenge from",a);const l=await fetch(a);if(l.status!==200)throw new Error(`Server responded with ${l.status}.`);return l.json()}}async function at(l){let w=null;if("Worker"in window){try{w=await ut(l.challenge,l.salt,l.algorithm)}catch(ne){x(ne)}if((w==null?void 0:w.number)!==void 0)return{data:l,solution:w}}return{data:l,solution:await qe(l.challenge,l.salt,l.algorithm,j)}}async function ut(l,w,ne){const ye=new De;return new Promise(bt=>{ye.addEventListener("message",mt=>{bt(mt.data)}),ye.postMessage({alg:ne,challenge:l,max:j,salt:w})})}function ft(){[y.UNVERIFIED,y.ERROR].includes(O)?D():n(6,b=!0)}function ht(){O===y.VERIFYING&&alert(r.waitAlert)}function te(l=y.UNVERIFIED){n(6,b=!1),n(8,h=null),n(4,v=null),n(5,O=l)}async function D(){return te(y.VERIFYING),ct().then(l=>(st(l),x("challenge",l),at(l))).then(({data:l,solution:w})=>{if(x("solution",w),(w==null?void 0:w.number)!==void 0)x("verified"),n(5,O=y.VERIFIED),n(6,b=!0),n(4,v=lt(l,w)),x("payload",v),Me().then(()=>{Y("verified",{payload:v})});else throw new Error("Unexpected result returned.")}).catch(l=>{x(l),n(5,O=y.ERROR),n(6,b=!1),n(8,h=l)})}function dt(){b=this.checked,n(6,b)}function gt(l){J[l?"unshift":"push"](()=>{m=l,n(7,m)})}return t.$$set=l=>{"auto"in l&&n(0,s=l.auto),"challengeurl"in l&&n(12,a=l.challengeurl),"challengejson"in l&&n(13,f=l.challengejson),"debug"in l&&n(14,u=l.debug),"hidefooter"in l&&n(1,A=l.hidefooter),"hidelogo"in l&&n(2,k=l.hidelogo),"name"in l&&n(3,S=l.name),"maxnumber"in l&&n(15,j=l.maxnumber),"mockerror"in l&&n(16,M=l.mockerror),"strings"in l&&n(17,_=l.strings),"test"in l&&n(18,V=l.test)},t.$$.update=()=>{t.$$.dirty[0]&8192&&(o=f?$e(f):void 0),t.$$.dirty[0]&131072&&n(21,i=_?$e(_):{}),t.$$.dirty[0]&2097152&&n(9,r={error:"Verification failed. Try again later.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...i}),t.$$.dirty[0]&48&&Y("statechange",{payload:v,state:O})},[s,A,k,S,v,O,b,m,h,r,ft,ht,a,f,u,j,M,_,V,te,D,i,dt,gt]}class _e extends Te{constructor(e){super(),He(this,e,it,ot,ke,{auto:0,challengeurl:12,challengejson:13,debug:14,hidefooter:1,hidelogo:2,name:3,maxnumber:15,mockerror:16,strings:17,test:18,reset:19,verify:20},et,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),E()}get challengeurl(){return this.$$.ctx[12]}set challengeurl(e){this.$$set({challengeurl:e}),E()}get challengejson(){return this.$$.ctx[13]}set challengejson(e){this.$$set({challengejson:e}),E()}get debug(){return this.$$.ctx[14]}set debug(e){this.$$set({debug: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[15]}set maxnumber(e){this.$$set({maxnumber:e}),E()}get mockerror(){return this.$$.ctx[16]}set mockerror(e){this.$$set({mockerror:e}),E()}get strings(){return this.$$.ctx[17]}set strings(e){this.$$set({strings:e}),E()}get test(){return this.$$.ctx[18]}set test(e){this.$$set({test:e}),E()}get reset(){return this.$$.ctx[19]}get verify(){return this.$$.ctx[20]}}customElements.define("altcha-widget",We(_e,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset","verify"],!1)),L.Altcha=_e,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}); +(function(L,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(L=typeof globalThis<"u"?globalThis:L||self,_(L.altcha={}))})(this,function(L){"use strict";var _t=Object.defineProperty;var wt=(L,_,V)=>_ in L?_t(L,_,{enumerable:!0,configurable:!0,writable:!0,value:V}):L[_]=V;var N=(L,_,V)=>(wt(L,typeof _!="symbol"?_+"":_,V),V);function _(){}function V(t){return t()}function re(){return Object.create(null)}function W(t){t.forEach(V)}function ie(t){return typeof t=="function"}function Ee(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ce(t){return Object.keys(t).length===0}function g(t,e){t.appendChild(e)}function xe(t,e,n){const i=Le(t);if(!i.getElementById(e)){const l=y("style");l.id=e,l.textContent=n,Ie(i,l)}}function Le(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Ie(t,e){return g(t.head||t,e),e.sheet}function j(t,e,n){t.insertBefore(e,n||null)}function I(t){t.parentNode&&t.parentNode.removeChild(t)}function y(t){return document.createElement(t)}function M(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Re(t){return document.createTextNode(t)}function F(){return Re(" ")}function K(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}function c(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ne(t){return Array.from(t.childNodes)}function oe(t,e,n){t.classList.toggle(e,!!n)}function je(t,e,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:i})}function Ae(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let T;function P(t){T=t}function z(){if(!T)throw new Error("Function called outside component initialization");return T}function Ge(t){z().$$.on_mount.push(t)}function Se(t){z().$$.on_destroy.push(t)}function Me(){const t=z();return(e,n,{cancelable:i=!1}={})=>{const l=t.$$.callbacks[e];if(l){const r=je(e,n,{cancelable:i});return l.slice().forEach(s=>{s.call(t,r)}),!r.defaultPrevented}return!0}}const Z=[],J=[];let B=[];const le=[],se=Promise.resolve();let Q=!1;function ce(){Q||(Q=!0,se.then(E))}function Ue(){return ce(),se}function q(t){B.push(t)}const ee=new Set;let H=0;function E(){if(H!==0)return;const t=T;do{try{for(;Ht.indexOf(i)===-1?e.push(i):n.push(i)),n.forEach(i=>i()),B=e}const Fe=new Set;function Ye(t,e){t&&t.i&&(Fe.delete(t),t.i(e))}function Ze(t,e,n){const{fragment:i,after_update:l}=t.$$;i&&i.m(e,n),q(()=>{const r=t.$$.on_mount.map(V).filter(ie);t.$$.on_destroy?t.$$.on_destroy.push(...r):W(r),t.$$.on_mount=[]}),l.forEach(q)}function Be(t,e){const n=t.$$;n.fragment!==null&&(Oe(n.after_update),W(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function He(t,e){t.$$.dirty[0]===-1&&(Z.push(t),ce(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const S=R.length?R[0]:G;return a.ctx&&l(a.ctx[k],a.ctx[k]=S)&&(!a.skip_bound&&a.bound[k]&&a.bound[k](S),A&&He(t,k)),G}):[],a.update(),A=!0,W(a.before_update),a.fragment=i?i(a.ctx):!1,e.target){if(e.hydrate){const k=Ne(e.target);a.fragment&&a.fragment.l(k),k.forEach(I)}else a.fragment&&a.fragment.c();e.intro&&Ye(t.$$.fragment),Ze(t,e.target,e.anchor),E()}P(f)}let ue;typeof HTMLElement=="function"&&(ue=class extends HTMLElement{constructor(e,n,i){super();N(this,"$$ctor");N(this,"$$s");N(this,"$$c");N(this,"$$cn",!1);N(this,"$$d",{});N(this,"$$r",!1);N(this,"$$p_d",{});N(this,"$$l",{});N(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,i&&this.attachShadow({mode:"open"})}addEventListener(e,n,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const l=this.$$c.$on(e,n);this.$$l_u.set(n,l)}super.addEventListener(e,n,i)}removeEventListener(e,n,i){if(super.removeEventListener(e,n,i),this.$$c){const l=this.$$l_u.get(n);l&&(l(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let s;return{c:function(){s=y("slot"),r!=="default"&&c(s,"name",r)},m:function(a,A){j(a,s,A)},d:function(a){a&&I(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},i=Ae(this);for(const r of this.$$s)r in i&&(n[r]=[e(r)]);for(const r of this.attributes){const s=this.$$g_p(r.name);s in this.$$d||(this.$$d[s]=D(s,r.value,this.$$p_d,"toProp"))}for(const r in this.$$p_d)!(r in this.$$d)&&this[r]!==void 0&&(this.$$d[r]=this[r],delete this[r]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const r in this.$$p_d)if(this.$$d[r]=this.$$c.$$.ctx[this.$$c.$$.props[r]],this.$$p_d[r].reflect){const s=D(r,this.$$d[r],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,s)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const r in this.$$l)for(const s of this.$$l[r]){const u=this.$$c.$on(r,s);this.$$l_u.set(s,u)}this.$$l={}}}attributeChangedCallback(e,n,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=D(e,i,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function D(t,e,n,i){var r;const l=(r=n[t])==null?void 0:r.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!n[t])return e;if(i==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function Te(t,e,n,i,l,r){let s=class extends ue{constructor(){super(t,n,l),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(f){var a;f=D(u,f,e),this.$$d[u]=f,(a=this.$$c)==null||a.$set({[u]:f})}})}),i.forEach(u=>{Object.defineProperty(s.prototype,u,{get(){var f;return(f=this.$$c)==null?void 0:f[u]}})}),r&&(s=r(s)),t.element=s,s}class Pe{constructor(){N(this,"$$");N(this,"$$set")}$destroy(){Be(this,1),this.$destroy=_}$on(e,n){if(!ie(n))return _;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(n),()=>{const l=i.indexOf(n);l!==-1&&i.splice(l,1)}}$set(e){this.$$set&&!Ce(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Xe="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Xe);const ae="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",De=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),fe=typeof window<"u"&&window.Blob&&new Blob([De(ae)],{type:"text/javascript;charset=utf-8"});function Ke(t){let e;try{if(e=fe&&(window.URL||window.webkitURL).createObjectURL(fe),!e)throw"";const n=new Worker(e,{name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;base64,"+ae,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const ze=1e7,Je=new TextEncoder;function Qe(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function qe(t=1e5,e="SHA-256"){const n=Date.now().toString(16),i=Math.round(Math.random()*t),l=await he(n,i,e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function he(t,e,n){return Qe(await crypto.subtle.digest(n.toUpperCase(),Je.encode(t+e)))}async function et(t,e,n="SHA-256",i=ze){const l=Date.now();for(let r=0;r<=i;r++)if(await he(e,r,n)===t)return{number:r,took:Date.now()-l};return null}var p=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t))(p||{});function tt(t){xe(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 de(t){let e,n,i;return{c(){e=M("svg"),n=M("path"),i=M("path"),c(n,"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(n,"fill","currentColor"),c(n,"opacity",".25"),c(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(i,"fill","currentColor"),c(i,"class","altcha-spinner svelte-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(l,r){j(l,e,r),g(e,n),g(e,i)},d(l){l&&I(e)}}}function nt(t){let e,n=t[9].label+"",i;return{c(){e=y("label"),c(e,"for",i=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(l,r){j(l,e,r),e.innerHTML=n},p(l,r){r[0]&512&&n!==(n=l[9].label+"")&&(e.innerHTML=n),r[0]&8&&i!==(i=l[3]+"_checkbox")&&c(e,"for",i)},d(l){l&&I(e)}}}function rt(t){let e,n=t[9].verifying+"";return{c(){e=y("span")},m(i,l){j(i,e,l),e.innerHTML=n},p(i,l){l[0]&512&&n!==(n=i[9].verifying+"")&&(e.innerHTML=n)},d(i){i&&I(e)}}}function it(t){let e,n=t[9].verified+"",i,l;return{c(){e=y("span"),i=F(),l=y("input"),c(l,"type","hidden"),c(l,"name",t[3]),l.value=t[4]},m(r,s){j(r,e,s),e.innerHTML=n,j(r,i,s),j(r,l,s)},p(r,s){s[0]&512&&n!==(n=r[9].verified+"")&&(e.innerHTML=n),s[0]&8&&c(l,"name",r[3]),s[0]&16&&(l.value=r[4])},d(r){r&&(I(e),I(i),I(l))}}}function ge(t){let e,n,i,l,r,s;return{c(){e=y("div"),n=y("a"),i=M("svg"),l=M("path"),r=M("path"),s=M("path"),c(l,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(l,"fill","currentColor"),c(r,"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(r,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(i,"width","22"),c(i,"height","22"),c(i,"viewBox","0 0 20 20"),c(i,"fill","none"),c(i,"xmlns","http://www.w3.org/2000/svg"),c(n,"href",ve),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-vuofbg")},m(u,f){j(u,e,f),g(e,n),g(n,i),g(i,l),g(i,r),g(i,s)},p:_,d(u){u&&I(e)}}}function be(t){let e,n,i,l,r,s=t[9].error+"";return{c(){e=y("div"),n=M("svg"),i=M("path"),l=F(),r=y("div"),c(i,"stroke-linecap","round"),c(i,"stroke-linejoin","round"),c(i,"d","M6 18L18 6M6 6l12 12"),c(n,"width","14"),c(n,"height","14"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(n,"fill","none"),c(n,"viewBox","0 0 24 24"),c(n,"stroke-width","1.5"),c(n,"stroke","currentColor"),c(r,"title",t[8]),c(e,"class","altcha-error svelte-vuofbg")},m(u,f){j(u,e,f),g(e,n),g(n,i),g(e,l),g(e,r),r.innerHTML=s},p(u,f){f[0]&512&&s!==(s=u[9].error+"")&&(r.innerHTML=s),f[0]&256&&c(r,"title",u[8])},d(u){u&&I(e)}}}function me(t){let e,n,i=t[9].footer+"";return{c(){e=y("div"),n=y("div"),c(n,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(l,r){j(l,e,r),g(e,n),n.innerHTML=i},p(l,r){r[0]&512&&i!==(i=l[9].footer+"")&&(n.innerHTML=i)},d(l){l&&I(e)}}}function ot(t){let e,n,i,l,r,s,u,f,a,A,k,G,R,S,w=t[5]===p.VERIFYING&&de();function U(h,v){return h[5]===p.VERIFIED?it:h[5]===p.VERIFYING?rt:nt}let Y=U(t),C=Y(t),b=t[2]!==!0&&ge(),m=t[8]&&be(t),d=t[9].footer&&t[1]!==!0&&me(t);return{c(){e=y("div"),n=y("div"),w&&w.c(),i=F(),l=y("div"),r=y("input"),f=F(),a=y("div"),C.c(),A=F(),b&&b.c(),k=F(),m&&m.c(),G=F(),d&&d.c(),c(r,"type","checkbox"),c(r,"id",s=t[3]+"_checkbox"),r.required=u=t[0]!=="onsubmit",c(r,"class","svelte-vuofbg"),c(l,"class","altcha-checkbox svelte-vuofbg"),oe(l,"altcha-hidden",t[5]===p.VERIFYING),c(a,"class","altcha-label svelte-vuofbg"),c(n,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,v){j(h,e,v),g(e,n),w&&w.m(n,null),g(n,i),g(n,l),g(l,r),r.checked=t[6],g(n,f),g(n,a),C.m(a,null),g(n,A),b&&b.m(n,null),g(e,k),m&&m.m(e,null),g(e,G),d&&d.m(e,null),t[24](e),R||(S=[K(r,"change",t[23]),K(r,"change",t[10]),K(r,"invalid",t[11])],R=!0)},p(h,v){h[5]===p.VERIFYING?w||(w=de(),w.c(),w.m(n,i)):w&&(w.d(1),w=null),v[0]&8&&s!==(s=h[3]+"_checkbox")&&c(r,"id",s),v[0]&1&&u!==(u=h[0]!=="onsubmit")&&(r.required=u),v[0]&64&&(r.checked=h[6]),v[0]&32&&oe(l,"altcha-hidden",h[5]===p.VERIFYING),Y===(Y=U(h))&&C?C.p(h,v):(C.d(1),C=Y(h),C&&(C.c(),C.m(a,null))),h[2]!==!0?b?b.p(h,v):(b=ge(),b.c(),b.m(n,null)):b&&(b.d(1),b=null),h[8]?m?m.p(h,v):(m=be(h),m.c(),m.m(e,G)):m&&(m.d(1),m=null),h[9].footer&&h[1]!==!0?d?d.p(h,v):(d=me(h),d.c(),d.m(e,null)):d&&(d.d(1),d=null),v[0]&32&&c(e,"data-state",h[5])},i:_,o:_,d(h){h&&I(e),w&&w.d(),C.d(),b&&b.d(),m&&m.d(),d&&d.d(),t[24](null),R=!1,W(S)}}}const ve="https://altcha.org/";function _e(t){return JSON.parse(t)}function lt(t,e,n){let i,l,r,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:f=void 0}=e,{debug:a=!1}=e,{hidefooter:A=!1}=e,{hidelogo:k=!1}=e,{name:G="altcha"}=e,{maxnumber:R=void 0}=e,{mockerror:S=!1}=e,{strings:w=void 0}=e,{test:U=!1}=e;const Y=Me(),C=["SHA-256","SHA-384","SHA-512"];let b=!1,m,d=null,h=null,v=null,O=p.UNVERIFIED;Se(()=>{d&&(d.removeEventListener("submit",$e),d.removeEventListener("reset",ye),d=null)}),Ge(()=>{x("mounted","0.1.9"),U&&x("using test mode"),s!==void 0&&x("auto",s),d=m.closest("form"),d&&(d.addEventListener("submit",$e),d.addEventListener("reset",ye)),s==="onload"&&X()});function x(...o){(a||o.some($=>$ instanceof Error))&&console[o[0]instanceof Error?"error":"log"]("ALTCHA",...o)}function $e(o){d&&s==="onsubmit"&&O===p.UNVERIFIED&&(o.preventDefault(),o.stopPropagation(),X().then(()=>{d==null||d.requestSubmit()}))}function ye(){te()}function st(o,$){return btoa(JSON.stringify({algorithm:o.algorithm,challenge:o.challenge,number:$.number,salt:o.salt,signature:o.signature,test:U?!0:void 0,took:$.took}))}function pe(o){if(!o.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(o.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!C.includes(o.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${C.join(", ")}`);if(!o.challenge||o.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!o.salt||o.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function ct(){if(S)throw x("mocking error"),new Error("Mocked error.");if(i)return x("using provided json data"),i;if(U)return x("generating test challenge"),qe();{if(!u)throw new Error("Attribute challengeurl not set.");x("fetching challenge from",u);const o=await fetch(u);if(o.status!==200)throw new Error(`Server responded with ${o.status}.`);return o.json()}}async function ut(o){let $=null;if("Worker"in window){try{$=await at(o.challenge,o.salt,o.algorithm)}catch(ne){x(ne)}if(($==null?void 0:$.number)!==void 0)return{data:o,solution:$}}return{data:o,solution:await et(o.challenge,o.salt,o.algorithm,R)}}async function at(o,$,ne){const ke=new Ke;return new Promise(mt=>{ke.addEventListener("message",vt=>{mt(vt.data)}),ke.postMessage({alg:ne,challenge:o,max:R,salt:$})})}function ft(){[p.UNVERIFIED,p.ERROR].includes(O)?X():n(6,b=!0)}function ht(){O===p.VERIFYING&&alert(r.waitAlert)}function dt(o){o.auto!==void 0&&(n(0,s=o.auto),s==="onload"&&X()),o.challenge&&(pe(o.challenge),i=o.challenge),o.debug!==void 0&&n(12,a=!!o.debug),o.hidefooter!==void 0&&n(1,A=!!o.hidefooter),o.hidelogo!==void 0&&n(2,k=!!o.hidelogo),o.maxnumber!==void 0&&n(13,R=+o.maxnumber),o.mockerror!==void 0&&n(14,S=!!o.mockerror),o.name!==void 0&&n(3,G=o.name),o.test!==void 0&&n(15,U=!!o.test),o.strings&&n(22,l=o.strings)}function te(o=p.UNVERIFIED){n(6,b=!1),n(8,h=null),n(4,v=null),n(5,O=o)}async function X(){return te(p.VERIFYING),ct().then(o=>(pe(o),x("challenge",o),ut(o))).then(({data:o,solution:$})=>{if(x("solution",$),($==null?void 0:$.number)!==void 0)x("verified"),n(5,O=p.VERIFIED),n(6,b=!0),n(4,v=st(o,$)),x("payload",v),Ue().then(()=>{Y("verified",{payload:v})});else throw new Error("Unexpected result returned.")}).catch(o=>{x(o),n(5,O=p.ERROR),n(6,b=!1),n(8,h=o)})}function gt(){b=this.checked,n(6,b)}function bt(o){J[o?"unshift":"push"](()=>{m=o,n(7,m)})}return t.$$set=o=>{"auto"in o&&n(0,s=o.auto),"challengeurl"in o&&n(16,u=o.challengeurl),"challengejson"in o&&n(17,f=o.challengejson),"debug"in o&&n(12,a=o.debug),"hidefooter"in o&&n(1,A=o.hidefooter),"hidelogo"in o&&n(2,k=o.hidelogo),"name"in o&&n(3,G=o.name),"maxnumber"in o&&n(13,R=o.maxnumber),"mockerror"in o&&n(14,S=o.mockerror),"strings"in o&&n(18,w=o.strings),"test"in o&&n(15,U=o.test)},t.$$.update=()=>{t.$$.dirty[0]&131072&&(i=f?_e(f):void 0),t.$$.dirty[0]&262144&&n(22,l=w?_e(w):{}),t.$$.dirty[0]&4194304&&n(9,r={error:"Verification failed. Try again later.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),t.$$.dirty[0]&48&&Y("statechange",{payload:v,state:O})},[s,A,k,G,v,O,b,m,h,r,ft,ht,a,R,S,U,u,f,w,dt,te,X,l,gt,bt]}class we extends Pe{constructor(e){super(),We(this,e,lt,ot,Ee,{auto:0,challengeurl:16,challengejson:17,debug:12,hidefooter:1,hidelogo:2,name:3,maxnumber:13,mockerror:14,strings:18,test:15,configure:19,reset:20,verify:21},tt,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),E()}get challengeurl(){return this.$$.ctx[16]}set challengeurl(e){this.$$set({challengeurl:e}),E()}get challengejson(){return this.$$.ctx[17]}set challengejson(e){this.$$set({challengejson:e}),E()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug: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[13]}set maxnumber(e){this.$$set({maxnumber:e}),E()}get mockerror(){return this.$$.ctx[14]}set mockerror(e){this.$$set({mockerror:e}),E()}get strings(){return this.$$.ctx[18]}set strings(e){this.$$set({strings:e}),E()}get test(){return this.$$.ctx[15]}set test(e){this.$$set({test:e}),E()}get configure(){return this.$$.ctx[19]}get reset(){return this.$$.ctx[20]}get verify(){return this.$$.ctx[21]}}customElements.define("altcha-widget",Te(we,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["configure","reset","verify"],!1)),L.Altcha=we,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}); diff --git a/e2e/altcha.spec.ts b/e2e/altcha.spec.ts index 0cb6676..ff7715f 100644 --- a/e2e/altcha.spec.ts +++ b/e2e/altcha.spec.ts @@ -22,5 +22,12 @@ test('should be without the footer', async ({ page }) => { expect(await page.locator('#test-hidefooter .altcha-footer').first().count()).toBe(0); }); +test('should set options via configure()', async ({ page }) => { + await page.goto('./e2e/index.html'); + const cmp = page.locator('#test-configure .altcha').first(); + await expect(cmp).toContainText(/configured label/); + expect(await page.locator('#test-configure .altcha-logo').first().count()).toBe(0); +}); + diff --git a/e2e/index.html b/e2e/index.html index 479f2fe..4ce6450 100644 --- a/e2e/index.html +++ b/e2e/index.html @@ -33,6 +33,23 @@ > +
+ + + +
+ \ No newline at end of file diff --git a/package.json b/package.json index 196770e..ddea963 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "altcha", - "version": "0.1.8", + "description": "GDPR compliant, self-hosted CAPTCHA alternative.", + "version": "0.1.9", "license": "MIT", "author": { "name": "Daniel Regeci" @@ -39,7 +40,7 @@ "build": "rimraf dist && vite build && echo \"declare module 'altcha';\" > dist/altcha.d.ts", "preview": "vite preview", "check": "svelte-check --tsconfig ./tsconfig.json", - "test": "vitest", + "test": "vitest run tests/helpers.test.ts", "test:e2e": "playwright test" }, "devDependencies": { diff --git a/src/Altcha.svelte b/src/Altcha.svelte index 6f9f358..c2ab102 100644 --- a/src/Altcha.svelte +++ b/src/Altcha.svelte @@ -8,7 +8,7 @@ import InlineWorker from './worker?worker&inline'; import { solveChallenge, createTestChallenge } from './helpers'; import { State } from './types'; - import type { Payload, Challenge, Solution } from './types'; + import type { Configure, Payload, Challenge, Solution } from './types'; export let auto: 'onload' | 'onsubmit' | undefined = undefined; export let challengeurl: string | undefined = undefined; @@ -201,6 +201,43 @@ alert(_strings.waitAlert); } } + + export function configure(options: Configure) { + if (options.auto !== void 0) { + auto = options.auto; + if (auto === 'onload') { + verify(); + } + } + if (options.challenge) { + validateChallenge(options.challenge); + parsedChallenge = options.challenge; + } + if (options.debug !== void 0) { + debug = !!options.debug; + } + if (options.hidefooter !== void 0) { + hidefooter = !!options.hidefooter; + } + if (options.hidelogo !== void 0) { + hidelogo = !!options.hidelogo; + } + if (options.maxnumber !== void 0) { + maxnumber = +options.maxnumber; + } + if (options.mockerror !== void 0) { + mockerror = !!options.mockerror; + } + if (options.name !== void 0) { + name = options.name; + } + if (options.test !== void 0) { + test = !!options.test; + } + if (options.strings) { + parsedStrings = options.strings; + } + } export function reset(newState: State = State.UNVERIFIED) { checked = false; diff --git a/src/App.svelte b/src/App.svelte index afdf6c8..c3d3d63 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -11,8 +11,25 @@ let test: boolean = !challengeurl && params.get('test') !== '0'; let mockerror: boolean = false; + let altcha: Altcha; + onMount(() => { location.hash = ''; + + if (altcha) { + altcha?.configure({ + challenge: { + algorithm: 'SHA-256', + challenge: 'xx', + salt:'dd', + signature: '', + }, + strings: { + label:'xx' + }, + }) + } + }); @@ -63,6 +80,7 @@ ; + test?: boolean; +} + export interface Solution { number: number; took: number;