altcha 0.1.2 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,7 +14,19 @@ https://altcha.org
14
14
 
15
15
  ALTCHA widget is distributed as a "Web Component" and [supports all modern browsers](https://developer.mozilla.org/en-US/docs/Web/API/Web_components#browser_compatibility).
16
16
 
17
- ### 1. Add `<script>` tag to your website
17
+ ### 1. Install ALTCHA
18
+
19
+ ```sh
20
+ npm install altcha
21
+ ```
22
+
23
+ import `altcha` in your main file:
24
+
25
+ ```js
26
+ import 'altcha';
27
+ ```
28
+
29
+ or insert `<script>` tag to your website:
18
30
 
19
31
  ```html
20
32
  <script async defer src="/altcha.js" type="module"></script>
@@ -47,6 +59,7 @@ Required options (at least one is required):
47
59
 
48
60
  Additional options:
49
61
 
62
+ - __auto__ - Automatically verify without user interaction (possible values: `onload`, `onsubmit`).
50
63
  - __hidefooter__ - Hide the footer (ALTCHA link).
51
64
  - __hidelogo__ - Hide the ALTCHA logo.
52
65
  - __maxnumber__ - The max. number to iterate to (defaults to 10,000,000).
@@ -73,6 +86,8 @@ document.querySelector('#altcha').addEventListener('statechange', (ev) => {
73
86
  });
74
87
  ```
75
88
 
89
+ ## Contributing
90
+ 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).
76
91
 
77
92
  ## License
78
93
 
