altcha 0.1.7 → 0.1.9

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
@@ -72,7 +72,54 @@ Development / testing options:
72
72
  - __mockerror__ - Causes the verification to always fail with a "mock" error.
73
73
  - __test__ - Generates a "mock" challenge within the widget, bypassing the request to `challengeurl`.
74
74
 
75
- Events:
75
+ ## Programmatic Configuration
76
+
77
+ To configure the widget programmatically, use the `configure()` method:
78
+
79
+ ```ts
80
+ document.querySelector('#altcha').configure({
81
+ challenge: {
82
+ algorithm: 'SHA-256',
83
+ challenge: '...',
84
+ salt: '...',
85
+ signature: '...',
86
+ },
87
+ strings: {
88
+ label: 'Verify',
89
+ },
90
+ });
91
+ ```
92
+
93
+ Available configuration options:
94
+
95
+ ```ts
96
+ export interface Configure {
97
+ auto?: 'onload' | 'onsubmit';
98
+ challenge?: {
99
+ algorithm: string;
100
+ challenge: string;
101
+ salt: string;
102
+ signature: string;
103
+ };
104
+ debug?: boolean;
105
+ hidefooter?: boolean;
106
+ hidelogo?: boolean;
107
+ maxnumber?: number;
108
+ mockerror?: boolean;
109
+ name?: string;
110
+ strings?: {
111
+ error?: string;
112
+ footer?: string;
113
+ label?: string;
114
+ verified?: string;
115
+ verifying?: string;
116
+ waitAlert?: string;
117
+ };
118
+ test?: boolean;
119
+ }
120
+ ```
121
+
122
+ ## Events
76
123
 
77
124
  - __statechange__ - Triggers whenever an internal `state` changes.
78
125
  - __verified__ - Triggers when the challenge is verified.
