altcha 0.1.9 → 0.2.0

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
@@ -60,11 +60,13 @@ Required options (at least one is required):
60
60
  Additional options:
61
61
 
62
62
  - __auto__ - Automatically verify without user interaction (possible values: `onload`, `onsubmit`).
63
+ - __expire__ - The challenge expiration (duration in milliseconds).
63
64
  - __hidefooter__ - Hide the footer (ALTCHA link).
64
65
  - __hidelogo__ - Hide the ALTCHA logo.
65
- - __maxnumber__ - The max. number to iterate to (defaults to 10,000,000).
66
+ - __maxnumber__ - The max. number to iterate to (defaults to 1,000,000).
66
67
  - __name__ - The name of the hidden field containing the payload (defaults to "altcha").
67
68
  - __strings__ - JSON-encoded translation strings. Refer to [customization](/docs/widget-customization).
69
+ - __workers__ - The number of workers to utilize for PoW (defaults to `navigator.hardwareConcurrency || 8`).
68
70
 
69
71
  Development / testing options:
70
72
 
@@ -102,6 +104,7 @@ export interface Configure {
102
104
  signature: string;
103
105
  };
104
106
  debug?: boolean;
107
+ expire?: number;
105
108
  hidefooter?: boolean;
106
109
  hidelogo?: boolean;
107
110
  maxnumber?: number;
@@ -116,6 +119,7 @@ export interface Configure {
116
119
  waitAlert?: string;
117
120
  };
118
121
  test?: boolean;
122
+ workers?: number;
119
123
  }
120
124
  ```
121
125
 
@@ -124,11 +128,21 @@ export interface Configure {
124
128
  - __statechange__ - Triggers whenever an internal `state` changes.
125
129
  - __verified__ - Triggers when the challenge is verified.
126
130
 
131
+ ```ts
132
+ enum State {
133
+ ERROR = 'error',
134
+ VERIFIED = 'verified',
135
+ VERIFYING = 'verifying',
136
+ UNVERIFIED = 'unverified',
137
+ EXPIRED = 'expired',
138
+ };
139
+ ```
140
+
127
141
  Using events:
128
142
 
129
143
  ```js
130
144
  document.querySelector('#altcha').addEventListener('statechange', (ev) => {
131
- // state can be: unverified, verifying, verified, error
145
+ // See enum State above
132
146
  console.log('state:', ev.detail.state);
133
147
  });
