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