From b18b6bc8c157444b1cf954e3dd09b79b2f175c10 Mon Sep 17 00:00:00 2001 From: tdruez Date: Tue, 21 Oct 2025 15:00:04 +0400 Subject: [PATCH 1/2] Upgrade JS lib to latest altcha v2.2.4 release Signed-off-by: tdruez --- django_altcha/__init__.py | 41 +++++++++++++++++-- django_altcha/static/altcha/altcha.min.js | 4 +- .../static/altcha/altcha.min.js.ABOUT | 6 +-- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/django_altcha/__init__.py b/django_altcha/__init__.py index ececf99..4c7b0a5 100644 --- a/django_altcha/__init__.py +++ b/django_altcha/__init__.py @@ -150,16 +150,30 @@ class AltchaField(forms.Field): "replay": _("Challenge has already been used."), } default_options = { + ## Required options: + # # URL of your server to fetch the challenge from. "challengeurl": None, - # JSON-encoded challenge data - # (use instead of challengeurl to avoid HTTP request). + # JSON-encoded challenge data. + # If avoiding an HTTP request to challengeurl, provide the data here. "challengejson": None, + ## Additional options: + # # Automatically verify without user interaction. # Possible values: "off", "onfocus", "onload", "onsubmit". "auto": None, + # Whether to include credentials with the challenge request + # Possible values: "omit", "same-origin", "include". + "credentials": None, + # A custom fetch function for retrieving the challenge. + # Accepts `url: string` and `init: RequestInit` as arguments and must return a + # `Response`. + "customfetch": None, # Artificial delay before verification (in milliseconds, default: 0). "delay": None, + # If true, prevents the code-challenge input from automatically receiving + # focus on render (defaults to "false"). + "disableautofocus": None, # Challenge expiration duration (in milliseconds). "expire": ALTCHA_CHALLENGE_EXPIRE, # Enable floating UI. @@ -172,14 +186,27 @@ class AltchaField(forms.Field): "floatingoffset": None, # Enable a “persistent” mode to keep the widget visible under specific # conditions. - # Possible values: "true", "focus". + # Possible values: "true", "false", "focus". "floatingpersist": None, # Hide the footer (ALTCHA link). "hidefooter": None, # Hide the ALTCHA logo. "hidelogo": None, + # The checkbox id attribute. + # Useful for multiple instances of the widget on the same page. + "id": None, + # The ISO alpha-2 code of the language to use + # (the language file be imported from `altcha/i18n/*`). + "language": None, # Max number to iterate to (default: 1,000,000). "maxnumber": None, + # Name of the hidden field containing the payload (defaults to "altcha"). + "name": None, + # Enables overlay UI mode (automatically sets `auto="onsubmit"`). + "overlay": None, + # CSS selector of the HTML element to display in the overlay modal before the + # widget. + "overlaycontent": None, # JSON-encoded translation strings for customization. "strings": None, # Automatically re-fetch and re-validate when the challenge expires @@ -190,6 +217,14 @@ class AltchaField(forms.Field): "workers": None, # URL of the Worker script (default: ./worker.js, only for external builds). "workerurl": None, + # Data Obfuscation options: + # + # The obfuscated data provided as a base64-encoded string (requires + # altcha/obfuscation plugin). + # Use only without challengeurl/challengejson. + "obfuscated": None, + ## Development / testing options: + # # Print log messages in the console (for debugging). "debug": None, # Causes verification to always fail with a "mock" error. diff --git a/django_altcha/static/altcha/altcha.min.js b/django_altcha/static/altcha/altcha.min.js index 2ffce43..1201504 100644 --- a/django_altcha/static/altcha/altcha.min.js +++ b/django_altcha/static/altcha/altcha.min.js @@ -1,4 +1,4 @@ /** - * Original file: /gh/altcha-org/altcha@1.4.2/dist/altcha.js + * Original file: /gh/altcha-org/altcha@2.2.4/dist/altcha.js */ -var mi=Object.defineProperty,Mr=e=>{throw TypeError(e)},wi=(e,t,n)=>t in e?mi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t,n)=>wi(e,"symbol"!=typeof t?t+"":t,n),Ur=(e,t,n)=>t.has(e)||Mr("Cannot "+n),Y=(e,t,n)=>(Ur(e,t,"read from private field"),n?n.call(e):t.get(e)),jt=(e,t,n)=>t.has(e)?Mr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Vt=(e,t,n,r)=>(Ur(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n);const nn='(function(){"use strict";const d=new TextEncoder;function p(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}async function b(e,t,r){if(typeof crypto>"u"||!("subtle"in crypto)||!("digest"in crypto.subtle))throw new Error("Web Crypto is not available. Secure context is required (https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts).");return p(await crypto.subtle.digest(r.toUpperCase(),d.encode(e+t)))}function w(e,t,r="SHA-256",n=1e6,s=0){const o=new AbortController,a=Date.now();return{promise:(async()=>{for(let c=s;c<=n;c+=1){if(o.signal.aborted)return null;if(await b(t,c,r)===e)return{number:c,took:Date.now()-a}}return null})(),controller:o}}function h(e){const t=atob(e),r=new Uint8Array(t.length);for(let n=0;n{for(let u=n;u<=r;u+=1){if(o.signal.aborted||!c||!y)return null;try{const f=await crypto.subtle.decrypt({name:s,iv:g(u)},c,y);if(f)return{clearText:new TextDecoder().decode(f),took:Date.now()-a}}catch{}}return null};let c=null,y=null;try{y=h(e);const u=await crypto.subtle.digest("SHA-256",d.encode(t));c=await crypto.subtle.importKey("raw",u,s,!1,["decrypt"])}catch{return{promise:Promise.reject(),controller:o}}return{promise:l(),controller:o}}let i;onmessage=async e=>{const{type:t,payload:r,start:n,max:s}=e.data;let o=null;if(t==="abort")i==null||i.abort(),i=void 0;else if(t==="work"){if("obfuscated"in r){const{key:a,obfuscated:l}=r||{};o=await m(l,a,s,n)}else{const{algorithm:a,challenge:l,salt:c}=r||{};o=w(l,c,a,s,n)}i=o.controller,o.promise.then(a=>{self.postMessage(a&&{...a,worker:!0})})}}})();\n',jr=typeof self<"u"&&self.Blob&&new Blob([nn],{type:"text/javascript;charset=utf-8"});function pi(e){let t;try{if(t=jr&&(self.URL||self.webkitURL).createObjectURL(jr),!t)throw"";const n=new Worker(t,{name:null==e?void 0:e.name});return n.addEventListener("error",(()=>{(self.URL||self.webkitURL).revokeObjectURL(t)})),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(nn),{name:null==e?void 0:e.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}const bi="5";var rn;typeof window<"u"&&((rn=window.__svelte??(window.__svelte={})).v??(rn.v=new Set)).add(bi);const yi=1,Ei=4,xi=8,$i=16,ki=1,Ci=2,Zt="[",ln="[!",an="]",Ke={},Z=Symbol(),Ai="http://www.w3.org/1999/xhtml",Vr=!1,se=2,on=4,St=8,Gt=16,be=32,Fe=64,yt=128,ne=256,Et=512,X=1024,ye=2048,tt=4096,Xe=8192,Tt=16384,Ri=32768,Jt=65536,Ii=1<<19,sn=1<<20,dt=Symbol("$state"),fn=Symbol("legacy props"),Si=Symbol("");var un=Array.isArray,Ti=Array.prototype.indexOf,Ni=Array.from,xt=Object.keys,$t=Object.defineProperty,Oe=Object.getOwnPropertyDescriptor,Li=Object.getOwnPropertyDescriptors,Di=Object.prototype,Pi=Array.prototype,cn=Object.getPrototypeOf;function dn(e){for(var t=0;t"u"?e=>setTimeout(e,1):requestIdleCallback;let ht=[],gt=[];function vn(){var e=ht;ht=[],dn(e)}function hn(){var e=gt;gt=[],dn(e)}function Kt(e){0===ht.length&&queueMicrotask(vn),ht.push(e)}function zi(e){0===gt.length&&Oi(hn),gt.push(e)}function Br(){ht.length>0&&vn(),gt.length>0&&hn()}function gn(e){return e===this.v}function Fi(e,t){return e!=e?t==t:e!==t||null!==e&&"object"==typeof e||"function"==typeof e}function _n(e){return!Fi(e,this.v)}function Mi(e){throw new Error("https://svelte.dev/e/effect_in_teardown")}function Ui(){throw new Error("https://svelte.dev/e/effect_in_unowned_derived")}function ji(e){throw new Error("https://svelte.dev/e/effect_orphan")}function Vi(){throw new Error("https://svelte.dev/e/effect_update_depth_exceeded")}function Bi(){throw new Error("https://svelte.dev/e/hydration_failed")}function qi(e){throw new Error("https://svelte.dev/e/props_invalid_value")}function Hi(){throw new Error("https://svelte.dev/e/state_descriptors_fixed")}function Wi(){throw new Error("https://svelte.dev/e/state_prototype_fixed")}function Yi(){throw new Error("https://svelte.dev/e/state_unsafe_local_read")}function Zi(){throw new Error("https://svelte.dev/e/state_unsafe_mutation")}let Gi=!1;function ue(e,t){return{f:0,v:e,reactions:null,equals:gn,rv:0,wv:0}}function We(e){return Ji(ue(e))}function mn(e,t=!1){const n=ue(e);return t||(n.equals=_n),n}function Ji(e){return null!==k&&!oe&&!!(2&k.f)&&(null===ce?rl([e]):ce.push(e)),e}function D(e,t){return null!==k&&!oe&&zn()&&!!(18&k.f)&&(null===ce||!ce.includes(e))&&Zi(),Ki(e,t)}function Ki(e,t){return e.equals(t)||(e.v,e.v=t,e.wv=kn(),wn(e,ye),null!==R&&!!(R.f&X)&&!(96&R.f)&&(null===_e?nl([e]):_e.push(e))),t}function wn(e,t){var n=e.reactions;if(null!==n)for(var r=n.length,o=0;o=h.v&&D(h,p+1)}qr(a)}return!0},ownKeys(e){d(a);var t=Reflect.ownKeys(e).filter((e=>{var t=l.get(e);return void 0===t||t.v!==Z}));for(var[n,r]of l)r.v!==Z&&!(n in e)&&t.push(n);return t},setPrototypeOf(){Wi()}})}function qr(e,t=1){D(e,e.v+t)}var Hr,yn,En,xn;function Bt(){if(void 0===Hr){Hr=window,yn=/Firefox/.test(navigator.userAgent);var e=Element.prototype,t=Node.prototype;En=Oe(t,"firstChild").get,xn=Oe(t,"nextSibling").get,e.__click=void 0,e.__className=void 0,e.__attributes=null,e.__style=void 0,e.__e=void 0,Text.prototype.__t=void 0}}function Xt(e=""){return document.createTextNode(e)}function we(e){return En.call(e)}function Te(e){return xn.call(e)}function J(e,t){if(!L)return we(e);var n=we(P);return null===n&&(n=P.appendChild(Xt())),Re(n),n}function Wr(e,t){if(!L){var n=we(e);return n instanceof Comment&&""===n.data?Te(n):n}return P}function ge(e,t=1,n=!1){let r=L?P:e;for(var o;t--;)o=r,r=Te(r);if(!L)return r;var l=null==r?void 0:r.nodeType;if(n&&3!==l){var i=Xt();return null===r?null==o||o.after(i):r.before(i),Re(i),i}return Re(r),r}function tl(e){e.textContent=""}let pt=!1,kt=!1,Ct=null,ze=!1,Qt=!1;function Yr(e){Qt=e}let vt=[],k=null,oe=!1;function Ie(e){k=e}let R=null;function Se(e){R=e}let ce=null;function rl(e){ce=e}let V=null,K=0,_e=null;function nl(e){_e=e}let $n=1,At=0,Ce=!1;function kn(){return++$n}function _t(e){var t,n=e.f;if(n&ye)return!0;if(n&tt){var r=e.deps,o=!!(n&ne);if(null!==r){var l,i,a=!!(n&Et),s=o&&null!==R&&!Ce,u=r.length;if(a||s){var c=e,d=c.parent;for(l=0;le.wv)return!0}(!o||null!==R&&!Ce)&&de(e,X)}return!1}function il(e,t){for(var n=t;null!==n;){if(n.f&yt)try{return void n.fn(e)}catch{n.f^=yt}n=n.parent}throw pt=!1,e}function ll(e){return!(e.f&Tt||null!==e.parent&&e.parent.f&yt)}function Lt(e,t,n,r){if(pt){if(null===n&&(pt=!1),ll(t))throw e}else null!==n&&(pt=!0),il(e,t)}function Cn(e,t,n=!0){var r=e.reactions;if(null!==r)for(var o=0;o0)for(f.length=K+V.length,v=0;v0;){t++>1e3&&ol();var n=vt,r=n.length;vt=[];for(var o=0;o0;)kt=!0,Rn(),Br()}async function ul(){await Promise.resolve(),$()}function d(e){var t=!!(2&e.f);if(null===k||oe){if(t&&null===e.deps&&null===e.effects){var n=e,r=n.parent;null!==r&&!(r.f&ne)&&(n.f^=ne)}}else{null!==ce&&ce.includes(e)&&Yi();var o=k.deps;e.rv{pe(t)}}function _l(e){const t=Me(64,e,!0);return(e={})=>new Promise((n=>{e.outro?Ht(t,(()=>{pe(t),n(void 0)})):(pe(t),n(void 0))}))}function tr(e){return Me(4,e,!1)}function rr(e){return Me(8,e,!0)}function Ye(e,t=[],n=Pe){const r=t.map(n);return nr((()=>e(...r.map(d))))}function nr(e,t=0){return Me(24|t,e,!0)}function It(e,t=!0){return Me(40,e,!0,t)}function In(e){var t=e.teardown;if(null!==t){const e=Qt,n=k;Yr(!0),Ie(null);try{t.call(null)}finally{Yr(e),Ie(n)}}}function Sn(e,t=!1){var n=e.first;for(e.first=e.last=null;null!==n;){var r=n.next;64&n.f?n.parent=null:pe(n,t),n=r}}function ml(e){for(var t=e.first;null!==t;){var n=t.next;!(32&t.f)&&pe(t),t=n}}function pe(e,t=!0){var n=!1;if((t||e.f&Ii)&&null!==e.nodes_start){for(var r=e.nodes_start,o=e.nodes_end;null!==r;){var l=r===o?null:Te(r);r.remove(),r=l}n=!0}Sn(e,t&&!n),Rt(e,0),de(e,Tt);var i=e.transitions;if(null!==i)for(const e of i)e.stop();In(e);var a=e.parent;null!==a&&null!==a.first&&Tn(e),e.next=e.prev=e.teardown=e.ctx=e.deps=e.fn=e.nodes_start=e.nodes_end=null}function Tn(e){var t=e.parent,n=e.prev,r=e.next;null!==n&&(n.next=r),null!==r&&(r.prev=n),null!==t&&(t.first===e&&(t.first=r),t.last===e&&(t.last=n))}function Ht(e,t){var n=[];Nn(e,n,!0),wl(n,(()=>{pe(e),t&&t()}))}function wl(e,t){var n=e.length;if(n>0){var r=()=>--n||t();for(var o of e)o.out(r)}else t()}function Nn(e,t,n){if(!(e.f&Xe)){if(e.f^=Xe,null!==e.transitions)for(const r of e.transitions)(r.is_global||n)&&t.push(r);for(var r=e.first;null!==r;){var o=r.next;Nn(r,t,!!(!!(r.f&Jt)||!!(32&r.f))&&n),r=o}}}function Zr(e){Ln(e,!0)}function Ln(e,t){if(e.f&Xe){e.f^=Xe,!(e.f&X)&&(e.f^=X),_t(e)&&(de(e,ye),Dt(e));for(var n=e.first;null!==n;){var r=n.next;Ln(n,!!(!!(n.f&Jt)||!!(32&n.f))&&t),n=r}if(null!==e.transitions)for(const n of e.transitions)(n.is_global||t)&&n.in()}}function Dn(e){throw new Error("https://svelte.dev/e/lifecycle_outside_component")}let B=null;function Gr(e){B=e}function Pn(e,t=!1,n){B={p:B,c:null,e:null,m:!1,s:e,x:null,l:null}}function On(e){const t=B;if(null!==t){void 0!==e&&(t.x=e);const i=t.e;if(null!==i){var n=R,r=k;t.e=null;try{for(var o=0;o{Promise.resolve().then((()=>{var t;if(!e.defaultPrevented)for(const n of e.target.elements)null==(t=n.__on_r)||t.call(n)}))}),{capture:!0}))}function Mn(e){var t=k,n=R;Ie(null),Se(null);try{return e()}finally{Ie(t),Se(n)}}function yl(e,t,n,r=n){e.addEventListener(t,(()=>Mn(n)));const o=e.__on_r;e.__on_r=o?()=>{o(),r(!0)}:()=>r(!0),Fn()}const Un=new Set,Wt=new Set;function El(e,t,n,r={}){function o(e){if(r.capture||ct.call(t,e),!e.cancelBubble)return Mn((()=>null==n?void 0:n.call(this,e)))}return e.startsWith("pointer")||e.startsWith("touch")||"wheel"===e?Kt((()=>{t.addEventListener(e,o,r)})):t.addEventListener(e,o,r),o}function xl(e,t,n,r,o){var l={capture:r,passive:o},i=El(e,t,n,l);(t===document.body||t===window||t===document)&&hl((()=>{t.removeEventListener(e,i,l)}))}function $l(e){for(var t=0;ti||r});var d=k,f=R;Ie(null),Se(null);try{for(var v,h=[];null!==i;){var p=i.assignedSlot||i.parentNode||i.host||null;try{var g=i["__"+o];if(null!=g&&(!i.disabled||e.target===i))if(un(g)){var[m,...y]=g;m.apply(i,[e,...y])}else g.call(i,e)}catch(e){v?h.push(e):v=e}if(e.cancelBubble||p===n||null===p)break;i=p}if(v){for(let e of h)queueMicrotask((()=>{throw e}));throw v}}finally{e.__root=n,delete e.currentTarget,Ie(d),Se(f)}}}function ir(e){var t=document.createElement("template");return t.innerHTML=e,t.content}function Ae(e,t){var n=R;null===n.nodes_start&&(n.nodes_start=e,n.nodes_end=t)}function ve(e,t){var n,r=!!(1&t),o=!!(2&t),l=!e.startsWith("");return()=>{if(L)return Ae(P,null),P;void 0===n&&(n=ir(l?e:""+e),r||(n=we(n)));var t=o||yn?document.importNode(n,!0):n.cloneNode(!0);r?Ae(we(t),t.lastChild):Ae(t,t);return t}}function kl(e,t,n="svg"){var r,o=`<${n}>${!e.startsWith("")?e:""+e}`;return()=>{if(L)return Ae(P,null),P;if(!r){var e=ir(o);r=we(we(e))}var t=r.cloneNode(!0);return Ae(t,t),t}}function te(e,t){if(L)return R.nodes_end=P,void Qe();null!==e&&e.before(t)}function jn(e,t){return Vn(e,t)}function Cl(e,t){Bt(),t.intro=t.intro??!1;const n=t.target,r=L,o=P;try{for(var l=we(n);l&&(8!==l.nodeType||l.data!==Zt);)l=Te(l);if(!l)throw Ke;Je(!0),Re(l),Qe();const r=Vn(e,{...t,anchor:l});if(null===P||8!==P.nodeType||P.data!==an)throw Nt(),Ke;return Je(!1),r}catch(r){if(r===Ke)return!1===t.recover&&Bi(),Bt(),tl(n),Je(!1),jn(e,t);throw r}finally{Je(r),Re(o)}}const Ze=new Map;function Vn(e,{target:t,anchor:n,props:r={},events:o,context:l,intro:i=!0}){Bt();var a=new Set,s=e=>{for(var n=0;n{var i=n??t.appendChild(Xt());return It((()=>{l&&(Pn({}),B.c=l);o&&(r.$$events=o),L&&Ae(i,null),u=e(i,r)||{},L&&(R.nodes_end=P),l&&On()})),()=>{var e;for(var r of a){t.removeEventListener(r,ct);var o=Ze.get(r);0==--o?(document.removeEventListener(r,ct),Ze.delete(r)):Ze.set(r,o)}Wt.delete(s),i!==n&&(null==(e=i.parentNode)||e.removeChild(i))}}));return Yt.set(u,c),u}let Yt=new WeakMap;function Al(e,t){const n=Yt.get(e);return n?(Yt.delete(e),n(t)):Promise.resolve()}function ke(e,t,[n,r]=[0,0]){L&&0===n&&Qe();var o=e,l=null,i=null,a=Z,s=!1;const u=(e,t=!0)=>{s=!0,c(t,e)},c=(e,t)=>{if(a===(a=e))return;let s=!1;if(L&&-1!==r){if(0===n){const e=o.data;e===Zt?r=0:e===ln?r=1/0:(r=parseInt(e.substring(1)))!=r&&(r=a?1/0:-1)}!!a===r>n&&(Re(o=el()),Je(!1),s=!0,r=-1)}a?(l?Zr(l):t&&(l=It((()=>t(o)))),i&&Ht(i,(()=>{i=null}))):(i?Zr(i):t&&(i=It((()=>t(o,[n+1,r])))),l&&Ht(l,(()=>{l=null}))),s&&Je(!0)};nr((()=>{s=!1,t(u),s||c(null,null)}),n>0?Jt:0),L&&(o=P)}function Ge(e,t,n,r,o){var l,i=e,a="";nr((()=>{a!==(a=t()??"")?(void 0!==l&&(pe(l),l=void 0),""!==a&&(l=It((()=>{if(L){P.data;for(var e=Qe(),t=e;null!==e&&(8!==e.nodeType||""!==e.data);)t=e,e=Te(e);if(null===e)throw Nt(),Ke;return Ae(P,t),void(i=Re(e))}var n=ir(a+"");Ae(we(n),n.lastChild),i.before(n)})))):L&&Qe()}))}function Rl(e,t,n,r,o){var l;L&&Qe();var i=null==(l=t.$$slots)?void 0:l[n],a=!1;!0===i&&(i=t.children,a=!0),void 0===i||i(e,a?()=>r:r)}function Il(e,t){Kt((()=>{var n=e.getRootNode(),r=n.host?n:n.head??n.ownerDocument.head;if(!r.querySelector("#"+t.hash)){const e=document.createElement("style");e.id=t.hash,e.textContent=t.code,r.appendChild(e)}}))}const Kr=[..." \t\n\r\f \v\ufeff"];function Sl(e,t,n){var r=""+e;if(n)for(var o in n)if(n[o])r=r?r+" "+o:o;else if(r.length)for(var l=o.length,i=0;(i=r.indexOf(o,i))>=0;){var a=i+l;0!==i&&!Kr.includes(r[i-1])||a!==r.length&&!Kr.includes(r[a])?i=a:r=(0===i?"":r.substring(0,i))+r.substring(a+1)}return""===r?null:r}function Tl(e,t,n,r,o,l){var i=e.__className;if(L||i!==n){var a=Sl(n,r,l);(!L||a!==e.getAttribute("class"))&&(null==a?e.removeAttribute("class"):e.className=a),e.__className=n}else if(l&&o!==l)for(var s in l){var u=!!l[s];(null==o||u!==!!o[s])&&e.classList.toggle(s,u)}return l}const Nl=Symbol("is custom element"),Ll=Symbol("is html");function Xr(e){if(L){var t=!1,n=()=>{if(!t){if(t=!0,e.hasAttribute("value")){var n=e.value;le(e,"value",null),e.value=n}if(e.hasAttribute("checked")){var r=e.checked;le(e,"checked",null),e.checked=r}}};e.__on_r=n,zi(n),Fn()}}function Dl(e,t){var n=Bn(e);n.value===(n.value=t??void 0)||e.value===t&&(0!==t||"PROGRESS"!==e.nodeName)||(e.value=t??"")}function le(e,t,n,r){var o=Bn(e);L&&(o[t]=e.getAttribute(t),"src"===t||"srcset"===t||"href"===t&&"LINK"===e.nodeName)||o[t]!==(o[t]=n)&&("loading"===t&&(e[Si]=n),null==n?e.removeAttribute(t):"string"!=typeof n&&Pl(e).includes(t)?e[t]=n:e.setAttribute(t,n))}function Bn(e){return e.__attributes??(e.__attributes={[Nl]:e.nodeName.includes("-"),[Ll]:e.namespaceURI===Ai})}var Qr=new Map;function Pl(e){var t=Qr.get(e.nodeName);if(t)return t;Qr.set(e.nodeName,t=[]);for(var n,r=e,o=Element.prototype;o!==r;){for(var l in n=Li(r))n[l].set&&t.push(l);r=cn(r)}return t}function Ol(e,t,n=t){yl(e,"change",(t=>{var r=t?e.defaultChecked:e.checked;n(r)})),(L&&e.defaultChecked!==e.checked||null==et(t))&&n(e.checked),rr((()=>{var n=t();e.checked=!!n}))}function en(e,t){return e===t||(null==e?void 0:e[dt])===t}function tn(e={},t,n,r){return tr((()=>{var r,o;return rr((()=>{r=o,o=[],et((()=>{e!==n(...o)&&(t(e,...o),r&&en(n(...r),e)&&t(null,...r))}))})),()=>{Kt((()=>{o&&en(n(...o),e)&&t(null,...o)}))}})),e}function qn(e){null===B&&Dn(),qt((()=>{const t=et(e);if("function"==typeof t)return t}))}function zl(e){null===B&&Dn(),qn((()=>()=>et(e)))}let wt=!1;function Fl(e){var t=wt;try{return wt=!1,[e(),wt]}finally{wt=t}}function A(e,t,n,r){var o,l,i=!!(1&n),a=!!(8&n),s=!!(16&n),u=!1;a?[l,u]=Fl((()=>e[t])):l=e[t];var c,f=dt in e||fn in e,v=a&&((null==(o=Oe(e,t))?void 0:o.set)??(f&&t in e&&(n=>e[t]=n)))||void 0,h=r,p=!0,g=!1,m=()=>(g=!0,p&&(p=!1,h=s?et(r):r),h);if(void 0===l&&void 0!==r&&(v&&qi(),l=m(),v&&v(l)),c=()=>{var n=e[t];return void 0===n?m():(p=!0,g=!1,n)},!(4&n))return c;if(v){var y=e.$$legacy;return function(e,t){return arguments.length>0?((!t||y||u)&&v(t?c():e),e):c()}}var w=!1,b=mn(l),$=Pe((()=>{var e=c(),t=d(b);return w?(w=!1,t):b.v=e}));return i||($.equals=_n),function(e,t){if(arguments.length>0){const n=t?d($):a?ae(e):e;return $.equals(n)||(w=!0,D(b,n),g&&void 0!==h&&(h=n),et((()=>d($)))),e}return d($)}}function Ml(e){return new Ul(e)}var me,re;class Ul{constructor(e){var t;jt(this,me),jt(this,re);var n=new Map,r=(e,t)=>{var r=mn(t);return n.set(e,r),r};const o=new Proxy({...e.props||{},$$events:{}},{get:(e,t)=>d(n.get(t)??r(t,Reflect.get(e,t))),has:(e,t)=>t===fn||(d(n.get(t)??r(t,Reflect.get(e,t))),Reflect.has(e,t)),set:(e,t,o)=>(D(n.get(t)??r(t,o),o),Reflect.set(e,t,o))});Vt(this,re,(e.hydrate?Cl:jn)(e.component,{target:e.target,anchor:e.anchor,props:o,context:e.context,intro:e.intro??!1,recover:e.recover})),(!(null!=(t=null==e?void 0:e.props)&&t.$$host)||!1===e.sync)&&$(),Vt(this,me,o.$$events);for(const e of Object.keys(Y(this,re)))"$set"===e||"$destroy"===e||"$on"===e||$t(this,e,{get(){return Y(this,re)[e]},set(t){Y(this,re)[e]=t},enumerable:!0});Y(this,re).$set=e=>{Object.assign(o,e)},Y(this,re).$destroy=()=>{Al(Y(this,re))}}$set(e){Y(this,re).$set(e)}$on(e,t){Y(this,me)[e]=Y(this,me)[e]||[];const n=(...e)=>t.call(this,...e);return Y(this,me)[e].push(n),()=>{Y(this,me)[e]=Y(this,me)[e].filter((e=>e!==n))}}$destroy(){Y(this,re).$destroy()}}let Hn;function bt(e,t,n,r){var o;const l=null==(o=n[e])?void 0:o.type;if(t="Boolean"===l&&"boolean"!=typeof t?null!=t:t,!r||!n[e])return t;if("toAttribute"===r)switch(l){case"Object":case"Array":return null==t?null:JSON.stringify(t);case"Boolean":return t?"":null;case"Number":return t??null;default:return t}else switch(l){case"Object":case"Array":return t&&JSON.parse(t);case"Boolean":default:return t;case"Number":return null!=t?+t:t}}function jl(e){const t={};return e.childNodes.forEach((e=>{t[e.slot||"default"]=!0})),t}function Vl(e,t,n,r,o,l){let i=class extends Hn{constructor(){super(e,n,o),this.$$p_d=t}static get observedAttributes(){return xt(t).map((e=>(t[e].attribute||e).toLowerCase()))}};return xt(t).forEach((e=>{$t(i.prototype,e,{get(){return this.$$c&&e in this.$$c?this.$$c[e]:this.$$d[e]},set(n){var r;n=bt(e,n,t),this.$$d[e]=n;var o=this.$$c;o&&((null==(r=Oe(o,e))?void 0:r.get)?o[e]=n:o.$set({[e]:n}))}})})),r.forEach((e=>{$t(i.prototype,e,{get(){var t;return null==(t=this.$$c)?void 0:t[e]}})})),e.element=i,i}me=new WeakMap,re=new WeakMap,"function"==typeof HTMLElement&&(Hn=class extends HTMLElement{constructor(e,t,n){super(),ie(this,"$$ctor"),ie(this,"$$s"),ie(this,"$$c"),ie(this,"$$cn",!1),ie(this,"$$d",{}),ie(this,"$$r",!1),ie(this,"$$p_d",{}),ie(this,"$$l",{}),ie(this,"$$l_u",new Map),ie(this,"$$me"),this.$$ctor=e,this.$$s=t,n&&this.attachShadow({mode:"open"})}addEventListener(e,t,n){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(t),this.$$c){const n=this.$$c.$on(e,t);this.$$l_u.set(t,n)}super.addEventListener(e,t,n)}removeEventListener(e,t,n){if(super.removeEventListener(e,t,n),this.$$c){const e=this.$$l_u.get(t);e&&(e(),this.$$l_u.delete(t))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(e){return t=>{const n=document.createElement("slot");"default"!==e&&(n.name=e),te(t,n)}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const t={},n=jl(this);for(const r of this.$$s)r in n&&("default"!==r||this.$$d.children?t[r]=e(r):(this.$$d.children=e(r),t.default=!0));for(const e of this.attributes){const t=this.$$g_p(e.name);t in this.$$d||(this.$$d[t]=bt(t,e.value,this.$$p_d,"toProp"))}for(const e in this.$$p_d)!(e in this.$$d)&&void 0!==this[e]&&(this.$$d[e]=this[e],delete this[e]);this.$$c=Ml({component:this.$$ctor,target:this.shadowRoot||this,props:{...this.$$d,$$slots:t,$$host:this}}),this.$$me=gl((()=>{rr((()=>{var e;this.$$r=!0;for(const t of xt(this.$$c)){if(null==(e=this.$$p_d[t])||!e.reflect)continue;this.$$d[t]=this.$$c[t];const n=bt(t,this.$$d[t],this.$$p_d,"toAttribute");null==n?this.removeAttribute(this.$$p_d[t].attribute||t):this.setAttribute(this.$$p_d[t].attribute||t,n)}this.$$r=!1}))}));for(const e in this.$$l)for(const t of this.$$l[e]){const n=this.$$c.$on(e,t);this.$$l_u.set(t,n)}this.$$l={}}}attributeChangedCallback(e,t,n){var r;this.$$r||(e=this.$$g_p(e),this.$$d[e]=bt(e,n,this.$$p_d,"toProp"),null==(r=this.$$c)||r.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then((()=>{!this.$$cn&&this.$$c&&(this.$$c.$destroy(),this.$$me(),this.$$c=void 0)}))}$$g_p(e){return xt(this.$$p_d).find((t=>this.$$p_d[t].attribute===e||!this.$$p_d[t].attribute&&t.toLowerCase()===e))||e}});const Wn=new TextEncoder;function Bl(e){return[...new Uint8Array(e)].map((e=>e.toString(16).padStart(2,"0"))).join("")}async function ql(e,t="SHA-256",n=1e5){const r=Date.now().toString(16);e||(e=Math.round(Math.random()*n));return{algorithm:t,challenge:await Yn(r,e,t),salt:r,signature:""}}async function Yn(e,t,n){if(typeof crypto>"u"||!("subtle"in crypto)||!("digest"in crypto.subtle))throw new Error("Web Crypto is not available. Secure context is required (https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts).");return Bl(await crypto.subtle.digest(n.toUpperCase(),Wn.encode(e+t)))}function Hl(e,t,n="SHA-256",r=1e6,o=0){const l=new AbortController,i=Date.now();return{promise:(async()=>{for(let a=o;a<=r;a+=1){if(l.signal.aborted)return null;if(await Yn(t,a,n)===e)return{number:a,took:Date.now()-i}}return null})(),controller:l}}function Wl(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}function Yl(e){const t=atob(e),n=new Uint8Array(t.length);for(let e=0;e{for(let e=r;e<=n;e+=1){if(l.signal.aborted||!a||!s)return null;try{const t=await crypto.subtle.decrypt({name:o,iv:Zl(e)},a,s);if(t)return{clearText:(new TextDecoder).decode(t),took:Date.now()-i}}catch{}}return null})(),controller:l}}var y=(e=>(e.ERROR="error",e.VERIFIED="verified",e.VERIFYING="verifying",e.UNVERIFIED="unverified",e.EXPIRED="expired",e))(y||{}),Jl=kl(''),Kl=ve(' ',1),Xl=ve(''),Ql=ve(''),ea=ve('
'),ta=ve('
'),ra=ve('
'),na=ve('
'),ia=ve(''),la=ve('
'),aa=ve('
',1);const oa={hash:"svelte-ddsc3z",code:'.altcha.svelte-ddsc3z {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);position:relative;text-align:left;}.altcha.svelte-ddsc3z:focus-within {border-color:var(--altcha-color-border-focus, currentColor);}.altcha[data-floating].svelte-ddsc3z {background:var(--altcha-color-base, white);display:none;filter:drop-shadow(3px 3px 6px rgba(0, 0, 0, 0.2));left:-100%;position:fixed;top:-100%;width:var(--altcha-max-width, 260px);z-index:999999;}.altcha[data-floating=top].svelte-ddsc3z .altcha-anchor-arrow:where(.svelte-ddsc3z) {border-bottom-color:transparent;border-top-color:var(--altcha-color-border, #a0a0a0);bottom:-12px;top:auto;}.altcha[data-floating=bottom].svelte-ddsc3z:focus-within::after {border-bottom-color:var(--altcha-color-border-focus, currentColor);}.altcha[data-floating=top].svelte-ddsc3z:focus-within::after {border-top-color:var(--altcha-color-border-focus, currentColor);}.altcha[data-floating].svelte-ddsc3z:not([data-state=unverified]) {display:block;}.altcha-anchor-arrow.svelte-ddsc3z {border:6px solid transparent;border-bottom-color:var(--altcha-color-border, #a0a0a0);content:"";height:0;left:12px;position:absolute;top:-12px;width:0;}.altcha-main.svelte-ddsc3z {align-items:center;display:flex;gap:0.4rem;padding:0.7rem;}.altcha-label.svelte-ddsc3z {flex-grow:1;}.altcha-label.svelte-ddsc3z label:where(.svelte-ddsc3z) {cursor:pointer;}.altcha-logo.svelte-ddsc3z {color:currentColor;opacity:0.3;}.altcha-logo.svelte-ddsc3z:hover {opacity:1;}.altcha-error.svelte-ddsc3z {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-ddsc3z {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-ddsc3z:hover {opacity:1;}.altcha-footer.svelte-ddsc3z > :where(.svelte-ddsc3z):first-child {flex-grow:1;}.altcha-footer.svelte-ddsc3z a {color:currentColor;}.altcha-checkbox.svelte-ddsc3z {display:flex;align-items:center;height:24px;width:24px;}.altcha-checkbox.svelte-ddsc3z input:where(.svelte-ddsc3z) {width:18px;height:18px;margin:0;}.altcha-hidden.svelte-ddsc3z {display:none;}.altcha-spinner.svelte-ddsc3z {\n animation: svelte-ddsc3z-altcha-spinner 0.75s infinite linear;transform-origin:center;}\n\n@keyframes svelte-ddsc3z-altcha-spinner {\n 100% {\n transform: rotate(360deg);\n }\n}'};function sa(e,t){var n,r;Pn(t,!0),Il(e,oa);let o=A(t,"auto",7,void 0),l=A(t,"blockspam",7,void 0),i=A(t,"challengeurl",7,void 0),a=A(t,"challengejson",7,void 0),s=A(t,"customfetch",7,void 0),u=A(t,"debug",7,!1),c=A(t,"delay",7,0),f=A(t,"expire",7,void 0),v=A(t,"floating",7,void 0),h=A(t,"floatinganchor",7,void 0),p=A(t,"floatingoffset",7,void 0),g=A(t,"floatingpersist",7,!1),m=A(t,"hidefooter",7,!1),w=A(t,"hidelogo",7,!1),b=A(t,"id",7,void 0),x=A(t,"name",7,"altcha"),k=A(t,"maxnumber",7,1e6),E=A(t,"mockerror",7,!1),_=A(t,"obfuscated",7,void 0),R=A(t,"plugins",7,void 0),C=A(t,"refetchonexpire",7,!0),L=A(t,"spamfilter",7,!1),I=A(t,"strings",7,void 0),P=A(t,"test",7,!1),S=A(t,"verifyurl",7,void 0),z=A(t,"workers",23,(()=>Math.min(16,navigator.hardwareConcurrency||8))),N=A(t,"workerurl",7,void 0);const V=["SHA-256","SHA-384","SHA-512"],M="Visit Altcha.org",T="https://altcha.org/",O=(e,n)=>{t.$$host.dispatchEvent(new CustomEvent(e,{detail:n}))},B=null==(r=null==(n=document.documentElement.lang)?void 0:n.split("-"))?void 0:r[0],j=Pe((()=>{var e;return i()&&new URL(i(),location.origin).host.endsWith(".altcha.org")&&!(null==(e=i())||!e.includes("apiKey=ckey_"))})),U=Pe((()=>a()?ye(a()):void 0)),F=Pe((()=>I()?ye(I()):{})),Z=Pe((()=>{var e;return{ariaLinkLabel:M,error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...d(F)}})),Y=Pe((()=>b()||`${x()}_checkbox`));let W=We(!1),q=We(ae(y.UNVERIFIED)),K=We(void 0),X=We(null),H=null,Q=null,ee=We(null),ne=null,re=[],oe=We(null);function ie(e,t){return btoa(JSON.stringify({algorithm:e.algorithm,challenge:e.challenge,number:t.number,salt:e.salt,signature:e.signature,test:!!P()||void 0,took:t.took}))}function se(){i()&&C()&&d(q)===y.VERIFIED?Me():De(y.EXPIRED,d(Z).expired)}function ue(...e){(u()||e.some((e=>e instanceof Error)))&&console[e[0]instanceof Error?"error":"log"]("ALTCHA",`[name=${x()}]`,...e)}function ce(e){const t=e.target;v()&&t&&!d(K).contains(t)&&(d(q)===y.VERIFIED&&!1===g()||d(q)===y.VERIFIED&&"focus"===g()&&(null==Q||!Q.matches(":focus-within"))||"off"===o()&&d(q)===y.UNVERIFIED)&&Ie()}function de(){v()&&d(q)!==y.UNVERIFIED&&Se()}function fe(e){d(q)===y.UNVERIFIED?Me():v()&&"focus"===g()&&d(q)===y.VERIFIED&&Ve()}function ve(e){Q&&"onsubmit"===o()?d(q)===y.UNVERIFIED?(e.preventDefault(),e.stopPropagation(),Me().then((()=>{null==Q||Q.requestSubmit()}))):d(q)!==y.VERIFIED&&(e.preventDefault(),e.stopPropagation(),d(q)===y.VERIFYING&&pe()):Q&&v()&&"off"===o()&&d(q)===y.UNVERIFIED&&(e.preventDefault(),e.stopPropagation(),Ve())}function he(){De()}function pe(){d(q)===y.VERIFYING&&d(Z).waitAlert&&alert(d(Z).waitAlert)}function me(){v()&&Se()}function ye(e){return JSON.parse(e)}async function we(e){if(!S())throw new Error("Attribute verifyurl not set.");ue("requesting server verification from",S());const t={payload:e};if(!1!==L()){const{blockedCountries:e,classifier:n,disableRules:r,email:o,expectedLanguages:l,expectedCountries:i,fields:a,ipAddress:s,text:u,timeZone:c}="ipAddress"===L()?{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:!1,expectedCountries:void 0,expectedLanguages:void 0,fields:!1,ipAddress:void 0,text:void 0,timeZone:void 0}:"object"==typeof L()?L():{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:void 0,expectedCountries:void 0,expectedLanguages:void 0,fields:void 0,ipAddress:void 0,text:void 0,timeZone:void 0};t.blockedCountries=e,t.classifier=n,t.disableRules=r,t.email=!1===o?void 0:function(e){var t;const n=null==Q?void 0:Q.querySelector("string"==typeof e?`input[name="${e}"]`:'input[type="email"]:not([data-no-spamfilter])');return(null==(t=null==n?void 0:n.value)?void 0:t.slice(n.value.indexOf("@")))||void 0}(o),t.expectedCountries=i,t.expectedLanguages=l||(B?[B]:void 0),t.fields=!1===a?void 0:function(e){return[...(null==Q?void 0:Q.querySelectorAll(null!=e&&e.length?e.map((e=>`input[name="${e}"]`)).join(", "):'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])'))||[]].reduce(((e,t)=>{const n=t.name,r=t.value;return n&&r&&(e[n]=/\n/.test(r)?r.replace(new RegExp("(?{const l=n*o;return new Promise((n=>{t.addEventListener("message",(e=>{if(e.data)for(const e of r)e!==t&&e.postMessage({type:"abort"});n(e.data)})),t.postMessage({payload:e,max:l+o,start:l,type:"work"})}))})));for(const e of r)e.terminate();return l.find((e=>!!e))||null}(e,e.maxNumber||e.maxnumber||k())}catch(e){ue(e)}if(void 0!==(null==t?void 0:t.number)||"obfuscated"in e)return{data:e,solution:t}}if("obfuscated"in e){const t=await Gl(e.obfuscated,e.key,e.maxNumber||e.maxnumber);return{data:e,solution:await t.promise}}return{data:e,solution:await Hl(e.challenge,e.salt,e.algorithm,e.maxNumber||e.maxnumber||k()).promise}}async function _e(){if(!_())return void Ne(y.ERROR);const e=re.find((e=>"obfuscation"===e.constructor.pluginName));return e&&"clarify"in e?"clarify"in e&&"function"==typeof e.clarify?e.clarify():void 0:(Ne(y.ERROR),void ue("Plugin `obfuscation` not found. Import `altcha/plugins/obfuscation` to load it."))}function Re(e){void 0!==e.obfuscated&&_(e.obfuscated),void 0!==e.auto&&(o(e.auto),"onload"===o()&&(_()?_e():Me())),void 0!==e.blockspam&&l(!!e.blockspam),void 0!==e.customfetch&&s(e.customfetch),void 0!==e.floatinganchor&&h(e.floatinganchor),void 0!==e.delay&&c(e.delay),void 0!==e.floatingoffset&&p(e.floatingoffset),void 0!==e.floating&&$e(e.floating),void 0!==e.expire&&(be(e.expire),f(e.expire)),e.challenge&&(a("string"==typeof e.challenge?e.challenge:JSON.stringify(e.challenge)),xe(d(U))),void 0!==e.challengeurl&&i(e.challengeurl),void 0!==e.debug&&u(!!e.debug),void 0!==e.hidefooter&&m(!!e.hidefooter),void 0!==e.hidelogo&&w(!!e.hidelogo),void 0!==e.maxnumber&&k(+e.maxnumber),void 0!==e.mockerror&&E(!!e.mockerror),void 0!==e.name&&x(e.name),void 0!==e.refetchonexpire&&C(!!e.refetchonexpire),void 0!==e.spamfilter&&L("object"==typeof e.spamfilter?e.spamfilter:!!e.spamfilter),e.strings&&I("string"==typeof e.strings?e.strings:JSON.stringify(e.strings)),void 0!==e.test&&P("number"==typeof e.test?e.test:!!e.test),void 0!==e.verifyurl&&S(e.verifyurl),void 0!==e.workers&&z(+e.workers),void 0!==e.workerurl&&N(e.workerurl)}function Ae(){return{auto:o(),blockspam:l(),challengeurl:i(),debug:u(),delay:c(),expire:f(),floating:v(),floatinganchor:h(),floatingoffset:p(),hidefooter:m(),hidelogo:w(),name:x(),maxnumber:k(),mockerror:E(),obfuscated:_(),refetchonexpire:C(),spamfilter:L(),strings:d(Z),test:P(),verifyurl:S(),workers:z(),workerurl:N()}}function Ce(){return H}function Le(){return d(q)}function Ie(){d(K).style.display="none"}function Se(e=20){if(d(K))if(H||(H=(h()?document.querySelector(h()):null==Q?void 0:Q.querySelector('input[type="submit"], button[type="submit"], button:not([type="button"]):not([type="reset"])'))||Q),H){const t=parseInt(p(),10)||12,n=H.getBoundingClientRect(),r=d(K).getBoundingClientRect(),o=document.documentElement.clientHeight,l=document.documentElement.clientWidth,i="auto"===v()?n.bottom+r.height+t+e>o:"top"===v(),a=Math.max(e,Math.min(l-e-r.width,n.left+n.width/2-r.width/2));if(d(K).style.top=i?n.top-(r.height+t)+"px":`${n.bottom+t}px`,d(K).style.left=`${a}px`,d(K).setAttribute("data-floating",i?"top":"bottom"),d(X)){const e=d(X).getBoundingClientRect();d(X).style.left=n.left-a+n.width/2-e.width/2+"px"}}else ue("unable to find floating anchor element")}function De(e=y.UNVERIFIED,t=null){ne&&(clearTimeout(ne),ne=null),D(W,!1),D(oe,null),Ne(e,t)}function ze(e){H=e}function Ne(e,t=null){D(q,ae(e)),D(ee,ae(t)),O("statechange",{payload:d(oe),state:d(q)})}function Ve(){d(K).style.display="block",v()&&Se()}async function Me(){return De(y.VERIFYING),await new Promise((e=>setTimeout(e,c()||0))),async function(){var e;if(E())throw ue("mocking error"),new Error("Mocked error.");if(d(U))return ue("using provided json data"),d(U);if(P())return ue("generating test challenge",{test:P()}),ql("boolean"!=typeof P()?+P():void 0);{if(!i()&&Q){const e=Q.getAttribute("action");null!=e&&e.includes("/form/")&&i(e+"/altcha")}if(!i())throw new Error("Attribute challengeurl not set.");ue("fetching challenge from",i());let t=null,n=null;if(s())if(ue("using customfetch"),"string"==typeof s()){if(t=globalThis[s()]||null,!t)throw new Error(`Custom fetch function not found: ${s()}`)}else t=s();const r={headers:!1!==L()?{"x-altcha-spam-filter":"1"}:{}};if(t){if(n=await t(i(),r),!(n&&n instanceof Response))throw new Error("Custom fetch function did not return a response.")}else n=await fetch(i(),r);if(200!==n.status)throw new Error(`Server responded with ${n.status}.`);const o=n.headers.get("X-Altcha-Config"),l=await n.json(),a=new URLSearchParams(null==(e=l.salt.split("?"))?void 0:e[1]),u=a.get("expires")||a.get("expire");if(u){const e=new Date(1e3*+u),t=isNaN(e.getTime())?0:e.getTime()-Date.now();t>0&&be(t)}if(o)try{const e=JSON.parse(o);e&&"object"==typeof e&&(e.verifyurl&&(e.verifyurl=new URL(e.verifyurl,new URL(i())).toString()),Re(e))}catch(e){ue("unable to configure from X-Altcha-Config",e)}return l}}().then((e=>(xe(e),ue("challenge",e),Ee(e)))).then((({data:e,solution:t})=>{if(ue("solution",t),!t||e&&"challenge"in e&&!("clearText"in t)){if(void 0===(null==t?void 0:t.number)||!("challenge"in e))throw ue("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."),new Error("Unexpected result returned.");if(S())return we(ie(e,t));D(oe,ae(ie(e,t))),ue("payload",d(oe))}})).then((()=>{Ne(y.VERIFIED),ue("verified"),ul().then((()=>{O("verified",{payload:d(oe)})}))})).catch((e=>{ue(e),Ne(y.ERROR,e.message)}))}qt((()=>{!function(){for(const e of re)"function"==typeof e.onErrorChange&&e.onErrorChange(d(ee))}(d(ee))})),qt((()=>{!function(){for(const e of re)"function"==typeof e.onStateChange&&e.onStateChange(d(q));v()&&d(q)!==y.UNVERIFIED&&requestAnimationFrame((()=>{Se()})),D(W,d(q)===y.VERIFIED)}(d(q))})),zl((()=>{(function(){for(const e of re)e.destroy()})(),Q&&(Q.removeEventListener("submit",ve),Q.removeEventListener("reset",he),Q.removeEventListener("focusin",fe),Q=null),ne&&(clearTimeout(ne),ne=null),document.removeEventListener("click",ce),document.removeEventListener("scroll",de),window.removeEventListener("resize",me)})),qn((()=>{var e;ue("mounted","1.4.2"),ue("workers",z()),function(){const e=void 0!==R()?R().split(","):void 0;for(const t of globalThis.altchaPlugins)(!e||e.includes(t.pluginName))&&re.push(new t({el:d(K),clarify:_e,dispatch:O,getConfiguration:Ae,getFloatingAnchor:Ce,getState:Le,log:ue,reset:De,solve:Ee,setState:Ne,setFloatingAnchor:ze,verify:Me}))}(),ue("plugins",re.length?re.map((e=>e.constructor.pluginName)).join(", "):"none"),P()&&ue("using test mode"),f()&&be(f()),void 0!==o()&&ue("auto",o()),void 0!==v()&&$e(v()),Q=null==(e=d(K))?void 0:e.closest("form"),Q&&(Q.addEventListener("submit",ve,{capture:!0}),Q.addEventListener("reset",he),("onfocus"===o()||"focus"===g())&&Q.addEventListener("focusin",fe)),"onload"===o()&&(_()?_e():Me()),d(j)&&(m()||w())&&ue("Attributes hidefooter and hidelogo ignored because usage with free API Keys requires attribution."),requestAnimationFrame((()=>{O("load")}))}));var Te=aa(),Oe=Wr(Te);Rl(Oe,t,"default",{});var Be=ge(Oe,2),je=J(Be),Ue=J(je),Fe=e=>{te(e,Jl())};ke(Ue,(e=>{d(q)===y.VERIFYING&&e(Fe)}));var Ze=ge(Ue,2);let Je;var qe=J(Ze);Xr(qe),qe.__change=function(){[y.UNVERIFIED,y.ERROR,y.EXPIRED].includes(d(q))?!1!==L()&&!1===(null==Q?void 0:Q.reportValidity())?D(W,!1):_()?_e():Me():D(W,!0)},G(Ze);var Ke=ge(Ze,2),Xe=J(Ke),He=e=>{var t=Kl(),n=Wr(t);Ge(J(n),(()=>d(Z).verified)),G(n);var r=ge(n,2);Xr(r),Ye((()=>{le(r,"name",x()),Dl(r,d(oe))})),te(e,t)},Qe=(e,t)=>{var n=e=>{var t=Xl();Ge(J(t),(()=>d(Z).verifying)),G(t),te(e,t)},r=e=>{var t=Ql();Ge(J(t),(()=>d(Z).label)),G(t),Ye((()=>le(t,"for",d(Y)))),te(e,t)};ke(e,(e=>{d(q)===y.VERIFYING?e(n):e(r,!1)}),t)};ke(Xe,(e=>{d(q)===y.VERIFIED?e(He):e(Qe,!1)})),G(Ke);var et=ge(Ke,2),tt=e=>{var t=ea(),n=J(t);le(n,"href",T),G(t),Ye((()=>le(n,"aria-label",d(Z).ariaLinkLabel))),te(e,t)};ke(et,(e=>{(!0!==w()||d(j))&&e(tt)})),G(je);var nt=ge(je,2),rt=e=>{var t=na(),n=ge(J(t),2),r=e=>{var t=ta();Ge(J(t),(()=>d(Z).expired)),G(t),Ye((()=>le(t,"title",d(ee)))),te(e,t)},o=e=>{var t=ra();Ge(J(t),(()=>d(Z).error)),G(t),Ye((()=>le(t,"title",d(ee)))),te(e,t)};ke(n,(e=>{d(q)===y.EXPIRED?e(r):e(o,!1)})),G(t),te(e,t)};ke(nt,(e=>{(d(ee)||d(q)===y.EXPIRED)&&e(rt)}));var ot=ge(nt,2),lt=e=>{var t=ia(),n=J(t);Ge(J(n),(()=>d(Z).footer)),G(n),G(t),te(e,t)};ke(ot,(e=>{d(Z).footer&&(!0!==m()||d(j))&&e(lt)}));var it=ge(ot,2),at=e=>{var t=la();tn(t,(e=>D(X,e)),(()=>d(X))),te(e,t)};return ke(it,(e=>{v()&&e(at)})),G(Be),tn(Be,(e=>D(K,e)),(()=>d(K))),Ye((e=>{le(Be,"data-state",d(q)),le(Be,"data-floating",v()),Je=Tl(Ze,1,"altcha-checkbox svelte-ddsc3z",null,Je,e),le(qe,"id",d(Y)),qe.required="onsubmit"!==o()&&(!v()||"off"!==o())}),[()=>({"altcha-hidden":d(q)===y.VERIFYING})]),xl("invalid",qe,pe),Ol(qe,(()=>d(W)),(e=>D(W,e))),te(e,Te),On({clarify:_e,configure:Re,getConfiguration:Ae,getFloatingAnchor:Ce,getPlugin:function(e){return re.find((t=>t.constructor.pluginName===e))},getState:Le,hide:Ie,repositionFloating:Se,reset:De,setFloatingAnchor:ze,setState:Ne,show:Ve,verify:Me,get auto(){return o()},set auto(e=void 0){o(e),$()},get blockspam(){return l()},set blockspam(e=void 0){l(e),$()},get challengeurl(){return i()},set challengeurl(e=void 0){i(e),$()},get challengejson(){return a()},set challengejson(e=void 0){a(e),$()},get customfetch(){return s()},set customfetch(e=void 0){s(e),$()},get debug(){return u()},set debug(e=!1){u(e),$()},get delay(){return c()},set delay(e=0){c(e),$()},get expire(){return f()},set expire(e=void 0){f(e),$()},get floating(){return v()},set floating(e=void 0){v(e),$()},get floatinganchor(){return h()},set floatinganchor(e=void 0){h(e),$()},get floatingoffset(){return p()},set floatingoffset(e=void 0){p(e),$()},get floatingpersist(){return g()},set floatingpersist(e=!1){g(e),$()},get hidefooter(){return m()},set hidefooter(e=!1){m(e),$()},get hidelogo(){return w()},set hidelogo(e=!1){w(e),$()},get id(){return b()},set id(e=void 0){b(e),$()},get name(){return x()},set name(e="altcha"){x(e),$()},get maxnumber(){return k()},set maxnumber(e=1e6){k(e),$()},get mockerror(){return E()},set mockerror(e=!1){E(e),$()},get obfuscated(){return _()},set obfuscated(e=void 0){_(e),$()},get plugins(){return R()},set plugins(e=void 0){R(e),$()},get refetchonexpire(){return C()},set refetchonexpire(e=!0){C(e),$()},get spamfilter(){return L()},set spamfilter(e=!1){L(e),$()},get strings(){return I()},set strings(e=void 0){I(e),$()},get test(){return P()},set test(e=!1){P(e),$()},get verifyurl(){return S()},set verifyurl(e=void 0){S(e),$()},get workers(){return z()},set workers(e=Math.min(16,navigator.hardwareConcurrency||8)){z(e),$()},get workerurl(){return N()},set workerurl(e=void 0){N(e),$()}})}$l(["change"]),customElements.define("altcha-widget",Vl(sa,{blockspam:{type:"Boolean"},debug:{type:"Boolean"},delay:{type:"Number"},expire:{type:"Number"},floatingoffset:{type:"Number"},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},maxnumber:{type:"Number"},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},test:{type:"Boolean"},workers:{type:"Number"},auto:{},challengeurl:{},challengejson:{},customfetch:{},floating:{},floatinganchor:{},floatingpersist:{},id:{},name:{},obfuscated:{},plugins:{},spamfilter:{},strings:{},verifyurl:{},workerurl:{}},["default"],["clarify","configure","getConfiguration","getFloatingAnchor","getPlugin","getState","hide","repositionFloating","reset","setFloatingAnchor","setState","show","verify"],!1)),globalThis.altchaCreateWorker=e=>e?new Worker(new URL(e)):new pi,globalThis.altchaPlugins=globalThis.altchaPlugins||[];export{sa as Altcha}; +const Yn='(function(){"use strict";const d=new TextEncoder;function p(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}async function b(e,t,r){if(typeof crypto>"u"||!("subtle"in crypto)||!("digest"in crypto.subtle))throw new Error("Web Crypto is not available. Secure context is required (https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts).");return p(await crypto.subtle.digest(r.toUpperCase(),d.encode(e+t)))}function w(e,t,r="SHA-256",n=1e6,l=0){const o=new AbortController,a=Date.now();return{promise:(async()=>{for(let c=l;c<=n;c+=1){if(o.signal.aborted)return null;if(await b(t,c,r)===e)return{number:c,took:Date.now()-a}}return null})(),controller:o}}function h(e){const t=atob(e),r=new Uint8Array(t.length);for(let n=0;n{for(let i=n;i<=r;i+=1){if(o.signal.aborted||!c||!u)return null;try{const f=await crypto.subtle.decrypt({name:l,iv:g(i)},c,u);if(f)return{clearText:new TextDecoder().decode(f),took:Date.now()-a}}catch{}}return null};let c=null,u=null;try{u=h(e);const i=await crypto.subtle.digest("SHA-256",d.encode(t));c=await crypto.subtle.importKey("raw",i,l,!1,["decrypt"])}catch{return{promise:Promise.reject(),controller:o}}return{promise:s(),controller:o}}let y;onmessage=async e=>{const{type:t,payload:r,start:n,max:l}=e.data;let o=null;if(t==="abort")y?.abort(),y=void 0;else if(t==="work"){if("obfuscated"in r){const{key:a,obfuscated:s}=r||{};o=await m(s,a,l,n)}else{const{algorithm:a,challenge:s,salt:c}=r||{};o=w(s,c,a,l,n)}y=o.controller,o.promise.then(a=>{self.postMessage(a&&{...a,worker:!0})})}}})();\n',Dn=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Yn],{type:"text/javascript;charset=utf-8"});function Ni(e){let t;try{if(t=Dn&&(self.URL||self.webkitURL).createObjectURL(Dn),!t)throw"";const n=new Worker(t,{name:e?.name});return n.addEventListener("error",(()=>{(self.URL||self.webkitURL).revokeObjectURL(t)})),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Yn),{name:e?.name})}}const Li="5";typeof window<"u"&&((window.__svelte??={}).v??=new Set).add(Li);const Pi=1,Oi=4,Fi=8,Mi=16,Vi=1,Ui=2,Mr="[",Zn="[!",zn="]",bt={},ae=Symbol(),ji="http://www.w3.org/1999/xhtml",Nn=!1;function Jn(e){throw new Error("https://svelte.dev/e/lifecycle_outside_component")}var Kn=Array.isArray,qi=Array.prototype.indexOf,Bi=Array.from,or=Object.keys,Mt=Object.defineProperty,rt=Object.getOwnPropertyDescriptor,Hi=Object.getOwnPropertyDescriptors,Gi=Object.prototype,Wi=Array.prototype,Xn=Object.getPrototypeOf,Ln=Object.isExtensible;const yt=()=>{};function Qn(e){for(var t=0;t{var t=$;Re(a);var n=e();return Re(t),n};return r&&n.set("length",N(e.length)),new Proxy(e,{defineProperty(e,t,r){(!("value"in r)||!1===r.configurable||!1===r.enumerable||!1===r.writable)&&na();var o=n.get(t);return void 0===o?(o=l((()=>N(r.value))),n.set(t,o)):b(o,l((()=>Me(r.value)))),!0},deleteProperty(e,t){var i=n.get(t);if(void 0===i)t in e&&(n.set(t,l((()=>N(ae)))),Ir(o));else{if(r&&"string"==typeof t){var a=n.get("length"),s=Number(t);Number.isInteger(s)&&sN(Me(s?t[r]:ae)))),n.set(r,a)),void 0!==a){var c=i(a);return c===ae?void 0:c}return Reflect.get(t,r,o)},getOwnPropertyDescriptor(e,t){var r=Reflect.getOwnPropertyDescriptor(e,t);if(r&&"value"in r){var o=n.get(t);o&&(r.value=i(o))}else if(void 0===r){var a=n.get(t),l=a?.v;if(void 0!==a&&l!==ae)return{enumerable:!0,configurable:!0,value:l,writable:!0}}return r},has(e,t){if(t===Ot)return!0;var r=n.get(t),o=void 0!==r&&r.v!==ae||Reflect.has(e,t);if((void 0!==r||null!==S&&(!o||rt(e,t)?.writable))&&(void 0===r&&(r=l((()=>N(o?Me(e[t]):ae))),n.set(t,r)),i(r)===ae))return!1;return o},set(e,t,i,a){var s=n.get(t),c=t in e;if(r&&"length"===t)for(var u=i;uN(ae))),n.set(u+"",f))}void 0===s?(!c||rt(e,t)?.writable)&&(b(s=l((()=>N(void 0))),l((()=>Me(i)))),n.set(t,s)):(c=s.v!==ae,b(s,l((()=>Me(i)))));var d=Reflect.getOwnPropertyDescriptor(e,t);if(d?.set&&d.set.call(a,i),!c){if(r&&"string"==typeof t){var h=n.get("length"),v=Number(t);Number.isInteger(v)&&v>=h.v&&b(h,v+1)}Ir(o)}return!0},ownKeys(e){i(o);var t=Reflect.ownKeys(e).filter((e=>{var t=n.get(e);return void 0===t||t.v!==ae}));for(var[r,a]of n)a.v!==ae&&!(r in e)&&t.push(r);return t},setPrototypeOf(){oa()}})}function Ir(e,t=1){b(e,e.v+t)}var Pn,no,oo,io;function Tr(){if(void 0===Pn){Pn=window,no=/Firefox/.test(navigator.userAgent);var e=Element.prototype,t=Node.prototype,n=Text.prototype;oo=rt(t,"firstChild").get,io=rt(t,"nextSibling").get,Ln(e)&&(e.__click=void 0,e.__className=void 0,e.__attributes=null,e.__style=void 0,e.__e=void 0),Ln(n)&&(n.__t=void 0)}}function vr(e=""){return document.createTextNode(e)}function ve(e){return oo.call(e)}function Be(e){return io.call(e)}function z(e,t){if(!O)return ve(e);var n=ve(P);return null===n&&(n=P.appendChild(vr())),Ue(n),n}function Nt(e,t){if(!O){var n=ve(e);return n instanceof Comment&&""===n.data?Be(n):n}return P}function J(e,t=1,n=!1){let r=O?P:e;for(var o;t--;)o=r,r=Be(r);if(!O)return r;var i=r?.nodeType;if(n&&3!==i){var a=vr();return null===r?o?.after(a):r.before(a),Ue(a),a}return Ue(r),r}function sa(e){e.textContent=""}function ao(e){return e===this.v}function lo(e,t){return e!=e?t==t:e!==t||null!==e&&"object"==typeof e||"function"==typeof e}function jr(e){return!lo(e,this.v)}function gr(e){var t=2050,n=null!==$&&2&$.f?$:null;return null===S||null!==n&&n.f&fe?t|=fe:S.f|=to,{ctx:ne,deps:null,effects:null,equals:ao,f:t,fn:e,reactions:null,rv:0,v:null,wv:0,parent:n??S}}function Lt(e){const t=gr(e);return wo(t),t}function ua(e){const t=gr(e);return t.equals=jr,t}function so(e){var t=e.effects;if(null!==t){e.effects=null;for(var n=0;n{je(t)}}function va(e){const t=lt(64,e,!0);return(e={})=>new Promise((n=>{e.outro?Lr(t,(()=>{je(t),n(void 0)})):(je(t),n(void 0))}))}function Br(e){return lt(4,e,!1)}function Hr(e){return lt(8,e,!0)}function Ce(e,t=[],n=gr){const r=t.map(n);return fo((()=>e(...r.map(i))))}function fo(e,t=0){return lt(24|t,e,!0)}function Nr(e,t=!0){return lt(40,e,!0,t)}function ho(e){var t=e.teardown;if(null!==t){const e=qt,n=$;Fn(!0),Re(null);try{t.call(null)}finally{Fn(e),Re(n)}}}function vo(e,t=!1){var n=e.first;for(e.first=e.last=null;null!==n;){var r=n.next;64&n.f?n.parent=null:je(n,t),n=r}}function ga(e){for(var t=e.first;null!==t;){var n=t.next;!(32&t.f)&&je(t),t=n}}function je(e,t=!0){var n=!1;(t||!!(e.f&zi))&&null!==e.nodes_start&&(go(e.nodes_start,e.nodes_end),n=!0),vo(e,t&&!n),cr(e,0),_e(e,dr);var r=e.transitions;if(null!==r)for(const e of r)e.stop();ho(e);var o=e.parent;null!==o&&null!==o.first&&po(e),e.next=e.prev=e.teardown=e.ctx=e.deps=e.fn=e.nodes_start=e.nodes_end=null}function go(e,t){for(;null!==e;){var n=e===t?null:Be(e);e.remove(),e=n}}function po(e){var t=e.parent,n=e.prev,r=e.next;null!==n&&(n.next=r),null!==r&&(r.prev=n),null!==t&&(t.first===e&&(t.first=r),t.last===e&&(t.last=n))}function Lr(e,t){var n=[];mo(e,n,!0),pa(n,(()=>{je(e),t&&t()}))}function pa(e,t){var n=e.length;if(n>0){var r=()=>--n||t();for(var o of e)o.out(r)}else t()}function mo(e,t,n){if(!(e.f&wt)){if(e.f^=wt,null!==e.transitions)for(const r of e.transitions)(r.is_global||n)&&t.push(r);for(var r=e.first;null!==r;){var o=r.next;mo(r,t,!!(!!(r.f&Ur)||!!(32&r.f))&&n),r=o}}}function On(e){_o(e,!0)}function _o(e,t){if(e.f&wt){e.f^=wt,!(e.f&le)&&(e.f^=le),Bt(e)&&(_e(e,Ie),mr(e));for(var n=e.first;null!==n;){var r=n.next;_o(n,!!(!!(n.f&Ur)||!!(32&n.f))&&t),n=r}if(null!==e.transitions)for(const n of e.transitions)(n.is_global||t)&&n.in()}}const ma=typeof requestIdleCallback>"u"?e=>setTimeout(e,1):requestIdleCallback;let Vt=[],Ut=[];function bo(){var e=Vt;Vt=[],Qn(e)}function yo(){var e=Ut;Ut=[],Qn(e)}function Gr(e){0===Vt.length&&queueMicrotask(bo),Vt.push(e)}function _a(e){0===Ut.length&&ma(yo),Ut.push(e)}function ba(){Vt.length>0&&bo(),Ut.length>0&&yo()}let tr=!1,lr=!1,sr=null,nt=!1,qt=!1;function Fn(e){qt=e}let Ft=[],$=null,ke=!1;function Re(e){$=e}let S=null;function qe(e){S=e}let Te=null;function wo(e){null!==$&&$.f&Sr&&(null===Te?Te=[e]:Te.push(e))}let re=null,ce=0,he=null;function ya(e){he=e}let Eo=1,ur=0,Ve=!1;function xo(){return++Eo}function Bt(e){var t=e.f;if(t&Ie)return!0;if(t&at){var n=e.deps,r=!!(t&fe);if(null!==n){var o,i,a=!!(t&ar),l=r&&null!==S&&!Ve,s=n.length;if(a||l){var c=e,u=c.parent;for(o=0;oe.wv)return!0}(!r||null!==S&&!Ve)&&_e(e,le)}return!1}function wa(e,t){for(var n=t;null!==n;){if(n.f&ir)try{return void n.fn(e)}catch{n.f^=ir}n=n.parent}throw tr=!1,e}function Mn(e){return!(e.f&dr||null!==e.parent&&e.parent.f&ir)}function pr(e,t,n,r){if(tr){if(null===n&&(tr=!1),Mn(t))throw e}else if(null!==n&&(tr=!0),wa(e,t),Mn(t))throw e}function Co(e,t,n=!0){var r=e.reactions;if(null!==r)for(var o=0;o0)for(f.length=ce+re.length,d=0;d0;){t++>1e3&&xa();var n=Ft,r=n.length;Ft=[];for(var o=0;o{r.d=!0}))}function So(e){const t=ne;if(null!==t){void 0!==e&&(t.x=e);const a=t.e;if(null!==a){var n=S,r=$;t.e=null;try{for(var o=0;o{document.activeElement===t&&e.focus()}))}}let Un=!1;function Do(){Un||(Un=!0,document.addEventListener("reset",(e=>{Promise.resolve().then((()=>{if(!e.defaultPrevented)for(const t of e.target.elements)t.__on_r?.()}))}),{capture:!0}))}function No(e){var t=$,n=S;Re(null),qe(null);try{return e()}finally{Re(t),qe(n)}}function Ta(e,t,n,r=n){e.addEventListener(t,(()=>No(n)));const o=e.__on_r;e.__on_r=o?()=>{o(),r(!0)}:()=>r(!0),Do()}const Lo=new Set,Pr=new Set;function Da(e,t,n,r={}){function o(e){if(r.capture||Pt.call(t,e),!e.cancelBubble)return No((()=>n?.call(this,e)))}return e.startsWith("pointer")||e.startsWith("touch")||"wheel"===e?Gr((()=>{t.addEventListener(e,o,r)})):t.addEventListener(e,o,r),o}function Fe(e,t,n,r,o){var i={capture:r,passive:o},a=Da(e,t,n,i);(t===document.body||t===window||t===document)&&qr((()=>{t.removeEventListener(e,a,i)}))}function Na(e){for(var t=0;ti||n});var u=$,f=S;Re(null),qe(null);try{for(var d,h=[];null!==i;){var v=i.assignedSlot||i.parentNode||i.host||null;try{var p=i["__"+r];if(null!=p&&(!i.disabled||e.target===i))if(Kn(p)){var[g,...b]=p;g.apply(i,[e,...b])}else p.call(i,e)}catch(e){d?h.push(e):d=e}if(e.cancelBubble||v===t||null===v)break;i=v}if(d){for(let e of h)queueMicrotask((()=>{throw e}));throw d}}finally{e.__root=t,delete e.currentTarget,Re(u),qe(f)}}}function Zr(e){var t=document.createElement("template");return t.innerHTML=e,t.content}function Ae(e,t){var n=S;null===n.nodes_start&&(n.nodes_start=e,n.nodes_end=t)}function be(e,t){var n,r=!!(1&t),o=!!(2&t),i=!e.startsWith("");return()=>{if(O)return Ae(P,null),P;void 0===n&&(n=Zr(i?e:""+e),r||(n=ve(n)));var t=o||no?document.importNode(n,!0):n.cloneNode(!0);r?Ae(ve(t),t.lastChild):Ae(t,t);return t}}function _r(e,t,n="svg"){var r,o=`<${n}>${!e.startsWith("")?e:""+e}`;return()=>{if(O)return Ae(P,null),P;if(!r){var e=Zr(o);r=ve(ve(e))}var t=r.cloneNode(!0);return Ae(t,t),t}}function Xt(){if(O)return Ae(P,null),P;var e=document.createDocumentFragment(),t=document.createComment(""),n=vr();return e.append(t,n),Ae(t,n),e}function B(e,t){if(O)return S.nodes_end=P,void Et();null!==e&&e.before(t)}function La(e,t){var n=null==t?"":"object"==typeof t?t+"":t;n!==(e.__t??=e.nodeValue)&&(e.__t=n,e.nodeValue=n+"")}function Po(e,t){return Oo(e,t)}function Pa(e,t){Tr(),t.intro=t.intro??!1;const n=t.target,r=O,o=P;try{for(var i=ve(n);i&&(8!==i.nodeType||i.data!==Mr);)i=Be(i);if(!i)throw bt;_t(!0),Ue(i),Et();const r=Oo(e,{...t,anchor:i});if(null===P||8!==P.nodeType||P.data!==zn)throw hr(),bt;return _t(!1),r}catch(r){if(r===bt)return!1===t.recover&&ta(),Tr(),sa(n),_t(!1),Po(e,t);throw r}finally{_t(r),Ue(o)}}const pt=new Map;function Oo(e,{target:t,anchor:n,props:r={},events:o,context:i,intro:a=!0}){Tr();var l=new Set,s=e=>{for(var n=0;n{var a=n??t.appendChild(vr());return Nr((()=>{i&&($o({}),ne.c=i);o&&(r.$$events=o),O&&Ae(a,null),c=e(a,r)||{},O&&(S.nodes_end=P),i&&So()})),()=>{for(var e of l){t.removeEventListener(e,Pt);var r=pt.get(e);0==--r?(document.removeEventListener(e,Pt),pt.delete(e)):pt.set(e,r)}Pr.delete(s),a!==n&&a.parentNode?.removeChild(a)}}));return Or.set(c,u),c}let Or=new WeakMap;function Oa(e,t){const n=Or.get(e);return n?(Or.delete(e),n(t)):Promise.resolve()}function K(e,t,[n,r]=[0,0]){O&&0===n&&Et();var o=e,i=null,a=null,l=ae,s=!1;const c=(e,t=!0)=>{s=!0,u(t,e)},u=(e,t)=>{if(l===(l=e))return;let s=!1;if(O&&-1!==r){if(0===n){const e=o.data;e===Mr?r=0:e===Zn?r=1/0:(r=parseInt(e.substring(1)))!=r&&(r=l?1/0:-1)}!!l===r>n&&(Ue(o=aa()),_t(!1),s=!0,r=-1)}l?(i?On(i):t&&(i=Nr((()=>t(o)))),a&&Lr(a,(()=>{a=null}))):(a?On(a):t&&(a=Nr((()=>t(o,[n+1,r])))),i&&Lr(i,(()=>{i=null}))),s&&_t(!0)};fo((()=>{s=!1,t(c),s||u(null,null)}),n>0?Ur:0),O&&(o=P)}function tt(e,t,n=!1,r=!1,o=!1){var i=e,a="";Ce((()=>{var e=S;if(a!==(a=t()??"")){if(null!==e.nodes_start&&(go(e.nodes_start,e.nodes_end),e.nodes_start=e.nodes_end=null),""!==a){if(O){P.data;for(var o=Et(),l=o;null!==o&&(8!==o.nodeType||""!==o.data);)l=o,o=Be(o);if(null===o)throw hr(),bt;return Ae(P,l),void(i=Ue(o))}var s=a+"";n?s=`${s}`:r&&(s=`${s}`);var c=Zr(s);if((n||r)&&(c=ve(c)),Ae(ve(c),c.lastChild),n||r)for(;ve(c);)i.before(ve(c));else i.before(c)}}else O&&Et()}))}function Fa(e,t,n,r,o){O&&Et();var i=t.$$slots?.[n],a=!1;!0===i&&(i=t.children,a=!0),void 0===i||i(e,a?()=>r:r)}const jn=[..." \t\n\r\f \v\ufeff"];function Ma(e,t,n){var r=""+e;if(n)for(var o in n)if(n[o])r=r?r+" "+o:o;else if(r.length)for(var i=o.length,a=0;(a=r.indexOf(o,a))>=0;){var l=a+i;0!==a&&!jn.includes(r[a-1])||l!==r.length&&!jn.includes(r[l])?a=l:r=(0===a?"":r.substring(0,a))+r.substring(l+1)}return""===r?null:r}function Va(e,t,n,r,o,i){var a=e.__className;if(O||a!==n||void 0===a){var l=Ma(n,r,i);(!O||l!==e.getAttribute("class"))&&(null==l?e.removeAttribute("class"):e.className=l),e.__className=n}else if(i&&o!==i)for(var s in i){var c=!!i[s];(null==o||c!==!!o[s])&&e.classList.toggle(s,c)}return i}const Ua=Symbol("is custom element"),ja=Symbol("is html");function qn(e){if(O){var t=!1,n=()=>{if(!t){if(t=!0,e.hasAttribute("value")){var n=e.value;R(e,"value",null),e.value=n}if(e.hasAttribute("checked")){var r=e.checked;R(e,"checked",null),e.checked=r}}};e.__on_r=n,_a(n),Do()}}function qa(e,t){var n=Fo(e);n.value===(n.value=t??void 0)||e.value===t&&(0!==t||"PROGRESS"!==e.nodeName)||(e.value=t??"")}function R(e,t,n,r){var o=Fo(e);O&&(o[t]=e.getAttribute(t),"src"===t||"srcset"===t||"href"===t&&"LINK"===e.nodeName)||o[t]!==(o[t]=n)&&("loading"===t&&(e[Ji]=n),null==n?e.removeAttribute(t):"string"!=typeof n&&Ba(e).includes(t)?e[t]=n:e.setAttribute(t,n))}function Fo(e){return e.__attributes??={[Ua]:e.nodeName.includes("-"),[ja]:e.namespaceURI===ji}}var Bn=new Map;function Ba(e){var t=Bn.get(e.nodeName);if(t)return t;Bn.set(e.nodeName,t=[]);for(var n,r=e,o=Element.prototype;o!==r;){for(var i in n=Hi(r))n[i].set&&t.push(i);r=Xn(r)}return t}function Ha(e,t,n=t){Ta(e,"change",(t=>{var r=t?e.defaultChecked:e.checked;n(r)})),(O&&e.defaultChecked!==e.checked||null==ot(t))&&n(e.checked),Hr((()=>{var n=t();e.checked=!!n}))}function Hn(e,t){return e===t||e?.[Ot]===t}function Qt(e={},t,n,r){return Br((()=>{var r,o;return Hr((()=>{r=o,o=[],ot((()=>{e!==n(...o)&&(t(e,...o),r&&Hn(n(...r),e)&&t(null,...r))}))})),()=>{Gr((()=>{o&&Hn(n(...o),e)&&t(null,...o)}))}})),e}function Mo(e){null===ne&&Jn(),Dr((()=>{const t=ot(e);if("function"==typeof t)return t}))}function Ga(e){null===ne&&Jn(),Mo((()=>()=>ot(e)))}function Vo(e,t,n){if(null==e)return t(void 0),yt;const r=ot((()=>e.subscribe(t,n)));return r.unsubscribe?()=>r.unsubscribe():r}const mt=[];function Wa(e,t=yt){let n=null;const r=new Set;function o(t){if(lo(e,t)&&(e=t,n)){const t=!mt.length;for(const t of r)t[1](),mt.push(t,e);if(t){for(let e=0;e{r.delete(s),0===r.size&&n&&(n(),n=null)}}}}function rr(e){let t;return Vo(e,(e=>t=e))(),t}let Uo,er=!1,Fr=Symbol();function Ya(e,t,n){const r=n[t]??={store:null,source:Yr(void 0),unsubscribe:yt};if(r.store!==e&&!(Fr in n))if(r.unsubscribe(),r.store=e??null,null==e)r.source.v=void 0,r.unsubscribe=yt;else{var o=!0;r.unsubscribe=Vo(e,(e=>{o?r.source.v=e:b(r.source,e)})),o=!1}return e&&Fr in n?rr(e):i(r.source)}function Za(){const e={};return[e,function(){qr((()=>{for(var t in e)e[t].unsubscribe();Mt(e,Fr,{enumerable:!1,value:!0})}))}]}function za(e){var t=er;try{return er=!1,[e(),er]}finally{er=t}}function Gn(e){return e.ctx?.d??!1}function x(e,t,n,r){var o,a=!!(1&n),l=!!(8&n),s=!!(16&n),c=!1;l?[o,c]=za((()=>e[t])):o=e[t];var u,f=Ot in e||ro in e,d=l&&(rt(e,t)?.set??(f&&t in e&&(n=>e[t]=n)))||void 0,h=r,v=!0,p=!1,g=()=>(p=!0,v&&(v=!1,h=s?ot(r):r),h);if(void 0===o&&void 0!==r&&(d&&ra(),o=g(),d&&d(o)),u=()=>{var n=e[t];return void 0===n?g():(v=!0,p=!1,n)},!(4&n))return u;if(d){var m=e.$$legacy;return function(e,t){return arguments.length>0?((!t||m||c)&&d(t?u():e),e):u()}}var y=!1,w=Yr(o),x=gr((()=>{var e=u(),t=i(w);return y?(y=!1,t):w.v=e}));return l&&i(x),a||(x.equals=jr),function(e,t){if(arguments.length>0){const n=t?i(x):l?Me(e):e;if(!x.equals(n)){if(y=!0,b(w,n),p&&void 0!==h&&(h=n),Gn(x))return e;ot((()=>i(x)))}return e}return Gn(x)?x.v:i(x)}}function Ja(e){return new Ka(e)}class Ka{#e;#t;constructor(e){var t=new Map,n=(e,n)=>{var r=Yr(n);return t.set(e,r),r};const r=new Proxy({...e.props||{},$$events:{}},{get:(e,r)=>i(t.get(r)??n(r,Reflect.get(e,r))),has:(e,r)=>r===ro||(i(t.get(r)??n(r,Reflect.get(e,r))),Reflect.has(e,r)),set:(e,r,o)=>(b(t.get(r)??n(r,o),o),Reflect.set(e,r,o))});this.#t=(e.hydrate?Pa:Po)(e.component,{target:e.target,anchor:e.anchor,props:r,context:e.context,intro:e.intro??!1,recover:e.recover}),(!e?.props?.$$host||!1===e.sync)&&E(),this.#e=r.$$events;for(const e of Object.keys(this.#t))"$set"===e||"$destroy"===e||"$on"===e||Mt(this,e,{get(){return this.#t[e]},set(t){this.#t[e]=t},enumerable:!0});this.#t.$set=e=>{Object.assign(r,e)},this.#t.$destroy=()=>{Oa(this.#t)}}$set(e){this.#t.$set(e)}$on(e,t){this.#e[e]=this.#e[e]||[];const n=(...e)=>t.call(this,...e);return this.#e[e].push(n),()=>{this.#e[e]=this.#e[e].filter((e=>e!==n))}}$destroy(){this.#t.$destroy()}}function nr(e,t,n,r){const o=n[e]?.type;if(t="Boolean"===o&&"boolean"!=typeof t?null!=t:t,!r||!n[e])return t;if("toAttribute"===r)switch(o){case"Object":case"Array":return null==t?null:JSON.stringify(t);case"Boolean":return t?"":null;case"Number":return t??null;default:return t}else switch(o){case"Object":case"Array":return t&&JSON.parse(t);case"Boolean":default:return t;case"Number":return null!=t?+t:t}}function Xa(e){const t={};return e.childNodes.forEach((e=>{t[e.slot||"default"]=!0})),t}function Qa(e,t,n,r,o,i){let a=class extends Uo{constructor(){super(e,n,o),this.$$p_d=t}static get observedAttributes(){return or(t).map((e=>(t[e].attribute||e).toLowerCase()))}};return or(t).forEach((e=>{Mt(a.prototype,e,{get(){return this.$$c&&e in this.$$c?this.$$c[e]:this.$$d[e]},set(n){n=nr(e,n,t),this.$$d[e]=n;var r=this.$$c;if(r){var o=rt(r,e)?.get;o?r[e]=n:r.$set({[e]:n})}}})})),r.forEach((e=>{Mt(a.prototype,e,{get(){return this.$$c?.[e]}})})),e.element=a,a}"function"==typeof HTMLElement&&(Uo=class extends HTMLElement{$$ctor;$$s;$$c;$$cn=!1;$$d={};$$r=!1;$$p_d={};$$l={};$$l_u=new Map;$$me;constructor(e,t,n){super(),this.$$ctor=e,this.$$s=t,n&&this.attachShadow({mode:"open"})}addEventListener(e,t,n){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(t),this.$$c){const n=this.$$c.$on(e,t);this.$$l_u.set(t,n)}super.addEventListener(e,t,n)}removeEventListener(e,t,n){if(super.removeEventListener(e,t,n),this.$$c){const e=this.$$l_u.get(t);e&&(e(),this.$$l_u.delete(t))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(e){return t=>{const n=document.createElement("slot");"default"!==e&&(n.name=e),B(t,n)}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const t={},n=Xa(this);for(const r of this.$$s)r in n&&("default"!==r||this.$$d.children?t[r]=e(r):(this.$$d.children=e(r),t.default=!0));for(const e of this.attributes){const t=this.$$g_p(e.name);t in this.$$d||(this.$$d[t]=nr(t,e.value,this.$$p_d,"toProp"))}for(const e in this.$$p_d)!(e in this.$$d)&&void 0!==this[e]&&(this.$$d[e]=this[e],delete this[e]);this.$$c=Ja({component:this.$$ctor,target:this.shadowRoot||this,props:{...this.$$d,$$slots:t,$$host:this}}),this.$$me=ha((()=>{Hr((()=>{this.$$r=!0;for(const e of or(this.$$c)){if(!this.$$p_d[e]?.reflect)continue;this.$$d[e]=this.$$c[e];const t=nr(e,this.$$d[e],this.$$p_d,"toAttribute");null==t?this.removeAttribute(this.$$p_d[e].attribute||e):this.setAttribute(this.$$p_d[e].attribute||e,t)}this.$$r=!1}))}));for(const e in this.$$l)for(const t of this.$$l[e]){const n=this.$$c.$on(e,t);this.$$l_u.set(t,n)}this.$$l={}}}attributeChangedCallback(e,t,n){this.$$r||(e=this.$$g_p(e),this.$$d[e]=nr(e,n,this.$$p_d,"toProp"),this.$$c?.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then((()=>{!this.$$cn&&this.$$c&&(this.$$c.$destroy(),this.$$me(),this.$$c=void 0)}))}$$g_p(e){return or(this.$$p_d).find((t=>this.$$p_d[t].attribute===e||!this.$$p_d[t].attribute&&t.toLowerCase()===e))||e}});const jo=new TextEncoder;function el(e){return[...new Uint8Array(e)].map((e=>e.toString(16).padStart(2,"0"))).join("")}async function tl(e,t="SHA-256",n=1e5){const r=Date.now().toString(16);e||(e=Math.round(Math.random()*n));return{algorithm:t,challenge:await qo(r,e,t),salt:r,signature:""}}async function qo(e,t,n){if(typeof crypto>"u"||!("subtle"in crypto)||!("digest"in crypto.subtle))throw new Error("Web Crypto is not available. Secure context is required (https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts).");return el(await crypto.subtle.digest(n.toUpperCase(),jo.encode(e+t)))}function rl(e,t,n="SHA-256",r=1e6,o=0){const i=new AbortController,a=Date.now();return{promise:(async()=>{for(let l=o;l<=r;l+=1){if(i.signal.aborted)return null;if(await qo(t,l,n)===e)return{number:l,took:Date.now()-a}}return null})(),controller:i}}function Wn(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}function nl(e){const t=atob(e),n=new Uint8Array(t.length);for(let e=0;e{for(let e=r;e<=n;e+=1){if(i.signal.aborted||!l||!s)return null;try{const t=await crypto.subtle.decrypt({name:o,iv:ol(e)},l,s);if(t)return{clearText:(new TextDecoder).decode(t),took:Date.now()-a}}catch{}}return null})(),controller:i}}var y=(e=>(e.CODE="code",e.ERROR="error",e.VERIFIED="verified",e.VERIFYING="verifying",e.UNVERIFIED="unverified",e.EXPIRED="expired",e))(y||{}),Q=(e=>(e.ERROR="error",e.LOADING="loading",e.PLAYING="playing",e.PAUSED="paused",e.READY="ready",e))(Q||{});globalThis.altchaPlugins=globalThis.altchaPlugins||[],globalThis.altchaI18n=globalThis.altchaI18n||{get:e=>rr(globalThis.altchaI18n.store)[e],set:(e,t)=>{Object.assign(rr(globalThis.altchaI18n.store),{[e]:t}),globalThis.altchaI18n.store.set(rr(globalThis.altchaI18n.store))},store:Wa({})};const al={ariaLinkLabel:"Visit Altcha.org",enterCode:"Enter code",enterCodeAria:"Enter code you hear. Press Space to play audio.",error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:'Protected by ALTCHA',getAudioChallenge:"Get an audio challenge",label:"I'm not a robot",loading:"Loading...",reload:"Reload",verify:"Verify",verificationRequired:"Verification required!",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait."};globalThis.altchaI18n.set("en",al);const $r=(e,t)=>{let n=ua((()=>Yi(t?.(),24)));var r=cl();Ce((()=>{R(r,"width",i(n)),R(r,"height",i(n))})),B(e,r)};function ll(e,t){"Space"===e.code&&(e.preventDefault(),e.stopImmediatePropagation(),t())}function sl(e,t){e.preventDefault(),t()}function ul(e,t,n,r,o,a,l,s){[y.UNVERIFIED,y.ERROR,y.EXPIRED,y.CODE].includes(i(t))?!1!==n()&&!1===i(r)?.reportValidity()?b(o,!1):a()?l():s():b(o,!0)}var cl=_r(''),fl=be(''),dl=be('
'),hl=_r(''),vl=_r(''),gl=_r(''),pl=be(''),ml=be(""),_l=be(''),bl=be("
"),yl=be("
"),wl=be('
'),El=be(''),xl=be('
'),Cl=be('
',1);function kl(e,t){$o(t,!0);const[n,r]=Za(),o=()=>Ya(X,"$altchaI18nStore",n);let a=x(t,"auto",7,void 0),l=x(t,"blockspam",7,void 0),s=x(t,"challengeurl",7,void 0),c=x(t,"challengejson",7,void 0),u=x(t,"credentials",7,void 0),f=x(t,"customfetch",7,void 0),d=x(t,"debug",7,!1),h=x(t,"delay",7,0),v=x(t,"disableautofocus",7,!1),p=x(t,"refetchonexpire",7,!0),g=x(t,"disablerefetchonexpire",23,(()=>!p())),m=x(t,"expire",7,void 0),w=x(t,"floating",7,void 0),$=x(t,"floatinganchor",7,void 0),C=x(t,"floatingoffset",7,void 0),_=x(t,"floatingpersist",7,!1),k=x(t,"hidefooter",7,!1),A=x(t,"hidelogo",7,!1),I=x(t,"id",7,void 0),S=x(t,"language",7,void 0),L=x(t,"name",7,"altcha"),O=x(t,"maxnumber",7,1e6),P=x(t,"mockerror",7,!1),D=x(t,"obfuscated",7,void 0),V=x(t,"overlay",7,void 0),M=x(t,"overlaycontent",7,void 0),j=x(t,"plugins",7,void 0),T=x(t,"sentinel",7,void 0),F=x(t,"spamfilter",7,!1),U=x(t,"strings",7,void 0),q=x(t,"test",7,!1),H=x(t,"verifyurl",7,void 0),G=x(t,"workers",23,(()=>Math.min(16,navigator.hardwareConcurrency||8))),W=x(t,"workerurl",7,void 0);const{altchaI18n:Y}=globalThis,X=Y.store,ee=["SHA-256","SHA-384","SHA-512"],te=(e,n)=>{t.$$host.dispatchEvent(new CustomEvent(e,{detail:n}))},ne=document.documentElement.lang?.split("-")?.[0],re=Lt((()=>s()&&new URL(s(),location.origin).host.endsWith(".altcha.org")&&!!s()?.includes("apiKey=ckey_"))),oe=Lt((()=>c()?Ye(c()):void 0)),ie=Lt((()=>U()?Ye(U()):{})),ae=Lt((()=>({...Se(o()),...i(ie)}))),le=Lt((()=>`${I()||L()}_checkbox_${Math.round(1e8*Math.random())}`));let se=N(null),ce=N(!1),ue=N(null),fe=N(Me(y.UNVERIFIED)),de=N(void 0),he=N(null),ve=N(null),pe=N(null),ge=N(null),be=N(null),me=N(null),ye=N(null),we=N(null),xe=null,$e=N(null),Ee=N(!1),Re=[],_e=N(!1),ke=N(null);function Ae(e,t){return btoa(JSON.stringify({algorithm:e.algorithm,challenge:e.challenge,number:t.number,salt:e.salt,signature:e.signature,test:!!q()||void 0,took:t.took}))}function Ne(){s()&&!g()&&i(fe)===y.VERIFIED?wt():gt(y.EXPIRED,i(ae).expired)}function Ie(){let e=fetch;if(f())if(Pe("using customfetch"),"string"==typeof f()){if(e=globalThis[f()]||null,!e)throw new Error(`Custom fetch function not found: ${f()}`)}else e=f();return e}function Se(e,t=[S()||"",document.documentElement.lang||"",...navigator.languages]){const n=Object.keys(e).map((e=>e.toLowerCase())),r=t.reduce(((t,r)=>(r=r.toLowerCase(),t||(e[r]?r:null)||n.find((e=>r.split("-")[0]===e.split("-")[0]))||null)),null);return e[r||"en"]}function Le(e){return[...i(me)?.querySelectorAll(e?.length?e.map((e=>`input[name="${e}"]`)).join(", "):'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])')||[]].reduce(((e,t)=>{const n=t.name,r=t.value;return n&&r&&(e[n]=/\n/.test(r)?r.replace(new RegExp("(?e instanceof Error)))&&console[e[0]instanceof Error?"error":"log"]("ALTCHA",`[name=${L()}]`,...e)}function De(){b($e,Q.PAUSED,!0)}function Ve(e){b($e,Q.ERROR,!0)}function Be(){b($e,Q.READY,!0)}function je(){b($e,Q.LOADING,!0)}function Te(){b($e,Q.PLAYING,!0)}function Ue(){b($e,Q.PAUSED,!0)}function qe(e){if(e.preventDefault(),e.stopPropagation(),i(ue)){const t=new FormData(e.target),n=String(t.get("code"));if(H()?.startsWith("fn:")){const e=H().replace(/^fn:/,"");if(Pe(`calling ${e} function instead of verifyurl`),!(e in globalThis))throw new Error(`Global function "${e}" is undefined.`);return globalThis[e]({challenge:i(ue).challenge,code:n,solution:i(ue).solution})}b(Ee,!0),nt(Ae(i(ue).challenge,i(ue).solution),n).then((({reason:e,verified:t})=>{t?(b(ue,null),mt(y.VERIFIED),Pe("verified"),Rr().then((()=>{i(ge)?.focus(),te("verified",{payload:i(ke)}),"onsubmit"===a()?rt(i(ye)):V()&&vt()}))):(gt(),b(we,e||"Verification failed",!0))})).catch((e=>{b(ue,null),mt(y.ERROR,e),Pe("sentinel verification failed:",e)})).finally((()=>{b(Ee,!1)}))}}function Ze(e){const t=e.target;w()&&t&&!i(de).contains(t)&&(i(fe)===y.VERIFIED&&!1===_()||i(fe)===y.VERIFIED&&"focus"===_()&&!i(me)?.matches(":focus-within")||"off"===a()&&i(fe)===y.UNVERIFIED)&&vt()}function ze(){w()&&i(fe)!==y.UNVERIFIED&&pt()}function He(e){i(fe)===y.UNVERIFIED?wt():w()&&"focus"===_()&&i(fe)===y.VERIFIED&&yt()}function Ge(e){e.target?.hasAttribute("data-code-challenge-form")||(b(ye,e.submitter,!0),i(me)&&"onsubmit"===a()?(i(ye)?.blur(),i(fe)===y.UNVERIFIED?(e.preventDefault(),e.stopPropagation(),wt().then((()=>{rt(i(ye))}))):i(fe)!==y.VERIFIED&&(e.preventDefault(),e.stopPropagation(),i(fe)===y.VERIFYING&&Ke())):i(me)&&w()&&"off"===a()&&i(fe)===y.UNVERIFIED&&(e.preventDefault(),e.stopPropagation(),yt()))}function Je(){gt()}function Ke(){i(fe)===y.VERIFYING&&i(ae).waitAlert&&alert(i(ae).waitAlert)}function We(){i(ve)?i(ve).paused?(i(ve).currentTime=0,i(ve).play()):i(ve).pause():(b(_e,!0),requestAnimationFrame((()=>{i(ve)?.play()})))}function Qe(){w()&&pt()}function Ye(e){return JSON.parse(e)}function Xe(e){const t=new URLSearchParams(e.split("?")?.[1]),n=t.get("expires")||t.get("expire");if(n){const e=new Date(1e3*+n),t=isNaN(e.getTime())?0:e.getTime()-Date.now();t>0&&ot(t)}else xe&&(clearTimeout(xe),xe=null)}async function et(e){if(!H())throw new Error("Attribute verifyurl not set.");Pe("requesting server verification from",H());const t={payload:e};if(!1!==F()){const{blockedCountries:e,classifier:n,disableRules:r,email:o,expectedLanguages:a,expectedCountries:l,fields:s,ipAddress:c,text:u,timeZone:f}="ipAddress"===F()?{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:!1,expectedCountries:void 0,expectedLanguages:void 0,fields:!1,ipAddress:void 0,text:void 0,timeZone:void 0}:"object"==typeof F()?F():{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:void 0,expectedCountries:void 0,expectedLanguages:void 0,fields:void 0,ipAddress:void 0,text:void 0,timeZone:void 0};t.blockedCountries=e,t.classifier=n,t.disableRules=r,t.email=!1===o?void 0:function(e){const t=i(me)?.querySelector("string"==typeof e?`input[name="${e}"]`:'input[type="email"]:not([data-no-spamfilter])');return t?.value?.slice(t.value.indexOf("@"))||void 0}(o),t.expectedCountries=l,t.expectedLanguages=a||(ne?[ne]:void 0),t.fields=!1===s?void 0:Le(s),t.ipAddress=!1===c?void 0:c||"auto",t.text=u,t.timeZone=!1===f?void 0:f||Wn()}const n=await Ie()(H(),{body:JSON.stringify(t),headers:{"content-type":"application/json"},method:"POST"});if(!(n&&n instanceof Response))throw new Error("Custom fetch function did not return a response.");if(200!==n.status)throw new Error(`Server responded with ${n.status}.`);const r=await n.json();if(r?.payload&&b(ke,r.payload,!0),te("serververification",r),l()&&"BAD"===r.classification)throw new Error("SpamFilter returned negative classification.")}async function nt(e,t){if(!H())throw new Error("Attribute verifyurl not set.");Pe("requesting sentinel verification from",H());const n={code:t,payload:e};T()&&(n.fields=T().fields?Le():void 0,n.timeZone=T().timeZone?Wn():void 0);const r=await Ie()(H(),{body:JSON.stringify(n),headers:{"content-type":"application/json"},method:"POST"});if(!(r&&r instanceof Response))throw new Error("Fetch function did not return a response.");if(200!==r.status)throw new Error(`Server responded with ${r.status}.`);const o=await r.json();return o?.payload&&b(ke,o.payload,!0),te("sentinelverification",o),o}function rt(e){i(me)&&"requestSubmit"in i(me)?i(me).requestSubmit(e):i(me)?.reportValidity()&&(e?e.click():i(me).submit())}function ot(e){Pe("expire",e),xe&&(clearTimeout(xe),xe=null),e<1?Ne():xe=setTimeout(Ne,e)}function it(e){Pe("floating",e),w()!==e&&(i(de).style.left="",i(de).style.top=""),w(!0===e||""===e?"auto":!1===e||"false"===e?void 0:w()),w()?(a()||a("onsubmit"),document.addEventListener("scroll",ze),document.addEventListener("click",Ze),window.addEventListener("resize",Qe)):"onsubmit"===a()&&a(void 0)}function at(e){if(Pe("overlay",e),V(e),e){if(a()||a("onsubmit"),i(pe)&&i(de).parentElement&&i(pe).replaceWith(i(de).parentElement),i(de)?.parentElement?.parentElement){b(pe,document.createElement("div"),!0),i(de).parentElement.parentElement.appendChild(i(pe));const e=document.createElement("div"),t=document.createElement("button");t.type="button",t.innerHTML="×",t.addEventListener("click",(e=>{e.preventDefault(),gt()})),i(pe).classList.add("altcha-overlay-backdrop"),t.classList.add("altcha-overlay-close-button"),e.classList.add("altcha-overlay"),i(pe).append(e),e.append(t),M()&&e.append(...document.querySelectorAll(M())),e.append(i(de).parentElement)}}else i(pe)&&i(de).parentElement&&(i(pe).replaceWith(i(de).parentElement),i(de).style.display="block")}function lt(e){if(!e.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(void 0===e.signature)throw new Error("Invalid challenge. Property signature is missing.");if(!ee.includes(e.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${ee.join(", ")}`);if(!e.challenge||e.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!e.salt||e.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function st(e){let t=null,n=null;if("Worker"in window){try{t=function(e,t=("number"==typeof q()?q():e.maxNumber||e.maxnumber||O()),n=Math.ceil(G())){const r=new AbortController,o=[];n=Math.min(16,t,Math.max(1,n));for(let e=0;e{const t=await Promise.all(o.map(((t,n)=>{const a=n*i;return r.signal.addEventListener("abort",(()=>{t.postMessage({type:"abort"})})),new Promise((n=>{t.addEventListener("message",(e=>{if(e.data)for(const e of o)e!==t&&e.postMessage({type:"abort"});n(e.data)})),t.postMessage({payload:e,max:a+i,start:a,type:"work"})}))})));for(const e of o)e.terminate();return t.find((e=>!!e))||null})(),controller:r}}(e,e.maxNumber||e.maxnumber||O()),b(se,t.controller,!0),n=await t.promise}catch(e){Pe(e)}finally{b(se,null)}if(null===n||void 0!==n?.number||"obfuscated"in e)return{data:e,solution:n}}if("obfuscated"in e){const t=await il(e.obfuscated,e.key,e.maxNumber||e.maxnumber);return{data:e,solution:await t.promise}}t=rl(e.challenge,e.salt,e.algorithm,e.maxNumber||e.maxnumber||O()),b(se,t.controller,!0);try{n=await t.promise}catch(e){Pe(e)}finally{b(se,null)}return{data:e,solution:n}}async function ct(){if(!D())return void mt(y.ERROR);const e=Re.find((e=>"obfuscation"===e.constructor.pluginName));return e&&"clarify"in e?"clarify"in e&&"function"==typeof e.clarify?e.clarify():void 0:(mt(y.ERROR),void Pe("Plugin `obfuscation` not found. Import `altcha/plugins/obfuscation` to load it."))}function ut(e){void 0!==e.obfuscated&&D(e.obfuscated),void 0!==e.auto&&(a(e.auto),"onload"===a()&&(D()?ct():wt())),void 0!==e.blockspam&&l(!!e.blockspam),void 0!==e.customfetch&&f(e.customfetch),void 0!==e.floatinganchor&&$(e.floatinganchor),void 0!==e.delay&&h(e.delay),void 0!==e.floatingoffset&&C(e.floatingoffset),void 0!==e.floating&&it(e.floating),void 0!==e.expire&&(ot(e.expire),m(e.expire)),e.challenge&&(c("string"==typeof e.challenge?e.challenge:JSON.stringify(e.challenge)),lt(i(oe))),void 0!==e.challengeurl&&s(e.challengeurl),void 0!==e.debug&&d(!!e.debug),void 0!==e.hidefooter&&k(!!e.hidefooter),void 0!==e.hidelogo&&A(!!e.hidelogo),void 0!==e.language&&U(Se(o(),[e.language])),void 0!==e.maxnumber&&O(+e.maxnumber),void 0!==e.mockerror&&P(!!e.mockerror),void 0!==e.name&&L(e.name),void 0!==e.overlaycontent&&M(e.overlaycontent),void 0!==e.overlay&&at(e.overlay),void 0!==e.refetchonexpire&&g(!e.refetchonexpire),void 0!==e.disablerefetchonexpire&&g(!e.disablerefetchonexpire),void 0!==e.sentinel&&"object"==typeof e.sentinel&&T(e.sentinel),void 0!==e.spamfilter&&F("object"==typeof e.spamfilter?e.spamfilter:!!e.spamfilter),e.strings&&U("string"==typeof e.strings?e.strings:JSON.stringify(e.strings)),void 0!==e.test&&q("number"==typeof e.test?e.test:!!e.test),void 0!==e.verifyurl&&H(e.verifyurl),void 0!==e.workers&&G(+e.workers),void 0!==e.workerurl&&W(e.workerurl)}function ft(){return{auto:a(),blockspam:l(),challengeurl:s(),debug:d(),delay:h(),disableautofocus:v(),disablerefetchonexpire:g(),expire:m(),floating:w(),floatinganchor:$(),floatingoffset:C(),hidefooter:k(),hidelogo:A(),name:L(),maxnumber:O(),mockerror:P(),obfuscated:D(),overlay:V(),refetchonexpire:!g(),spamfilter:F(),strings:i(ae),test:q(),verifyurl:H(),workers:G(),workerurl:W()}}function dt(){return i(be)}function ht(){return i(fe)}function vt(){i(de).style.display="none",V()&&i(pe)&&(i(pe).style.display="none")}function pt(e=20){if(i(de))if(i(be)||b(be,($()?document.querySelector($()):i(me)?.querySelector('input[type="submit"], button[type="submit"], button:not([type="button"]):not([type="reset"])'))||i(me),!0),i(be)){const t=parseInt(C(),10)||12,n=i(be).getBoundingClientRect(),r=i(de).getBoundingClientRect(),o=document.documentElement.clientHeight,a=document.documentElement.clientWidth,l="auto"===w()?n.bottom+r.height+t+e>o:"top"===w(),s=Math.max(e,Math.min(a-e-r.width,n.left+n.width/2-r.width/2));if(i(de).style.top=l?n.top-(r.height+t)+"px":`${n.bottom+t}px`,i(de).style.left=`${s}px`,i(de).setAttribute("data-floating",l?"top":"bottom"),i(he)){const e=i(he).getBoundingClientRect();i(he).style.left=n.left-s+n.width/2-e.width/2+"px"}}else Pe("unable to find floating anchor element")}function gt(e=y.UNVERIFIED,t=null){i(se)&&(i(se).abort(),b(se,null)),b(ce,!1),b(ke,null),b(ue,null),b(_e,!1),b($e,null),mt(e,t)}function bt(e){b(be,e,!0)}function mt(e,t=null){b(fe,e,!0),b(we,t,!0),te("statechange",{payload:i(ke),state:i(fe)})}function yt(){i(de).style.display="block",w()&&pt(),V()&&i(pe)&&(i(pe).style.display="flex")}async function wt(){return gt(y.VERIFYING),await new Promise((e=>setTimeout(e,h()||0))),async function(){if(P())throw Pe("mocking error"),new Error("Mocked error.");if(i(oe))return Pe("using provided json data"),Xe(i(oe).salt),i(oe);if(q())return Pe("generating test challenge",{test:q()}),tl("boolean"!=typeof q()?+q():void 0);{if(!s()&&i(me)){const e=i(me).getAttribute("action");e?.includes("/form/")&&s(e+"/altcha")}if(!s())throw new Error("Attribute challengeurl not set.");Pe("fetching challenge from",s());const e={credentials:"boolean"==typeof u()?"include":u(),headers:!1!==F()?{"x-altcha-spam-filter":"1"}:{}},t=await Ie()(s(),e);if(!(t&&t instanceof Response))throw new Error("Custom fetch function did not return a response.");if(200!==t.status)throw new Error(`Server responded with ${t.status}.`);const n=t.headers.get("X-Altcha-Config"),r=await t.json();if(Xe(r.salt),n)try{const e=JSON.parse(n);e&&"object"==typeof e&&(e.verifyurl&&!e.verifyurl.startsWith("fn:")&&(e.verifyurl=Oe(e.verifyurl)),ut(e))}catch(e){Pe("unable to configure from X-Altcha-Config",e)}return r}}().then((e=>(lt(e),Pe("challenge",e),st(e)))).then((({data:e,solution:t})=>{if(Pe("solution",t),!t||e&&"challenge"in e&&!("clearText"in t))if(void 0!==t?.number&&"challenge"in e)if(H()&&"codeChallenge"in e)["INPUT","BUTTON","SELECT","TEXTAREA"].includes(document.activeElement?.tagName||"")&&!1===v()&&document.activeElement.blur(),b(ue,{challenge:e,solution:t},!0);else{if(H()&&void 0!==T())return nt(Ae(e,t));if(H())return et(Ae(e,t));b(ke,Ae(e,t),!0),Pe("payload",i(ke))}else if(i(fe)!==y.EXPIRED)throw Pe("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."),new Error("Unexpected result returned.")})).then((()=>{i(ue)?(mt(y.CODE),Rr().then((()=>{te("code",{codeChallenge:i(ue)})}))):i(ke)&&(mt(y.VERIFIED),Pe("verified"),Rr().then((()=>{te("verified",{payload:i(ke)}),V()&&vt()})))})).catch((e=>{Pe(e),mt(y.ERROR,e.message)}))}Dr((()=>{!function(){for(const e of Re)"function"==typeof e.onErrorChange&&e.onErrorChange(i(we))}(i(we))})),Dr((()=>{!function(){for(const e of Re)"function"==typeof e.onStateChange&&e.onStateChange(i(fe));w()&&i(fe)!==y.UNVERIFIED&&requestAnimationFrame((()=>{pt()})),b(ce,i(fe)===y.VERIFIED),V()&&i(pe)&&(i(fe)!==y.UNVERIFIED?yt():vt())}(i(fe))})),Ga((()=>{(function(){for(const e of Re)e.destroy()})(),b(ye,null),i(me)&&(i(me).removeEventListener("submit",Ge),i(me).removeEventListener("reset",Je),i(me).removeEventListener("focusin",He),b(me,null)),xe&&(clearTimeout(xe),xe=null),document.removeEventListener("click",Ze),document.removeEventListener("scroll",ze),window.removeEventListener("resize",Qe)})),Mo((()=>{Pe("mounted","2.2.4"),Pe("workers",G()),function(){const e=void 0!==j()?j().split(","):void 0;for(const t of globalThis.altchaPlugins)(!e||e.includes(t.pluginName))&&Re.push(new t({el:i(de),clarify:ct,dispatch:te,getConfiguration:ft,getFloatingAnchor:dt,getState:ht,log:Pe,reset:gt,solve:st,setState:mt,setFloatingAnchor:bt,verify:wt}))}(),Pe("plugins",Re.length?Re.map((e=>e.constructor.pluginName)).join(", "):"none"),q()&&Pe("using test mode"),m()&&ot(m()),void 0!==a()&&Pe("auto",a()),void 0!==w()&&it(w()),b(me,i(de)?.closest("form"),!0),i(me)&&(i(me).addEventListener("submit",Ge,{capture:!0}),i(me).addEventListener("reset",Je),("onfocus"===a()||"focus"===_())&&i(me).addEventListener("focusin",He)),V()&&at(!0),"onload"===a()&&(D()?ct():wt()),i(re)&&(k()||A())&&Pe("Attributes hidefooter and hidelogo ignored because usage with free API Keys requires attribution."),requestAnimationFrame((()=>{te("load")}))}));var xt=Cl(),$t=Nt(xt);Fa($t,t,"default",{});var Et=J($t,2),Ct=z(Et),Rt=z(Ct);let _t;var kt=z(Rt),At=e=>{$r(e)};K(kt,(e=>{i(fe)===y.VERIFYING&&e(At)}));var It=J(kt,2);qn(It),It.__change=[ul,fe,F,me,ce,D,ct,wt],Qt(It,(e=>b(ge,e)),(()=>i(ge))),Z(Rt);var St=J(Rt,2),Ot=z(St),Pt=e=>{var t=Xt();tt(Nt(t),(()=>i(ae).verified)),B(e,t)},Dt=(e,t)=>{var n=e=>{var t=Xt();tt(Nt(t),(()=>i(ae).verifying)),B(e,t)},r=(e,t)=>{var n=e=>{var t=Xt();tt(Nt(t),(()=>i(ae).verificationRequired)),B(e,t)},r=e=>{var t=Xt();tt(Nt(t),(()=>i(ae).label)),B(e,t)};K(e,(e=>{i(fe)===y.CODE?e(n):e(r,!1)}),t)};K(e,(e=>{i(fe)===y.VERIFYING?e(n):e(r,!1)}),t)};K(Ot,(e=>{i(fe)===y.VERIFIED?e(Pt):e(Dt,!1)})),Z(St);var Vt=J(St,2),Bt=e=>{var t=fl();qn(t),Ce((()=>{R(t,"name",L()),qa(t,i(ke))})),B(e,t)};K(Vt,(e=>{i(fe)===y.VERIFIED&&e(Bt)}));var Mt=J(Vt,2),jt=e=>{var t=dl(),n=z(t);R(n,"href","https://altcha.org/"),Z(t),Ce((()=>R(n,"aria-label",i(ae).ariaLinkLabel))),B(e,t)};K(Mt,(e=>{(!0!==A()||i(re))&&e(jt)}));var Tt=J(Mt,2),Ft=e=>{var t=_l(),n=J(z(t),2),r=z(n),o=J(r,2);Sa(o,!v()),o.__keydown=[ll,We];var a=J(o,2),l=z(a),s=z(l),c=e=>{var t=pl();t.__click=We;var n=z(t),r=e=>{$r(e,(()=>20))},o=(e,t)=>{var n=e=>{B(e,hl())},r=(e,t)=>{var n=e=>{B(e,vl())},r=e=>{B(e,gl())};K(e,(e=>{i($e)===Q.PLAYING?e(n):e(r,!1)}),t)};K(e,(e=>{i($e)===Q.ERROR?e(n):e(r,!1)}),t)};K(n,(e=>{i($e)===Q.LOADING?e(r):e(o,!1)})),Z(t),Ce((()=>{R(t,"title",i(ae).getAudioChallenge),t.disabled=i($e)===Q.LOADING||i($e)===Q.ERROR||i(Ee),R(t,"aria-label",i($e)===Q.LOADING?i(ae).loading:i(ae).getAudioChallenge)})),B(e,t)};K(s,(e=>{i(ue).challenge.codeChallenge.audio&&e(c)}));var u=J(s,2);u.__click=[sl,wt],Z(l);var f=J(l,2),d=z(f),h=e=>{$r(e,(()=>16))};K(d,(e=>{i(Ee)&&e(h)}));var p=J(d);Z(f),Z(a);var g=J(a,2),m=e=>{var t=ml(),n=z(t);Z(t),Qt(t,(e=>b(ve,e)),(()=>i(ve))),Ce((e=>R(n,"src",e)),[()=>Oe(i(ue).challenge.codeChallenge.audio,{language:S()})]),Fe("loadstart",t,je),Fe("canplay",t,Be),Fe("pause",t,Ue),Fe("playing",t,Te),Fe("ended",t,De),Fe("error",n,Ve),B(e,t)};K(g,(e=>{i(ue).challenge.codeChallenge.audio&&i(_e)&&e(m)})),Z(n),Z(t),Ce((()=>{R(t,"aria-label",i(ae).verificationRequired),R(r,"src",i(ue).challenge.codeChallenge.image),R(o,"minlength",i(ue).challenge.codeChallenge.length||1),R(o,"maxlength",i(ue).challenge.codeChallenge.length),R(o,"placeholder",i(ae).enterCode),R(o,"aria-label",i($e)===Q.LOADING?i(ae).loading:i($e)===Q.PLAYING?"":i(ae).enterCodeAria),R(o,"aria-live",i($e)?"assertive":"polite"),R(o,"aria-busy",i($e)===Q.LOADING),o.disabled=i(Ee),R(u,"aria-label",i(ae).reload),R(u,"title",i(ae).reload),u.disabled=i(Ee),f.disabled=i(Ee),R(f,"aria-label",i(ae).verify),La(p,` ${i(ae).verify??""}`)})),Fe("submit",n,qe,!0),B(e,t)};K(Tt,(e=>{i(ue)?.challenge.codeChallenge&&e(Ft)})),Z(Ct);var Ut=J(Ct,2),qt=e=>{var t=wl(),n=J(z(t),2),r=e=>{var t=bl();tt(z(t),(()=>i(ae).expired)),Z(t),Ce((()=>R(t,"title",i(we)))),B(e,t)},o=e=>{var t=yl();tt(z(t),(()=>i(ae).error)),Z(t),Ce((()=>R(t,"title",i(we)))),B(e,t)};K(n,(e=>{i(fe)===y.EXPIRED?e(r):e(o,!1)})),Z(t),B(e,t)};K(Ut,(e=>{(i(we)||i(fe)===y.EXPIRED)&&e(qt)}));var Zt=J(Ut,2),zt=e=>{var t=El(),n=z(t);tt(z(n),(()=>i(ae).footer)),Z(n),Z(t),B(e,t)};K(Zt,(e=>{i(ae).footer&&(!0!==k()||i(re))&&e(zt)}));var Ht=J(Zt,2),Gt=e=>{var t=xl();Qt(t,(e=>b(he,e)),(()=>i(he))),B(e,t)};K(Ht,(e=>{w()&&e(Gt)})),Z(Et),Qt(Et,(e=>b(de,e)),(()=>i(de))),Ce((e=>{R(Et,"data-state",i(fe)),R(Et,"data-floating",w()),R(Et,"data-overlay",V()),_t=Va(Rt,1,"altcha-checkbox",null,_t,e),R(It,"id",i(le)),It.required="onsubmit"!==a()&&(!w()||"off"!==a()),R(St,"for",i(le))}),[()=>({"altcha-checkbox-verifying":i(fe)===y.VERIFYING})]),Fe("invalid",It,Ke),Ha(It,(()=>i(ce)),(e=>b(ce,e))),B(e,xt);var Jt=So({clarify:ct,configure:ut,getConfiguration:ft,getFloatingAnchor:dt,getPlugin:function(e){return Re.find((t=>t.constructor.pluginName===e))},getState:ht,hide:vt,repositionFloating:pt,reset:gt,setFloatingAnchor:bt,setState:mt,show:yt,verify:wt,get auto(){return a()},set auto(e=void 0){a(e),E()},get blockspam(){return l()},set blockspam(e=void 0){l(e),E()},get challengeurl(){return s()},set challengeurl(e=void 0){s(e),E()},get challengejson(){return c()},set challengejson(e=void 0){c(e),E()},get credentials(){return u()},set credentials(e=void 0){u(e),E()},get customfetch(){return f()},set customfetch(e=void 0){f(e),E()},get debug(){return d()},set debug(e=!1){d(e),E()},get delay(){return h()},set delay(e=0){h(e),E()},get disableautofocus(){return v()},set disableautofocus(e=!1){v(e),E()},get refetchonexpire(){return p()},set refetchonexpire(e=!0){p(e),E()},get disablerefetchonexpire(){return g()},set disablerefetchonexpire(e=!p){g(e),E()},get expire(){return m()},set expire(e=void 0){m(e),E()},get floating(){return w()},set floating(e=void 0){w(e),E()},get floatinganchor(){return $()},set floatinganchor(e=void 0){$(e),E()},get floatingoffset(){return C()},set floatingoffset(e=void 0){C(e),E()},get floatingpersist(){return _()},set floatingpersist(e=!1){_(e),E()},get hidefooter(){return k()},set hidefooter(e=!1){k(e),E()},get hidelogo(){return A()},set hidelogo(e=!1){A(e),E()},get id(){return I()},set id(e=void 0){I(e),E()},get language(){return S()},set language(e=void 0){S(e),E()},get name(){return L()},set name(e="altcha"){L(e),E()},get maxnumber(){return O()},set maxnumber(e=1e6){O(e),E()},get mockerror(){return P()},set mockerror(e=!1){P(e),E()},get obfuscated(){return D()},set obfuscated(e=void 0){D(e),E()},get overlay(){return V()},set overlay(e=void 0){V(e),E()},get overlaycontent(){return M()},set overlaycontent(e=void 0){M(e),E()},get plugins(){return j()},set plugins(e=void 0){j(e),E()},get sentinel(){return T()},set sentinel(e=void 0){T(e),E()},get spamfilter(){return F()},set spamfilter(e=!1){F(e),E()},get strings(){return U()},set strings(e=void 0){U(e),E()},get test(){return q()},set test(e=!1){q(e),E()},get verifyurl(){return H()},set verifyurl(e=void 0){H(e),E()},get workers(){return G()},set workers(e=Math.min(16,navigator.hardwareConcurrency||8)){G(e),E()},get workerurl(){return W()},set workerurl(e=void 0){W(e),E()}});return r(),Jt}Na(["change","keydown","click"]),customElements.define("altcha-widget",Qa(kl,{blockspam:{type:"Boolean"},debug:{type:"Boolean"},delay:{type:"Number"},disableautofocus:{type:"Boolean"},disablerefetchonexpire:{type:"Boolean"},expire:{type:"Number"},floatingoffset:{type:"Number"},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},maxnumber:{type:"Number"},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},test:{type:"Boolean"},workers:{type:"Number"},auto:{},challengeurl:{},challengejson:{},credentials:{},customfetch:{},floating:{},floatinganchor:{},floatingpersist:{},id:{},language:{},name:{},obfuscated:{},overlay:{},overlaycontent:{},plugins:{},sentinel:{},spamfilter:{},strings:{},verifyurl:{},workerurl:{}},["default"],["clarify","configure","getConfiguration","getFloatingAnchor","getPlugin","getState","hide","repositionFloating","reset","setFloatingAnchor","setState","show","verify"],!1));const Bo='@keyframes overlay-slidein{to{opacity:1;top:50%}}@keyframes altcha-spinner{to{transform:rotate(360deg)}}.altcha{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);position:relative}.altcha:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha[data-floating]{background:var(--altcha-color-base, white);display:none;filter:drop-shadow(3px 3px 6px rgba(0,0,0,.2));left:-100%;position:fixed;top:-100%;width:var(--altcha-max-width, 260px);z-index:999999}.altcha[data-floating=top] .altcha-anchor-arrow{border-bottom-color:transparent;border-top-color:var(--altcha-color-border, #a0a0a0);bottom:-12px;top:auto}.altcha[data-floating=bottom]:focus-within::after{border-bottom-color:var(--altcha-color-border-focus, currentColor)}.altcha[data-floating=top]:focus-within::after{border-top-color:var(--altcha-color-border-focus, currentColor)}.altcha[data-floating]:not([data-state=unverified]){display:block}.altcha-anchor-arrow{border:6px solid transparent;border-bottom-color:var(--altcha-color-border, #a0a0a0);content:"";height:0;left:12px;position:absolute;top:-12px;width:0}.altcha-main{align-items:center;display:flex;gap:.4rem;padding:.7rem;position:relative}.altcha-code-challenge{background:var(--altcha-color-base, white);border:1px solid var(--altcha-color-border-focus, currentColor);border-radius:var(--altcha-border-radius, 3px);filter:drop-shadow(3px 3px 6px rgba(0,0,0,.2));padding:.5rem;position:absolute;top:2.5rem;z-index:9999999}.altcha-code-challenge>form{display:flex;flex-direction:column;gap:.5rem}.altcha-code-challenge-input{border:1px solid currentColor;border-radius:3px;box-sizing:border-box;outline:0;font-size:16px;padding:.35rem;width:220px}.altcha-code-challenge-input:focus{outline:2px solid color-mix(in srgb,var(--altcha-color-active, #1D1DC9) 20%,transparent)}.altcha-code-challenge-input:disabled{opacity:.7}.altcha-code-challenge-image{background-color:#fff;border:1px solid currentColor;border-radius:3px;box-sizing:border-box;object-fit:contain;height:50px;width:220px}.altcha-code-challenge-audio,.altcha-code-challenge-reload{background:color-mix(in srgb,var(--altcha-color-text, currentColor) 10%,transparent);border:0;border-radius:3px;color:var(--altcha-color-text, currentColor);cursor:pointer;display:flex;align-items:center;justify-content:center;padding:.35rem}.altcha-code-challenge-audio:disabled,.altcha-code-challenge-reload:disabled,.altcha-code-challenge-verify:disabled{opacity:.7;pointer-events:none}.altcha-code-challenge-audio>*,.altcha-code-challenge-reload>*{height:20px;width:20px}.altcha-code-challenge-buttons{display:flex;justify-content:space-between}.altcha-code-challenge-buttons-left{display:flex;gap:.25rem}.altcha-code-challenge-verify{align-items:center;background:var(--altcha-color-active, #1D1DC9);border:0;border-radius:3px;color:#fff;cursor:pointer;display:flex;gap:.5rem;font-size:100%;padding:.35rem 1rem}.altcha-code-challenge-arrow{border:6px solid transparent;border-bottom-color:var(--altcha-color-border, currentColor);content:"";height:0;left:.15rem;position:absolute;top:-12px;width:0}.altcha[data-floating=top] .altcha-code-challenge{top:-150px}.altcha[data-floating=top] .altcha-code-challenge-arrow{border-bottom-color:transparent;border-top-color:var(--altcha-color-border, currentColor);bottom:-12px;top:auto}.altcha-label{cursor:pointer;flex-grow:1}.altcha-logo{color:currentColor!important;opacity:.7}.altcha-footer:hover,.altcha-logo:hover{opacity:1}.altcha-error{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:.85rem;gap:.3rem;padding:0 .7rem .7rem}.altcha-footer{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:.75rem;opacity:.7;justify-content:end;padding:.2rem .7rem}.altcha-footer a{color:currentColor}.altcha-checkbox{display:flex;align-items:center;justify-content:center;height:24px;position:relative;width:24px}.altcha-checkbox .altcha-spinner{bottom:0;left:0;position:absolute;right:0;top:0}.altcha-checkbox input{width:18px;height:18px;margin:0}.altcha-checkbox-verifying input{appearance:none;opacity:0;pointer-events:none}.altcha-spinner{animation:altcha-spinner .75s infinite linear;transform-origin:center}.altcha-overlay{--altcha-color-base:#fff;--altcha-color-text:#000;animation:overlay-slidein .5s forwards;display:flex;flex-direction:column;gap:.5rem;left:50%;width:260px;opacity:0;position:fixed;top:45%;transform:translate(-50%,-50%)}.altcha-overlay-backdrop{background:rgba(0,0,0,.5);bottom:0;display:none;left:0;position:fixed;right:0;top:0;z-index:99999999}.altcha-overlay-close-button{align-self:flex-end;background:0 0;border:0;padding:.25rem;cursor:pointer;color:currentColor;font-size:130%;line-height:1;opacity:.7}@media (max-height:450px){.altcha-overlay{top:10%!important;transform:translate(-50%,0)}}';function Ho(e,t="__altcha-css"){if(!document.getElementById(t)){const n=document.createElement("style");n.id=t,n.textContent=e,document.head.appendChild(n)}}globalThis.altchaCreateWorker=e=>e?new Worker(new URL(e)):new Ni,Ho(Bo),Ho(Bo);export{kl as Altcha}; diff --git a/django_altcha/static/altcha/altcha.min.js.ABOUT b/django_altcha/static/altcha/altcha.min.js.ABOUT index 0679034..f9d9d20 100644 --- a/django_altcha/static/altcha/altcha.min.js.ABOUT +++ b/django_altcha/static/altcha/altcha.min.js.ABOUT @@ -1,7 +1,7 @@ about_resource: altcha.min.js name: altcha -version: 1.4.2 -download_url: https://github.com/altcha-org/altcha/archive/refs/tags/v1.4.2.tar.gz -package_url: pkg:github/altcha-org/altcha@1.4.2 +version: 2.2.4 +download_url: https://github.com/altcha-org/altcha/archive/refs/tags/v2.2.4.tar.gz +package_url: pkg:github/altcha-org/altcha@2.2.4 license_expression: mit copyright: Copyright (c) 2023 Daniel Regeci From 6aeffea1f1dcdafebb2508054acefe9a36702051 Mon Sep 17 00:00:00 2001 From: tdruez Date: Tue, 21 Oct 2025 15:10:28 +0400 Subject: [PATCH 2/2] Add support for providing dict values to AltchaWidget Signed-off-by: tdruez --- django_altcha/__init__.py | 15 ++++++++++++++- tests/test_widget.py | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/django_altcha/__init__.py b/django_altcha/__init__.py index 4c7b0a5..595a949 100644 --- a/django_altcha/__init__.py +++ b/django_altcha/__init__.py @@ -137,9 +137,22 @@ def get_context(self, name, value, attrs): ) self.options["challengejson"] = json.dumps(challenge.__dict__) - context["widget"]["altcha_options"] = self.options + # JSON-encode list/dict values before setting in context + encoded_options = self.encode_values(self.options) + context["widget"]["altcha_options"] = encoded_options + return context + @staticmethod + def encode_values(data): + """Return a shallow copy of `data` where lists and dicts are JSON encoded.""" + encoded = {} + for key, value in data.items(): + if isinstance(value, (list, dict)): + value = json.dumps(value) + encoded[key] = value + return encoded + class AltchaField(forms.Field): widget = AltchaWidget diff --git a/tests/test_widget.py b/tests/test_widget.py index ab3340b..be0ede6 100644 --- a/tests/test_widget.py +++ b/tests/test_widget.py @@ -38,3 +38,18 @@ def test_widget_generates_challengejson_if_no_challengeurl(self): self.assertEqual("SHA-256", challengejson["algorithm"]) self.assertEqual(64, len(challengejson["challenge"])) self.assertIn("?expires=", challengejson.get("salt")) + + def test_widget_rendering_with_complex_options(self): + options = { + "strings": { + "label": "Label", + "verified": "Verified", + } + } + widget = AltchaWidget(options) + rendered_widget_html = widget.render("name", "value") + expected = ( + 'strings="{"label": "Label", ' + '"verified": "Verified"}"' + ) + self.assertIn(expected, rendered_widget_html)