altcha 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/altcha.iife.js +1 -1
- package/dist/altcha.js +330 -327
- package/dist/altcha.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/altcha.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var altcha=function(j){"use strict";var Mt=Object.defineProperty;var St=(j,L,P)=>L in j?Mt(j,L,{enumerable:!0,configurable:!0,writable:!0,value:P}):j[L]=P;var M=(j,L,P)=>(St(j,typeof L!="symbol"?L+"":L,P),P);function L(){}function P(t){return t()}function ae(){return Object.create(null)}function K(t){t.forEach(P)}function he(t){return typeof t=="function"}function je(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ve(t){return Object.keys(t).length===0}function b(t,e){t.appendChild(e)}function Ze(t,e,r){const n=He(t);if(!n.getElementById(e)){const o=w("style");o.id=e,o.textContent=r,Pe(n,o)}}function He(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Pe(t,e){return b(t.head||t,e),e.sheet}function I(t,e,r){t.insertBefore(e,r||null)}function R(t){t.parentNode&&t.parentNode.removeChild(t)}function w(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Fe(t){return document.createTextNode(t)}function F(){return Fe(" ")}function re(t,e,r,n){return t.addEventListener(e,r,n),()=>t.removeEventListener(e,r,n)}function c(t,e,r){r==null?t.removeAttribute(e):t.getAttribute(e)!==r&&t.setAttribute(e,r)}function Oe(t){return Array.from(t.childNodes)}function de(t,e,r){t.classList.toggle(e,!!r)}function We(t,e,{bubbles:r=!1,cancelable:n=!1}={}){return new CustomEvent(t,{detail:e,bubbles:r,cancelable:n})}function De(t){const e={};return t.childNodes.forEach(r=>{e[r.slot||"default"]=!0}),e}let J;function z(t){J=t}function ne(){if(!J)throw new Error("Function called outside component initialization");return J}function Be(t){ne().$$.on_mount.push(t)}function Ye(t){ne().$$.on_destroy.push(t)}function Ue(){const t=ne();return(e,r,{cancelable:n=!1}={})=>{const o=t.$$.callbacks[e];if(o){const l=We(e,r,{cancelable:n});return o.slice().forEach(s=>{s.call(t,l)}),!l.defaultPrevented}return!0}}const W=[],ie=[];let D=[];const ge=[],be=Promise.resolve();let oe=!1;function me(){oe||(oe=!0,be.then(E))}function Xe(){return me(),be}function le(t){D.push(t)}const se=new Set;let B=0;function E(){if(B!==0)return;const t=J;do{try{for(;B<W.length;){const e=W[B];B++,z(e),Ke(e.$$)}}catch(e){throw W.length=0,B=0,e}for(z(null),W.length=0,B=0;ie.length;)ie.pop()();for(let e=0;e<D.length;e+=1){const r=D[e];se.has(r)||(se.add(r),r())}D.length=0}while(W.length);for(;ge.length;)ge.pop()();oe=!1,se.clear(),z(t)}function Ke(t){if(t.fragment!==null){t.update(),K(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(le)}}function Je(t){const e=[],r=[];D.forEach(n=>t.indexOf(n)===-1?e.push(n):r.push(n)),r.forEach(n=>n()),D=e}const ze=new Set;function Qe(t,e){t&&t.i&&(ze.delete(t),t.i(e))}function qe(t,e,r){const{fragment:n,after_update:o}=t.$$;n&&n.m(e,r),le(()=>{const l=t.$$.on_mount.map(P).filter(he);t.$$.on_destroy?t.$$.on_destroy.push(...l):K(l),t.$$.on_mount=[]}),o.forEach(le)}function et(t,e){const r=t.$$;r.fragment!==null&&(Je(r.after_update),K(r.on_destroy),r.fragment&&r.fragment.d(e),r.on_destroy=r.fragment=null,r.ctx=[])}function tt(t,e){t.$$.dirty[0]===-1&&(W.push(t),me(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function rt(t,e,r,n,o,l,s=null,u=[-1]){const a=J;z(t);const f=t.$$={fragment:null,ctx:[],props:l,update:L,not_equal:o,bound:ae(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(a?a.$$.context:[])),callbacks:ae(),dirty:u,skip_bound:!1,root:e.target||a.$$.root};s&&s(f.root);let x=!1;if(f.ctx=r?r(t,e.props||{},(m,N,...A)=>{const S=A.length?A[0]:N;return f.ctx&&o(f.ctx[m],f.ctx[m]=S)&&(!f.skip_bound&&f.bound[m]&&f.bound[m](S),x&&tt(t,m)),N}):[],f.update(),x=!0,K(f.before_update),f.fragment=n?n(f.ctx):!1,e.target){if(e.hydrate){const m=Oe(e.target);f.fragment&&f.fragment.l(m),m.forEach(R)}else f.fragment&&f.fragment.c();e.intro&&Qe(t.$$.fragment),qe(t,e.target,e.anchor),E()}z(a)}let ve;typeof HTMLElement=="function"&&(ve=class extends HTMLElement{constructor(e,r,n){super();M(this,"$$ctor");M(this,"$$s");M(this,"$$c");M(this,"$$cn",!1);M(this,"$$d",{});M(this,"$$r",!1);M(this,"$$p_d",{});M(this,"$$l",{});M(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=r,n&&this.attachShadow({mode:"open"})}addEventListener(e,r,n){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(r),this.$$c){const o=this.$$c.$on(e,r);this.$$l_u.set(r,o)}super.addEventListener(e,r,n)}removeEventListener(e,r,n){if(super.removeEventListener(e,r,n),this.$$c){const o=this.$$l_u.get(r);o&&(o(),this.$$l_u.delete(r))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(l){return()=>{let s;return{c:function(){s=w("slot"),l!=="default"&&c(s,"name",l)},m:function(f,x){I(f,s,x)},d:function(f){f&&R(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const r={},n=De(this);for(const l of this.$$s)l in n&&(r[l]=[e(l)]);for(const l of this.attributes){const s=this.$$g_p(l.name);s in this.$$d||(this.$$d[s]=Q(s,l.value,this.$$p_d,"toProp"))}for(const l in this.$$p_d)!(l in this.$$d)&&this[l]!==void 0&&(this.$$d[l]=this[l],delete this[l]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:r,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const l in this.$$p_d)if(this.$$d[l]=this.$$c.$$.ctx[this.$$c.$$.props[l]],this.$$p_d[l].reflect){const s=Q(l,this.$$d[l],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[l].attribute||l):this.setAttribute(this.$$p_d[l].attribute||l,s)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const l in this.$$l)for(const s of this.$$l[l]){const u=this.$$c.$on(l,s);this.$$l_u.set(s,u)}this.$$l={}}}attributeChangedCallback(e,r,n){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Q(e,n,this.$$p_d,"toProp"),(o=this.$$c)==null||o.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(r=>this.$$p_d[r].attribute===e||!this.$$p_d[r].attribute&&r.toLowerCase()===e)||e}});function Q(t,e,r,n){var l;const o=(l=r[t])==null?void 0:l.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!n||!r[t])return e;if(n==="toAttribute")switch(o){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function nt(t,e,r,n,o,l){let s=class extends ve{constructor(){super(t,r,o),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(u=>(e[u].attribute||u).toLowerCase())}};return Object.keys(e).forEach(u=>{Object.defineProperty(s.prototype,u,{get(){return this.$$c&&u in this.$$c?this.$$c[u]:this.$$d[u]},set(a){var f;a=Q(u,a,e),this.$$d[u]=a,(f=this.$$c)==null||f.$set({[u]:a})}})}),n.forEach(u=>{Object.defineProperty(s.prototype,u,{get(){var a;return(a=this.$$c)==null?void 0:a[u]}})}),l&&(s=l(s)),t.element=s,s}class it{constructor(){M(this,"$$");M(this,"$$set")}$destroy(){et(this,1),this.$destroy=L}$on(e,r){if(!he(r))return L;const n=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return n.push(r),()=>{const o=n.indexOf(r);o!==-1&&n.splice(o,1)}}$set(e){this.$$set&&!Ve(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const ot="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ot);const we="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+aT9zKG51bGwpOmgoZSxsLG8pLnRoZW4odz0+e3c9PT10P3Moe251bWJlcjpsLHRvb2s6RGF0ZS5ub3coKS1yfSk6ZChsKzEpfSkuY2F0Y2goYyl9O2QocCl9KSxjb250cm9sbGVyOmF9fWxldCBuO29ubWVzc2FnZT1hc3luYyB0PT57Y29uc3R7dHlwZTplLHBheWxvYWQ6b309dC5kYXRhO2lmKGU9PT0iYWJvcnQiKW49PW51bGx8fG4uYWJvcnQoKSxuPXZvaWQgMDtlbHNlIGlmKGU9PT0id29yayIpe2NvbnN0e2FsZzppLGNoYWxsZW5nZTpwLG1heDphLHNhbHQ6dSxzdGFydDpzfT1vfHx7fSxjPW0ocCx1LGksYSxzKTtuPWMuY29udHJvbGxlcixjLnByb21pc2UudGhlbihyPT57c2VsZi5wb3N0TWVzc2FnZShyJiZ7Li4ucix3b3JrZXI6ITB9KX0pfX19KSgpOwo=",lt=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),_e=typeof window<"u"&&window.Blob&&new Blob([lt(we)],{type:"text/javascript;charset=utf-8"});function st(t){let e;try{if(e=_e&&(window.URL||window.webkitURL).createObjectURL(_e),!e)throw"";const r=new Worker(e,{name:t==null?void 0:t.name});return r.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),r}catch{return new Worker("data:text/javascript;base64,"+we,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const ct=new TextEncoder;function ut(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ft(t,e="SHA-256",r=1e5){const n=Date.now().toString(16);t||(t=Math.round(Math.random()*r));const o=await pe(n,t,e);return{algorithm:e,challenge:o,salt:n,signature:""}}async function pe(t,e,r){return ut(await crypto.subtle.digest(r.toUpperCase(),ct.encode(t+e)))}function at(t,e,r="SHA-256",n=1e6,o=0){const l=new AbortController;return{promise:new Promise((u,a)=>{const f=Date.now(),x=m=>{l.signal.aborted||m>n?u(null):pe(e,m,r).then(N=>{N===t?u({number:m,took:Date.now()-f}):x(m+1)}).catch(a)};x(o)}),controller:l}}var g=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(g||{});function ht(t){Ze(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-vuofbg.svelte-vuofbg{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function ye(t){let e,r,n;return{c(){e=V("svg"),r=V("path"),n=V("path"),c(r,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(r,"fill","currentColor"),c(r,"opacity",".25"),c(n,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(n,"fill","currentColor"),c(n,"class","altcha-spinner svelte-vuofbg"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(o,l){I(o,e,l),b(e,r),b(e,n)},d(o){o&&R(e)}}}function dt(t){let e,r=t[9].label+"",n;return{c(){e=w("label"),c(e,"for",n=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(o,l){I(o,e,l),e.innerHTML=r},p(o,l){l[0]&512&&r!==(r=o[9].label+"")&&(e.innerHTML=r),l[0]&8&&n!==(n=o[3]+"_checkbox")&&c(e,"for",n)},d(o){o&&R(e)}}}function gt(t){let e,r=t[9].verifying+"";return{c(){e=w("span")},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].verifying+"")&&(e.innerHTML=r)},d(n){n&&R(e)}}}function bt(t){let e,r=t[9].verified+"",n,o;return{c(){e=w("span"),n=F(),o=w("input"),c(o,"type","hidden"),c(o,"name",t[3]),o.value=t[4]},m(l,s){I(l,e,s),e.innerHTML=r,I(l,n,s),I(l,o,s)},p(l,s){s[0]&512&&r!==(r=l[9].verified+"")&&(e.innerHTML=r),s[0]&8&&c(o,"name",l[3]),s[0]&16&&(o.value=l[4])},d(l){l&&(R(e),R(n),R(o))}}}function ke(t){let e,r,n,o,l,s;return{c(){e=w("div"),r=w("a"),n=V("svg"),o=V("path"),l=V("path"),s=V("path"),c(o,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(o,"fill","currentColor"),c(l,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(l,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(n,"width","22"),c(n,"height","22"),c(n,"viewBox","0 0 20 20"),c(n,"fill","none"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(r,"href",xe),c(r,"target","_blank"),c(r,"class","altcha-logo svelte-vuofbg")},m(u,a){I(u,e,a),b(e,r),b(r,n),b(n,o),b(n,l),b(n,s)},p:L,d(u){u&&R(e)}}}function $e(t){let e,r,n,o;function l(a,f){return a[5]===g.EXPIRED?vt:mt}let s=l(t),u=s(t);return{c(){e=w("div"),r=V("svg"),n=V("path"),o=F(),u.c(),c(n,"stroke-linecap","round"),c(n,"stroke-linejoin","round"),c(n,"d","M6 18L18 6M6 6l12 12"),c(r,"width","14"),c(r,"height","14"),c(r,"xmlns","http://www.w3.org/2000/svg"),c(r,"fill","none"),c(r,"viewBox","0 0 24 24"),c(r,"stroke-width","1.5"),c(r,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(a,f){I(a,e,f),b(e,r),b(r,n),b(e,o),u.m(e,null)},p(a,f){s===(s=l(a))&&u?u.p(a,f):(u.d(1),u=s(a),u&&(u.c(),u.m(e,null)))},d(a){a&&R(e),u.d()}}}function mt(t){let e,r=t[9].error+"";return{c(){e=w("div"),c(e,"title",t[8])},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].error+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&R(e)}}}function vt(t){let e,r=t[9].expired+"";return{c(){e=w("div"),c(e,"title",t[8])},m(n,o){I(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].expired+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&R(e)}}}function Ee(t){let e,r,n=t[9].footer+"";return{c(){e=w("div"),r=w("div"),c(r,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(o,l){I(o,e,l),b(e,r),r.innerHTML=n},p(o,l){l[0]&512&&n!==(n=o[9].footer+"")&&(r.innerHTML=n)},d(o){o&&R(e)}}}function wt(t){let e,r,n,o,l,s,u,a,f,x,m,N,A,S,_=t[5]===g.VERIFYING&&ye();function O(h,$){return h[5]===g.VERIFIED?bt:h[5]===g.VERIFYING?gt:dt}let Z=O(t),p=Z(t),v=t[2]!==!0&&ke(),y=(t[8]||t[5]===g.EXPIRED)&&$e(t),k=t[9].footer&&t[1]!==!0&&Ee(t);return{c(){e=w("div"),r=w("div"),_&&_.c(),n=F(),o=w("div"),l=w("input"),a=F(),f=w("div"),p.c(),x=F(),v&&v.c(),m=F(),y&&y.c(),N=F(),k&&k.c(),c(l,"type","checkbox"),c(l,"id",s=t[3]+"_checkbox"),l.required=u=t[0]!=="onsubmit",c(l,"class","svelte-vuofbg"),c(o,"class","altcha-checkbox svelte-vuofbg"),de(o,"altcha-hidden",t[5]===g.VERIFYING),c(f,"class","altcha-label svelte-vuofbg"),c(r,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,$){I(h,e,$),b(e,r),_&&_.m(r,null),b(r,n),b(r,o),b(o,l),l.checked=t[6],b(r,a),b(r,f),p.m(f,null),b(r,x),v&&v.m(r,null),b(e,m),y&&y.m(e,null),b(e,N),k&&k.m(e,null),t[27](e),A||(S=[re(l,"change",t[26]),re(l,"change",t[10]),re(l,"invalid",t[11])],A=!0)},p(h,$){h[5]===g.VERIFYING?_||(_=ye(),_.c(),_.m(r,n)):_&&(_.d(1),_=null),$[0]&8&&s!==(s=h[3]+"_checkbox")&&c(l,"id",s),$[0]&1&&u!==(u=h[0]!=="onsubmit")&&(l.required=u),$[0]&64&&(l.checked=h[6]),$[0]&32&&de(o,"altcha-hidden",h[5]===g.VERIFYING),Z===(Z=O(h))&&p?p.p(h,$):(p.d(1),p=Z(h),p&&(p.c(),p.m(f,null))),h[2]!==!0?v?v.p(h,$):(v=ke(),v.c(),v.m(r,null)):v&&(v.d(1),v=null),h[8]||h[5]===g.EXPIRED?y?y.p(h,$):(y=$e(h),y.c(),y.m(e,N)):y&&(y.d(1),y=null),h[9].footer&&h[1]!==!0?k?k.p(h,$):(k=Ee(h),k.c(),k.m(e,null)):k&&(k.d(1),k=null),$[0]&32&&c(e,"data-state",h[5])},i:L,o:L,d(h){h&&R(e),_&&_.d(),p.d(),v&&v.d(),y&&y.d(),k&&k.d(),t[27](null),A=!1,K(S)}}}const xe="https://altcha.org/";function Ce(t){return JSON.parse(t)}function _t(t,e,r){let n,o,l,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:a=void 0}=e,{debug:f=!1}=e,{expire:x=void 0}=e,{hidefooter:m=!1}=e,{hidelogo:N=!1}=e,{name:A="altcha"}=e,{maxnumber:S=1e6}=e,{mockerror:_=!1}=e,{refetchonexpire:O=!0}=e,{strings:Z=void 0}=e,{test:p=!1}=e,{workers:v=navigator.hardwareConcurrency||8}=e;const y=Ue(),k=["SHA-256","SHA-384","SHA-512"];let h=!1,$,T=null,ce=null,Y=null,H=g.UNVERIFIED,ue;Ye(()=>{T&&(T.removeEventListener("submit",Re),T.removeEventListener("reset",Ie),T=null)}),Be(()=>{C("mounted","0.2.2"),C("workers",v),p&&C("using test mode"),x&&fe(x),s!==void 0&&C("auto",s),T=$.closest("form"),T&&(T.addEventListener("submit",Re),T.addEventListener("reset",Ie)),s==="onload"&&U()});function C(...i){(f||i.some(d=>d instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function Re(i){T&&s==="onsubmit"&&H===g.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),U().then(()=>{T==null||T.requestSubmit()}))}function Ie(){q()}function pt(i,d){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:d.number,salt:i.salt,signature:i.signature,test:p?!0:void 0,took:d.took}))}function Ne(i){if(!i.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(i.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!k.includes(i.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${k.join(", ")}`);if(!i.challenge||i.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!i.salt||i.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function yt(){if(_)throw C("mocking error"),new Error("Mocked error.");if(n)return C("using provided json data"),n;if(p)return C("generating test challenge"),ft();{if(!u)throw new Error("Attribute challengeurl not set.");C("fetching challenge from",u);const i=await fetch(u);if(i.status!==200)throw new Error(`Server responded with ${i.status}.`);const d=i.headers.get("Expires");if(d!=null&&d.length){const X=Date.parse(d);isNaN(X)||fe(X-Date.now())}return i.json()}}function Te(){u&&O&&H===g.VERIFIED?U():q(g.EXPIRED,l.expired)}async function kt(i){let d=null;if("Worker"in window){try{d=await $t(i.challenge,i.salt,i.algorithm)}catch(X){C(X)}if((d==null?void 0:d.number)!==void 0)return{data:i,solution:d}}return{data:i,solution:await at(i.challenge,i.salt,i.algorithm,S).promise}}async function $t(i,d,X,ee=Math.ceil(v)){const te=[];if(ee<1)throw new Error("Wrong number of workers configured.");if(ee>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let G=0;G<ee;G++)te.push(new st);const Me=Math.ceil(S/ee),It=await Promise.all(te.map((G,Nt)=>{const Se=Nt*Me;return new Promise(Tt=>{G.addEventListener("message",Ae=>{if(Ae.data)for(const Ge of te)Ge!==G&&Ge.postMessage({type:"abort"});Tt(Ae.data)}),G.postMessage({payload:{alg:X,challenge:i,max:Se+Me,salt:d,start:Se},type:"work"})})}));for(const G of te)G.terminate();return It.find(G=>!!G)||null}function Et(){[g.UNVERIFIED,g.ERROR,g.EXPIRED].includes(H)?U():r(6,h=!0)}function xt(){H===g.VERIFYING&&alert(l.waitAlert)}function fe(i){C("expire",i),clearTimeout(ue),i<1?Te():ue=setTimeout(Te,i)}function Ct(i){i.auto!==void 0&&(r(0,s=i.auto),s==="onload"&&U()),i.expire!==void 0&&(fe(i.expire),r(13,x=i.expire)),i.challenge&&(Ne(i.challenge),n=i.challenge),i.debug!==void 0&&r(12,f=!!i.debug),i.hidefooter!==void 0&&r(1,m=!!i.hidefooter),i.hidelogo!==void 0&&r(2,N=!!i.hidelogo),i.maxnumber!==void 0&&r(14,S=+i.maxnumber),i.mockerror!==void 0&&r(15,_=!!i.mockerror),i.name!==void 0&&r(3,A=i.name),i.refetchonexpire!==void 0&&r(16,O=!!i.refetchonexpire),i.strings&&r(25,o=i.strings),i.test!==void 0&&r(17,p=!!i.test),i.workers!==void 0&&r(18,v=+i.workers)}function q(i=g.UNVERIFIED,d=null){clearTimeout(ue),r(6,h=!1),r(8,ce=d),r(4,Y=null),r(5,H=i)}async function U(){return q(g.VERIFYING),yt().then(i=>(Ne(i),C("challenge",i),kt(i))).then(({data:i,solution:d})=>{if(C("solution",d),(d==null?void 0:d.number)!==void 0)C("verified"),r(5,H=g.VERIFIED),r(6,h=!0),r(4,Y=pt(i,d)),C("payload",Y),Xe().then(()=>{y("verified",{payload:Y})});else throw new Error("Unexpected result returned.")}).catch(i=>{C(i),r(5,H=g.ERROR),r(6,h=!1),r(8,ce=i.message)})}function Lt(){h=this.checked,r(6,h)}function Rt(i){ie[i?"unshift":"push"](()=>{$=i,r(7,$)})}return t.$$set=i=>{"auto"in i&&r(0,s=i.auto),"challengeurl"in i&&r(19,u=i.challengeurl),"challengejson"in i&&r(20,a=i.challengejson),"debug"in i&&r(12,f=i.debug),"expire"in i&&r(13,x=i.expire),"hidefooter"in i&&r(1,m=i.hidefooter),"hidelogo"in i&&r(2,N=i.hidelogo),"name"in i&&r(3,A=i.name),"maxnumber"in i&&r(14,S=i.maxnumber),"mockerror"in i&&r(15,_=i.mockerror),"refetchonexpire"in i&&r(16,O=i.refetchonexpire),"strings"in i&&r(21,Z=i.strings),"test"in i&&r(17,p=i.test),"workers"in i&&r(18,v=i.workers)},t.$$.update=()=>{t.$$.dirty[0]&1048576&&(n=a?Ce(a):void 0),t.$$.dirty[0]&2097152&&r(25,o=Z?Ce(Z):{}),t.$$.dirty[0]&33554432&&r(9,l={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by <a href="${xe}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...o}),t.$$.dirty[0]&48&&y("statechange",{payload:Y,state:H})},[s,m,N,A,Y,H,h,$,ce,l,Et,xt,f,x,S,_,O,p,v,u,a,Z,Ct,q,U,o,Lt,Rt]}class Le extends it{constructor(e){super(),rt(this,e,_t,wt,je,{auto:0,challengeurl:19,challengejson:20,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,refetchonexpire:16,strings:21,test:17,workers:18,configure:22,reset:23,verify:24},ht,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),E()}get challengeurl(){return this.$$.ctx[19]}set challengeurl(e){this.$$set({challengeurl:e}),E()}get challengejson(){return this.$$.ctx[20]}set challengejson(e){this.$$set({challengejson:e}),E()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),E()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),E()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),E()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),E()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),E()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),E()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),E()}get refetchonexpire(){return this.$$.ctx[16]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),E()}get strings(){return this.$$.ctx[21]}set strings(e){this.$$set({strings:e}),E()}get test(){return this.$$.ctx[17]}set test(e){this.$$set({test:e}),E()}get workers(){return this.$$.ctx[18]}set workers(e){this.$$set({workers:e}),E()}get configure(){return this.$$.ctx[22]}get reset(){return this.$$.ctx[23]}get verify(){return this.$$.ctx[24]}}return customElements.define("altcha-widget",nt(Le,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),j.Altcha=Le,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"}),j}({});
|
|
1
|
+
var altcha=function(j){"use strict";var St=Object.defineProperty;var At=(j,L,P)=>L in j?St(j,L,{enumerable:!0,configurable:!0,writable:!0,value:P}):j[L]=P;var M=(j,L,P)=>(At(j,typeof L!="symbol"?L+"":L,P),P);function L(){}function P(t){return t()}function he(){return Object.create(null)}function K(t){t.forEach(P)}function de(t){return typeof t=="function"}function Ve(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ze(t){return Object.keys(t).length===0}function b(t,e){t.appendChild(e)}function He(t,e,r){const i=Pe(t);if(!i.getElementById(e)){const o=w("style");o.id=e,o.textContent=r,Fe(i,o)}}function Pe(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Fe(t,e){return b(t.head||t,e),e.sheet}function I(t,e,r){t.insertBefore(e,r||null)}function R(t){t.parentNode&&t.parentNode.removeChild(t)}function w(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Oe(t){return document.createTextNode(t)}function F(){return Oe(" ")}function ne(t,e,r,i){return t.addEventListener(e,r,i),()=>t.removeEventListener(e,r,i)}function c(t,e,r){r==null?t.removeAttribute(e):t.getAttribute(e)!==r&&t.setAttribute(e,r)}function We(t){return Array.from(t.childNodes)}function ge(t,e,r){t.classList.toggle(e,!!r)}function De(t,e,{bubbles:r=!1,cancelable:i=!1}={}){return new CustomEvent(t,{detail:e,bubbles:r,cancelable:i})}function Be(t){const e={};return t.childNodes.forEach(r=>{e[r.slot||"default"]=!0}),e}let J;function z(t){J=t}function ie(){if(!J)throw new Error("Function called outside component initialization");return J}function Ye(t){ie().$$.on_mount.push(t)}function Ue(t){ie().$$.on_destroy.push(t)}function Xe(){const t=ie();return(e,r,{cancelable:i=!1}={})=>{const o=t.$$.callbacks[e];if(o){const l=De(e,r,{cancelable:i});return o.slice().forEach(s=>{s.call(t,l)}),!l.defaultPrevented}return!0}}const W=[],oe=[];let D=[];const be=[],me=Promise.resolve();let le=!1;function ve(){le||(le=!0,me.then(x))}function Ke(){return ve(),me}function se(t){D.push(t)}const ce=new Set;let B=0;function x(){if(B!==0)return;const t=J;do{try{for(;B<W.length;){const e=W[B];B++,z(e),Je(e.$$)}}catch(e){throw W.length=0,B=0,e}for(z(null),W.length=0,B=0;oe.length;)oe.pop()();for(let e=0;e<D.length;e+=1){const r=D[e];ce.has(r)||(ce.add(r),r())}D.length=0}while(W.length);for(;be.length;)be.pop()();le=!1,ce.clear(),z(t)}function Je(t){if(t.fragment!==null){t.update(),K(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(se)}}function ze(t){const e=[],r=[];D.forEach(i=>t.indexOf(i)===-1?e.push(i):r.push(i)),r.forEach(i=>i()),D=e}const Qe=new Set;function qe(t,e){t&&t.i&&(Qe.delete(t),t.i(e))}function et(t,e,r){const{fragment:i,after_update:o}=t.$$;i&&i.m(e,r),se(()=>{const l=t.$$.on_mount.map(P).filter(de);t.$$.on_destroy?t.$$.on_destroy.push(...l):K(l),t.$$.on_mount=[]}),o.forEach(se)}function tt(t,e){const r=t.$$;r.fragment!==null&&(ze(r.after_update),K(r.on_destroy),r.fragment&&r.fragment.d(e),r.on_destroy=r.fragment=null,r.ctx=[])}function rt(t,e){t.$$.dirty[0]===-1&&(W.push(t),ve(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function nt(t,e,r,i,o,l,s=null,u=[-1]){const a=J;z(t);const f=t.$$={fragment:null,ctx:[],props:l,update:L,not_equal:o,bound:he(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(a?a.$$.context:[])),callbacks:he(),dirty:u,skip_bound:!1,root:e.target||a.$$.root};s&&s(f.root);let p=!1;if(f.ctx=r?r(t,e.props||{},(m,N,...A)=>{const S=A.length?A[0]:N;return f.ctx&&o(f.ctx[m],f.ctx[m]=S)&&(!f.skip_bound&&f.bound[m]&&f.bound[m](S),p&&rt(t,m)),N}):[],f.update(),p=!0,K(f.before_update),f.fragment=i?i(f.ctx):!1,e.target){if(e.hydrate){const m=We(e.target);f.fragment&&f.fragment.l(m),m.forEach(R)}else f.fragment&&f.fragment.c();e.intro&&qe(t.$$.fragment),et(t,e.target,e.anchor),x()}z(a)}let we;typeof HTMLElement=="function"&&(we=class extends HTMLElement{constructor(e,r,i){super();M(this,"$$ctor");M(this,"$$s");M(this,"$$c");M(this,"$$cn",!1);M(this,"$$d",{});M(this,"$$r",!1);M(this,"$$p_d",{});M(this,"$$l",{});M(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=r,i&&this.attachShadow({mode:"open"})}addEventListener(e,r,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(r),this.$$c){const o=this.$$c.$on(e,r);this.$$l_u.set(r,o)}super.addEventListener(e,r,i)}removeEventListener(e,r,i){if(super.removeEventListener(e,r,i),this.$$c){const o=this.$$l_u.get(r);o&&(o(),this.$$l_u.delete(r))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(l){return()=>{let s;return{c:function(){s=w("slot"),l!=="default"&&c(s,"name",l)},m:function(f,p){I(f,s,p)},d:function(f){f&&R(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const r={},i=Be(this);for(const l of this.$$s)l in i&&(r[l]=[e(l)]);for(const l of this.attributes){const s=this.$$g_p(l.name);s in this.$$d||(this.$$d[s]=Q(s,l.value,this.$$p_d,"toProp"))}for(const l in this.$$p_d)!(l in this.$$d)&&this[l]!==void 0&&(this.$$d[l]=this[l],delete this[l]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:r,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const l in this.$$p_d)if(this.$$d[l]=this.$$c.$$.ctx[this.$$c.$$.props[l]],this.$$p_d[l].reflect){const s=Q(l,this.$$d[l],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[l].attribute||l):this.setAttribute(this.$$p_d[l].attribute||l,s)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const l in this.$$l)for(const s of this.$$l[l]){const u=this.$$c.$on(l,s);this.$$l_u.set(s,u)}this.$$l={}}}attributeChangedCallback(e,r,i){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Q(e,i,this.$$p_d,"toProp"),(o=this.$$c)==null||o.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(r=>this.$$p_d[r].attribute===e||!this.$$p_d[r].attribute&&r.toLowerCase()===e)||e}});function Q(t,e,r,i){var l;const o=(l=r[t])==null?void 0:l.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!r[t])return e;if(i==="toAttribute")switch(o){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function it(t,e,r,i,o,l){let s=class extends we{constructor(){super(t,r,o),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(u=>(e[u].attribute||u).toLowerCase())}};return Object.keys(e).forEach(u=>{Object.defineProperty(s.prototype,u,{get(){return this.$$c&&u in this.$$c?this.$$c[u]:this.$$d[u]},set(a){var f;a=Q(u,a,e),this.$$d[u]=a,(f=this.$$c)==null||f.$set({[u]:a})}})}),i.forEach(u=>{Object.defineProperty(s.prototype,u,{get(){var a;return(a=this.$$c)==null?void 0:a[u]}})}),l&&(s=l(s)),t.element=s,s}class ot{constructor(){M(this,"$$");M(this,"$$set")}$destroy(){tt(this,1),this.$destroy=L}$on(e,r){if(!de(r))return L;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(r),()=>{const o=i.indexOf(r);o!==-1&&i.splice(o,1)}}$set(e){this.$$set&&!Ze(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const lt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(lt);const _e="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+aT9zKG51bGwpOmgoZSxsLG8pLnRoZW4odz0+e3c9PT10P3Moe251bWJlcjpsLHRvb2s6RGF0ZS5ub3coKS1yfSk6ZChsKzEpfSkuY2F0Y2goYyl9O2QocCl9KSxjb250cm9sbGVyOmF9fWxldCBuO29ubWVzc2FnZT1hc3luYyB0PT57Y29uc3R7dHlwZTplLHBheWxvYWQ6b309dC5kYXRhO2lmKGU9PT0iYWJvcnQiKW49PW51bGx8fG4uYWJvcnQoKSxuPXZvaWQgMDtlbHNlIGlmKGU9PT0id29yayIpe2NvbnN0e2FsZzppLGNoYWxsZW5nZTpwLG1heDphLHNhbHQ6dSxzdGFydDpzfT1vfHx7fSxjPW0ocCx1LGksYSxzKTtuPWMuY29udHJvbGxlcixjLnByb21pc2UudGhlbihyPT57c2VsZi5wb3N0TWVzc2FnZShyJiZ7Li4ucix3b3JrZXI6ITB9KX0pfX19KSgpOwo=",st=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),pe=typeof window<"u"&&window.Blob&&new Blob([st(_e)],{type:"text/javascript;charset=utf-8"});function ct(t){let e;try{if(e=pe&&(window.URL||window.webkitURL).createObjectURL(pe),!e)throw"";const r=new Worker(e,{name:t==null?void 0:t.name});return r.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),r}catch{return new Worker("data:text/javascript;base64,"+_e,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const ut=new TextEncoder;function ft(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function at(t,e="SHA-256",r=1e5){const i=Date.now().toString(16);t||(t=Math.round(Math.random()*r));const o=await ye(i,t,e);return{algorithm:e,challenge:o,salt:i,signature:""}}async function ye(t,e,r){return ft(await crypto.subtle.digest(r.toUpperCase(),ut.encode(t+e)))}function ht(t,e,r="SHA-256",i=1e6,o=0){const l=new AbortController;return{promise:new Promise((u,a)=>{const f=Date.now(),p=m=>{l.signal.aborted||m>i?u(null):ye(e,m,r).then(N=>{N===t?u({number:m,took:Date.now()-f}):p(m+1)}).catch(a)};p(o)}),controller:l}}var g=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(g||{});function dt(t){He(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-vuofbg.svelte-vuofbg{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function ke(t){let e,r,i;return{c(){e=V("svg"),r=V("path"),i=V("path"),c(r,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(r,"fill","currentColor"),c(r,"opacity",".25"),c(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(i,"fill","currentColor"),c(i,"class","altcha-spinner svelte-vuofbg"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(o,l){I(o,e,l),b(e,r),b(e,i)},d(o){o&&R(e)}}}function gt(t){let e,r=t[9].label+"",i;return{c(){e=w("label"),c(e,"for",i=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(o,l){I(o,e,l),e.innerHTML=r},p(o,l){l[0]&512&&r!==(r=o[9].label+"")&&(e.innerHTML=r),l[0]&8&&i!==(i=o[3]+"_checkbox")&&c(e,"for",i)},d(o){o&&R(e)}}}function bt(t){let e,r=t[9].verifying+"";return{c(){e=w("span")},m(i,o){I(i,e,o),e.innerHTML=r},p(i,o){o[0]&512&&r!==(r=i[9].verifying+"")&&(e.innerHTML=r)},d(i){i&&R(e)}}}function mt(t){let e,r=t[9].verified+"",i,o;return{c(){e=w("span"),i=F(),o=w("input"),c(o,"type","hidden"),c(o,"name",t[3]),o.value=t[4]},m(l,s){I(l,e,s),e.innerHTML=r,I(l,i,s),I(l,o,s)},p(l,s){s[0]&512&&r!==(r=l[9].verified+"")&&(e.innerHTML=r),s[0]&8&&c(o,"name",l[3]),s[0]&16&&(o.value=l[4])},d(l){l&&(R(e),R(i),R(o))}}}function $e(t){let e,r,i,o,l,s;return{c(){e=w("div"),r=w("a"),i=V("svg"),o=V("path"),l=V("path"),s=V("path"),c(o,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(o,"fill","currentColor"),c(l,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(l,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(i,"width","22"),c(i,"height","22"),c(i,"viewBox","0 0 20 20"),c(i,"fill","none"),c(i,"xmlns","http://www.w3.org/2000/svg"),c(r,"href",Ce),c(r,"target","_blank"),c(r,"class","altcha-logo svelte-vuofbg")},m(u,a){I(u,e,a),b(e,r),b(r,i),b(i,o),b(i,l),b(i,s)},p:L,d(u){u&&R(e)}}}function Ee(t){let e,r,i,o;function l(a,f){return a[5]===g.EXPIRED?wt:vt}let s=l(t),u=s(t);return{c(){e=w("div"),r=V("svg"),i=V("path"),o=F(),u.c(),c(i,"stroke-linecap","round"),c(i,"stroke-linejoin","round"),c(i,"d","M6 18L18 6M6 6l12 12"),c(r,"width","14"),c(r,"height","14"),c(r,"xmlns","http://www.w3.org/2000/svg"),c(r,"fill","none"),c(r,"viewBox","0 0 24 24"),c(r,"stroke-width","1.5"),c(r,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(a,f){I(a,e,f),b(e,r),b(r,i),b(e,o),u.m(e,null)},p(a,f){s===(s=l(a))&&u?u.p(a,f):(u.d(1),u=s(a),u&&(u.c(),u.m(e,null)))},d(a){a&&R(e),u.d()}}}function vt(t){let e,r=t[9].error+"";return{c(){e=w("div"),c(e,"title",t[8])},m(i,o){I(i,e,o),e.innerHTML=r},p(i,o){o[0]&512&&r!==(r=i[9].error+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",i[8])},d(i){i&&R(e)}}}function wt(t){let e,r=t[9].expired+"";return{c(){e=w("div"),c(e,"title",t[8])},m(i,o){I(i,e,o),e.innerHTML=r},p(i,o){o[0]&512&&r!==(r=i[9].expired+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",i[8])},d(i){i&&R(e)}}}function xe(t){let e,r,i=t[9].footer+"";return{c(){e=w("div"),r=w("div"),c(r,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(o,l){I(o,e,l),b(e,r),r.innerHTML=i},p(o,l){l[0]&512&&i!==(i=o[9].footer+"")&&(r.innerHTML=i)},d(o){o&&R(e)}}}function _t(t){let e,r,i,o,l,s,u,a,f,p,m,N,A,S,_=t[5]===g.VERIFYING&&ke();function O(h,E){return h[5]===g.VERIFIED?mt:h[5]===g.VERIFYING?bt:gt}let Z=O(t),y=Z(t),v=t[2]!==!0&&$e(),k=(t[8]||t[5]===g.EXPIRED)&&Ee(t),$=t[9].footer&&t[1]!==!0&&xe(t);return{c(){e=w("div"),r=w("div"),_&&_.c(),i=F(),o=w("div"),l=w("input"),a=F(),f=w("div"),y.c(),p=F(),v&&v.c(),m=F(),k&&k.c(),N=F(),$&&$.c(),c(l,"type","checkbox"),c(l,"id",s=t[3]+"_checkbox"),l.required=u=t[0]!=="onsubmit",c(l,"class","svelte-vuofbg"),c(o,"class","altcha-checkbox svelte-vuofbg"),ge(o,"altcha-hidden",t[5]===g.VERIFYING),c(f,"class","altcha-label svelte-vuofbg"),c(r,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,E){I(h,e,E),b(e,r),_&&_.m(r,null),b(r,i),b(r,o),b(o,l),l.checked=t[6],b(r,a),b(r,f),y.m(f,null),b(r,p),v&&v.m(r,null),b(e,m),k&&k.m(e,null),b(e,N),$&&$.m(e,null),t[27](e),A||(S=[ne(l,"change",t[26]),ne(l,"change",t[10]),ne(l,"invalid",t[11])],A=!0)},p(h,E){h[5]===g.VERIFYING?_||(_=ke(),_.c(),_.m(r,i)):_&&(_.d(1),_=null),E[0]&8&&s!==(s=h[3]+"_checkbox")&&c(l,"id",s),E[0]&1&&u!==(u=h[0]!=="onsubmit")&&(l.required=u),E[0]&64&&(l.checked=h[6]),E[0]&32&&ge(o,"altcha-hidden",h[5]===g.VERIFYING),Z===(Z=O(h))&&y?y.p(h,E):(y.d(1),y=Z(h),y&&(y.c(),y.m(f,null))),h[2]!==!0?v?v.p(h,E):(v=$e(),v.c(),v.m(r,null)):v&&(v.d(1),v=null),h[8]||h[5]===g.EXPIRED?k?k.p(h,E):(k=Ee(h),k.c(),k.m(e,N)):k&&(k.d(1),k=null),h[9].footer&&h[1]!==!0?$?$.p(h,E):($=xe(h),$.c(),$.m(e,null)):$&&($.d(1),$=null),E[0]&32&&c(e,"data-state",h[5])},i:L,o:L,d(h){h&&R(e),_&&_.d(),y.d(),v&&v.d(),k&&k.d(),$&&$.d(),t[27](null),A=!1,K(S)}}}const Ce="https://altcha.org/";function Le(t){return JSON.parse(t)}function pt(t,e,r){let i,o,l,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:a=void 0}=e,{debug:f=!1}=e,{expire:p=void 0}=e,{hidefooter:m=!1}=e,{hidelogo:N=!1}=e,{name:A="altcha"}=e,{maxnumber:S=1e6}=e,{mockerror:_=!1}=e,{refetchonexpire:O=!0}=e,{strings:Z=void 0}=e,{test:y=!1}=e,{workers:v=navigator.hardwareConcurrency||8}=e;const k=Xe(),$=["SHA-256","SHA-384","SHA-512"];let h=!1,E,T=null,ue=null,Y=null,H=g.UNVERIFIED,fe;Ue(()=>{T&&(T.removeEventListener("submit",Ie),T.removeEventListener("reset",Ne),T=null)}),Ye(()=>{C("mounted","0.2.3"),C("workers",v),y&&C("using test mode"),p&&ae(p),s!==void 0&&C("auto",s),T=E.closest("form"),T&&(T.addEventListener("submit",Ie),T.addEventListener("reset",Ne)),s==="onload"&&U()});function C(...n){(f||n.some(d=>d instanceof Error))&&console[n[0]instanceof Error?"error":"log"]("ALTCHA",...n)}function Ie(n){T&&s==="onsubmit"&&H===g.UNVERIFIED&&(n.preventDefault(),n.stopPropagation(),U().then(()=>{T==null||T.requestSubmit()}))}function Ne(){q()}function yt(n,d){return btoa(JSON.stringify({algorithm:n.algorithm,challenge:n.challenge,number:d.number,salt:n.salt,signature:n.signature,test:y?!0:void 0,took:d.took}))}function Te(n){if(!n.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(n.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!$.includes(n.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${$.join(", ")}`);if(!n.challenge||n.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!n.salt||n.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function kt(){if(_)throw C("mocking error"),new Error("Mocked error.");if(i)return C("using provided json data"),i;if(y)return C("generating test challenge"),at();{if(!u)throw new Error("Attribute challengeurl not set.");C("fetching challenge from",u);const n=await fetch(u);if(n.status!==200)throw new Error(`Server responded with ${n.status}.`);const d=n.headers.get("Expires");if(!p&&(d!=null&&d.length)){const X=Date.parse(d);if(X){const ee=X-Date.now();ee>0&&ae(ee)}}return n.json()}}function Me(){u&&O&&H===g.VERIFIED?U():q(g.EXPIRED,l.expired)}async function $t(n){let d=null;if("Worker"in window){try{d=await Et(n.challenge,n.salt,n.algorithm,n.maxnumber)}catch(X){C(X)}if((d==null?void 0:d.number)!==void 0)return{data:n,solution:d}}return{data:n,solution:await ht(n.challenge,n.salt,n.algorithm,n.maxnumber||S).promise}}async function Et(n,d,X,ee=S,te=Math.ceil(v)){const re=[];if(te<1)throw new Error("Wrong number of workers configured.");if(te>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let G=0;G<te;G++)re.push(new ct);const Se=Math.ceil(ee/te),Nt=await Promise.all(re.map((G,Tt)=>{const Ae=Tt*Se;return new Promise(Mt=>{G.addEventListener("message",Ge=>{if(Ge.data)for(const je of re)je!==G&&je.postMessage({type:"abort"});Mt(Ge.data)}),G.postMessage({payload:{alg:X,challenge:n,max:Ae+Se,salt:d,start:Ae},type:"work"})})}));for(const G of re)G.terminate();return Nt.find(G=>!!G)||null}function xt(){[g.UNVERIFIED,g.ERROR,g.EXPIRED].includes(H)?U():r(6,h=!0)}function Ct(){H===g.VERIFYING&&alert(l.waitAlert)}function ae(n){C("expire",n),clearTimeout(fe),n<1?Me():fe=setTimeout(Me,n)}function Lt(n){n.auto!==void 0&&(r(0,s=n.auto),s==="onload"&&U()),n.expire!==void 0&&(ae(n.expire),r(13,p=n.expire)),n.challenge&&(Te(n.challenge),i=n.challenge),n.debug!==void 0&&r(12,f=!!n.debug),n.hidefooter!==void 0&&r(1,m=!!n.hidefooter),n.hidelogo!==void 0&&r(2,N=!!n.hidelogo),n.maxnumber!==void 0&&r(14,S=+n.maxnumber),n.mockerror!==void 0&&r(15,_=!!n.mockerror),n.name!==void 0&&r(3,A=n.name),n.refetchonexpire!==void 0&&r(16,O=!!n.refetchonexpire),n.strings&&r(25,o=n.strings),n.test!==void 0&&r(17,y=!!n.test),n.workers!==void 0&&r(18,v=+n.workers)}function q(n=g.UNVERIFIED,d=null){clearTimeout(fe),r(6,h=!1),r(8,ue=d),r(4,Y=null),r(5,H=n)}async function U(){return q(g.VERIFYING),kt().then(n=>(Te(n),C("challenge",n),$t(n))).then(({data:n,solution:d})=>{if(C("solution",d),(d==null?void 0:d.number)!==void 0)C("verified"),r(5,H=g.VERIFIED),r(6,h=!0),r(4,Y=yt(n,d)),C("payload",Y),Ke().then(()=>{k("verified",{payload:Y})});else throw C("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."),new Error("Unexpected result returned.")}).catch(n=>{C(n),r(5,H=g.ERROR),r(6,h=!1),r(8,ue=n.message)})}function Rt(){h=this.checked,r(6,h)}function It(n){oe[n?"unshift":"push"](()=>{E=n,r(7,E)})}return t.$$set=n=>{"auto"in n&&r(0,s=n.auto),"challengeurl"in n&&r(19,u=n.challengeurl),"challengejson"in n&&r(20,a=n.challengejson),"debug"in n&&r(12,f=n.debug),"expire"in n&&r(13,p=n.expire),"hidefooter"in n&&r(1,m=n.hidefooter),"hidelogo"in n&&r(2,N=n.hidelogo),"name"in n&&r(3,A=n.name),"maxnumber"in n&&r(14,S=n.maxnumber),"mockerror"in n&&r(15,_=n.mockerror),"refetchonexpire"in n&&r(16,O=n.refetchonexpire),"strings"in n&&r(21,Z=n.strings),"test"in n&&r(17,y=n.test),"workers"in n&&r(18,v=n.workers)},t.$$.update=()=>{t.$$.dirty[0]&1048576&&(i=a?Le(a):void 0),t.$$.dirty[0]&2097152&&r(25,o=Z?Le(Z):{}),t.$$.dirty[0]&33554432&&r(9,l={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by <a href="${Ce}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...o}),t.$$.dirty[0]&48&&k("statechange",{payload:Y,state:H})},[s,m,N,A,Y,H,h,E,ue,l,xt,Ct,f,p,S,_,O,y,v,u,a,Z,Lt,q,U,o,Rt,It]}class Re extends ot{constructor(e){super(),nt(this,e,pt,_t,Ve,{auto:0,challengeurl:19,challengejson:20,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,refetchonexpire:16,strings:21,test:17,workers:18,configure:22,reset:23,verify:24},dt,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),x()}get challengeurl(){return this.$$.ctx[19]}set challengeurl(e){this.$$set({challengeurl:e}),x()}get challengejson(){return this.$$.ctx[20]}set challengejson(e){this.$$set({challengejson:e}),x()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),x()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),x()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),x()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),x()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),x()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),x()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),x()}get refetchonexpire(){return this.$$.ctx[16]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),x()}get strings(){return this.$$.ctx[21]}set strings(e){this.$$set({strings:e}),x()}get test(){return this.$$.ctx[17]}set test(e){this.$$set({test:e}),x()}get workers(){return this.$$.ctx[18]}set workers(e){this.$$set({workers:e}),x()}get configure(){return this.$$.ctx[22]}get reset(){return this.$$.ctx[23]}get verify(){return this.$$.ctx[24]}}return customElements.define("altcha-widget",it(Re,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),j.Altcha=Re,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"}),j}({});
|