@@ -87,7 +134,7 @@ document.querySelector('#altcha').addEventListener('statechange', (ev) => {
87
134
  ```
88
135
 
89
136
  > [!IMPORTANT]
90
- > Ensure that you attach event listeners after the ALTCHA script loads, such as within window.addEventListener('load', ...), to ensure the events trigger correctly.
137
+ > Both programmatic configuration and event listeners have to called/attached after the ALTCHA script loads, such as within window.addEventListener('load', ...).
91
138
 
92
139
  ## Contributing
93
140
  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).
@@ -1 +1 @@
1
- var altcha=function(A){"use strict";var wt=Object.defineProperty;var bt=(A,y,U)=>y in A?wt(A,y,{enumerable:!0,configurable:!0,writable:!0,value:U}):A[y]=U;var I=(A,y,U)=>(bt(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 ie(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 v(t,e){t.appendChild(e)}function Ce(t,e,n){const i=xe(t);if(!i.getElementById(e)){const l=_("style");l.id=e,l.textContent=n,Le(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 Le(t,e){return v(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 _(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,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 Re(t){return Array.from(t.childNodes)}function le(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 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:i=!1}={})=>{const l=t.$$.callbacks[e];if(l){const r=Ne(e,n,{cancelable:i});return l.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 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(;H<Z.length;){const e=Z[H];H++,T(e),Ue(e.$$)}}catch(e){throw Z.length=0,H=0,e}for(T(null),Z.length=0,H=0;J.length;)J.pop()();for(let e=0;e<B.length;e+=1){const n=B[e];ee.has(n)||(ee.add(n),n())}B.length=0}while(Z.length);for(;oe.length;)oe.pop()();Q=!1,ee.clear(),T(t)}function Ue(t){if(t.fragment!==null){t.update(),W(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(q)}}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 Oe=new Set;function Fe(t,e){t&&t.i&&(Oe.delete(t),t.i(e))}function Ye(t,e,n){const{fragment:i,after_update:l}=t.$$;i&&i.m(e,n),q(()=>{const r=t.$$.on_mount.map(U).filter(ie);t.$$.on_destroy?t.$$.on_destroy.push(...r):W(r),t.$$.on_mount=[]}),l.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<<e%31}function He(t,e,n,i,l,r,s=null,a=[-1]){const f=P;T(t);const u=t.$$={fragment:null,ctx:[],props:r,update:y,not_equal:l,bound:re(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(f?f.$$.context:[])),callbacks:re(),dirty:a,skip_bound:!1,root:e.target||f.$$.root};s&&s(u.root);let j=!1;if(u.ctx=n?n(t,e.props||{},(k,S,...N)=>{const M=N.length?N[0]:S;return u.ctx&&l(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=i?i(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,i){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,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=_("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={},i=je(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]=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 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=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(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)}this.$$l={}}}attributeChangedCallback(e,n,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=X(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 X(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 We(t,e,n,i,l,r){let s=class extends ae{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(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})}})}),i.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(!ie(n))return y;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 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),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 Je(await crypto.subtle.digest(n.toUpperCase(),ze.encode(t+e)))}async function qe(t,e,n="SHA-256",i=Ke){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 et(t){Ce(t,"svelte-1wvv726",".altcha.svelte-1wvv726.svelte-1wvv726{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 3px) 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-1wvv726.svelte-1wvv726:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-1wvv726.svelte-1wvv726{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-1wvv726.svelte-1wvv726{flex-grow:1}.altcha-label.svelte-1wvv726 label.svelte-1wvv726{cursor:pointer}.altcha-logo.svelte-1wvv726.svelte-1wvv726{color:currentColor;opacity:0.3}.altcha-logo.svelte-1wvv726.svelte-1wvv726:hover{opacity:1}.altcha-error.svelte-1wvv726.svelte-1wvv726{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-1wvv726.svelte-1wvv726{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-1wvv726.svelte-1wvv726:hover{opacity:1}.altcha-footer.svelte-1wvv726>.svelte-1wvv726:first-child{flex-grow:1}.altcha-footer.svelte-1wvv726 a{color:currentColor}.altcha-checkbox.svelte-1wvv726.svelte-1wvv726{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-1wvv726 input.svelte-1wvv726{width:18px;height:18px;margin:0}.altcha-hidden.svelte-1wvv726.svelte-1wvv726{display:none}.altcha-spinner.svelte-1wvv726.svelte-1wvv726{animation:svelte-1wvv726-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-1wvv726-altcha-spinner{100%{transform:rotate(360deg)}}")}function de(t){let e,n,i;return{c(){e=G("svg"),n=G("path"),i=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(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-1wvv726"),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){R(l,e,r),v(e,n),v(e,i)},d(l){l&&L(e)}}}function tt(t){let e,n=t[9].label+"",i;return{c(){e=_("label"),c(e,"for",i=t[3]+"_checkbox"),c(e,"class","svelte-1wvv726")},m(l,r){R(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&&L(e)}}}function nt(t){let e,n=t[9].verifying+"";return{c(){e=_("span")},m(i,l){R(i,e,l),e.innerHTML=n},p(i,l){l[0]&512&&n!==(n=i[9].verifying+"")&&(e.innerHTML=n)},d(i){i&&L(e)}}}function rt(t){let e,n=t[9].verified+"",i,l;return{c(){e=_("span"),i=F(),l=_("input"),c(l,"type","hidden"),c(l,"name",t[3]),l.value=t[4]},m(r,s){R(r,e,s),e.innerHTML=n,R(r,i,s),R(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&&(L(e),L(i),L(l))}}}function ve(t){let e,n,i,l,r,s;return{c(){e=_("div"),n=_("a"),i=G("svg"),l=G("path"),r=G("path"),s=G("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",we),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-1wvv726")},m(a,f){R(a,e,f),v(e,n),v(n,i),v(i,l),v(i,r),v(i,s)},p:y,d(a){a&&L(e)}}}function ge(t){let e,n,i,l,r,s=t[9].error+"";return{c(){e=_("div"),n=G("svg"),i=G("path"),l=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-1wvv726")},m(a,f){R(a,e,f),v(e,n),v(n,i),v(e,l),v(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,i=t[9].footer+"";return{c(){e=_("div"),n=_("div"),c(n,"class","svelte-1wvv726"),c(e,"class","altcha-footer svelte-1wvv726")},m(l,r){R(l,e,r),v(e,n),n.innerHTML=i},p(l,r){r[0]&512&&i!==(i=l[9].footer+"")&&(n.innerHTML=i)},d(l){l&&L(e)}}}function it(t){let e,n,i,l,r,s,a,f,u,j,k,S,N,M,b=t[5]===p.VERIFYING&&de();function V(h,w){return h[5]===p.VERIFIED?rt:h[5]===p.VERIFYING?nt:tt}let Y=V(t),C=Y(t),g=t[2]!==!0&&ve(),m=t[8]&&ge(t),d=t[9].footer&&t[1]!==!0&&me(t);return{c(){e=_("div"),n=_("div"),b&&b.c(),i=F(),l=_("div"),r=_("input"),f=F(),u=_("div"),C.c(),j=F(),g&&g.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-1wvv726"),c(l,"class","altcha-checkbox svelte-1wvv726"),le(l,"altcha-hidden",t[5]===p.VERIFYING),c(u,"class","altcha-label svelte-1wvv726"),c(n,"class","altcha-main svelte-1wvv726"),c(e,"class","altcha svelte-1wvv726"),c(e,"data-state",t[5])},m(h,w){R(h,e,w),v(e,n),b&&b.m(n,null),v(n,i),v(n,l),v(l,r),r.checked=t[6],v(n,f),v(n,u),C.m(u,null),v(n,j),g&&g.m(n,null),v(e,k),m&&m.m(e,null),v(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,w){h[5]===p.VERIFYING?b||(b=de(),b.c(),b.m(n,i)):b&&(b.d(1),b=null),w[0]&8&&s!==(s=h[3]+"_checkbox")&&c(r,"id",s),w[0]&1&&a!==(a=h[0]!=="onsubmit")&&(r.required=a),w[0]&64&&(r.checked=h[6]),w[0]&32&&le(l,"altcha-hidden",h[5]===p.VERIFYING),Y===(Y=V(h))&&C?C.p(h,w):(C.d(1),C=Y(h),C&&(C.c(),C.m(u,null))),h[2]!==!0?g?g.p(h,w):(g=ve(),g.c(),g.m(n,null)):g&&(g.d(1),g=null),h[8]?m?m.p(h,w):(m=ge(h),m.c(),m.m(e,S)):m&&(m.d(1),m=null),h[9].footer&&h[1]!==!0?d?d.p(h,w):(d=me(h),d.c(),d.m(e,null)):d&&(d.d(1),d=null),w[0]&32&&c(e,"data-state",h[5])},i:y,o:y,d(h){h&&L(e),b&&b.d(),C.d(),g&&g.d(),m&&m.d(),d&&d.d(),t[23](null),N=!1,W(M)}}}const we="https://altcha.org/";function be(t){return JSON.parse(t)}function lt(t,e,n){let i,l,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:b=void 0}=e,{test:V=!1}=e;const Y=Se(),C=["SHA-256","SHA-384","SHA-512"];let g=!1,m,d=null,h=null,w=null,O=p.UNVERIFIED;Ge(()=>{d&&(d.removeEventListener("submit",_e),d.removeEventListener("reset",pe),d=null)}),Ae(()=>{x("mounted","0.1.7"),V&&x("using test mode"),s!==void 0&&x("auto",s),d=m.closest("form"),d&&(d.addEventListener("submit",_e),d.addEventListener("reset",pe)),s==="onload"&&D()});function x(...o){(u||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(),D().then(()=>{d==null||d.requestSubmit()}))}function pe(){te()}function ot(o,$){return btoa(JSON.stringify({algorithm:o.algorithm,challenge:o.challenge,number:$.number,salt:o.salt,signature:o.signature,test:V?!0:void 0,took:$.took}))}function st(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(M)throw x("mocking error"),new Error("Mocked error.");if(i)return x("using provided json data"),i;if(V)return x("generating test challenge"),Qe();{if(!a)throw new Error("Attribute challengeurl not set.");x("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 at(o){let $=null;if("Worker"in window){try{$=await ut(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 qe(o.challenge,o.salt,o.algorithm,N)}}async function ut(o,$,ne){const ye=new De;return new Promise(gt=>{ye.addEventListener("message",mt=>{gt(mt.data)}),ye.postMessage({alg:ne,challenge:o,max:N,salt:$})})}function ft(){[p.UNVERIFIED,p.ERROR].includes(O)?D():n(6,g=!0)}function ht(){O===p.VERIFYING&&alert(r.waitAlert)}function te(o=p.UNVERIFIED){n(6,g=!1),n(8,h=null),n(4,w=null),n(5,O=o)}async function D(){return te(p.VERIFYING),ct().then(o=>(st(o),x("challenge",o),at(o))).then(({data:o,solution:$})=>{if(x("solution",$),($==null?void 0:$.number)!==void 0)x("verified"),n(5,O=p.VERIFIED),n(6,g=!0),n(4,w=ot(o,$)),x("payload",w),Me().then(()=>{Y("verified",{payload:w})});else throw new Error("Unexpected result returned.")}).catch(o=>{x(o),n(5,O=p.ERROR),n(6,g=!1),n(8,h=o)})}function dt(){g=this.checked,n(6,g)}function vt(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(12,a=o.challengeurl),"challengejson"in o&&n(13,f=o.challengejson),"debug"in o&&n(14,u=o.debug),"hidefooter"in o&&n(1,j=o.hidefooter),"hidelogo"in o&&n(2,k=o.hidelogo),"name"in o&&n(3,S=o.name),"maxnumber"in o&&n(15,N=o.maxnumber),"mockerror"in o&&n(16,M=o.mockerror),"strings"in o&&n(17,b=o.strings),"test"in o&&n(18,V=o.test)},t.$$.update=()=>{t.$$.dirty[0]&8192&&(i=f?be(f):void 0),t.$$.dirty[0]&131072&&n(21,l=b?be(b):{}),t.$$.dirty[0]&2097152&&n(9,r={error:"Verification failed. Try again later.",footer:`Protected by <a href="${we}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),t.$$.dirty[0]&48&&Y("statechange",{payload:w,state:O})},[s,j,k,S,w,O,g,m,h,r,ft,ht,a,f,u,N,M,b,V,te,D,l,dt,vt]}class $e extends Pe{constructor(e){super(),He(this,e,lt,it,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}({});
1
+ 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(;H<Z.length;){const e=Z[H];H++,T(e),Ve(e.$$)}}catch(e){throw Z.length=0,H=0,e}for(T(null),Z.length=0,H=0;J.length;)J.pop()();for(let e=0;e<B.length;e+=1){const n=B[e];ee.has(n)||(ee.add(n),n())}B.length=0}while(Z.length);for(;oe.length;)oe.pop()();Q=!1,ee.clear(),T(t)}function Ve(t){if(t.fragment!==null){t.update(),W(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(q)}}function Oe(t){const e=[],n=[];B.forEach(i=>t.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<<e%31}function We(t,e,n,i,o,r,s=null,u=[-1]){const f=P;T(t);const a=t.$$={fragment:null,ctx:[],props:r,update:p,not_equal:o,bound:re(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(f?f.$$.context:[])),callbacks:re(),dirty:u,skip_bound:!1,root:e.target||f.$$.root};s&&s(a.root);let j=!1;if(a.ctx=n?n(t,e.props||{},(k,A,...I)=>{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 <a href="${ve}" target="_blank">ALTCHA</a>`,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}({});