134
148
  ```
@@ -1 +1 @@
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}({});
1
+ var altcha=function(G){"use strict";var jt=Object.defineProperty;var At=(G,L,H)=>L in G?jt(G,L,{enumerable:!0,configurable:!0,writable:!0,value:H}):G[L]=H;var j=(G,L,H)=>(At(G,typeof L!="symbol"?L+"":L,H),H);function L(){}function H(t){return t()}function ae(){return Object.create(null)}function B(t){t.forEach(H)}function fe(t){return typeof t=="function"}function Se(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ge(t){return Object.keys(t).length===0}function v(t,e){t.appendChild(e)}function Ve(t,e,r){const n=Ze(t);if(!n.getElementById(e)){const o=_("style");o.id=e,o.textContent=r,He(n,o)}}function Ze(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function He(t,e){return v(t.head||t,e),e.sheet}function R(t,e,r){t.insertBefore(e,r||null)}function I(t){t.parentNode&&t.parentNode.removeChild(t)}function _(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Oe(t){return document.createTextNode(t)}function O(){return Oe(" ")}function te(t,e,r,n){return t.addEventListener(e,r,n),()=>t.removeEventListener(e,r,n)}function c(t,e,r){r==null?t.removeAttribute(e):t.getAttribute(e)!==r&&t.setAttribute(e,r)}function Fe(t){return Array.from(t.childNodes)}function he(t,e,r){t.classList.toggle(e,!!r)}function Pe(t,e,{bubbles:r=!1,cancelable:n=!1}={}){return new CustomEvent(t,{detail:e,bubbles:r,cancelable:n})}function Ue(t){const e={};return t.childNodes.forEach(r=>{e[r.slot||"default"]=!0}),e}let W;function J(t){W=t}function re(){if(!W)throw new Error("Function called outside component initialization");return W}function De(t){re().$$.on_mount.push(t)}function Xe(t){re().$$.on_destroy.push(t)}function Ye(){const t=re();return(e,r,{cancelable:n=!1}={})=>{const o=t.$$.callbacks[e];if(o){const l=Pe(e,r,{cancelable:n});return o.slice().forEach(s=>{s.call(t,l)}),!l.defaultPrevented}return!0}}const P=[],ne=[];let U=[];const de=[],ge=Promise.resolve();let ie=!1;function be(){ie||(ie=!0,ge.then(x))}function Ke(){return be(),ge}function oe(t){U.push(t)}const le=new Set;let D=0;function x(){if(D!==0)return;const t=W;do{try{for(;D<P.length;){const e=P[D];D++,J(e),Be(e.$$)}}catch(e){throw P.length=0,D=0,e}for(J(null),P.length=0,D=0;ne.length;)ne.pop()();for(let e=0;e<U.length;e+=1){const r=U[e];le.has(r)||(le.add(r),r())}U.length=0}while(P.length);for(;de.length;)de.pop()();ie=!1,le.clear(),J(t)}function Be(t){if(t.fragment!==null){t.update(),B(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(oe)}}function We(t){const e=[],r=[];U.forEach(n=>t.indexOf(n)===-1?e.push(n):r.push(n)),r.forEach(n=>n()),U=e}const Je=new Set;function Qe(t,e){t&&t.i&&(Je.delete(t),t.i(e))}function ze(t,e,r){const{fragment:n,after_update:o}=t.$$;n&&n.m(e,r),oe(()=>{const l=t.$$.on_mount.map(H).filter(fe);t.$$.on_destroy?t.$$.on_destroy.push(...l):B(l),t.$$.on_mount=[]}),o.forEach(oe)}function qe(t,e){const r=t.$$;r.fragment!==null&&(We(r.after_update),B(r.on_destroy),r.fragment&&r.fragment.d(e),r.on_destroy=r.fragment=null,r.ctx=[])}function et(t,e){t.$$.dirty[0]===-1&&(P.push(t),be(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function tt(t,e,r,n,o,l,s=null,u=[-1]){const f=W;J(t);const a=t.$$={fragment:null,ctx:[],props:l,update:L,not_equal:o,bound:ae(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(f?f.$$.context:[])),callbacks:ae(),dirty:u,skip_bound:!1,root:e.target||f.$$.root};s&&s(a.root);let $=!1;if(a.ctx=r?r(t,e.props||{},(w,N,...T)=>{const A=T.length?T[0]:N;return a.ctx&&o(a.ctx[w],a.ctx[w]=A)&&(!a.skip_bound&&a.bound[w]&&a.bound[w](A),$&&et(t,w)),N}):[],a.update(),$=!0,B(a.before_update),a.fragment=n?n(a.ctx):!1,e.target){if(e.hydrate){const w=Fe(e.target);a.fragment&&a.fragment.l(w),w.forEach(I)}else a.fragment&&a.fragment.c();e.intro&&Qe(t.$$.fragment),ze(t,e.target,e.anchor),x()}J(f)}let me;typeof HTMLElement=="function"&&(me=class extends HTMLElement{constructor(e,r,n){super();j(this,"$$ctor");j(this,"$$s");j(this,"$$c");j(this,"$$cn",!1);j(this,"$$d",{});j(this,"$$r",!1);j(this,"$$p_d",{});j(this,"$$l",{});j(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=r,n&&this.attachShadow({mode:"open"})}addEventListener(e,r,n){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(r),this.$$c){const o=this.$$c.$on(e,r);this.$$l_u.set(r,o)}super.addEventListener(e,r,n)}removeEventListener(e,r,n){if(super.removeEventListener(e,r,n),this.$$c){const o=this.$$l_u.get(r);o&&(o(),this.$$l_u.delete(r))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(l){return()=>{let s;return{c:function(){s=_("slot"),l!=="default"&&c(s,"name",l)},m:function(a,$){R(a,s,$)},d:function(a){a&&I(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const r={},n=Ue(this);for(const l of this.$$s)l in n&&(r[l]=[e(l)]);for(const l of this.attributes){const s=this.$$g_p(l.name);s in this.$$d||(this.$$d[s]=Q(s,l.value,this.$$p_d,"toProp"))}for(const l in this.$$p_d)!(l in this.$$d)&&this[l]!==void 0&&(this.$$d[l]=this[l],delete this[l]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:r,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const l in this.$$p_d)if(this.$$d[l]=this.$$c.$$.ctx[this.$$c.$$.props[l]],this.$$p_d[l].reflect){const s=Q(l,this.$$d[l],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[l].attribute||l):this.setAttribute(this.$$p_d[l].attribute||l,s)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const l in this.$$l)for(const s of this.$$l[l]){const u=this.$$c.$on(l,s);this.$$l_u.set(s,u)}this.$$l={}}}attributeChangedCallback(e,r,n){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Q(e,n,this.$$p_d,"toProp"),(o=this.$$c)==null||o.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(r=>this.$$p_d[r].attribute===e||!this.$$p_d[r].attribute&&r.toLowerCase()===e)||e}});function Q(t,e,r,n){var l;const o=(l=r[t])==null?void 0:l.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!n||!r[t])return e;if(n==="toAttribute")switch(o){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function rt(t,e,r,n,o,l){let s=class extends me{constructor(){super(t,r,o),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(u=>(e[u].attribute||u).toLowerCase())}};return Object.keys(e).forEach(u=>{Object.defineProperty(s.prototype,u,{get(){return this.$$c&&u in this.$$c?this.$$c[u]:this.$$d[u]},set(f){var a;f=Q(u,f,e),this.$$d[u]=f,(a=this.$$c)==null||a.$set({[u]:f})}})}),n.forEach(u=>{Object.defineProperty(s.prototype,u,{get(){var f;return(f=this.$$c)==null?void 0:f[u]}})}),l&&(s=l(s)),t.element=s,s}class nt{constructor(){j(this,"$$");j(this,"$$set")}$destroy(){qe(this,1),this.$destroy=L}$on(e,r){if(!fe(r))return L;const n=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return n.push(r),()=>{const o=n.indexOf(r);o!==-1&&n.splice(o,1)}}$set(e){this.$$set&&!Ge(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const it="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(it);const ve="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+PWk/cyhudWxsKTpoKGUsbCxvKS50aGVuKHc9Pnt3PT09dD9zKHtudW1iZXI6bCx0b29rOkRhdGUubm93KCktcn0pOmQobCsxKX0pLmNhdGNoKGMpfTtkKHApfSksY29udHJvbGxlcjphfX1sZXQgbjtvbm1lc3NhZ2U9YXN5bmMgdD0+e2NvbnN0e3R5cGU6ZSxwYXlsb2FkOm99PXQuZGF0YTtpZihlPT09ImFib3J0IiluPT1udWxsfHxuLmFib3J0KCksbj12b2lkIDA7ZWxzZSBpZihlPT09IndvcmsiKXtjb25zdHthbGc6aSxjaGFsbGVuZ2U6cCxtYXg6YSxzYWx0OnUsc3RhcnQ6c309b3x8e30sYz1tKHAsdSxpLGEscyk7bj1jLmNvbnRyb2xsZXIsYy5wcm9taXNlLnRoZW4ocj0+e3NlbGYucG9zdE1lc3NhZ2UociYmey4uLnIsd29ya2VyOiEwfSl9KX19fSkoKTsK",ot=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),we=typeof window<"u"&&window.Blob&&new Blob([ot(ve)],{type:"text/javascript;charset=utf-8"});function lt(t){let e;try{if(e=we&&(window.URL||window.webkitURL).createObjectURL(we),!e)throw"";const r=new Worker(e,{name:t==null?void 0:t.name});return r.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),r}catch{return new Worker("data:text/javascript;base64,"+ve,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const st=new TextEncoder;function ct(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ut(t,e="SHA-256",r=1e5){const n=Date.now().toString(16);t||(t=Math.round(Math.random()*r));const o=await _e(n,t,e);return{algorithm:e,challenge:o,salt:n,signature:""}}async function _e(t,e,r){return ct(await crypto.subtle.digest(r.toUpperCase(),st.encode(t+e)))}function at(t,e,r="SHA-256",n=1e6,o=0){const l=new AbortController;return{promise:new Promise((u,f)=>{const a=Date.now(),$=w=>{l.signal.aborted||w>=n?u(null):_e(e,w,r).then(N=>{N===t?u({number:w,took:Date.now()-a}):$(w+1)}).catch(f)};$(o)}),controller:l}}var b=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(b||{});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)}}")}function pe(t){let e,r,n;return{c(){e=V("svg"),r=V("path"),n=V("path"),c(r,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(r,"fill","currentColor"),c(r,"opacity",".25"),c(n,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(n,"fill","currentColor"),c(n,"class","altcha-spinner svelte-vuofbg"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(o,l){R(o,e,l),v(e,r),v(e,n)},d(o){o&&I(e)}}}function ht(t){let e,r=t[9].label+"",n;return{c(){e=_("label"),c(e,"for",n=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(o,l){R(o,e,l),e.innerHTML=r},p(o,l){l[0]&512&&r!==(r=o[9].label+"")&&(e.innerHTML=r),l[0]&8&&n!==(n=o[3]+"_checkbox")&&c(e,"for",n)},d(o){o&&I(e)}}}function dt(t){let e,r=t[9].verifying+"";return{c(){e=_("span")},m(n,o){R(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].verifying+"")&&(e.innerHTML=r)},d(n){n&&I(e)}}}function gt(t){let e,r=t[9].verified+"",n,o;return{c(){e=_("span"),n=O(),o=_("input"),c(o,"type","hidden"),c(o,"name",t[3]),o.value=t[4]},m(l,s){R(l,e,s),e.innerHTML=r,R(l,n,s),R(l,o,s)},p(l,s){s[0]&512&&r!==(r=l[9].verified+"")&&(e.innerHTML=r),s[0]&8&&c(o,"name",l[3]),s[0]&16&&(o.value=l[4])},d(l){l&&(I(e),I(n),I(o))}}}function ke(t){let e,r,n,o,l,s;return{c(){e=_("div"),r=_("a"),n=V("svg"),o=V("path"),l=V("path"),s=V("path"),c(o,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(o,"fill","currentColor"),c(l,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(l,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(n,"width","22"),c(n,"height","22"),c(n,"viewBox","0 0 20 20"),c(n,"fill","none"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(r,"href",Ee),c(r,"target","_blank"),c(r,"class","altcha-logo svelte-vuofbg")},m(u,f){R(u,e,f),v(e,r),v(r,n),v(n,o),v(n,l),v(n,s)},p:L,d(u){u&&I(e)}}}function ye(t){let e,r,n,o;function l(f,a){return f[5]===b.EXPIRED?mt:bt}let s=l(t),u=s(t);return{c(){e=_("div"),r=V("svg"),n=V("path"),o=O(),u.c(),c(n,"stroke-linecap","round"),c(n,"stroke-linejoin","round"),c(n,"d","M6 18L18 6M6 6l12 12"),c(r,"width","14"),c(r,"height","14"),c(r,"xmlns","http://www.w3.org/2000/svg"),c(r,"fill","none"),c(r,"viewBox","0 0 24 24"),c(r,"stroke-width","1.5"),c(r,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(f,a){R(f,e,a),v(e,r),v(r,n),v(e,o),u.m(e,null)},p(f,a){s===(s=l(f))&&u?u.p(f,a):(u.d(1),u=s(f),u&&(u.c(),u.m(e,null)))},d(f){f&&I(e),u.d()}}}function bt(t){let e,r=t[9].error+"";return{c(){e=_("div"),c(e,"title",t[8])},m(n,o){R(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].error+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&I(e)}}}function mt(t){let e,r=t[9].expired+"";return{c(){e=_("div"),c(e,"title",t[8])},m(n,o){R(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].expired+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&I(e)}}}function $e(t){let e,r,n=t[9].footer+"";return{c(){e=_("div"),r=_("div"),c(r,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(o,l){R(o,e,l),v(e,r),r.innerHTML=n},p(o,l){l[0]&512&&n!==(n=o[9].footer+"")&&(r.innerHTML=n)},d(o){o&&I(e)}}}function vt(t){let e,r,n,o,l,s,u,f,a,$,w,N,T,A,p=t[5]===b.VERIFYING&&pe();function F(h,d){return h[5]===b.VERIFIED?gt:h[5]===b.VERIFYING?dt:ht}let M=F(t),E=M(t),k=t[2]!==!0&&ke(),y=(t[8]||t[5]===b.EXPIRED)&&ye(t),m=t[9].footer&&t[1]!==!0&&$e(t);return{c(){e=_("div"),r=_("div"),p&&p.c(),n=O(),o=_("div"),l=_("input"),f=O(),a=_("div"),E.c(),$=O(),k&&k.c(),w=O(),y&&y.c(),N=O(),m&&m.c(),c(l,"type","checkbox"),c(l,"id",s=t[3]+"_checkbox"),l.required=u=t[0]!=="onsubmit",c(l,"class","svelte-vuofbg"),c(o,"class","altcha-checkbox svelte-vuofbg"),he(o,"altcha-hidden",t[5]===b.VERIFYING),c(a,"class","altcha-label svelte-vuofbg"),c(r,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,d){R(h,e,d),v(e,r),p&&p.m(r,null),v(r,n),v(r,o),v(o,l),l.checked=t[6],v(r,f),v(r,a),E.m(a,null),v(r,$),k&&k.m(r,null),v(e,w),y&&y.m(e,null),v(e,N),m&&m.m(e,null),t[26](e),T||(A=[te(l,"change",t[25]),te(l,"change",t[10]),te(l,"invalid",t[11])],T=!0)},p(h,d){h[5]===b.VERIFYING?p||(p=pe(),p.c(),p.m(r,n)):p&&(p.d(1),p=null),d[0]&8&&s!==(s=h[3]+"_checkbox")&&c(l,"id",s),d[0]&1&&u!==(u=h[0]!=="onsubmit")&&(l.required=u),d[0]&64&&(l.checked=h[6]),d[0]&32&&he(o,"altcha-hidden",h[5]===b.VERIFYING),M===(M=F(h))&&E?E.p(h,d):(E.d(1),E=M(h),E&&(E.c(),E.m(a,null))),h[2]!==!0?k?k.p(h,d):(k=ke(),k.c(),k.m(r,null)):k&&(k.d(1),k=null),h[8]||h[5]===b.EXPIRED?y?y.p(h,d):(y=ye(h),y.c(),y.m(e,N)):y&&(y.d(1),y=null),h[9].footer&&h[1]!==!0?m?m.p(h,d):(m=$e(h),m.c(),m.m(e,null)):m&&(m.d(1),m=null),d[0]&32&&c(e,"data-state",h[5])},i:L,o:L,d(h){h&&I(e),p&&p.d(),E.d(),k&&k.d(),y&&y.d(),m&&m.d(),t[26](null),T=!1,B(A)}}}const Ee="https://altcha.org/";function xe(t){return JSON.parse(t)}function wt(t,e,r){let n,o,l,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:f=void 0}=e,{debug:a=!1}=e,{expire:$=void 0}=e,{hidefooter:w=!1}=e,{hidelogo:N=!1}=e,{name:T="altcha"}=e,{maxnumber:A=1e6}=e,{mockerror:p=!1}=e,{strings:F=void 0}=e,{test:M=!1}=e,{workers:E=navigator.hardwareConcurrency||8}=e;const k=Ye(),y=["SHA-256","SHA-384","SHA-512"];let m=!1,h,d=null,se=null,X=null,Z=b.UNVERIFIED,ce;Xe(()=>{d&&(d.removeEventListener("submit",Le),d.removeEventListener("reset",Ie),d=null)}),De(()=>{C("mounted","0.2.0"),C("workers",E),M&&C("using test mode"),$&&ue($),s!==void 0&&C("auto",s),d=h.closest("form"),d&&(d.addEventListener("submit",Le),d.addEventListener("reset",Ie)),s==="onload"&&Y()});function C(...i){(a||i.some(g=>g instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function Le(i){d&&s==="onsubmit"&&Z===b.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),Y().then(()=>{d==null||d.requestSubmit()}))}function Ie(){z()}function _t(i,g){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:g.number,salt:i.salt,signature:i.signature,test:M?!0:void 0,took:g.took}))}function Re(i){if(!i.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(i.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!y.includes(i.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${y.join(", ")}`);if(!i.challenge||i.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!i.salt||i.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function pt(){if(p)throw C("mocking error"),new Error("Mocked error.");if(n)return C("using provided json data"),n;if(M)return C("generating test challenge"),ut();{if(!u)throw new Error("Attribute challengeurl not set.");C("fetching challenge from",u);const i=await fetch(u);if(i.status!==200)throw new Error(`Server responded with ${i.status}.`);const g=i.headers.get("Expires");if(g!=null&&g.length){const K=Date.parse(g);isNaN(K)||ue(K-Date.now())}return i.json()}}function Ne(){u&&Z===b.VERIFIED?Y():z(b.EXPIRED,l.expired)}async function kt(i){let g=null;if("Worker"in window){try{g=await yt(i.challenge,i.salt,i.algorithm)}catch(K){C(K)}if((g==null?void 0:g.number)!==void 0)return{data:i,solution:g}}return{data:i,solution:await at(i.challenge,i.salt,i.algorithm,A).promise}}async function yt(i,g,K,q=Math.ceil(E)){const ee=[];if(q<1)throw new Error("Wrong number of workers configured.");if(q>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let S=0;S<q;S++)ee.push(new lt);const je=Math.ceil(A/q),It=await Promise.all(ee.map((S,Rt)=>{const Ae=Rt*je;return new Promise(Nt=>{S.addEventListener("message",Me=>{if(Me.data)for(const Te of ee)Te!==S&&Te.postMessage({type:"abort"});Nt(Me.data)}),S.postMessage({payload:{alg:K,challenge:i,max:Ae+je,salt:g,start:Ae},type:"work"})})}));for(const S of ee)S.terminate();return It.find(S=>!!S)||null}function $t(){[b.UNVERIFIED,b.ERROR,b.EXPIRED].includes(Z)?Y():r(6,m=!0)}function Et(){Z===b.VERIFYING&&alert(l.waitAlert)}function ue(i){console.log(">>>"),C("expire",i),clearTimeout(ce),i<1?Ne():ce=setTimeout(Ne,i)}function xt(i){i.auto!==void 0&&(r(0,s=i.auto),s==="onload"&&Y()),i.expire!==void 0&&(ue(i.expire),r(13,$=i.expire)),i.challenge&&(Re(i.challenge),n=i.challenge),i.debug!==void 0&&r(12,a=!!i.debug),i.hidefooter!==void 0&&r(1,w=!!i.hidefooter),i.hidelogo!==void 0&&r(2,N=!!i.hidelogo),i.maxnumber!==void 0&&r(14,A=+i.maxnumber),i.mockerror!==void 0&&r(15,p=!!i.mockerror),i.name!==void 0&&r(3,T=i.name),i.test!==void 0&&r(16,M=!!i.test),i.strings&&r(24,o=i.strings),i.workers!==void 0&&r(17,E=+i.workers)}function z(i=b.UNVERIFIED,g=null){clearTimeout(ce),r(6,m=!1),r(8,se=g),r(4,X=null),r(5,Z=i)}async function Y(){return z(b.VERIFYING),pt().then(i=>(Re(i),C("challenge",i),kt(i))).then(({data:i,solution:g})=>{if(C("solution",g),(g==null?void 0:g.number)!==void 0)C("verified"),r(5,Z=b.VERIFIED),r(6,m=!0),r(4,X=_t(i,g)),C("payload",X),Ke().then(()=>{k("verified",{payload:X})});else throw new Error("Unexpected result returned.")}).catch(i=>{C(i),r(5,Z=b.ERROR),r(6,m=!1),r(8,se=i.message)})}function Ct(){m=this.checked,r(6,m)}function Lt(i){ne[i?"unshift":"push"](()=>{h=i,r(7,h)})}return t.$$set=i=>{"auto"in i&&r(0,s=i.auto),"challengeurl"in i&&r(18,u=i.challengeurl),"challengejson"in i&&r(19,f=i.challengejson),"debug"in i&&r(12,a=i.debug),"expire"in i&&r(13,$=i.expire),"hidefooter"in i&&r(1,w=i.hidefooter),"hidelogo"in i&&r(2,N=i.hidelogo),"name"in i&&r(3,T=i.name),"maxnumber"in i&&r(14,A=i.maxnumber),"mockerror"in i&&r(15,p=i.mockerror),"strings"in i&&r(20,F=i.strings),"test"in i&&r(16,M=i.test),"workers"in i&&r(17,E=i.workers)},t.$$.update=()=>{t.$$.dirty[0]&524288&&(n=f?xe(f):void 0),t.$$.dirty[0]&1048576&&r(24,o=F?xe(F):{}),t.$$.dirty[0]&16777216&&r(9,l={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by <a href="${Ee}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...o}),t.$$.dirty[0]&48&&k("statechange",{payload:X,state:Z})},[s,w,N,T,X,Z,m,h,se,l,$t,Et,a,$,A,p,M,E,u,f,F,xt,z,Y,o,Ct,Lt]}class Ce extends nt{constructor(e){super(),tt(this,e,wt,vt,Se,{auto:0,challengeurl:18,challengejson:19,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,strings:20,test:16,workers:17,configure:21,reset:22,verify:23},ft,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),x()}get challengeurl(){return this.$$.ctx[18]}set challengeurl(e){this.$$set({challengeurl:e}),x()}get challengejson(){return this.$$.ctx[19]}set challengejson(e){this.$$set({challengejson:e}),x()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),x()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),x()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),x()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),x()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),x()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),x()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),x()}get strings(){return this.$$.ctx[20]}set strings(e){this.$$set({strings:e}),x()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),x()}get workers(){return this.$$.ctx[17]}set workers(e){this.$$set({workers:e}),x()}get configure(){return this.$$.ctx[21]}get reset(){return this.$$.ctx[22]}get verify(){return this.$$.ctx[23]}}return customElements.define("altcha-widget",rt(Ce,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),G.Altcha=Ce,Object.defineProperty(G,Symbol.toStringTag,{value:"Module"}),G}({});