@@ -1 +1 @@
1
- var altcha=function(O){"use strict";var ft=Object.defineProperty;var ht=(O,y,H)=>y in O?ft(O,y,{enumerable:!0,configurable:!0,writable:!0,value:H}):O[y]=H;var x=(O,y,H)=>(ht(O,typeof y!="symbol"?y+"":y,H),H);function y(){}function H(t){return t()}function le(){return Object.create(null)}function U(t){t.forEach(H)}function ie(t){return typeof t=="function"}function ve(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function we(t){return Object.keys(t).length===0}function d(t,e){t.appendChild(e)}function je(t,e,n){const l=pe(t);if(!l.getElementById(e)){const i=$("style");i.id=e,i.textContent=n,ye(l,i)}}function pe(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function ye(t,e){return d(t.head||t,e),e.sheet}function V(t,e,n){t.insertBefore(e,n||null)}function R(t){t.parentNode&&t.parentNode.removeChild(t)}function $(t){return document.createElement(t)}function S(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function ke(t){return document.createTextNode(t)}function T(){return ke(" ")}function J(t,e,n,l){return t.addEventListener(e,n,l),()=>t.removeEventListener(e,n,l)}function o(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ee(t){return Array.from(t.childNodes)}function se(t,e,n){t.classList.toggle(e,!!n)}function Ce(t,e,{bubbles:n=!1,cancelable:l=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:l})}function Le(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let K;function P(t){K=t}function Q(){if(!K)throw new Error("Function called outside component initialization");return K}function xe(t){Q().$$.on_mount.push(t)}function Re(t){Q().$$.on_destroy.push(t)}function Ie(){const t=Q();return(e,n,{cancelable:l=!1}={})=>{const i=t.$$.callbacks[e];if(i){const r=Ce(e,n,{cancelable:l});return i.slice().forEach(c=>{c.call(t,r)}),!r.defaultPrevented}return!0}}const B=[],q=[];let Y=[];const oe=[],Ne=Promise.resolve();let ee=!1;function Ae(){ee||(ee=!0,Ne.then(I))}function te(t){Y.push(t)}const ne=new Set;let Z=0;function I(){if(Z!==0)return;const t=K;do{try{for(;Z<B.length;){const e=B[Z];Z++,P(e),Me(e.$$)}}catch(e){throw B.length=0,Z=0,e}for(P(null),B.length=0,Z=0;q.length;)q.pop()();for(let e=0;e<Y.length;e+=1){const n=Y[e];ne.has(n)||(ne.add(n),n())}Y.length=0}while(B.length);for(;oe.length;)oe.pop()();ee=!1,ne.clear(),P(t)}function Me(t){if(t.fragment!==null){t.update(),U(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(te)}}function Ve(t){const e=[],n=[];Y.forEach(l=>t.indexOf(l)===-1?e.push(l):n.push(l)),n.forEach(l=>l()),Y=e}const Oe=new Set;function Se(t,e){t&&t.i&&(Oe.delete(t),t.i(e))}function Fe(t,e,n){const{fragment:l,after_update:i}=t.$$;l&&l.m(e,n),te(()=>{const r=t.$$.on_mount.map(H).filter(ie);t.$$.on_destroy?t.$$.on_destroy.push(...r):U(r),t.$$.on_mount=[]}),i.forEach(te)}function He(t,e){const n=t.$$;n.fragment!==null&&(Ve(n.after_update),U(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Ge(t,e){t.$$.dirty[0]===-1&&(B.push(t),Ae(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function Te(t,e,n,l,i,r,c=null,a=[-1]){const u=K;P(t);const f=t.$$={fragment:null,ctx:[],props:r,update:y,not_equal:i,bound:le(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(u?u.$$.context:[])),callbacks:le(),dirty:a,skip_bound:!1,root:e.target||u.$$.root};c&&c(f.root);let N=!1;if(f.ctx=n?n(t,e.props||{},(g,_,...E)=>{const k=E.length?E[0]:_;return f.ctx&&i(f.ctx[g],f.ctx[g]=k)&&(!f.skip_bound&&f.bound[g]&&f.bound[g](k),N&&Ge(t,g)),_}):[],f.update(),N=!0,U(f.before_update),f.fragment=l?l(f.ctx):!1,e.target){if(e.hydrate){const g=Ee(e.target);f.fragment&&f.fragment.l(g),g.forEach(R)}else f.fragment&&f.fragment.c();e.intro&&Se(t.$$.fragment),Fe(t,e.target,e.anchor),I()}P(u)}let ce;typeof HTMLElement=="function"&&(ce=class extends HTMLElement{constructor(e,n,l){super();x(this,"$$ctor");x(this,"$$s");x(this,"$$c");x(this,"$$cn",!1);x(this,"$$d",{});x(this,"$$r",!1);x(this,"$$p_d",{});x(this,"$$l",{});x(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,l&&this.attachShadow({mode:"open"})}addEventListener(e,n,l){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,l)}removeEventListener(e,n,l){if(super.removeEventListener(e,n,l),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 c;return{c:function(){c=$("slot"),r!=="default"&&o(c,"name",r)},m:function(f,N){V(f,c,N)},d:function(f){f&&R(c)}}}};if(await Promise.resolve(),!this.$$cn)return;const n={},l=Le(this);for(const r of this.$$s)r in l&&(n[r]=[e(r)]);for(const r of this.attributes){const c=this.$$g_p(r.name);c in this.$$d||(this.$$d[c]=D(c,r.value,this.$$p_d,"toProp"))}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 c=D(r,this.$$d[r],this.$$p_d,"toAttribute");c==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,c)}this.$$r=!1};this.$$c.$$.after_update.push(i),i();for(const r in this.$$l)for(const c of this.$$l[r]){const a=this.$$c.$on(r,c);this.$$l_u.set(c,a)}this.$$l={}}}attributeChangedCallback(e,n,l){var i;this.$$r||(e=this.$$g_p(e),this.$$d[e]=D(e,l,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 D(t,e,n,l){var r;const i=(r=n[t])==null?void 0:r.type;if(e=i==="Boolean"&&typeof e!="boolean"?e!=null:e,!l||!n[t])return e;if(l==="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,l,i,r){let c=class extends ce{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(c.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(u){var f;u=D(a,u,e),this.$$d[a]=u,(f=this.$$c)==null||f.$set({[a]:u})}})}),l.forEach(a=>{Object.defineProperty(c.prototype,a,{get(){var u;return(u=this.$$c)==null?void 0:u[a]}})}),r&&(c=r(c)),t.element=c,c}class Be{constructor(){x(this,"$$");x(this,"$$set")}$destroy(){He(this,1),this.$destroy=y}$on(e,n){if(!ie(n))return y;const l=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return l.push(n),()=>{const i=l.indexOf(n);i!==-1&&l.splice(i,1)}}$set(e){this.$$set&&!we(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Ye="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ye);const ae="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLHIuZW5jb2RlKGUrbikpKX1hc3luYyBmdW5jdGlvbiBpKGUsbixhPSJTSEEtMjU2IixvPTFlNyl7Y29uc3Qgcz1EYXRlLm5vdygpO2ZvcihsZXQgdD0wO3Q8PW87dCsrKWlmKGF3YWl0IGwobix0LGEpPT09ZSlyZXR1cm57bnVtYmVyOnQsdG9vazpEYXRlLm5vdygpLXN9O3JldHVybiBudWxsfW9ubWVzc2FnZT1hc3luYyBlPT57Y29uc3R7YWxnOm4sY2hhbGxlbmdlOmEsbWF4Om8sc2FsdDpzfT1lLmRhdGF8fHt9O2lmKGEmJnMpe2NvbnN0IHQ9YXdhaXQgaShhLHMsbixvKTtzZWxmLnBvc3RNZXNzYWdlKHQmJnsuLi50LHdvcmtlcjohMH0pfWVsc2Ugc2VsZi5wb3N0TWVzc2FnZShudWxsKX19KSgpOwo=",ue=typeof window<"u"&&window.Blob&&new Blob([atob(ae)],{type:"text/javascript;charset=utf-8"});function Ze(){let t;try{if(t=ue&&(window.URL||window.webkitURL).createObjectURL(ue),!t)throw"";return new Worker(t)}catch{return new Worker("data:application/javascript;base64,"+ae)}finally{t&&(window.URL||window.webkitURL).revokeObjectURL(t)}}const Ue=1e7,Ke=new TextEncoder;function Pe(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function Xe(t=1e5,e="SHA-256"){const n=Date.now().toString(16),l=Math.round(Math.random()*t),i=await fe(n,l,e);return{algorithm:e,challenge:i,salt:n,signature:""}}async function fe(t,e,n){return Pe(await crypto.subtle.digest(n,Ke.encode(t+e)))}async function De(t,e,n="SHA-256",l=Ue){const i=Date.now();for(let r=0;r<=l;r++)if(await fe(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="unverfied",t))(p||{});function ze(t){je(t,"svelte-mjm2j6",".altcha.svelte-mjm2j6.svelte-mjm2j6{background:var(--altcha-color-base, #ffffff);border:1px solid var(--altcha-color-border, #a0a0a0);border-radius:3px;color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:260px;overflow:hidden;position:relative}.altcha.svelte-mjm2j6.svelte-mjm2j6:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-mjm2j6.svelte-mjm2j6{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-mjm2j6.svelte-mjm2j6{flex-grow:1}.altcha-label.svelte-mjm2j6 label.svelte-mjm2j6{cursor:pointer}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6{color:currentColor;opacity:0.3}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6:hover{opacity:1}.altcha-error.svelte-mjm2j6.svelte-mjm2j6{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-mjm2j6.svelte-mjm2j6{align-items:center;background-color:var(--altcha-color-footer-bg, #f4f4f4);display:flex;font-size:0.75rem;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-mjm2j6>.svelte-mjm2j6:first-child{flex-grow:1}.altcha-footer.svelte-mjm2j6 a{color:currentColor}.altcha-checkbox.svelte-mjm2j6.svelte-mjm2j6{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-mjm2j6 input.svelte-mjm2j6{width:18px;height:18px;margin:0}.altcha-hidden.svelte-mjm2j6.svelte-mjm2j6{display:none}.altcha-spinner.svelte-mjm2j6.svelte-mjm2j6{animation:svelte-mjm2j6-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-mjm2j6-altcha-spinner{100%{transform:rotate(360deg)}}")}function he(t){let e,n,l;return{c(){e=S("svg"),n=S("path"),l=S("path"),o(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"),o(n,"fill","currentColor"),o(n,"opacity",".25"),o(l,"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"),o(l,"fill","currentColor"),o(l,"class","altcha-spinner svelte-mjm2j6"),o(e,"width","24"),o(e,"height","24"),o(e,"viewBox","0 0 24 24"),o(e,"xmlns","http://www.w3.org/2000/svg")},m(i,r){V(i,e,r),d(e,n),d(e,l)},d(i){i&&R(e)}}}function Je(t){let e,n=t[7].label+"",l;return{c(){e=$("label"),o(e,"for",l=t[1]+"_checkbox"),o(e,"class","svelte-mjm2j6")},m(i,r){V(i,e,r),e.innerHTML=n},p(i,r){r[0]&128&&n!==(n=i[7].label+"")&&(e.innerHTML=n),r[0]&2&&l!==(l=i[1]+"_checkbox")&&o(e,"for",l)},d(i){i&&R(e)}}}function Qe(t){let e,n=t[7].verifying+"";return{c(){e=$("span")},m(l,i){V(l,e,i),e.innerHTML=n},p(l,i){i[0]&128&&n!==(n=l[7].verifying+"")&&(e.innerHTML=n)},d(l){l&&R(e)}}}function qe(t){let e,n=t[7].verified+"",l,i;return{c(){e=$("span"),l=T(),i=$("input"),o(i,"type","hidden"),o(i,"name",t[1]),i.value=t[2]},m(r,c){V(r,e,c),e.innerHTML=n,V(r,l,c),V(r,i,c)},p(r,c){c[0]&128&&n!==(n=r[7].verified+"")&&(e.innerHTML=n),c[0]&2&&o(i,"name",r[1]),c[0]&4&&(i.value=r[2])},d(r){r&&(R(e),R(l),R(i))}}}function de(t){let e,n,l,i,r,c=t[7].error+"";return{c(){e=$("div"),n=S("svg"),l=S("path"),i=T(),r=$("div"),o(l,"stroke-linecap","round"),o(l,"stroke-linejoin","round"),o(l,"d","M6 18L18 6M6 6l12 12"),o(n,"width","14"),o(n,"height","14"),o(n,"xmlns","http://www.w3.org/2000/svg"),o(n,"fill","none"),o(n,"viewBox","0 0 24 24"),o(n,"stroke-width","1.5"),o(n,"stroke","currentColor"),o(r,"title",t[6]),o(e,"class","altcha-error svelte-mjm2j6")},m(a,u){V(a,e,u),d(e,n),d(n,l),d(e,i),d(e,r),r.innerHTML=c},p(a,u){u[0]&128&&c!==(c=a[7].error+"")&&(r.innerHTML=c),u[0]&64&&o(r,"title",a[6])},d(a){a&&R(e)}}}function me(t){let e,n,l=t[7].footer+"";return{c(){e=$("div"),n=$("div"),o(n,"class","svelte-mjm2j6"),o(e,"class","altcha-footer svelte-mjm2j6")},m(i,r){V(i,e,r),d(e,n),n.innerHTML=l},p(i,r){r[0]&128&&l!==(l=i[7].footer+"")&&(n.innerHTML=l)},d(i){i&&R(e)}}}function et(t){let e,n,l,i,r,c,a,u,f,N,g,_,E,k,W,X,A,G,M,v=t[3]===p.VERIFYING&&he();function F(h,L){return h[3]===p.VERIFIED?qe:h[3]===p.VERIFYING?Qe:Je}let C=F(t),m=C(t),w=t[6]&&de(t),j=t[7].footer&&t[0]!==!0&&me(t);return{c(){e=$("div"),n=$("div"),v&&v.c(),l=T(),i=$("div"),r=$("input"),a=T(),u=$("div"),m.c(),f=T(),N=$("div"),g=$("a"),_=S("svg"),E=S("path"),k=S("path"),W=S("path"),X=T(),w&&w.c(),A=T(),j&&j.c(),o(r,"type","checkbox"),o(r,"id",c=t[1]+"_checkbox"),r.required=!0,o(r,"class","svelte-mjm2j6"),o(i,"class","altcha-checkbox svelte-mjm2j6"),se(i,"altcha-hidden",t[3]===p.VERIFYING),o(u,"class","altcha-label svelte-mjm2j6"),o(E,"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"),o(E,"fill","currentColor"),o(k,"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"),o(k,"fill","currentColor"),o(W,"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"),o(W,"fill","currentColor"),o(_,"width","22"),o(_,"height","22"),o(_,"viewBox","0 0 20 20"),o(_,"fill","none"),o(_,"xmlns","http://www.w3.org/2000/svg"),o(g,"href",ge),o(g,"target","_blank"),o(g,"class","altcha-logo svelte-mjm2j6"),o(n,"class","altcha-main svelte-mjm2j6"),o(e,"class","altcha svelte-mjm2j6"),o(e,"data-state",t[3])},m(h,L){V(h,e,L),d(e,n),v&&v.m(n,null),d(n,l),d(n,i),d(i,r),r.checked=t[4],d(n,a),d(n,u),m.m(u,null),d(n,f),d(n,N),d(N,g),d(g,_),d(_,E),d(_,k),d(_,W),d(e,X),w&&w.m(e,null),d(e,A),j&&j.m(e,null),t[20](e),G||(M=[J(r,"change",t[19]),J(r,"change",t[8]),J(r,"invalid",t[9])],G=!0)},p(h,L){h[3]===p.VERIFYING?v||(v=he(),v.c(),v.m(n,l)):v&&(v.d(1),v=null),L[0]&2&&c!==(c=h[1]+"_checkbox")&&o(r,"id",c),L[0]&16&&(r.checked=h[4]),L[0]&8&&se(i,"altcha-hidden",h[3]===p.VERIFYING),C===(C=F(h))&&m?m.p(h,L):(m.d(1),m=C(h),m&&(m.c(),m.m(u,null))),h[6]?w?w.p(h,L):(w=de(h),w.c(),w.m(e,A)):w&&(w.d(1),w=null),h[7].footer&&h[0]!==!0?j?j.p(h,L):(j=me(h),j.c(),j.m(e,null)):j&&(j.d(1),j=null),L[0]&8&&o(e,"data-state",h[3])},i:y,o:y,d(h){h&&R(e),v&&v.d(),m.d(),w&&w.d(),j&&j.d(),t[20](null),G=!1,U(M)}}}const ge="https://altcha.org/";function be(t){return JSON.parse(t)}function tt(t,e,n){let l,i,r,{challengeurl:c=void 0}=e,{challengejson:a=void 0}=e,{debug:u=!1}=e,{hidefooter:f=!1}=e,{name:N="altcha"}=e,{maxnumber:g=void 0}=e,{mockerror:_=!1}=e,{strings:E=void 0}=e,{test:k=!1}=e;const W=Ie(),X=["SHA-256","SHA-384","SHA-512"];let A=!1,G,M=null,v=null,F=null,C=p.UNVERIFIED;Re(()=>{M&&(M.removeEventListener("submit",w),M.removeEventListener("reset",j),M=null)}),xe(()=>{m("mounted"),k&&m("using test mode"),M=G.closest("form"),M&&(M.addEventListener("submit",w),M.addEventListener("reset",j))});function m(...s){(u||s.some(b=>b instanceof Error))&&console[s[0]instanceof Error?"error":"log"]("ALTCHA",...s)}function w(){requestAnimationFrame(()=>{z()})}function j(){z()}function h(s,b){return btoa(JSON.stringify({algorithm:s.algorithm,challenge:s.challenge,number:b.number,salt:s.salt,signature:s.signature,test:k?!0:void 0,took:b.took}))}function L(s){if(!s.algorithm||!X.includes(s.algorithm))throw new Error(`Unknown algorithm value. Allowed values: ${X.join(", ")}`);if(!s.challenge||s.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!s.salt||s.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.");if(s.signature===void 0)throw new Error("Signature is missing.")}async function nt(){if(_)throw m("mocking error"),new Error("Mocked error.");if(l)return m("using provided json data"),l;if(k)return m("generating test challenge"),Xe();{if(!c)throw new Error("Attribute challengeurl not set.");m("fetching challenge from",c);const s=await fetch(c);if(s.status!==200)throw new Error(`Server responded with ${s.status}.`);return s.json()}}async function rt(s){let b=null;if("Worker"in window){try{b=await lt(s.challenge,s.salt,s.algorithm)}catch(re){m(re)}if((b==null?void 0:b.number)!==void 0)return{data:s,solution:b}}return{data:s,solution:await De(s.challenge,s.salt,s.algorithm,g)}}async function lt(s,b,re){const _e=new Ze;return new Promise(at=>{_e.addEventListener("message",ut=>{at(ut.data)}),_e.postMessage({alg:re,challenge:s,max:g,salt:b})})}function it(){[p.UNVERIFIED,p.ERROR].includes(C)?(z(p.VERIFYING),nt().then(s=>(L(s),m("challenge",s),rt(s))).then(({data:s,solution:b})=>{if(m("solution",b),(b==null?void 0:b.number)!==void 0)m("verified"),n(3,C=p.VERIFIED),n(4,A=!0),n(2,F=h(s,b)),W("verified",{payload:F}),m("payload",F);else throw new Error("Unexpected result returned.")}).catch(s=>{m(s),n(3,C=p.ERROR),n(4,A=!1),n(6,v=s)})):n(4,A=!0)}function st(){C===p.VERIFYING&&alert(r.waitAlert)}function z(s=p.UNVERIFIED){n(4,A=!1),n(6,v=null),n(2,F=null),n(3,C=s)}function ot(){A=this.checked,n(4,A)}function ct(s){q[s?"unshift":"push"](()=>{G=s,n(5,G)})}return t.$$set=s=>{"challengeurl"in s&&n(10,c=s.challengeurl),"challengejson"in s&&n(11,a=s.challengejson),"debug"in s&&n(12,u=s.debug),"hidefooter"in s&&n(0,f=s.hidefooter),"name"in s&&n(1,N=s.name),"maxnumber"in s&&n(13,g=s.maxnumber),"mockerror"in s&&n(14,_=s.mockerror),"strings"in s&&n(15,E=s.strings),"test"in s&&n(16,k=s.test)},t.$$.update=()=>{t.$$.dirty[0]&2048&&(l=a?be(a):void 0),t.$$.dirty[0]&32768&&n(18,i=E?be(E):{}),t.$$.dirty[0]&262144&&n(7,r={error:"Verification failed. Try again later.",footer:`Protected by <a href="${ge}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...i}),t.$$.dirty[0]&12&&W("statechange",{payload:F,state:C})},[f,N,F,C,A,G,v,r,it,st,c,a,u,g,_,E,k,z,i,ot,ct]}class $e extends Be{constructor(e){super(),Te(this,e,tt,et,ve,{challengeurl:10,challengejson:11,debug:12,hidefooter:0,name:1,maxnumber:13,mockerror:14,strings:15,test:16,reset:17},ze,[-1,-1])}get challengeurl(){return this.$$.ctx[10]}set challengeurl(e){this.$$set({challengeurl:e}),I()}get challengejson(){return this.$$.ctx[11]}set challengejson(e){this.$$set({challengejson:e}),I()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),I()}get hidefooter(){return this.$$.ctx[0]}set hidefooter(e){this.$$set({hidefooter:e}),I()}get name(){return this.$$.ctx[1]}set name(e){this.$$set({name:e}),I()}get maxnumber(){return this.$$.ctx[13]}set maxnumber(e){this.$$set({maxnumber:e}),I()}get mockerror(){return this.$$.ctx[14]}set mockerror(e){this.$$set({mockerror:e}),I()}get strings(){return this.$$.ctx[15]}set strings(e){this.$$set({strings:e}),I()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),I()}get reset(){return this.$$.ctx[17]}}return customElements.define("altcha-widget",We($e,{challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset"],!1)),O.Altcha=$e,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"}),O}({});
1
+ var altcha=function(M){"use strict";var gt=Object.defineProperty;var mt=(M,C,F)=>C in M?gt(M,C,{enumerable:!0,configurable:!0,writable:!0,value:F}):M[C]=F;var N=(M,C,F)=>(mt(M,typeof C!="symbol"?C+"":C,F),F);function C(){}function F(t){return t()}function oe(){return Object.create(null)}function P(t){t.forEach(F)}function se(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 i=xe(t);if(!i.getElementById(e)){const l=w("style");l.id=e,l.textContent=n,Ie(i,l)}}function xe(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 A(t,e,n){t.insertBefore(e,n||null)}function R(t){t.parentNode&&t.parentNode.removeChild(t)}function w(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Le(t){return document.createTextNode(t)}function Y(){return Le(" ")}function J(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}function s(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function qe(t){return Array.from(t.childNodes)}function ce(t,e,n){t.classList.toggle(e,!!n)}function Ne(t,e,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:i})}function Re(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let T;function X(t){T=t}function Q(){if(!T)throw new Error("Function called outside component initialization");return T}function je(t){Q().$$.on_mount.push(t)}function Ae(t){Q().$$.on_destroy.push(t)}function Ge(){const t=Q();return(e,n,{cancelable:i=!1}={})=>{const l=t.$$.callbacks[e];if(l){const r=Ne(e,n,{cancelable:i});return l.slice().forEach(c=>{c.call(t,r)}),!r.defaultPrevented}return!0}}const H=[],ee=[];let B=[];const ae=[],ue=Promise.resolve();let te=!1;function fe(){te||(te=!0,ue.then(L))}function Se(){return fe(),ue}function ne(t){B.push(t)}const re=new Set;let W=0;function L(){if(W!==0)return;const t=T;do{try{for(;W<H.length;){const e=H[W];W++,X(e),Me(e.$$)}}catch(e){throw H.length=0,W=0,e}for(X(null),H.length=0,W=0;ee.length;)ee.pop()();for(let e=0;e<B.length;e+=1){const n=B[e];re.has(n)||(re.add(n),n())}B.length=0}while(H.length);for(;ae.length;)ae.pop()();te=!1,re.clear(),X(t)}function Me(t){if(t.fragment!==null){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(ne)}}function Ve(t){const e=[],n=[];B.forEach(i=>t.indexOf(i)===-1?e.push(i):n.push(i)),n.forEach(i=>i()),B=e}const Ue=new Set;function Fe(t,e){t&&t.i&&(Ue.delete(t),t.i(e))}function Oe(t,e,n){const{fragment:i,after_update:l}=t.$$;i&&i.m(e,n),ne(()=>{const r=t.$$.on_mount.map(F).filter(se);t.$$.on_destroy?t.$$.on_destroy.push(...r):P(r),t.$$.on_mount=[]}),l.forEach(ne)}function Ye(t,e){const n=t.$$;n.fragment!==null&&(Ve(n.after_update),P(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Ze(t,e){t.$$.dirty[0]===-1&&(H.push(t),fe(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function He(t,e,n,i,l,r,c=null,a=[-1]){const f=T;X(t);const u=t.$$={fragment:null,ctx:[],props:r,update:C,not_equal:l,bound:oe(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(f?f.$$.context:[])),callbacks:oe(),dirty:a,skip_bound:!1,root:e.target||f.$$.root};c&&c(u.root);let G=!1;if(u.ctx=n?n(t,e.props||{},(y,E,...b)=>{const q=b.length?b[0]:E;return u.ctx&&l(u.ctx[y],u.ctx[y]=q)&&(!u.skip_bound&&u.bound[y]&&u.bound[y](q),G&&Ze(t,y)),E}):[],u.update(),G=!0,P(u.before_update),u.fragment=i?i(u.ctx):!1,e.target){if(e.hydrate){const y=qe(e.target);u.fragment&&u.fragment.l(y),y.forEach(R)}else u.fragment&&u.fragment.c();e.intro&&Fe(t.$$.fragment),Oe(t,e.target,e.anchor),L()}X(f)}let he;typeof HTMLElement=="function"&&(he=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 c;return{c:function(){c=w("slot"),r!=="default"&&s(c,"name",r)},m:function(u,G){A(u,c,G)},d:function(u){u&&R(c)}}}};if(await Promise.resolve(),!this.$$cn)return;const n={},i=Re(this);for(const r of this.$$s)r in i&&(n[r]=[e(r)]);for(const r of this.attributes){const c=this.$$g_p(r.name);c in this.$$d||(this.$$d[c]=K(c,r.value,this.$$p_d,"toProp"))}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 c=K(r,this.$$d[r],this.$$p_d,"toAttribute");c==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,c)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const r in this.$$l)for(const c of this.$$l[r]){const a=this.$$c.$on(r,c);this.$$l_u.set(c,a)}this.$$l={}}}attributeChangedCallback(e,n,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=K(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 K(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 Be(t,e,n,i,l,r){let c=class extends he{constructor(){super(t,n,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(c.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(f){var u;f=K(a,f,e),this.$$d[a]=f,(u=this.$$c)==null||u.$set({[a]:f})}})}),i.forEach(a=>{Object.defineProperty(c.prototype,a,{get(){var f;return(f=this.$$c)==null?void 0:f[a]}})}),r&&(c=r(c)),t.element=c,c}class We{constructor(){N(this,"$$");N(this,"$$set")}$destroy(){Ye(this,1),this.$destroy=C}$on(e,n){if(!se(n))return C;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&&!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 de="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",ge=typeof window<"u"&&window.Blob&&new Blob([atob(de)],{type:"text/javascript;charset=utf-8"});function Te(){let t;try{if(t=ge&&(window.URL||window.webkitURL).createObjectURL(ge),!t)throw"";return new Worker(t)}catch{return new Worker("data:application/javascript;base64,"+de)}finally{t&&(window.URL||window.webkitURL).revokeObjectURL(t)}}const Xe=1e7,De=new TextEncoder;function Ke(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ze(t=1e5,e="SHA-256"){const n=Date.now().toString(16),i=Math.round(Math.random()*t),l=await me(n,i,e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function me(t,e,n){return Ke(await crypto.subtle.digest(n.toUpperCase(),De.encode(t+e)))}async function Je(t,e,n="SHA-256",i=Xe){const l=Date.now();for(let r=0;r<=i;r++)if(await me(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 Qe(t){Ce(t,"svelte-fqcw55",".altcha.svelte-fqcw55.svelte-fqcw55{background:var(--altcha-color-base, transparent);border:1px solid var(--altcha-color-border, #a0a0a0);border-radius:3px;color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:260px;overflow:hidden;position:relative;text-align:left}.altcha.svelte-fqcw55.svelte-fqcw55:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-fqcw55.svelte-fqcw55{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-fqcw55.svelte-fqcw55{flex-grow:1}.altcha-label.svelte-fqcw55 label.svelte-fqcw55{cursor:pointer}.altcha-logo.svelte-fqcw55.svelte-fqcw55{color:currentColor;opacity:0.3}.altcha-logo.svelte-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-error.svelte-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-footer.svelte-fqcw55>.svelte-fqcw55:first-child{flex-grow:1}.altcha-footer.svelte-fqcw55 a{color:currentColor}.altcha-checkbox.svelte-fqcw55.svelte-fqcw55{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-fqcw55 input.svelte-fqcw55{width:18px;height:18px;margin:0}.altcha-hidden.svelte-fqcw55.svelte-fqcw55{display:none}.altcha-spinner.svelte-fqcw55.svelte-fqcw55{animation:svelte-fqcw55-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-fqcw55-altcha-spinner{100%{transform:rotate(360deg)}}")}function we(t){let e,n,i;return{c(){e=V("svg"),n=V("path"),i=V("path"),s(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"),s(n,"fill","currentColor"),s(n,"opacity",".25"),s(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"),s(i,"fill","currentColor"),s(i,"class","altcha-spinner svelte-fqcw55"),s(e,"width","24"),s(e,"height","24"),s(e,"viewBox","0 0 24 24"),s(e,"xmlns","http://www.w3.org/2000/svg")},m(l,r){A(l,e,r),g(e,n),g(e,i)},d(l){l&&R(e)}}}function et(t){let e,n=t[8].label+"",i;return{c(){e=w("label"),s(e,"for",i=t[2]+"_checkbox"),s(e,"class","svelte-fqcw55")},m(l,r){A(l,e,r),e.innerHTML=n},p(l,r){r[0]&256&&n!==(n=l[8].label+"")&&(e.innerHTML=n),r[0]&4&&i!==(i=l[2]+"_checkbox")&&s(e,"for",i)},d(l){l&&R(e)}}}function tt(t){let e,n=t[8].verifying+"";return{c(){e=w("span")},m(i,l){A(i,e,l),e.innerHTML=n},p(i,l){l[0]&256&&n!==(n=i[8].verifying+"")&&(e.innerHTML=n)},d(i){i&&R(e)}}}function nt(t){let e,n=t[8].verified+"",i,l;return{c(){e=w("span"),i=Y(),l=w("input"),s(l,"type","hidden"),s(l,"name",t[2]),l.value=t[3]},m(r,c){A(r,e,c),e.innerHTML=n,A(r,i,c),A(r,l,c)},p(r,c){c[0]&256&&n!==(n=r[8].verified+"")&&(e.innerHTML=n),c[0]&4&&s(l,"name",r[2]),c[0]&8&&(l.value=r[3])},d(r){r&&(R(e),R(i),R(l))}}}function be(t){let e,n,i,l,r,c=t[8].error+"";return{c(){e=w("div"),n=V("svg"),i=V("path"),l=Y(),r=w("div"),s(i,"stroke-linecap","round"),s(i,"stroke-linejoin","round"),s(i,"d","M6 18L18 6M6 6l12 12"),s(n,"width","14"),s(n,"height","14"),s(n,"xmlns","http://www.w3.org/2000/svg"),s(n,"fill","none"),s(n,"viewBox","0 0 24 24"),s(n,"stroke-width","1.5"),s(n,"stroke","currentColor"),s(r,"title",t[7]),s(e,"class","altcha-error svelte-fqcw55")},m(a,f){A(a,e,f),g(e,n),g(n,i),g(e,l),g(e,r),r.innerHTML=c},p(a,f){f[0]&256&&c!==(c=a[8].error+"")&&(r.innerHTML=c),f[0]&128&&s(r,"title",a[7])},d(a){a&&R(e)}}}function $e(t){let e,n,i=t[8].footer+"";return{c(){e=w("div"),n=w("div"),s(n,"class","svelte-fqcw55"),s(e,"class","altcha-footer svelte-fqcw55")},m(l,r){A(l,e,r),g(e,n),n.innerHTML=i},p(l,r){r[0]&256&&i!==(i=l[8].footer+"")&&(n.innerHTML=i)},d(l){l&&R(e)}}}function rt(t){let e,n,i,l,r,c,a,f,u,G,y,E,b,q,S,Z,D,j,O,k,$=t[4]===p.VERIFYING&&we();function U(h,I){return h[4]===p.VERIFIED?nt:h[4]===p.VERIFYING?tt:et}let x=U(t),d=x(t),v=t[7]&&be(t),_=t[8].footer&&t[1]!==!0&&$e(t);return{c(){e=w("div"),n=w("div"),$&&$.c(),i=Y(),l=w("div"),r=w("input"),f=Y(),u=w("div"),d.c(),G=Y(),y=w("div"),E=w("a"),b=V("svg"),q=V("path"),S=V("path"),Z=V("path"),D=Y(),v&&v.c(),j=Y(),_&&_.c(),s(r,"type","checkbox"),s(r,"id",c=t[2]+"_checkbox"),r.required=a=t[0]!=="onsubmit",s(r,"class","svelte-fqcw55"),s(l,"class","altcha-checkbox svelte-fqcw55"),ce(l,"altcha-hidden",t[4]===p.VERIFYING),s(u,"class","altcha-label svelte-fqcw55"),s(q,"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"),s(q,"fill","currentColor"),s(S,"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"),s(S,"fill","currentColor"),s(Z,"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"),s(Z,"fill","currentColor"),s(b,"width","22"),s(b,"height","22"),s(b,"viewBox","0 0 20 20"),s(b,"fill","none"),s(b,"xmlns","http://www.w3.org/2000/svg"),s(E,"href",ve),s(E,"target","_blank"),s(E,"class","altcha-logo svelte-fqcw55"),s(n,"class","altcha-main svelte-fqcw55"),s(e,"class","altcha svelte-fqcw55"),s(e,"data-state",t[4])},m(h,I){A(h,e,I),g(e,n),$&&$.m(n,null),g(n,i),g(n,l),g(l,r),r.checked=t[5],g(n,f),g(n,u),d.m(u,null),g(n,G),g(n,y),g(y,E),g(E,b),g(b,q),g(b,S),g(b,Z),g(e,D),v&&v.m(e,null),g(e,j),_&&_.m(e,null),t[22](e),O||(k=[J(r,"change",t[21]),J(r,"change",t[9]),J(r,"invalid",t[10])],O=!0)},p(h,I){h[4]===p.VERIFYING?$||($=we(),$.c(),$.m(n,i)):$&&($.d(1),$=null),I[0]&4&&c!==(c=h[2]+"_checkbox")&&s(r,"id",c),I[0]&1&&a!==(a=h[0]!=="onsubmit")&&(r.required=a),I[0]&32&&(r.checked=h[5]),I[0]&16&&ce(l,"altcha-hidden",h[4]===p.VERIFYING),x===(x=U(h))&&d?d.p(h,I):(d.d(1),d=x(h),d&&(d.c(),d.m(u,null))),h[7]?v?v.p(h,I):(v=be(h),v.c(),v.m(e,j)):v&&(v.d(1),v=null),h[8].footer&&h[1]!==!0?_?_.p(h,I):(_=$e(h),_.c(),_.m(e,null)):_&&(_.d(1),_=null),I[0]&16&&s(e,"data-state",h[4])},i:C,o:C,d(h){h&&R(e),$&&$.d(),d.d(),v&&v.d(),_&&_.d(),t[22](null),O=!1,P(k)}}}const ve="https://altcha.org/";function _e(t){return JSON.parse(t)}function it(t,e,n){let i,l,r,{auto:c=void 0}=e,{challengeurl:a=void 0}=e,{challengejson:f=void 0}=e,{debug:u=!1}=e,{hidefooter:G=!1}=e,{name:y="altcha"}=e,{maxnumber:E=void 0}=e,{mockerror:b=!1}=e,{strings:q=void 0}=e,{test:S=!1}=e;const Z=Ge(),D=["SHA-256","SHA-384","SHA-512"];let j=!1,O,k=null,$=null,U=null,x=p.UNVERIFIED;Ae(()=>{k&&(k.removeEventListener("submit",v),k.removeEventListener("reset",_),k=null)}),je(()=>{d("mounted","0.1.5"),S&&d("using test mode"),c!==void 0&&d("auto",c),k=O.closest("form"),k&&(k.addEventListener("submit",v),k.addEventListener("reset",_)),c==="onload"&&z()});function d(...o){(u||o.some(m=>m instanceof Error))&&console[o[0]instanceof Error?"error":"log"]("ALTCHA",...o)}function v(o){k&&c==="onsubmit"&&x===p.UNVERIFIED&&(o.preventDefault(),o.stopPropagation(),z().then(()=>{k==null||k.requestSubmit()}))}function _(){ie()}function h(o,m){return btoa(JSON.stringify({algorithm:o.algorithm,challenge:o.challenge,number:m.number,salt:o.salt,signature:o.signature,test:S?!0:void 0,took:m.took}))}function I(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(!D.includes(o.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${D.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 lt(){if(b)throw d("mocking error"),new Error("Mocked error.");if(i)return d("using provided json data"),i;if(S)return d("generating test challenge"),ze();{if(!a)throw new Error("Attribute challengeurl not set.");d("fetching challenge from",a);const o=await fetch(a);if(o.status!==200)throw new Error(`Server responded with ${o.status}.`);return o.json()}}async function ot(o){let m=null;if("Worker"in window){try{m=await st(o.challenge,o.salt,o.algorithm)}catch(le){d(le)}if((m==null?void 0:m.number)!==void 0)return{data:o,solution:m}}return{data:o,solution:await Je(o.challenge,o.salt,o.algorithm,E)}}async function st(o,m,le){const ye=new Te;return new Promise(ht=>{ye.addEventListener("message",dt=>{ht(dt.data)}),ye.postMessage({alg:le,challenge:o,max:E,salt:m})})}function ct(){[p.UNVERIFIED,p.ERROR].includes(x)?z():n(5,j=!0)}function at(){x===p.VERIFYING&&alert(r.waitAlert)}function ie(o=p.UNVERIFIED){n(5,j=!1),n(7,$=null),n(3,U=null),n(4,x=o)}async function z(){return ie(p.VERIFYING),lt().then(o=>(I(o),d("challenge",o),ot(o))).then(({data:o,solution:m})=>{if(d("solution",m),(m==null?void 0:m.number)!==void 0)d("verified"),n(4,x=p.VERIFIED),n(5,j=!0),n(3,U=h(o,m)),d("payload",U),Se().then(()=>{Z("verified",{payload:U})});else throw new Error("Unexpected result returned.")}).catch(o=>{d(o),n(4,x=p.ERROR),n(5,j=!1),n(7,$=o)})}function ut(){j=this.checked,n(5,j)}function ft(o){ee[o?"unshift":"push"](()=>{O=o,n(6,O)})}return t.$$set=o=>{"auto"in o&&n(0,c=o.auto),"challengeurl"in o&&n(11,a=o.challengeurl),"challengejson"in o&&n(12,f=o.challengejson),"debug"in o&&n(13,u=o.debug),"hidefooter"in o&&n(1,G=o.hidefooter),"name"in o&&n(2,y=o.name),"maxnumber"in o&&n(14,E=o.maxnumber),"mockerror"in o&&n(15,b=o.mockerror),"strings"in o&&n(16,q=o.strings),"test"in o&&n(17,S=o.test)},t.$$.update=()=>{t.$$.dirty[0]&4096&&(i=f?_e(f):void 0),t.$$.dirty[0]&65536&&n(20,l=q?_e(q):{}),t.$$.dirty[0]&1048576&&n(8,r={error:"Verification failed. Try again later.",footer:`Protected by <a href="${ve}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),t.$$.dirty[0]&24&&Z("statechange",{payload:U,state:x})},[c,G,y,U,x,j,O,$,r,ct,at,a,f,u,E,b,q,S,ie,z,l,ut,ft]}class pe extends We{constructor(e){super(),He(this,e,it,rt,ke,{auto:0,challengeurl:11,challengejson:12,debug:13,hidefooter:1,name:2,maxnumber:14,mockerror:15,strings:16,test:17,reset:18,verify:19},Qe,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),L()}get challengeurl(){return this.$$.ctx[11]}set challengeurl(e){this.$$set({challengeurl:e}),L()}get challengejson(){return this.$$.ctx[12]}set challengejson(e){this.$$set({challengejson:e}),L()}get debug(){return this.$$.ctx[13]}set debug(e){this.$$set({debug:e}),L()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),L()}get name(){return this.$$.ctx[2]}set name(e){this.$$set({name:e}),L()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),L()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),L()}get strings(){return this.$$.ctx[16]}set strings(e){this.$$set({strings:e}),L()}get test(){return this.$$.ctx[17]}set test(e){this.$$set({test:e}),L()}get reset(){return this.$$.ctx[18]}get verify(){return this.$$.ctx[19]}}return customElements.define("altcha-widget",Be(pe,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset","verify"],!1)),M.Altcha=pe,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"}),M}({});