diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b6d6c53 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,19 @@ +name: ci +on: + push: + branches: [main, next] + pull_request: + branches: ['*'] + +jobs: + tests: + name: 'Tests' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-node@v4 + with: + bun-version: 20.x + - run: npm install + - run: npm run test + - run: npm run test:e2e diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..ad49029 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,2 @@ +npm run build +git add dist diff --git a/README.md b/README.md index 239f7fb..56a1fd4 100644 --- a/README.md +++ b/README.md @@ -60,11 +60,13 @@ Required options (at least one is required): Additional options: - __auto__ - Automatically verify without user interaction (possible values: `onload`, `onsubmit`). +- __expire__ - The challenge expiration (duration in milliseconds). - __hidefooter__ - Hide the footer (ALTCHA link). - __hidelogo__ - Hide the ALTCHA logo. -- __maxnumber__ - The max. number to iterate to (defaults to 10,000,000). +- __maxnumber__ - The max. number to iterate to (defaults to 1,000,000). - __name__ - The name of the hidden field containing the payload (defaults to "altcha"). - __strings__ - JSON-encoded translation strings. Refer to [customization](/docs/widget-customization). +- __workers__ - The number of workers to utilize for PoW (defaults to `navigator.hardwareConcurrency || 8`). Development / testing options: @@ -102,6 +104,7 @@ export interface Configure { signature: string; }; debug?: boolean; + expire?: number; hidefooter?: boolean; hidelogo?: boolean; maxnumber?: number; @@ -116,6 +119,7 @@ export interface Configure { waitAlert?: string; }; test?: boolean; + workers?: number; } ``` @@ -124,11 +128,21 @@ export interface Configure { - __statechange__ - Triggers whenever an internal `state` changes. - __verified__ - Triggers when the challenge is verified. +```ts +enum State { + ERROR = 'error', + VERIFIED = 'verified', + VERIFYING = 'verifying', + UNVERIFIED = 'unverified', + EXPIRED = 'expired', +}; +``` + Using events: ```js document.querySelector('#altcha').addEventListener('statechange', (ev) => { - // state can be: unverified, verifying, verified, error + // See enum State above console.log('state:', ev.detail.state); }); ``` diff --git a/dist/altcha.iife.js b/dist/altcha.iife.js index 0b7eb62..1a1db87 100644 --- a/dist/altcha.iife.js +++ b/dist/altcha.iife.js @@ -1 +1 @@ -var altcha=function(G){"use strict";var jt=Object.defineProperty;var At=(G,x,H)=>x in G?jt(G,x,{enumerable:!0,configurable:!0,writable:!0,value:H}):G[x]=H;var j=(G,x,H)=>(At(G,typeof x!="symbol"?x+"":x,H),H);function x(){}function H(t){return t()}function ae(){return Object.create(null)}function B(t){t.forEach(H)}function fe(t){return typeof t=="function"}function Te(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ge(t){return Object.keys(t).length===0}function v(t,e){t.appendChild(e)}function Ve(t,e,n){const r=Ze(t);if(!r.getElementById(e)){const l=_("style");l.id=e,l.textContent=n,He(r,l)}}function Ze(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function He(t,e){return v(t.head||t,e),e.sheet}function I(t,e,n){t.insertBefore(e,n||null)}function C(t){t.parentNode&&t.parentNode.removeChild(t)}function _(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Oe(t){return document.createTextNode(t)}function O(){return Oe(" ")}function ee(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 Fe(t){return Array.from(t.childNodes)}function he(t,e,n){t.classList.toggle(e,!!n)}function Pe(t,e,{bubbles:n=!1,cancelable:r=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:r})}function Ue(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let W;function J(t){W=t}function te(){if(!W)throw new Error("Function called outside component initialization");return W}function De(t){te().$$.on_mount.push(t)}function Xe(t){te().$$.on_destroy.push(t)}function Ye(){const t=te();return(e,n,{cancelable:r=!1}={})=>{const l=t.$$.callbacks[e];if(l){const o=Pe(e,n,{cancelable:r});return l.slice().forEach(s=>{s.call(t,o)}),!o.defaultPrevented}return!0}}const P=[],ne=[];let U=[];const de=[],ge=Promise.resolve();let re=!1;function be(){re||(re=!0,ge.then(E))}function Ke(){return be(),ge}function ie(t){U.push(t)}const le=new Set;let D=0;function E(){if(D!==0)return;const t=W;do{try{for(;D
{const Ae=Rt*je;return new Promise(Nt=>{S.addEventListener("message",Me=>{if(Me.data)for(const Te of ee)Te!==S&&Te.postMessage({type:"abort"});Nt(Me.data)}),S.postMessage({payload:{alg:K,challenge:i,max:Ae+je,salt:g,start:Ae},type:"work"})})}));for(const S of ee)S.terminate();return It.find(S=>!!S)||null}function $t(){[b.UNVERIFIED,b.ERROR,b.EXPIRED].includes(Z)?Y():r(6,m=!0)}function Et(){Z===b.VERIFYING&&alert(l.waitAlert)}function ue(i){console.log(">>>"),C("expire",i),clearTimeout(ce),i<1?Ne():ce=setTimeout(Ne,i)}function xt(i){i.auto!==void 0&&(r(0,s=i.auto),s==="onload"&&Y()),i.expire!==void 0&&(ue(i.expire),r(13,$=i.expire)),i.challenge&&(Re(i.challenge),n=i.challenge),i.debug!==void 0&&r(12,a=!!i.debug),i.hidefooter!==void 0&&r(1,w=!!i.hidefooter),i.hidelogo!==void 0&&r(2,N=!!i.hidelogo),i.maxnumber!==void 0&&r(14,A=+i.maxnumber),i.mockerror!==void 0&&r(15,p=!!i.mockerror),i.name!==void 0&&r(3,T=i.name),i.test!==void 0&&r(16,M=!!i.test),i.strings&&r(24,o=i.strings),i.workers!==void 0&&r(17,E=+i.workers)}function z(i=b.UNVERIFIED,g=null){clearTimeout(ce),r(6,m=!1),r(8,se=g),r(4,X=null),r(5,Z=i)}async function Y(){return z(b.VERIFYING),pt().then(i=>(Re(i),C("challenge",i),kt(i))).then(({data:i,solution:g})=>{if(C("solution",g),(g==null?void 0:g.number)!==void 0)C("verified"),r(5,Z=b.VERIFIED),r(6,m=!0),r(4,X=_t(i,g)),C("payload",X),Ke().then(()=>{k("verified",{payload:X})});else throw new Error("Unexpected result returned.")}).catch(i=>{C(i),r(5,Z=b.ERROR),r(6,m=!1),r(8,se=i.message)})}function Ct(){m=this.checked,r(6,m)}function Lt(i){ne[i?"unshift":"push"](()=>{h=i,r(7,h)})}return t.$$set=i=>{"auto"in i&&r(0,s=i.auto),"challengeurl"in i&&r(18,u=i.challengeurl),"challengejson"in i&&r(19,f=i.challengejson),"debug"in i&&r(12,a=i.debug),"expire"in i&&r(13,$=i.expire),"hidefooter"in i&&r(1,w=i.hidefooter),"hidelogo"in i&&r(2,N=i.hidelogo),"name"in i&&r(3,T=i.name),"maxnumber"in i&&r(14,A=i.maxnumber),"mockerror"in i&&r(15,p=i.mockerror),"strings"in i&&r(20,F=i.strings),"test"in i&&r(16,M=i.test),"workers"in i&&r(17,E=i.workers)},t.$$.update=()=>{t.$$.dirty[0]&524288&&(n=f?xe(f):void 0),t.$$.dirty[0]&1048576&&r(24,o=F?xe(F):{}),t.$$.dirty[0]&16777216&&r(9,l={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...o}),t.$$.dirty[0]&48&&k("statechange",{payload:X,state:Z})},[s,w,N,T,X,Z,m,h,se,l,$t,Et,a,$,A,p,M,E,u,f,F,xt,z,Y,o,Ct,Lt]}class Ce extends nt{constructor(e){super(),tt(this,e,wt,vt,Se,{auto:0,challengeurl:18,challengejson:19,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,strings:20,test:16,workers:17,configure:21,reset:22,verify:23},ft,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),x()}get challengeurl(){return this.$$.ctx[18]}set challengeurl(e){this.$$set({challengeurl:e}),x()}get challengejson(){return this.$$.ctx[19]}set challengejson(e){this.$$set({challengejson:e}),x()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),x()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),x()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),x()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),x()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),x()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),x()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),x()}get strings(){return this.$$.ctx[20]}set strings(e){this.$$set({strings:e}),x()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),x()}get workers(){return this.$$.ctx[17]}set workers(e){this.$$set({workers:e}),x()}get configure(){return this.$$.ctx[21]}get reset(){return this.$$.ctx[22]}get verify(){return this.$$.ctx[23]}}return customElements.define("altcha-widget",rt(Ce,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),G.Altcha=Ce,Object.defineProperty(G,Symbol.toStringTag,{value:"Module"}),G}({}); diff --git a/dist/altcha.js b/dist/altcha.js index 85447fa..5e51db1 100644 --- a/dist/altcha.js +++ b/dist/altcha.js @@ -1,6 +1,6 @@ var Xe = Object.defineProperty; -var Ye = (t, e, n) => e in t ? Xe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; -var N = (t, e, n) => (Ye(t, typeof e != "symbol" ? e + "" : e, n), n); +var Ye = (t, e, r) => e in t ? Xe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r; +var N = (t, e, r) => (Ye(t, typeof e != "symbol" ? e + "" : e, r), r); function X() { } function xe(t) { @@ -24,11 +24,11 @@ function Be(t) { function v(t, e) { t.appendChild(e); } -function We(t, e, n) { - const r = Je(t); - if (!r.getElementById(e)) { - const l = p("style"); - l.id = e, l.textContent = n, Qe(r, l); +function We(t, e, r) { + const n = Je(t); + if (!n.getElementById(e)) { + const o = p("style"); + o.id = e, o.textContent = r, Qe(n, o); } } function Je(t) { @@ -48,10 +48,10 @@ function Qe(t, e) { e ), e.sheet; } -function I(t, e, n) { - t.insertBefore(e, n || null); +function I(t, e, r) { + t.insertBefore(e, r || null); } -function C(t) { +function L(t) { t.parentNode && t.parentNode.removeChild(t); } function p(t) { @@ -66,27 +66,27 @@ function ze(t) { function Z() { return ze(" "); } -function ne(t, e, n, r) { - return t.addEventListener(e, n, r), () => t.removeEventListener(e, n, r); +function re(t, e, r, n) { + return t.addEventListener(e, r, n), () => t.removeEventListener(e, r, n); } -function c(t, e, n) { - n == null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n); +function c(t, e, r) { + r == null ? t.removeAttribute(e) : t.getAttribute(e) !== r && t.setAttribute(e, r); } function qe(t) { return Array.from(t.childNodes); } -function ve(t, e, n) { - t.classList.toggle(e, !!n); +function ve(t, e, r) { + t.classList.toggle(e, !!r); } -function et(t, e, { bubbles: n = !1, cancelable: r = !1 } = {}) { - return new CustomEvent(t, { detail: e, bubbles: n, cancelable: r }); +function et(t, e, { bubbles: r = !1, cancelable: n = !1 } = {}) { + return new CustomEvent(t, { detail: e, bubbles: r, cancelable: n }); } function tt(t) { const e = {}; return t.childNodes.forEach( /** @param {Element} node */ - (n) => { - e[n.slot || "default"] = !0; + (r) => { + e[r.slot || "default"] = !0; } ), e; } @@ -99,26 +99,26 @@ function se() { throw new Error("Function called outside component initialization"); return K; } -function nt(t) { +function rt(t) { se().$$.on_mount.push(t); } -function rt(t) { +function nt(t) { se().$$.on_destroy.push(t); } function it() { const t = se(); - return (e, n, { cancelable: r = !1 } = {}) => { - const l = t.$$.callbacks[e]; - if (l) { - const o = et( + return (e, r, { cancelable: n = !1 } = {}) => { + const o = t.$$.callbacks[e]; + if (o) { + const l = et( /** @type {string} */ e, - n, - { cancelable: r } + r, + { cancelable: n } ); - return l.slice().forEach((s) => { - s.call(t, o); - }), !o.defaultPrevented; + return o.slice().forEach((s) => { + s.call(t, l); + }), !l.defaultPrevented; } return !0; }; @@ -126,19 +126,19 @@ function it() { const D = [], ie = []; let P = []; const we = [], Le = /* @__PURE__ */ Promise.resolve(); -let le = !1; +let oe = !1; function Ie() { - le || (le = !0, Le.then(E)); + oe || (oe = !0, Le.then(C)); } -function lt() { +function ot() { return Ie(), Le; } -function oe(t) { +function le(t) { P.push(t); } -const re = /* @__PURE__ */ new Set(); +const ne = /* @__PURE__ */ new Set(); let U = 0; -function E() { +function C() { if (U !== 0) return; const t = K; @@ -146,7 +146,7 @@ function E() { try { for (; U < D.length; ) { const e = D[U]; - U++, Y(e), ot(e.$$); + U++, Y(e), lt(e.$$); } } catch (e) { throw D.length = 0, U = 0, e; @@ -154,54 +154,54 @@ function E() { for (Y(null), D.length = 0, U = 0; ie.length; ) ie.pop()(); for (let e = 0; e < P.length; e += 1) { - const n = P[e]; - re.has(n) || (re.add(n), n()); + const r = P[e]; + ne.has(r) || (ne.add(r), r()); } P.length = 0; } while (D.length); for (; we.length; ) we.pop()(); - le = !1, re.clear(), Y(t); + oe = !1, ne.clear(), Y(t); } -function ot(t) { +function lt(t) { if (t.fragment !== null) { t.update(), B(t.before_update); const e = t.dirty; - t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(oe); + t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(le); } } function st(t) { - const e = [], n = []; - P.forEach((r) => t.indexOf(r) === -1 ? e.push(r) : n.push(r)), n.forEach((r) => r()), P = e; + const e = [], r = []; + P.forEach((n) => t.indexOf(n) === -1 ? e.push(n) : r.push(n)), r.forEach((n) => n()), P = e; } const ct = /* @__PURE__ */ new Set(); function ut(t, e) { t && t.i && (ct.delete(t), t.i(e)); } -function at(t, e, n) { - const { fragment: r, after_update: l } = t.$$; - r && r.m(e, n), oe(() => { - const o = t.$$.on_mount.map(xe).filter(Ce); - t.$$.on_destroy ? t.$$.on_destroy.push(...o) : B(o), t.$$.on_mount = []; - }), l.forEach(oe); +function at(t, e, r) { + const { fragment: n, after_update: o } = t.$$; + n && n.m(e, r), le(() => { + const l = t.$$.on_mount.map(xe).filter(Ce); + t.$$.on_destroy ? t.$$.on_destroy.push(...l) : B(l), t.$$.on_mount = []; + }), o.forEach(le); } function ft(t, e) { - const n = t.$$; - n.fragment !== null && (st(n.after_update), B(n.on_destroy), n.fragment && n.fragment.d(e), n.on_destroy = n.fragment = null, n.ctx = []); + const r = t.$$; + r.fragment !== null && (st(r.after_update), B(r.on_destroy), r.fragment && r.fragment.d(e), r.on_destroy = r.fragment = null, r.ctx = []); } function ht(t, e) { t.$$.dirty[0] === -1 && (D.push(t), Ie(), t.$$.dirty.fill(0)), t.$$.dirty[e / 31 | 0] |= 1 << e % 31; } -function dt(t, e, n, r, l, o, s = null, u = [-1]) { +function dt(t, e, r, n, o, l, s = null, u = [-1]) { const f = K; Y(t); const a = t.$$ = { fragment: null, ctx: [], // state - props: o, + props: l, update: X, - not_equal: l, + not_equal: o, bound: me(), // lifecycle on_mount: [], @@ -217,23 +217,23 @@ function dt(t, e, n, r, l, o, s = null, u = [-1]) { root: e.target || f.$$.root }; s && s(a.root); - let k = !1; - if (a.ctx = n ? n(t, e.props || {}, (w, R, ...M) => { + let y = !1; + if (a.ctx = r ? r(t, e.props || {}, (w, R, ...M) => { const j = M.length ? M[0] : R; - return a.ctx && l(a.ctx[w], a.ctx[w] = j) && (!a.skip_bound && a.bound[w] && a.bound[w](j), k && ht(t, w)), R; - }) : [], a.update(), k = !0, B(a.before_update), a.fragment = r ? r(a.ctx) : !1, e.target) { + return a.ctx && o(a.ctx[w], a.ctx[w] = j) && (!a.skip_bound && a.bound[w] && a.bound[w](j), y && ht(t, w)), R; + }) : [], a.update(), y = !0, B(a.before_update), a.fragment = n ? n(a.ctx) : !1, e.target) { if (e.hydrate) { const w = qe(e.target); - a.fragment && a.fragment.l(w), w.forEach(C); + a.fragment && a.fragment.l(w), w.forEach(L); } else a.fragment && a.fragment.c(); - e.intro && ut(t.$$.fragment), at(t, e.target, e.anchor), E(); + e.intro && ut(t.$$.fragment), at(t, e.target, e.anchor), C(); } Y(f); } let Re; typeof HTMLElement == "function" && (Re = class extends HTMLElement { - constructor(e, n, r) { + constructor(e, r, n) { super(); /** The Svelte component constructor */ N(this, "$$ctor"); @@ -253,82 +253,82 @@ typeof HTMLElement == "function" && (Re = class extends HTMLElement { N(this, "$$l", {}); /** @type {Map} Event listener unsubscribe functions */ N(this, "$$l_u", /* @__PURE__ */ new Map()); - this.$$ctor = e, this.$$s = n, r && this.attachShadow({ mode: "open" }); + this.$$ctor = e, this.$$s = r, n && 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); + 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, n, r); + super.addEventListener(e, r, n); } - 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)); + 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(o) { + let e = function(l) { return () => { let s; return { c: function() { - s = p("slot"), o !== "default" && c(s, "name", o); + s = p("slot"), l !== "default" && c(s, "name", l); }, /** * @param {HTMLElement} target * @param {HTMLElement} [anchor] */ - m: function(a, k) { - I(a, s, k); + m: function(a, y) { + I(a, s, y); }, d: function(a) { - a && C(s); + a && L(s); } }; }; }; if (await Promise.resolve(), !this.$$cn || this.$$c) return; - const n = {}, r = tt(this); - for (const o of this.$$s) - o in r && (n[o] = [e(o)]); - for (const o of this.attributes) { - const s = this.$$g_p(o.name); - s in this.$$d || (this.$$d[s] = Q(s, o.value, this.$$p_d, "toProp")); + const r = {}, n = tt(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] = z(s, l.value, this.$$p_d, "toProp")); } - for (const o in this.$$p_d) - !(o in this.$$d) && this[o] !== void 0 && (this.$$d[o] = this[o], delete this[o]); + 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: n, + $$slots: r, $$scope: { ctx: [] } } }); - const l = () => { + const o = () => { this.$$r = !0; - for (const o in this.$$p_d) - if (this.$$d[o] = this.$$c.$$.ctx[this.$$c.$$.props[o]], this.$$p_d[o].reflect) { - const s = Q( - o, - this.$$d[o], + 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 = z( + l, + this.$$d[l], this.$$p_d, "toAttribute" ); - s == null ? this.removeAttribute(this.$$p_d[o].attribute || o) : this.setAttribute(this.$$p_d[o].attribute || o, s); + 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(l), l(); - for (const o in this.$$l) - for (const s of this.$$l[o]) { - const u = this.$$c.$on(o, s); + 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 = {}; @@ -336,9 +336,9 @@ typeof HTMLElement == "function" && (Re = class extends HTMLElement { } // We don't need this when working within Svelte code, but for compatibility of people using this outside of Svelte // and setting attributes through setAttribute etc, this is helpful - attributeChangedCallback(e, n, r) { - var l; - this.$$r || (e = this.$$g_p(e), this.$$d[e] = Q(e, r, this.$$p_d, "toProp"), (l = this.$$c) == null || l.$set({ [e]: this.$$d[e] })); + attributeChangedCallback(e, r, n) { + var o; + this.$$r || (e = this.$$g_p(e), this.$$d[e] = z(e, n, this.$$p_d, "toProp"), (o = this.$$c) == null || o.$set({ [e]: this.$$d[e] })); } disconnectedCallback() { this.$$cn = !1, Promise.resolve().then(() => { @@ -347,17 +347,17 @@ typeof HTMLElement == "function" && (Re = class extends HTMLElement { } $$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 + (r) => this.$$p_d[r].attribute === e || !this.$$p_d[r].attribute && r.toLowerCase() === e ) || e; } }); -function Q(t, e, n, r) { - var o; - const l = (o = n[t]) == null ? void 0 : o.type; - if (e = l === "Boolean" && typeof e != "boolean" ? e != null : e, !r || !n[t]) +function z(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 (r === "toAttribute") - switch (l) { + if (n === "toAttribute") + switch (o) { case "Object": case "Array": return e == null ? null : JSON.stringify(e); @@ -369,7 +369,7 @@ function Q(t, e, n, r) { return e; } else - switch (l) { + switch (o) { case "Object": case "Array": return e && JSON.parse(e); @@ -381,10 +381,10 @@ function Q(t, e, n, r) { return e; } } -function gt(t, e, n, r, l, o) { +function gt(t, e, r, n, o, l) { let s = class extends Re { constructor() { - super(t, n, l), this.$$p_d = e; + super(t, r, o), this.$$p_d = e; } static get observedAttributes() { return Object.keys(e).map( @@ -399,17 +399,17 @@ function gt(t, e, n, r, l, o) { }, set(f) { var a; - f = Q(u, f, e), this.$$d[u] = f, (a = this.$$c) == null || a.$set({ [u]: f }); + f = z(u, f, e), this.$$d[u] = f, (a = this.$$c) == null || a.$set({ [u]: f }); } }); - }), r.forEach((u) => { + }), n.forEach((u) => { Object.defineProperty(s.prototype, u, { get() { var f; return (f = this.$$c) == null ? void 0 : f[u]; } }); - }), o && (s = o(s)), t.element = /** @type {any} */ + }), l && (s = l(s)), t.element = /** @type {any} */ s, s; } class bt { @@ -441,13 +441,13 @@ class bt { * @param {((e: Events[K]) => void) | null | undefined} callback * @returns {() => void} */ - $on(e, n) { - if (!Ce(n)) + $on(e, r) { + if (!Ce(r)) return X; - const r = this.$$.callbacks[e] || (this.$$.callbacks[e] = []); - return r.push(n), () => { - const l = r.indexOf(n); - l !== -1 && r.splice(l, 1); + const n = this.$$.callbacks[e] || (this.$$.callbacks[e] = []); + return n.push(r), () => { + const o = n.indexOf(r); + o !== -1 && n.splice(o, 1); }; } /** @@ -466,12 +466,12 @@ function wt(t) { try { if (e = _e && (window.URL || window.webkitURL).createObjectURL(_e), !e) throw ""; - const n = new Worker(e, { + const r = new Worker(e, { name: t == null ? void 0 : t.name }); - return n.addEventListener("error", () => { + return r.addEventListener("error", () => { (window.URL || window.webkitURL).revokeObjectURL(e); - }), n; + }), r; } catch { return new Worker( "data:text/javascript;base64," + Ne, @@ -487,80 +487,82 @@ const _t = new TextEncoder(); function pt(t) { return [...new Uint8Array(t)].map((e) => e.toString(16).padStart(2, "0")).join(""); } -async function $t(t = 1e5, e = "SHA-256") { - const n = Date.now().toString(16), r = Math.round(Math.random() * t), l = await je(n, r, e); +async function kt(t, e = "SHA-256", r = 1e5) { + const n = Date.now().toString(16); + t || (t = Math.round(Math.random() * r)); + const o = await je(n, t, e); return { algorithm: e, - challenge: l, + challenge: o, salt: n, signature: "" }; } -async function je(t, e, n) { - return pt(await crypto.subtle.digest(n.toUpperCase(), _t.encode(t + e))); +async function je(t, e, r) { + return pt(await crypto.subtle.digest(r.toUpperCase(), _t.encode(t + e))); } -function yt(t, e, n = "SHA-256", r = 1e6, l = 0) { - const o = new AbortController(); +function $t(t, e, r = "SHA-256", n = 1e6, o = 0) { + const l = new AbortController(); return { promise: new Promise((u, f) => { - const a = Date.now(), k = (w) => { - o.signal.aborted || w >= r ? u(null) : je(e, w, n).then((R) => { + const a = Date.now(), y = (w) => { + l.signal.aborted || w >= n ? u(null) : je(e, w, r).then((R) => { R === t ? u({ number: w, took: Date.now() - a - }) : k(w + 1); + }) : y(w + 1); }).catch(f); }; - k(l); + y(o); }), - controller: o + controller: l }; } var m = /* @__PURE__ */ ((t) => (t.ERROR = "error", t.VERIFIED = "verified", t.VERIFYING = "verifying", t.UNVERIFIED = "unverified", t.EXPIRED = "expired", t))(m || {}); -function kt(t) { +function yt(t) { We(t, "svelte-vuofbg", ".altcha.svelte-vuofbg.svelte-vuofbg{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-vuofbg.svelte-vuofbg{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}"); } function pe(t) { - let e, n, r; + let e, r, n; return { c() { - e = S("svg"), n = S("path"), r = S("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-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"); + e = S("svg"), r = S("path"), n = S("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(l, o) { - I(l, e, o), v(e, n), v(e, r); + m(o, l) { + I(o, e, l), v(e, r), v(e, n); }, - d(l) { - l && C(e); + d(o) { + o && L(e); } }; } function Et(t) { - let e, n = ( + let e, r = ( /*_strings*/ t[9].label + "" - ), r; + ), n; return { c() { - e = p("label"), c(e, "for", r = /*name*/ + e = p("label"), c(e, "for", n = /*name*/ t[3] + "_checkbox"), c(e, "class", "svelte-vuofbg"); }, - m(l, o) { - I(l, e, o), e.innerHTML = n; + m(o, l) { + I(o, e, l), e.innerHTML = r; }, - p(l, o) { - o[0] & /*_strings*/ - 512 && n !== (n = /*_strings*/ - l[9].label + "") && (e.innerHTML = n), o[0] & /*name*/ - 8 && r !== (r = /*name*/ - l[3] + "_checkbox") && c(e, "for", r); + p(o, l) { + l[0] & /*_strings*/ + 512 && r !== (r = /*_strings*/ + o[9].label + "") && (e.innerHTML = r), l[0] & /*name*/ + 8 && n !== (n = /*name*/ + o[3] + "_checkbox") && c(e, "for", n); }, - d(l) { - l && C(e); + d(o) { + o && L(e); } }; } function xt(t) { - let e, n = ( + let e, r = ( /*_strings*/ t[9].verifying + "" ); @@ -568,96 +570,96 @@ function xt(t) { c() { e = p("span"); }, - m(r, l) { - I(r, e, l), e.innerHTML = n; + m(n, o) { + I(n, e, o), e.innerHTML = r; }, - p(r, l) { - l[0] & /*_strings*/ - 512 && n !== (n = /*_strings*/ - r[9].verifying + "") && (e.innerHTML = n); + p(n, o) { + o[0] & /*_strings*/ + 512 && r !== (r = /*_strings*/ + n[9].verifying + "") && (e.innerHTML = r); }, - d(r) { - r && C(e); + d(n) { + n && L(e); } }; } function Ct(t) { - let e, n = ( + let e, r = ( /*_strings*/ t[9].verified + "" - ), r, l; + ), n, o; return { c() { - e = p("span"), r = Z(), l = p("input"), c(l, "type", "hidden"), c( - l, + e = p("span"), n = Z(), o = p("input"), c(o, "type", "hidden"), c( + o, "name", /*name*/ t[3] - ), l.value = /*payload*/ + ), o.value = /*payload*/ t[4]; }, - m(o, s) { - I(o, e, s), e.innerHTML = n, I(o, r, s), I(o, l, s); + m(l, s) { + I(l, e, s), e.innerHTML = r, I(l, n, s), I(l, o, s); }, - p(o, s) { + p(l, s) { s[0] & /*_strings*/ - 512 && n !== (n = /*_strings*/ - o[9].verified + "") && (e.innerHTML = n), s[0] & /*name*/ + 512 && r !== (r = /*_strings*/ + l[9].verified + "") && (e.innerHTML = r), s[0] & /*name*/ 8 && c( - l, + o, "name", /*name*/ - o[3] + l[3] ), s[0] & /*payload*/ - 16 && (l.value = /*payload*/ - o[4]); + 16 && (o.value = /*payload*/ + l[4]); }, - d(o) { - o && (C(e), C(r), C(l)); + d(l) { + l && (L(e), L(n), L(o)); } }; } -function $e(t) { - let e, n, r, l, o, s; +function ke(t) { + let e, r, n, o, l, s; return { c() { - e = p("div"), n = p("a"), r = S("svg"), l = S("path"), o = S("path"), s = S("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(o, "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(o, "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", Ae), c(n, "target", "_blank"), c(n, "class", "altcha-logo svelte-vuofbg"); + e = p("div"), r = p("a"), n = S("svg"), o = S("path"), l = S("path"), s = S("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", Ae), c(r, "target", "_blank"), c(r, "class", "altcha-logo svelte-vuofbg"); }, m(u, f) { - I(u, e, f), v(e, n), v(n, r), v(r, l), v(r, o), v(r, s); + I(u, e, f), v(e, r), v(r, n), v(n, o), v(n, l), v(n, s); }, p: X, d(u) { - u && C(e); + u && L(e); } }; } -function ye(t) { - let e, n, r, l; - function o(f, a) { +function $e(t) { + let e, r, n, o; + function l(f, a) { return ( /*state*/ f[5] === m.EXPIRED ? It : Lt ); } - let s = o(t), u = s(t); + let s = l(t), u = s(t); return { c() { - e = p("div"), n = S("svg"), r = S("path"), l = Z(), u.c(), 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(e, "class", "altcha-error svelte-vuofbg"); + e = p("div"), r = S("svg"), n = S("path"), o = Z(), u.c(), c(n, "stroke-linecap", "round"), c(n, "stroke-linejoin", "round"), c(n, "d", "M6 18L18 6M6 6l12 12"), c(r, "width", "14"), c(r, "height", "14"), c(r, "xmlns", "http://www.w3.org/2000/svg"), c(r, "fill", "none"), c(r, "viewBox", "0 0 24 24"), c(r, "stroke-width", "1.5"), c(r, "stroke", "currentColor"), c(e, "class", "altcha-error svelte-vuofbg"); }, m(f, a) { - I(f, e, a), v(e, n), v(n, r), v(e, l), u.m(e, null); + I(f, e, a), v(e, r), v(r, n), v(e, o), u.m(e, null); }, p(f, a) { - s === (s = o(f)) && u ? u.p(f, a) : (u.d(1), u = s(f), u && (u.c(), u.m(e, null))); + s === (s = l(f)) && u ? u.p(f, a) : (u.d(1), u = s(f), u && (u.c(), u.m(e, null))); }, d(f) { - f && C(e), u.d(); + f && L(e), u.d(); } }; } function Lt(t) { - let e, n = ( + let e, r = ( /*_strings*/ t[9].error + "" ); @@ -670,27 +672,27 @@ function Lt(t) { t[8] ); }, - m(r, l) { - I(r, e, l), e.innerHTML = n; + m(n, o) { + I(n, e, o), e.innerHTML = r; }, - p(r, l) { - l[0] & /*_strings*/ - 512 && n !== (n = /*_strings*/ - r[9].error + "") && (e.innerHTML = n), l[0] & /*error*/ + p(n, o) { + o[0] & /*_strings*/ + 512 && r !== (r = /*_strings*/ + n[9].error + "") && (e.innerHTML = r), o[0] & /*error*/ 256 && c( e, "title", /*error*/ - r[8] + n[8] ); }, - d(r) { - r && C(e); + d(n) { + n && L(e); } }; } function It(t) { - let e, n = ( + let e, r = ( /*_strings*/ t[9].expired + "" ); @@ -703,49 +705,49 @@ function It(t) { t[8] ); }, - m(r, l) { - I(r, e, l), e.innerHTML = n; + m(n, o) { + I(n, e, o), e.innerHTML = r; }, - p(r, l) { - l[0] & /*_strings*/ - 512 && n !== (n = /*_strings*/ - r[9].expired + "") && (e.innerHTML = n), l[0] & /*error*/ + p(n, o) { + o[0] & /*_strings*/ + 512 && r !== (r = /*_strings*/ + n[9].expired + "") && (e.innerHTML = r), o[0] & /*error*/ 256 && c( e, "title", /*error*/ - r[8] + n[8] ); }, - d(r) { - r && C(e); + d(n) { + n && L(e); } }; } -function ke(t) { - let e, n, r = ( +function ye(t) { + let e, r, n = ( /*_strings*/ t[9].footer + "" ); return { c() { - e = p("div"), n = p("div"), c(n, "class", "svelte-vuofbg"), c(e, "class", "altcha-footer svelte-vuofbg"); + e = p("div"), r = p("div"), c(r, "class", "svelte-vuofbg"), c(e, "class", "altcha-footer svelte-vuofbg"); }, - m(l, o) { - I(l, e, o), v(e, n), n.innerHTML = r; + m(o, l) { + I(o, e, l), v(e, r), r.innerHTML = n; }, - p(l, o) { - o[0] & /*_strings*/ - 512 && r !== (r = /*_strings*/ - l[9].footer + "") && (n.innerHTML = r); + p(o, l) { + l[0] & /*_strings*/ + 512 && n !== (n = /*_strings*/ + o[9].footer + "") && (r.innerHTML = n); }, - d(l) { - l && C(e); + d(o) { + o && L(e); } }; } function Rt(t) { - let e, n, r, l, o, s, u, f, a, k, w, R, M, j, _ = ( + let e, r, n, o, l, s, u, f, a, y, w, R, M, j, _ = ( /*state*/ t[5] === m.VERIFYING && pe() ); @@ -758,28 +760,28 @@ function Rt(t) { ) ); } - let A = V(t), x = A(t), $ = ( + let A = V(t), E = A(t), k = ( /*hidelogo*/ - t[2] !== !0 && $e() - ), y = ( + t[2] !== !0 && ke() + ), $ = ( /*error*/ (t[8] || /*state*/ - t[5] === m.EXPIRED) && ye(t) + t[5] === m.EXPIRED) && $e(t) ), b = ( /*_strings*/ t[9].footer && /*hidefooter*/ - t[1] !== !0 && ke(t) + t[1] !== !0 && ye(t) ); return { c() { - e = p("div"), n = p("div"), _ && _.c(), r = Z(), l = p("div"), o = p("input"), f = Z(), a = p("div"), x.c(), k = Z(), $ && $.c(), w = Z(), y && y.c(), R = Z(), b && b.c(), c(o, "type", "checkbox"), c(o, "id", s = /*name*/ - t[3] + "_checkbox"), o.required = u = /*auto*/ - t[0] !== "onsubmit", c(o, "class", "svelte-vuofbg"), c(l, "class", "altcha-checkbox svelte-vuofbg"), ve( - l, + e = p("div"), r = p("div"), _ && _.c(), n = Z(), o = p("div"), l = p("input"), f = Z(), a = p("div"), E.c(), y = Z(), k && k.c(), w = Z(), $ && $.c(), R = Z(), b && b.c(), c(l, "type", "checkbox"), c(l, "id", s = /*name*/ + t[3] + "_checkbox"), l.required = u = /*auto*/ + t[0] !== "onsubmit", c(l, "class", "svelte-vuofbg"), c(o, "class", "altcha-checkbox svelte-vuofbg"), ve( + o, "altcha-hidden", /*state*/ t[5] === m.VERIFYING - ), c(a, "class", "altcha-label svelte-vuofbg"), c(n, "class", "altcha-main svelte-vuofbg"), c(e, "class", "altcha svelte-vuofbg"), c( + ), c(a, "class", "altcha-label svelte-vuofbg"), c(r, "class", "altcha-main svelte-vuofbg"), c(e, "class", "altcha svelte-vuofbg"), c( e, "data-state", /*state*/ @@ -787,22 +789,22 @@ function Rt(t) { ); }, m(h, d) { - I(h, e, d), v(e, n), _ && _.m(n, null), v(n, r), v(n, l), v(l, o), o.checked = /*checked*/ - t[6], v(n, f), v(n, a), x.m(a, null), v(n, k), $ && $.m(n, null), v(e, w), y && y.m(e, null), v(e, R), b && b.m(e, null), t[26](e), M || (j = [ - ne( - o, + I(h, e, d), v(e, r), _ && _.m(r, null), v(r, n), v(r, o), v(o, l), l.checked = /*checked*/ + t[6], v(r, f), v(r, a), E.m(a, null), v(r, y), k && k.m(r, null), v(e, w), $ && $.m(e, null), v(e, R), b && b.m(e, null), t[26](e), M || (j = [ + re( + l, "change", /*input_change_handler*/ t[25] ), - ne( - o, + re( + l, "change", /*onCheckedChange*/ t[10] ), - ne( - o, + re( + l, "invalid", /*onInvalid*/ t[11] @@ -811,24 +813,24 @@ function Rt(t) { }, p(h, d) { /*state*/ - h[5] === m.VERIFYING ? _ || (_ = pe(), _.c(), _.m(n, r)) : _ && (_.d(1), _ = null), d[0] & /*name*/ + h[5] === m.VERIFYING ? _ || (_ = pe(), _.c(), _.m(r, n)) : _ && (_.d(1), _ = null), d[0] & /*name*/ 8 && s !== (s = /*name*/ - h[3] + "_checkbox") && c(o, "id", s), d[0] & /*auto*/ + h[3] + "_checkbox") && c(l, "id", s), d[0] & /*auto*/ 1 && u !== (u = /*auto*/ - h[0] !== "onsubmit") && (o.required = u), d[0] & /*checked*/ - 64 && (o.checked = /*checked*/ + h[0] !== "onsubmit") && (l.required = u), d[0] & /*checked*/ + 64 && (l.checked = /*checked*/ h[6]), d[0] & /*state*/ 32 && ve( - l, + o, "altcha-hidden", /*state*/ h[5] === m.VERIFYING - ), A === (A = V(h)) && x ? x.p(h, d) : (x.d(1), x = A(h), x && (x.c(), x.m(a, null))), /*hidelogo*/ - h[2] !== !0 ? $ ? $.p(h, d) : ($ = $e(), $.c(), $.m(n, null)) : $ && ($.d(1), $ = null), /*error*/ + ), A === (A = V(h)) && E ? E.p(h, d) : (E.d(1), E = A(h), E && (E.c(), E.m(a, null))), /*hidelogo*/ + h[2] !== !0 ? k ? k.p(h, d) : (k = ke(), k.c(), k.m(r, null)) : k && (k.d(1), k = null), /*error*/ h[8] || /*state*/ - h[5] === m.EXPIRED ? y ? y.p(h, d) : (y = ye(h), y.c(), y.m(e, R)) : y && (y.d(1), y = null), /*_strings*/ + h[5] === m.EXPIRED ? $ ? $.p(h, d) : ($ = $e(h), $.c(), $.m(e, R)) : $ && ($.d(1), $ = null), /*_strings*/ h[9].footer && /*hidefooter*/ - h[1] !== !0 ? b ? b.p(h, d) : (b = ke(h), b.c(), b.m(e, null)) : b && (b.d(1), b = null), d[0] & /*state*/ + h[1] !== !0 ? b ? b.p(h, d) : (b = ye(h), b.c(), b.m(e, null)) : b && (b.d(1), b = null), d[0] & /*state*/ 32 && c( e, "data-state", @@ -839,7 +841,7 @@ function Rt(t) { i: X, o: X, d(h) { - h && C(e), _ && _.d(), x.d(), $ && $.d(), y && y.d(), b && b.d(), t[26](null), M = !1, B(j); + h && L(e), _ && _.d(), E.d(), k && k.d(), $ && $.d(), b && b.d(), t[26](null), M = !1, B(j); } }; } @@ -847,20 +849,20 @@ const Ae = "https://altcha.org/"; function Ee(t) { return JSON.parse(t); } -function Nt(t, e, n) { - let r, l, o, { auto: s = void 0 } = e, { challengeurl: u = void 0 } = e, { challengejson: f = void 0 } = e, { debug: a = !1 } = e, { expire: k = void 0 } = e, { hidefooter: w = !1 } = e, { hidelogo: R = !1 } = e, { name: M = "altcha" } = e, { maxnumber: j = 1e6 } = e, { mockerror: _ = !1 } = e, { strings: V = void 0 } = e, { test: A = !1 } = e, { workers: x = 8 } = e; - const $ = it(), y = ["SHA-256", "SHA-384", "SHA-512"]; - let b = !1, h, d = null, z = null, H = null, T = m.UNVERIFIED, q; - rt(() => { +function Nt(t, e, r) { + let n, o, l, { auto: s = void 0 } = e, { challengeurl: u = void 0 } = e, { challengejson: f = void 0 } = e, { debug: a = !1 } = e, { expire: y = void 0 } = e, { hidefooter: w = !1 } = e, { hidelogo: R = !1 } = e, { name: M = "altcha" } = e, { maxnumber: j = 1e6 } = e, { mockerror: _ = !1 } = e, { strings: V = void 0 } = e, { test: A = !1 } = e, { workers: E = navigator.hardwareConcurrency || 8 } = e; + const k = it(), $ = ["SHA-256", "SHA-384", "SHA-512"]; + let b = !1, h, d = null, q = null, H = null, G = m.UNVERIFIED, ee; + nt(() => { d && (d.removeEventListener("submit", ce), d.removeEventListener("reset", ue), d = null); - }), nt(() => { - L("mounted", "0.1.9"), A && L("using test mode"), k && ee(k), s !== void 0 && L("auto", s), d = h.closest("form"), d && (d.addEventListener("submit", ce), d.addEventListener("reset", ue)), s === "onload" && F(); + }), rt(() => { + x("mounted", "0.1.9"), x("workers", E), A && x("using test mode"), y && te(y), s !== void 0 && x("auto", s), d = h.closest("form"), d && (d.addEventListener("submit", ce), d.addEventListener("reset", ue)), s === "onload" && F(); }); - function L(...i) { + function x(...i) { (a || i.some((g) => g instanceof Error)) && console[i[0] instanceof Error ? "error" : "log"]("ALTCHA", ...i); } function ce(i) { - d && s === "onsubmit" && T === m.UNVERIFIED && (i.preventDefault(), i.stopPropagation(), F().then(() => { + d && s === "onsubmit" && G === m.UNVERIFIED && (i.preventDefault(), i.stopPropagation(), F().then(() => { d == null || d.requestSubmit(); })); } @@ -883,69 +885,71 @@ function Nt(t, e, n) { throw new Error("Invalid challenge. Property algorithm is missing."); if (i.signature === void 0) throw new Error("Invalid challenge. Property signature is missing."); - if (!y.includes(i.algorithm.toUpperCase())) - throw new Error(`Unknown algorithm value. Allowed values: ${y.join(", ")}`); + if (!$.includes(i.algorithm.toUpperCase())) + throw new Error(`Unknown algorithm value. Allowed values: ${$.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 Ge() { + async function Te() { if (_) - throw L("mocking error"), new Error("Mocked error."); - if (r) - return L("using provided json data"), r; + throw x("mocking error"), new Error("Mocked error."); + if (n) + return x("using provided json data"), n; if (A) - return L("generating test challenge"), $t(); + return x("generating test challenge"), kt(); { if (!u) throw new Error("Attribute challengeurl not set."); - L("fetching challenge from", u); + x("fetching challenge from", u); const i = await fetch(u); if (i.status !== 200) throw new Error(`Server responded with ${i.status}.`); const g = i.headers.get("Expires"); if (g != null && g.length) { const O = Date.parse(g); - isNaN(O) || ee(O - Date.now()); + isNaN(O) || te(O - Date.now()); } return i.json(); } } function fe() { - u && T === m.VERIFIED ? F() : W(m.EXPIRED, o.expired); + u && G === m.VERIFIED ? F() : W(m.EXPIRED, l.expired); } - async function Te(i) { + async function Ge(i) { let g = null; if ("Worker" in window) { try { g = await Se(i.challenge, i.salt, i.algorithm); } catch (O) { - L(O); + x(O); } if ((g == null ? void 0 : g.number) !== void 0) return { data: i, solution: g }; } return { data: i, - solution: await yt(i.challenge, i.salt, i.algorithm, j).promise + solution: await $t(i.challenge, i.salt, i.algorithm, j).promise }; } - async function Se(i, g, O, te = Math.ceil(x)) { - const J = []; - if (te < 1) + async function Se(i, g, O, J = Math.ceil(E)) { + const Q = []; + if (J < 1) throw new Error("Wrong number of workers configured."); - for (let G = 0; G < te; G++) - J.push(new wt()); - const he = Math.ceil(j / te), Ue = await Promise.all(J.map((G, De) => { + if (J > 16) + throw new Error("Too many workers. Max. 16 allowed workers."); + for (let T = 0; T < J; T++) + Q.push(new wt()); + const he = Math.ceil(j / J), Ue = await Promise.all(Q.map((T, De) => { const de = De * he; return new Promise((Pe) => { - G.addEventListener("message", (ge) => { + T.addEventListener("message", (ge) => { if (ge.data) - for (const be of J) - be !== G && be.postMessage({ type: "abort" }); + for (const be of Q) + be !== T && be.postMessage({ type: "abort" }); Pe(ge.data); - }), G.postMessage({ + }), T.postMessage({ payload: { alg: O, challenge: i, @@ -957,52 +961,52 @@ function Nt(t, e, n) { }); }); })); - for (const G of J) - G.terminate(); - return Ue.find((G) => !!G) || null; + for (const T of Q) + T.terminate(); + return Ue.find((T) => !!T) || null; } function Ve() { - [m.UNVERIFIED, m.ERROR, m.EXPIRED].includes(T) ? F() : n(6, b = !0); + [m.UNVERIFIED, m.ERROR, m.EXPIRED].includes(G) ? F() : r(6, b = !0); } function Ze() { - T === m.VERIFYING && alert(o.waitAlert); + G === m.VERIFYING && alert(l.waitAlert); } - function ee(i) { - clearTimeout(q), i < 1 ? fe() : q = setTimeout(fe, i); + function te(i) { + console.log(">>>"), x("expire", i), clearTimeout(ee), i < 1 ? fe() : ee = setTimeout(fe, i); } function He(i) { - i.auto !== void 0 && (n(0, s = i.auto), s === "onload" && F()), i.expire !== void 0 && (ee(i.expire), n(13, k = i.expire)), i.challenge && (ae(i.challenge), r = i.challenge), i.debug !== void 0 && n(12, a = !!i.debug), i.hidefooter !== void 0 && n(1, w = !!i.hidefooter), i.hidelogo !== void 0 && n(2, R = !!i.hidelogo), i.maxnumber !== void 0 && n(14, j = +i.maxnumber), i.mockerror !== void 0 && n(15, _ = !!i.mockerror), i.name !== void 0 && n(3, M = i.name), i.test !== void 0 && n(16, A = !!i.test), i.strings && n(24, l = i.strings); + i.auto !== void 0 && (r(0, s = i.auto), s === "onload" && F()), i.expire !== void 0 && (te(i.expire), r(13, y = i.expire)), i.challenge && (ae(i.challenge), n = i.challenge), i.debug !== void 0 && r(12, a = !!i.debug), i.hidefooter !== void 0 && r(1, w = !!i.hidefooter), i.hidelogo !== void 0 && r(2, R = !!i.hidelogo), i.maxnumber !== void 0 && r(14, j = +i.maxnumber), i.mockerror !== void 0 && r(15, _ = !!i.mockerror), i.name !== void 0 && r(3, M = i.name), i.test !== void 0 && r(16, A = !!i.test), i.strings && r(24, o = i.strings), i.workers !== void 0 && r(17, E = +i.workers); } function W(i = m.UNVERIFIED, g = null) { - clearTimeout(q), n(6, b = !1), n(8, z = g), n(4, H = null), n(5, T = i); + clearTimeout(ee), r(6, b = !1), r(8, q = g), r(4, H = null), r(5, G = i); } async function F() { - return W(m.VERIFYING), Ge().then((i) => (ae(i), L("challenge", i), Te(i))).then(({ data: i, solution: g }) => { - if (L("solution", g), (g == null ? void 0 : g.number) !== void 0) - L("verified"), n(5, T = m.VERIFIED), n(6, b = !0), n(4, H = Me(i, g)), L("payload", H), lt().then(() => { - $("verified", { payload: H }); + return W(m.VERIFYING), Te().then((i) => (ae(i), x("challenge", i), Ge(i))).then(({ data: i, solution: g }) => { + if (x("solution", g), (g == null ? void 0 : g.number) !== void 0) + x("verified"), r(5, G = m.VERIFIED), r(6, b = !0), r(4, H = Me(i, g)), x("payload", H), ot().then(() => { + k("verified", { payload: H }); }); else throw new Error("Unexpected result returned."); }).catch((i) => { - L(i), n(5, T = m.ERROR), n(6, b = !1), n(8, z = i.message); + x(i), r(5, G = m.ERROR), r(6, b = !1), r(8, q = i.message); }); } function Fe() { - b = this.checked, n(6, b); + b = this.checked, r(6, b); } function Oe(i) { ie[i ? "unshift" : "push"](() => { - h = i, n(7, h); + h = i, r(7, h); }); } return t.$$set = (i) => { - "auto" in i && n(0, s = i.auto), "challengeurl" in i && n(17, u = i.challengeurl), "challengejson" in i && n(18, f = i.challengejson), "debug" in i && n(12, a = i.debug), "expire" in i && n(13, k = i.expire), "hidefooter" in i && n(1, w = i.hidefooter), "hidelogo" in i && n(2, R = i.hidelogo), "name" in i && n(3, M = i.name), "maxnumber" in i && n(14, j = i.maxnumber), "mockerror" in i && n(15, _ = i.mockerror), "strings" in i && n(19, V = i.strings), "test" in i && n(16, A = i.test), "workers" in i && n(20, x = i.workers); + "auto" in i && r(0, s = i.auto), "challengeurl" in i && r(18, u = i.challengeurl), "challengejson" in i && r(19, f = i.challengejson), "debug" in i && r(12, a = i.debug), "expire" in i && r(13, y = i.expire), "hidefooter" in i && r(1, w = i.hidefooter), "hidelogo" in i && r(2, R = i.hidelogo), "name" in i && r(3, M = i.name), "maxnumber" in i && r(14, j = i.maxnumber), "mockerror" in i && r(15, _ = i.mockerror), "strings" in i && r(20, V = i.strings), "test" in i && r(16, A = i.test), "workers" in i && r(17, E = i.workers); }, t.$$.update = () => { t.$$.dirty[0] & /*challengejson*/ - 262144 && (r = f ? Ee(f) : void 0), t.$$.dirty[0] & /*strings*/ - 524288 && n(24, l = V ? Ee(V) : {}), t.$$.dirty[0] & /*parsedStrings*/ - 16777216 && n(9, o = { + 524288 && (n = f ? Ee(f) : void 0), t.$$.dirty[0] & /*strings*/ + 1048576 && r(24, o = V ? Ee(V) : {}), t.$$.dirty[0] & /*parsedStrings*/ + 16777216 && r(9, l = { error: "Verification failed. Try again later.", expired: "Verification expired. Try again.", footer: `Protected by ALTCHA`, @@ -1010,35 +1014,35 @@ function Nt(t, e, n) { verified: "Verified", verifying: "Verifying...", waitAlert: "Verifying... please wait.", - ...l + ...o }), t.$$.dirty[0] & /*payload, state*/ - 48 && $("statechange", { payload: H, state: T }); + 48 && k("statechange", { payload: H, state: G }); }, [ s, w, R, M, H, - T, + G, b, h, - z, - o, + q, + l, Ve, Ze, a, - k, + y, j, _, A, + E, u, f, V, - x, He, W, F, - l, + o, Fe, Oe ]; @@ -1053,8 +1057,8 @@ class jt extends bt { Ke, { auto: 0, - challengeurl: 17, - challengejson: 18, + challengeurl: 18, + challengejson: 19, debug: 12, expire: 13, hidefooter: 1, @@ -1062,14 +1066,14 @@ class jt extends bt { name: 3, maxnumber: 14, mockerror: 15, - strings: 19, + strings: 20, test: 16, - workers: 20, + workers: 17, configure: 21, reset: 22, verify: 23 }, - kt, + yt, [-1, -1] ); } @@ -1077,79 +1081,79 @@ class jt extends bt { return this.$$.ctx[0]; } set auto(e) { - this.$$set({ auto: e }), E(); + this.$$set({ auto: e }), C(); } get challengeurl() { - return this.$$.ctx[17]; + return this.$$.ctx[18]; } set challengeurl(e) { - this.$$set({ challengeurl: e }), E(); + this.$$set({ challengeurl: e }), C(); } get challengejson() { - return this.$$.ctx[18]; + return this.$$.ctx[19]; } set challengejson(e) { - this.$$set({ challengejson: e }), E(); + this.$$set({ challengejson: e }), C(); } get debug() { return this.$$.ctx[12]; } set debug(e) { - this.$$set({ debug: e }), E(); + this.$$set({ debug: e }), C(); } get expire() { return this.$$.ctx[13]; } set expire(e) { - this.$$set({ expire: e }), E(); + this.$$set({ expire: e }), C(); } get hidefooter() { return this.$$.ctx[1]; } set hidefooter(e) { - this.$$set({ hidefooter: e }), E(); + this.$$set({ hidefooter: e }), C(); } get hidelogo() { return this.$$.ctx[2]; } set hidelogo(e) { - this.$$set({ hidelogo: e }), E(); + this.$$set({ hidelogo: e }), C(); } get name() { return this.$$.ctx[3]; } set name(e) { - this.$$set({ name: e }), E(); + this.$$set({ name: e }), C(); } get maxnumber() { return this.$$.ctx[14]; } set maxnumber(e) { - this.$$set({ maxnumber: e }), E(); + this.$$set({ maxnumber: e }), C(); } get mockerror() { return this.$$.ctx[15]; } set mockerror(e) { - this.$$set({ mockerror: e }), E(); + this.$$set({ mockerror: e }), C(); } get strings() { - return this.$$.ctx[19]; + return this.$$.ctx[20]; } set strings(e) { - this.$$set({ strings: e }), E(); + this.$$set({ strings: e }), C(); } get test() { return this.$$.ctx[16]; } set test(e) { - this.$$set({ test: e }), E(); + this.$$set({ test: e }), C(); } get workers() { - return this.$$.ctx[20]; + return this.$$.ctx[17]; } set workers(e) { - this.$$set({ workers: e }), E(); + this.$$set({ workers: e }), C(); } get configure() { return this.$$.ctx[21]; diff --git a/dist/altcha.umd.cjs b/dist/altcha.umd.cjs index 07b57e5..3f01f43 100644 --- a/dist/altcha.umd.cjs +++ b/dist/altcha.umd.cjs @@ -1 +1 @@ -(function(N,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(N=typeof globalThis<"u"?globalThis:N||self,_(N.altcha={}))})(this,function(N){"use strict";var jt=Object.defineProperty;var At=(N,_,H)=>_ in N?jt(N,_,{enumerable:!0,configurable:!0,writable:!0,value:H}):N[_]=H;var A=(N,_,H)=>(At(N,typeof _!="symbol"?_+"":_,H),H);function _(){}function H(t){return t()}function fe(){return Object.create(null)}function B(t){t.forEach(H)}function ae(t){return typeof t=="function"}function Se(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ge(t){return Object.keys(t).length===0}function v(t,e){t.appendChild(e)}function Ve(t,e,n){const r=Ze(t);if(!r.getElementById(e)){const o=p("style");o.id=e,o.textContent=n,He(r,o)}}function Ze(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function He(t,e){return v(t.head||t,e),e.sheet}function I(t,e,n){t.insertBefore(e,n||null)}function C(t){t.parentNode&&t.parentNode.removeChild(t)}function p(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Oe(t){return document.createTextNode(t)}function O(){return Oe(" ")}function ee(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 Fe(t){return Array.from(t.childNodes)}function he(t,e,n){t.classList.toggle(e,!!n)}function Pe(t,e,{bubbles:n=!1,cancelable:r=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:r})}function Ue(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let W;function J(t){W=t}function te(){if(!W)throw new Error("Function called outside component initialization");return W}function De(t){te().$$.on_mount.push(t)}function Xe(t){te().$$.on_destroy.push(t)}function Ye(){const t=te();return(e,n,{cancelable:r=!1}={})=>{const o=t.$$.callbacks[e];if(o){const l=Pe(e,n,{cancelable:r});return o.slice().forEach(s=>{s.call(t,l)}),!l.defaultPrevented}return!0}}const P=[],ne=[];let U=[];const de=[],ge=Promise.resolve();let re=!1;function be(){re||(re=!0,ge.then(x))}function Ke(){return be(),ge}function ie(t){U.push(t)}const oe=new Set;let D=0;function x(){if(D!==0)return;const t=W;do{try{for(;D t.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),U=e}const Je=new Set;function Qe(t,e){t&&t.i&&(Je.delete(t),t.i(e))}function ze(t,e,n){const{fragment:r,after_update:o}=t.$$;r&&r.m(e,n),ie(()=>{const l=t.$$.on_mount.map(H).filter(ae);t.$$.on_destroy?t.$$.on_destroy.push(...l):B(l),t.$$.on_mount=[]}),o.forEach(ie)}function qe(t,e){const n=t.$$;n.fragment!==null&&(We(n.after_update),B(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function et(t,e){t.$$.dirty[0]===-1&&(P.push(t),be(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1< {const M=S.length?S[0]:j;return f.ctx&&o(f.ctx[w],f.ctx[w]=M)&&(!f.skip_bound&&f.bound[w]&&f.bound[w](M),E&&et(t,w)),j}):[],f.update(),E=!0,B(f.before_update),f.fragment=r?r(f.ctx):!1,e.target){if(e.hydrate){const w=Fe(e.target);f.fragment&&f.fragment.l(w),w.forEach(C)}else f.fragment&&f.fragment.c();e.intro&&Qe(t.$$.fragment),ze(t,e.target,e.anchor),x()}J(a)}let me;typeof HTMLElement=="function"&&(me=class extends HTMLElement{constructor(e,n,r){super();A(this,"$$ctor");A(this,"$$s");A(this,"$$c");A(this,"$$cn",!1);A(this,"$$d",{});A(this,"$$r",!1);A(this,"$$p_d",{});A(this,"$$l",{});A(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 o=this.$$c.$on(e,n);this.$$l_u.set(n,o)}super.addEventListener(e,n,r)}removeEventListener(e,n,r){if(super.removeEventListener(e,n,r),this.$$c){const o=this.$$l_u.get(n);o&&(o(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(l){return()=>{let s;return{c:function(){s=p("slot"),l!=="default"&&c(s,"name",l)},m:function(f,E){I(f,s,E)},d:function(f){f&&C(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},r=Ue(this);for(const l of this.$$s)l in r&&(n[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:n,$$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,n,r){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Q(e,r,this.$$p_d,"toProp"),(o=this.$$c)==null||o.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function Q(t,e,n,r){var l;const o=(l=n[t])==null?void 0:l.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!r||!n[t])return e;if(r==="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,n,r,o,l){let s=class extends me{constructor(){super(t,n,o),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(u=>(e[u].attribute||u).toLowerCase())}};return Object.keys(e).forEach(u=>{Object.defineProperty(s.prototype,u,{get(){return this.$$c&&u in this.$$c?this.$$c[u]:this.$$d[u]},set(a){var f;a=Q(u,a,e),this.$$d[u]=a,(f=this.$$c)==null||f.$set({[u]:a})}})}),r.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 rt{constructor(){A(this,"$$");A(this,"$$set")}$destroy(){qe(this,1),this.$destroy=_}$on(e,n){if(!ae(n))return _;const r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(n),()=>{const o=r.indexOf(n);o!==-1&&r.splice(o,1)}}$set(e){this.$$set&&!Ge(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const it="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(it);const ve="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+PWk/cyhudWxsKTpoKGUsbCxvKS50aGVuKHc9Pnt3PT09dD9zKHtudW1iZXI6bCx0b29rOkRhdGUubm93KCktcn0pOmQobCsxKX0pLmNhdGNoKGMpfTtkKHApfSksY29udHJvbGxlcjphfX1sZXQgbjtvbm1lc3NhZ2U9YXN5bmMgdD0+e2NvbnN0e3R5cGU6ZSxwYXlsb2FkOm99PXQuZGF0YTtpZihlPT09ImFib3J0IiluPT1udWxsfHxuLmFib3J0KCksbj12b2lkIDA7ZWxzZSBpZihlPT09IndvcmsiKXtjb25zdHthbGc6aSxjaGFsbGVuZ2U6cCxtYXg6YSxzYWx0OnUsc3RhcnQ6c309b3x8e30sYz1tKHAsdSxpLGEscyk7bj1jLmNvbnRyb2xsZXIsYy5wcm9taXNlLnRoZW4ocj0+e3NlbGYucG9zdE1lc3NhZ2UociYmey4uLnIsd29ya2VyOiEwfSl9KX19fSkoKTsK",ot=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),we=typeof window<"u"&&window.Blob&&new Blob([ot(ve)],{type:"text/javascript;charset=utf-8"});function lt(t){let e;try{if(e=we&&(window.URL||window.webkitURL).createObjectURL(we),!e)throw"";const n=new Worker(e,{name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;base64,"+ve,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const st=new TextEncoder;function ct(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ut(t=1e5,e="SHA-256"){const n=Date.now().toString(16),r=Math.round(Math.random()*t),o=await _e(n,r,e);return{algorithm:e,challenge:o,salt:n,signature:""}}async function _e(t,e,n){return ct(await crypto.subtle.digest(n.toUpperCase(),st.encode(t+e)))}function ft(t,e,n="SHA-256",r=1e6,o=0){const l=new AbortController;return{promise:new Promise((u,a)=>{const f=Date.now(),E=w=>{l.signal.aborted||w>=r?u(null):_e(e,w,n).then(j=>{j===t?u({number:w,took:Date.now()-f}):E(w+1)}).catch(a)};E(o)}),controller:l}}var b=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(b||{});function at(t){Ve(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-vuofbg.svelte-vuofbg{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function pe(t){let e,n,r;return{c(){e=V("svg"),n=V("path"),r=V("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-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),v(e,n),v(e,r)},d(o){o&&C(e)}}}function ht(t){let e,n=t[9].label+"",r;return{c(){e=p("label"),c(e,"for",r=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(o,l){I(o,e,l),e.innerHTML=n},p(o,l){l[0]&512&&n!==(n=o[9].label+"")&&(e.innerHTML=n),l[0]&8&&r!==(r=o[3]+"_checkbox")&&c(e,"for",r)},d(o){o&&C(e)}}}function dt(t){let e,n=t[9].verifying+"";return{c(){e=p("span")},m(r,o){I(r,e,o),e.innerHTML=n},p(r,o){o[0]&512&&n!==(n=r[9].verifying+"")&&(e.innerHTML=n)},d(r){r&&C(e)}}}function gt(t){let e,n=t[9].verified+"",r,o;return{c(){e=p("span"),r=O(),o=p("input"),c(o,"type","hidden"),c(o,"name",t[3]),o.value=t[4]},m(l,s){I(l,e,s),e.innerHTML=n,I(l,r,s),I(l,o,s)},p(l,s){s[0]&512&&n!==(n=l[9].verified+"")&&(e.innerHTML=n),s[0]&8&&c(o,"name",l[3]),s[0]&16&&(o.value=l[4])},d(l){l&&(C(e),C(r),C(o))}}}function ye(t){let e,n,r,o,l,s;return{c(){e=p("div"),n=p("a"),r=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(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",Ee),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-vuofbg")},m(u,a){I(u,e,a),v(e,n),v(n,r),v(r,o),v(r,l),v(r,s)},p:_,d(u){u&&C(e)}}}function $e(t){let e,n,r,o;function l(a,f){return a[5]===b.EXPIRED?mt:bt}let s=l(t),u=s(t);return{c(){e=p("div"),n=V("svg"),r=V("path"),o=O(),u.c(),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(e,"class","altcha-error svelte-vuofbg")},m(a,f){I(a,e,f),v(e,n),v(n,r),v(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&&C(e),u.d()}}}function bt(t){let e,n=t[9].error+"";return{c(){e=p("div"),c(e,"title",t[8])},m(r,o){I(r,e,o),e.innerHTML=n},p(r,o){o[0]&512&&n!==(n=r[9].error+"")&&(e.innerHTML=n),o[0]&256&&c(e,"title",r[8])},d(r){r&&C(e)}}}function mt(t){let e,n=t[9].expired+"";return{c(){e=p("div"),c(e,"title",t[8])},m(r,o){I(r,e,o),e.innerHTML=n},p(r,o){o[0]&512&&n!==(n=r[9].expired+"")&&(e.innerHTML=n),o[0]&256&&c(e,"title",r[8])},d(r){r&&C(e)}}}function ke(t){let e,n,r=t[9].footer+"";return{c(){e=p("div"),n=p("div"),c(n,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(o,l){I(o,e,l),v(e,n),n.innerHTML=r},p(o,l){l[0]&512&&r!==(r=o[9].footer+"")&&(n.innerHTML=r)},d(o){o&&C(e)}}}function vt(t){let e,n,r,o,l,s,u,a,f,E,w,j,S,M,y=t[5]===b.VERIFYING&&pe();function F(h,d){return h[5]===b.VERIFIED?gt:h[5]===b.VERIFYING?dt:ht}let T=F(t),L=T(t),$=t[2]!==!0&&ye(),k=(t[8]||t[5]===b.EXPIRED)&&$e(t),m=t[9].footer&&t[1]!==!0&&ke(t);return{c(){e=p("div"),n=p("div"),y&&y.c(),r=O(),o=p("div"),l=p("input"),a=O(),f=p("div"),L.c(),E=O(),$&&$.c(),w=O(),k&&k.c(),j=O(),m&&m.c(),c(l,"type","checkbox"),c(l,"id",s=t[3]+"_checkbox"),l.required=u=t[0]!=="onsubmit",c(l,"class","svelte-vuofbg"),c(o,"class","altcha-checkbox svelte-vuofbg"),he(o,"altcha-hidden",t[5]===b.VERIFYING),c(f,"class","altcha-label svelte-vuofbg"),c(n,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(h,d){I(h,e,d),v(e,n),y&&y.m(n,null),v(n,r),v(n,o),v(o,l),l.checked=t[6],v(n,a),v(n,f),L.m(f,null),v(n,E),$&&$.m(n,null),v(e,w),k&&k.m(e,null),v(e,j),m&&m.m(e,null),t[26](e),S||(M=[ee(l,"change",t[25]),ee(l,"change",t[10]),ee(l,"invalid",t[11])],S=!0)},p(h,d){h[5]===b.VERIFYING?y||(y=pe(),y.c(),y.m(n,r)):y&&(y.d(1),y=null),d[0]&8&&s!==(s=h[3]+"_checkbox")&&c(l,"id",s),d[0]&1&&u!==(u=h[0]!=="onsubmit")&&(l.required=u),d[0]&64&&(l.checked=h[6]),d[0]&32&&he(o,"altcha-hidden",h[5]===b.VERIFYING),T===(T=F(h))&&L?L.p(h,d):(L.d(1),L=T(h),L&&(L.c(),L.m(f,null))),h[2]!==!0?$?$.p(h,d):($=ye(),$.c(),$.m(n,null)):$&&($.d(1),$=null),h[8]||h[5]===b.EXPIRED?k?k.p(h,d):(k=$e(h),k.c(),k.m(e,j)):k&&(k.d(1),k=null),h[9].footer&&h[1]!==!0?m?m.p(h,d):(m=ke(h),m.c(),m.m(e,null)):m&&(m.d(1),m=null),d[0]&32&&c(e,"data-state",h[5])},i:_,o:_,d(h){h&&C(e),y&&y.d(),L.d(),$&&$.d(),k&&k.d(),m&&m.d(),t[26](null),S=!1,B(M)}}}const Ee="https://altcha.org/";function xe(t){return JSON.parse(t)}function wt(t,e,n){let r,o,l,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:a=void 0}=e,{debug:f=!1}=e,{expire:E=void 0}=e,{hidefooter:w=!1}=e,{hidelogo:j=!1}=e,{name:S="altcha"}=e,{maxnumber:M=1e6}=e,{mockerror:y=!1}=e,{strings:F=void 0}=e,{test:T=!1}=e,{workers:L=8}=e;const $=Ye(),k=["SHA-256","SHA-384","SHA-512"];let m=!1,h,d=null,le=null,X=null,Z=b.UNVERIFIED,se;Xe(()=>{d&&(d.removeEventListener("submit",Le),d.removeEventListener("reset",Ie),d=null)}),De(()=>{R("mounted","0.1.9"),T&&R("using test mode"),E&&ce(E),s!==void 0&&R("auto",s),d=h.closest("form"),d&&(d.addEventListener("submit",Le),d.addEventListener("reset",Ie)),s==="onload"&&Y()});function R(...i){(f||i.some(g=>g instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function Le(i){d&&s==="onsubmit"&&Z===b.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),Y().then(()=>{d==null||d.requestSubmit()}))}function Ie(){z()}function _t(i,g){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:g.number,salt:i.salt,signature:i.signature,test:T?!0:void 0,took:g.took}))}function Re(i){if(!i.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(i.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!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 pt(){if(y)throw R("mocking error"),new Error("Mocked error.");if(r)return R("using provided json data"),r;if(T)return R("generating test challenge"),ut();{if(!u)throw new Error("Attribute challengeurl not set.");R("fetching challenge from",u);const i=await fetch(u);if(i.status!==200)throw new Error(`Server responded with ${i.status}.`);const g=i.headers.get("Expires");if(g!=null&&g.length){const K=Date.parse(g);isNaN(K)||ce(K-Date.now())}return i.json()}}function Ne(){u&&Z===b.VERIFIED?Y():z(b.EXPIRED,l.expired)}async function yt(i){let g=null;if("Worker"in window){try{g=await $t(i.challenge,i.salt,i.algorithm)}catch(K){R(K)}if((g==null?void 0:g.number)!==void 0)return{data:i,solution:g}}return{data:i,solution:await ft(i.challenge,i.salt,i.algorithm,M).promise}}async function $t(i,g,K,ue=Math.ceil(L)){const q=[];if(ue<1)throw new Error("Wrong number of workers configured.");for(let G=0;G {const Ae=Rt*je;return new Promise(Nt=>{G.addEventListener("message",Me=>{if(Me.data)for(const Te of q)Te!==G&&Te.postMessage({type:"abort"});Nt(Me.data)}),G.postMessage({payload:{alg:K,challenge:i,max:Ae+je,salt:g,start:Ae},type:"work"})})}));for(const G of q)G.terminate();return It.find(G=>!!G)||null}function kt(){[b.UNVERIFIED,b.ERROR,b.EXPIRED].includes(Z)?Y():n(6,m=!0)}function Et(){Z===b.VERIFYING&&alert(l.waitAlert)}function ce(i){clearTimeout(se),i<1?Ne():se=setTimeout(Ne,i)}function xt(i){i.auto!==void 0&&(n(0,s=i.auto),s==="onload"&&Y()),i.expire!==void 0&&(ce(i.expire),n(13,E=i.expire)),i.challenge&&(Re(i.challenge),r=i.challenge),i.debug!==void 0&&n(12,f=!!i.debug),i.hidefooter!==void 0&&n(1,w=!!i.hidefooter),i.hidelogo!==void 0&&n(2,j=!!i.hidelogo),i.maxnumber!==void 0&&n(14,M=+i.maxnumber),i.mockerror!==void 0&&n(15,y=!!i.mockerror),i.name!==void 0&&n(3,S=i.name),i.test!==void 0&&n(16,T=!!i.test),i.strings&&n(24,o=i.strings)}function z(i=b.UNVERIFIED,g=null){clearTimeout(se),n(6,m=!1),n(8,le=g),n(4,X=null),n(5,Z=i)}async function Y(){return z(b.VERIFYING),pt().then(i=>(Re(i),R("challenge",i),yt(i))).then(({data:i,solution:g})=>{if(R("solution",g),(g==null?void 0:g.number)!==void 0)R("verified"),n(5,Z=b.VERIFIED),n(6,m=!0),n(4,X=_t(i,g)),R("payload",X),Ke().then(()=>{$("verified",{payload:X})});else throw new Error("Unexpected result returned.")}).catch(i=>{R(i),n(5,Z=b.ERROR),n(6,m=!1),n(8,le=i.message)})}function Ct(){m=this.checked,n(6,m)}function Lt(i){ne[i?"unshift":"push"](()=>{h=i,n(7,h)})}return t.$$set=i=>{"auto"in i&&n(0,s=i.auto),"challengeurl"in i&&n(17,u=i.challengeurl),"challengejson"in i&&n(18,a=i.challengejson),"debug"in i&&n(12,f=i.debug),"expire"in i&&n(13,E=i.expire),"hidefooter"in i&&n(1,w=i.hidefooter),"hidelogo"in i&&n(2,j=i.hidelogo),"name"in i&&n(3,S=i.name),"maxnumber"in i&&n(14,M=i.maxnumber),"mockerror"in i&&n(15,y=i.mockerror),"strings"in i&&n(19,F=i.strings),"test"in i&&n(16,T=i.test),"workers"in i&&n(20,L=i.workers)},t.$$.update=()=>{t.$$.dirty[0]&262144&&(r=a?xe(a):void 0),t.$$.dirty[0]&524288&&n(24,o=F?xe(F):{}),t.$$.dirty[0]&16777216&&n(9,l={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...o}),t.$$.dirty[0]&48&&$("statechange",{payload:X,state:Z})},[s,w,j,S,X,Z,m,h,le,l,kt,Et,f,E,M,y,T,u,a,F,L,xt,z,Y,o,Ct,Lt]}class Ce extends rt{constructor(e){super(),tt(this,e,wt,vt,Se,{auto:0,challengeurl:17,challengejson:18,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,strings:19,test:16,workers:20,configure:21,reset:22,verify:23},at,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),x()}get challengeurl(){return this.$$.ctx[17]}set challengeurl(e){this.$$set({challengeurl:e}),x()}get challengejson(){return this.$$.ctx[18]}set challengejson(e){this.$$set({challengejson:e}),x()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),x()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),x()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),x()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),x()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),x()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),x()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),x()}get strings(){return this.$$.ctx[19]}set strings(e){this.$$set({strings:e}),x()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),x()}get workers(){return this.$$.ctx[20]}set workers(e){this.$$set({workers:e}),x()}get configure(){return this.$$.ctx[21]}get reset(){return this.$$.ctx[22]}get verify(){return this.$$.ctx[23]}}customElements.define("altcha-widget",nt(Ce,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),N.Altcha=Ce,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})}); +(function(N,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(N=typeof globalThis<"u"?globalThis:N||self,_(N.altcha={}))})(this,function(N){"use strict";var jt=Object.defineProperty;var At=(N,_,H)=>_ in N?jt(N,_,{enumerable:!0,configurable:!0,writable:!0,value:H}):N[_]=H;var A=(N,_,H)=>(At(N,typeof _!="symbol"?_+"":_,H),H);function _(){}function H(t){return t()}function fe(){return Object.create(null)}function B(t){t.forEach(H)}function ae(t){return typeof t=="function"}function Se(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ge(t){return Object.keys(t).length===0}function v(t,e){t.appendChild(e)}function Ve(t,e,r){const n=Ze(t);if(!n.getElementById(e)){const o=p("style");o.id=e,o.textContent=r,He(n,o)}}function Ze(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function He(t,e){return v(t.head||t,e),e.sheet}function R(t,e,r){t.insertBefore(e,r||null)}function I(t){t.parentNode&&t.parentNode.removeChild(t)}function p(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Oe(t){return document.createTextNode(t)}function O(){return Oe(" ")}function te(t,e,r,n){return t.addEventListener(e,r,n),()=>t.removeEventListener(e,r,n)}function c(t,e,r){r==null?t.removeAttribute(e):t.getAttribute(e)!==r&&t.setAttribute(e,r)}function Fe(t){return Array.from(t.childNodes)}function he(t,e,r){t.classList.toggle(e,!!r)}function Pe(t,e,{bubbles:r=!1,cancelable:n=!1}={}){return new CustomEvent(t,{detail:e,bubbles:r,cancelable:n})}function Ue(t){const e={};return t.childNodes.forEach(r=>{e[r.slot||"default"]=!0}),e}let W;function J(t){W=t}function re(){if(!W)throw new Error("Function called outside component initialization");return W}function De(t){re().$$.on_mount.push(t)}function Xe(t){re().$$.on_destroy.push(t)}function Ye(){const t=re();return(e,r,{cancelable:n=!1}={})=>{const o=t.$$.callbacks[e];if(o){const l=Pe(e,r,{cancelable:n});return o.slice().forEach(s=>{s.call(t,l)}),!l.defaultPrevented}return!0}}const P=[],ne=[];let U=[];const de=[],ge=Promise.resolve();let ie=!1;function be(){ie||(ie=!0,ge.then(C))}function Ke(){return be(),ge}function oe(t){U.push(t)}const le=new Set;let D=0;function C(){if(D!==0)return;const t=W;do{try{for(;D t.indexOf(n)===-1?e.push(n):r.push(n)),r.forEach(n=>n()),U=e}const Je=new Set;function Qe(t,e){t&&t.i&&(Je.delete(t),t.i(e))}function ze(t,e,r){const{fragment:n,after_update:o}=t.$$;n&&n.m(e,r),oe(()=>{const l=t.$$.on_mount.map(H).filter(ae);t.$$.on_destroy?t.$$.on_destroy.push(...l):B(l),t.$$.on_mount=[]}),o.forEach(oe)}function qe(t,e){const r=t.$$;r.fragment!==null&&(We(r.after_update),B(r.on_destroy),r.fragment&&r.fragment.d(e),r.on_destroy=r.fragment=null,r.ctx=[])}function et(t,e){t.$$.dirty[0]===-1&&(P.push(t),be(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1< {const M=S.length?S[0]:j;return f.ctx&&o(f.ctx[w],f.ctx[w]=M)&&(!f.skip_bound&&f.bound[w]&&f.bound[w](M),E&&et(t,w)),j}):[],f.update(),E=!0,B(f.before_update),f.fragment=n?n(f.ctx):!1,e.target){if(e.hydrate){const w=Fe(e.target);f.fragment&&f.fragment.l(w),w.forEach(I)}else f.fragment&&f.fragment.c();e.intro&&Qe(t.$$.fragment),ze(t,e.target,e.anchor),C()}J(a)}let me;typeof HTMLElement=="function"&&(me=class extends HTMLElement{constructor(e,r,n){super();A(this,"$$ctor");A(this,"$$s");A(this,"$$c");A(this,"$$cn",!1);A(this,"$$d",{});A(this,"$$r",!1);A(this,"$$p_d",{});A(this,"$$l",{});A(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=p("slot"),l!=="default"&&c(s,"name",l)},m:function(f,E){R(f,s,E)},d:function(f){f&&I(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const r={},n=Ue(this);for(const l of this.$$s)l in n&&(r[l]=[e(l)]);for(const l of this.attributes){const s=this.$$g_p(l.name);s in this.$$d||(this.$$d[s]=Q(s,l.value,this.$$p_d,"toProp"))}for(const l in this.$$p_d)!(l in this.$$d)&&this[l]!==void 0&&(this.$$d[l]=this[l],delete this[l]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:r,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const l in this.$$p_d)if(this.$$d[l]=this.$$c.$$.ctx[this.$$c.$$.props[l]],this.$$p_d[l].reflect){const s=Q(l,this.$$d[l],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[l].attribute||l):this.setAttribute(this.$$p_d[l].attribute||l,s)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const l in this.$$l)for(const s of this.$$l[l]){const u=this.$$c.$on(l,s);this.$$l_u.set(s,u)}this.$$l={}}}attributeChangedCallback(e,r,n){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Q(e,n,this.$$p_d,"toProp"),(o=this.$$c)==null||o.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(r=>this.$$p_d[r].attribute===e||!this.$$p_d[r].attribute&&r.toLowerCase()===e)||e}});function Q(t,e,r,n){var l;const o=(l=r[t])==null?void 0:l.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!n||!r[t])return e;if(n==="toAttribute")switch(o){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function rt(t,e,r,n,o,l){let s=class extends me{constructor(){super(t,r,o),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(u=>(e[u].attribute||u).toLowerCase())}};return Object.keys(e).forEach(u=>{Object.defineProperty(s.prototype,u,{get(){return this.$$c&&u in this.$$c?this.$$c[u]:this.$$d[u]},set(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 nt{constructor(){A(this,"$$");A(this,"$$set")}$destroy(){qe(this,1),this.$destroy=_}$on(e,r){if(!ae(r))return _;const n=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return n.push(r),()=>{const o=n.indexOf(r);o!==-1&&n.splice(o,1)}}$set(e){this.$$set&&!Ge(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const it="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(it);const ve="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+PWk/cyhudWxsKTpoKGUsbCxvKS50aGVuKHc9Pnt3PT09dD9zKHtudW1iZXI6bCx0b29rOkRhdGUubm93KCktcn0pOmQobCsxKX0pLmNhdGNoKGMpfTtkKHApfSksY29udHJvbGxlcjphfX1sZXQgbjtvbm1lc3NhZ2U9YXN5bmMgdD0+e2NvbnN0e3R5cGU6ZSxwYXlsb2FkOm99PXQuZGF0YTtpZihlPT09ImFib3J0IiluPT1udWxsfHxuLmFib3J0KCksbj12b2lkIDA7ZWxzZSBpZihlPT09IndvcmsiKXtjb25zdHthbGc6aSxjaGFsbGVuZ2U6cCxtYXg6YSxzYWx0OnUsc3RhcnQ6c309b3x8e30sYz1tKHAsdSxpLGEscyk7bj1jLmNvbnRyb2xsZXIsYy5wcm9taXNlLnRoZW4ocj0+e3NlbGYucG9zdE1lc3NhZ2UociYmey4uLnIsd29ya2VyOiEwfSl9KX19fSkoKTsK",ot=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),we=typeof window<"u"&&window.Blob&&new Blob([ot(ve)],{type:"text/javascript;charset=utf-8"});function lt(t){let e;try{if(e=we&&(window.URL||window.webkitURL).createObjectURL(we),!e)throw"";const r=new Worker(e,{name:t==null?void 0:t.name});return r.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),r}catch{return new Worker("data:text/javascript;base64,"+ve,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const st=new TextEncoder;function ct(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ut(t,e="SHA-256",r=1e5){const n=Date.now().toString(16);t||(t=Math.round(Math.random()*r));const o=await _e(n,t,e);return{algorithm:e,challenge:o,salt:n,signature:""}}async function _e(t,e,r){return ct(await crypto.subtle.digest(r.toUpperCase(),st.encode(t+e)))}function ft(t,e,r="SHA-256",n=1e6,o=0){const l=new AbortController;return{promise:new Promise((u,a)=>{const f=Date.now(),E=w=>{l.signal.aborted||w>=n?u(null):_e(e,w,r).then(j=>{j===t?u({number:w,took:Date.now()-f}):E(w+1)}).catch(a)};E(o)}),controller:l}}var b=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(b||{});function at(t){Ve(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-vuofbg.svelte-vuofbg{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function pe(t){let e,r,n;return{c(){e=V("svg"),r=V("path"),n=V("path"),c(r,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(r,"fill","currentColor"),c(r,"opacity",".25"),c(n,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(n,"fill","currentColor"),c(n,"class","altcha-spinner svelte-vuofbg"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(o,l){R(o,e,l),v(e,r),v(e,n)},d(o){o&&I(e)}}}function ht(t){let e,r=t[9].label+"",n;return{c(){e=p("label"),c(e,"for",n=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(o,l){R(o,e,l),e.innerHTML=r},p(o,l){l[0]&512&&r!==(r=o[9].label+"")&&(e.innerHTML=r),l[0]&8&&n!==(n=o[3]+"_checkbox")&&c(e,"for",n)},d(o){o&&I(e)}}}function dt(t){let e,r=t[9].verifying+"";return{c(){e=p("span")},m(n,o){R(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].verifying+"")&&(e.innerHTML=r)},d(n){n&&I(e)}}}function gt(t){let e,r=t[9].verified+"",n,o;return{c(){e=p("span"),n=O(),o=p("input"),c(o,"type","hidden"),c(o,"name",t[3]),o.value=t[4]},m(l,s){R(l,e,s),e.innerHTML=r,R(l,n,s),R(l,o,s)},p(l,s){s[0]&512&&r!==(r=l[9].verified+"")&&(e.innerHTML=r),s[0]&8&&c(o,"name",l[3]),s[0]&16&&(o.value=l[4])},d(l){l&&(I(e),I(n),I(o))}}}function ye(t){let e,r,n,o,l,s;return{c(){e=p("div"),r=p("a"),n=V("svg"),o=V("path"),l=V("path"),s=V("path"),c(o,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(o,"fill","currentColor"),c(l,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(l,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(n,"width","22"),c(n,"height","22"),c(n,"viewBox","0 0 20 20"),c(n,"fill","none"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(r,"href",Ee),c(r,"target","_blank"),c(r,"class","altcha-logo svelte-vuofbg")},m(u,a){R(u,e,a),v(e,r),v(r,n),v(n,o),v(n,l),v(n,s)},p:_,d(u){u&&I(e)}}}function ke(t){let e,r,n,o;function l(a,f){return a[5]===b.EXPIRED?mt:bt}let s=l(t),u=s(t);return{c(){e=p("div"),r=V("svg"),n=V("path"),o=O(),u.c(),c(n,"stroke-linecap","round"),c(n,"stroke-linejoin","round"),c(n,"d","M6 18L18 6M6 6l12 12"),c(r,"width","14"),c(r,"height","14"),c(r,"xmlns","http://www.w3.org/2000/svg"),c(r,"fill","none"),c(r,"viewBox","0 0 24 24"),c(r,"stroke-width","1.5"),c(r,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(a,f){R(a,e,f),v(e,r),v(r,n),v(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&&I(e),u.d()}}}function bt(t){let e,r=t[9].error+"";return{c(){e=p("div"),c(e,"title",t[8])},m(n,o){R(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].error+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&I(e)}}}function mt(t){let e,r=t[9].expired+"";return{c(){e=p("div"),c(e,"title",t[8])},m(n,o){R(n,e,o),e.innerHTML=r},p(n,o){o[0]&512&&r!==(r=n[9].expired+"")&&(e.innerHTML=r),o[0]&256&&c(e,"title",n[8])},d(n){n&&I(e)}}}function $e(t){let e,r,n=t[9].footer+"";return{c(){e=p("div"),r=p("div"),c(r,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(o,l){R(o,e,l),v(e,r),r.innerHTML=n},p(o,l){l[0]&512&&n!==(n=o[9].footer+"")&&(r.innerHTML=n)},d(o){o&&I(e)}}}function vt(t){let e,r,n,o,l,s,u,a,f,E,w,j,S,M,y=t[5]===b.VERIFYING&&pe();function F(h,d){return h[5]===b.VERIFIED?gt:h[5]===b.VERIFYING?dt:ht}let T=F(t),x=T(t),k=t[2]!==!0&&ye(),$=(t[8]||t[5]===b.EXPIRED)&&ke(t),m=t[9].footer&&t[1]!==!0&&$e(t);return{c(){e=p("div"),r=p("div"),y&&y.c(),n=O(),o=p("div"),l=p("input"),a=O(),f=p("div"),x.c(),E=O(),k&&k.c(),w=O(),$&&$.c(),j=O(),m&&m.c(),c(l,"type","checkbox"),c(l,"id",s=t[3]+"_checkbox"),l.required=u=t[0]!=="onsubmit",c(l,"class","svelte-vuofbg"),c(o,"class","altcha-checkbox svelte-vuofbg"),he(o,"altcha-hidden",t[5]===b.VERIFYING),c(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,d){R(h,e,d),v(e,r),y&&y.m(r,null),v(r,n),v(r,o),v(o,l),l.checked=t[6],v(r,a),v(r,f),x.m(f,null),v(r,E),k&&k.m(r,null),v(e,w),$&&$.m(e,null),v(e,j),m&&m.m(e,null),t[26](e),S||(M=[te(l,"change",t[25]),te(l,"change",t[10]),te(l,"invalid",t[11])],S=!0)},p(h,d){h[5]===b.VERIFYING?y||(y=pe(),y.c(),y.m(r,n)):y&&(y.d(1),y=null),d[0]&8&&s!==(s=h[3]+"_checkbox")&&c(l,"id",s),d[0]&1&&u!==(u=h[0]!=="onsubmit")&&(l.required=u),d[0]&64&&(l.checked=h[6]),d[0]&32&&he(o,"altcha-hidden",h[5]===b.VERIFYING),T===(T=F(h))&&x?x.p(h,d):(x.d(1),x=T(h),x&&(x.c(),x.m(f,null))),h[2]!==!0?k?k.p(h,d):(k=ye(),k.c(),k.m(r,null)):k&&(k.d(1),k=null),h[8]||h[5]===b.EXPIRED?$?$.p(h,d):($=ke(h),$.c(),$.m(e,j)):$&&($.d(1),$=null),h[9].footer&&h[1]!==!0?m?m.p(h,d):(m=$e(h),m.c(),m.m(e,null)):m&&(m.d(1),m=null),d[0]&32&&c(e,"data-state",h[5])},i:_,o:_,d(h){h&&I(e),y&&y.d(),x.d(),k&&k.d(),$&&$.d(),m&&m.d(),t[26](null),S=!1,B(M)}}}const Ee="https://altcha.org/";function xe(t){return JSON.parse(t)}function wt(t,e,r){let n,o,l,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:a=void 0}=e,{debug:f=!1}=e,{expire:E=void 0}=e,{hidefooter:w=!1}=e,{hidelogo:j=!1}=e,{name:S="altcha"}=e,{maxnumber:M=1e6}=e,{mockerror:y=!1}=e,{strings:F=void 0}=e,{test:T=!1}=e,{workers:x=navigator.hardwareConcurrency||8}=e;const k=Ye(),$=["SHA-256","SHA-384","SHA-512"];let m=!1,h,d=null,se=null,X=null,Z=b.UNVERIFIED,ce;Xe(()=>{d&&(d.removeEventListener("submit",Le),d.removeEventListener("reset",Ie),d=null)}),De(()=>{L("mounted","0.1.9"),L("workers",x),T&&L("using test mode"),E&&ue(E),s!==void 0&&L("auto",s),d=h.closest("form"),d&&(d.addEventListener("submit",Le),d.addEventListener("reset",Ie)),s==="onload"&&Y()});function L(...i){(f||i.some(g=>g instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function Le(i){d&&s==="onsubmit"&&Z===b.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),Y().then(()=>{d==null||d.requestSubmit()}))}function Ie(){z()}function _t(i,g){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:g.number,salt:i.salt,signature:i.signature,test:T?!0:void 0,took:g.took}))}function Re(i){if(!i.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(i.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!$.includes(i.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${$.join(", ")}`);if(!i.challenge||i.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!i.salt||i.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function pt(){if(y)throw L("mocking error"),new Error("Mocked error.");if(n)return L("using provided json data"),n;if(T)return L("generating test challenge"),ut();{if(!u)throw new Error("Attribute challengeurl not set.");L("fetching challenge from",u);const i=await fetch(u);if(i.status!==200)throw new Error(`Server responded with ${i.status}.`);const g=i.headers.get("Expires");if(g!=null&&g.length){const K=Date.parse(g);isNaN(K)||ue(K-Date.now())}return i.json()}}function Ne(){u&&Z===b.VERIFIED?Y():z(b.EXPIRED,l.expired)}async function yt(i){let g=null;if("Worker"in window){try{g=await kt(i.challenge,i.salt,i.algorithm)}catch(K){L(K)}if((g==null?void 0:g.number)!==void 0)return{data:i,solution:g}}return{data:i,solution:await ft(i.challenge,i.salt,i.algorithm,M).promise}}async function kt(i,g,K,q=Math.ceil(x)){const ee=[];if(q<1)throw new Error("Wrong number of workers configured.");if(q>16)throw new Error("Too many workers. Max. 16 allowed workers.");for(let G=0;G {const Ae=Rt*je;return new Promise(Nt=>{G.addEventListener("message",Me=>{if(Me.data)for(const Te of ee)Te!==G&&Te.postMessage({type:"abort"});Nt(Me.data)}),G.postMessage({payload:{alg:K,challenge:i,max:Ae+je,salt:g,start:Ae},type:"work"})})}));for(const G of ee)G.terminate();return It.find(G=>!!G)||null}function $t(){[b.UNVERIFIED,b.ERROR,b.EXPIRED].includes(Z)?Y():r(6,m=!0)}function Et(){Z===b.VERIFYING&&alert(l.waitAlert)}function ue(i){console.log(">>>"),L("expire",i),clearTimeout(ce),i<1?Ne():ce=setTimeout(Ne,i)}function xt(i){i.auto!==void 0&&(r(0,s=i.auto),s==="onload"&&Y()),i.expire!==void 0&&(ue(i.expire),r(13,E=i.expire)),i.challenge&&(Re(i.challenge),n=i.challenge),i.debug!==void 0&&r(12,f=!!i.debug),i.hidefooter!==void 0&&r(1,w=!!i.hidefooter),i.hidelogo!==void 0&&r(2,j=!!i.hidelogo),i.maxnumber!==void 0&&r(14,M=+i.maxnumber),i.mockerror!==void 0&&r(15,y=!!i.mockerror),i.name!==void 0&&r(3,S=i.name),i.test!==void 0&&r(16,T=!!i.test),i.strings&&r(24,o=i.strings),i.workers!==void 0&&r(17,x=+i.workers)}function z(i=b.UNVERIFIED,g=null){clearTimeout(ce),r(6,m=!1),r(8,se=g),r(4,X=null),r(5,Z=i)}async function Y(){return z(b.VERIFYING),pt().then(i=>(Re(i),L("challenge",i),yt(i))).then(({data:i,solution:g})=>{if(L("solution",g),(g==null?void 0:g.number)!==void 0)L("verified"),r(5,Z=b.VERIFIED),r(6,m=!0),r(4,X=_t(i,g)),L("payload",X),Ke().then(()=>{k("verified",{payload:X})});else throw new Error("Unexpected result returned.")}).catch(i=>{L(i),r(5,Z=b.ERROR),r(6,m=!1),r(8,se=i.message)})}function Ct(){m=this.checked,r(6,m)}function Lt(i){ne[i?"unshift":"push"](()=>{h=i,r(7,h)})}return t.$$set=i=>{"auto"in i&&r(0,s=i.auto),"challengeurl"in i&&r(18,u=i.challengeurl),"challengejson"in i&&r(19,a=i.challengejson),"debug"in i&&r(12,f=i.debug),"expire"in i&&r(13,E=i.expire),"hidefooter"in i&&r(1,w=i.hidefooter),"hidelogo"in i&&r(2,j=i.hidelogo),"name"in i&&r(3,S=i.name),"maxnumber"in i&&r(14,M=i.maxnumber),"mockerror"in i&&r(15,y=i.mockerror),"strings"in i&&r(20,F=i.strings),"test"in i&&r(16,T=i.test),"workers"in i&&r(17,x=i.workers)},t.$$.update=()=>{t.$$.dirty[0]&524288&&(n=a?xe(a):void 0),t.$$.dirty[0]&1048576&&r(24,o=F?xe(F):{}),t.$$.dirty[0]&16777216&&r(9,l={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...o}),t.$$.dirty[0]&48&&k("statechange",{payload:X,state:Z})},[s,w,j,S,X,Z,m,h,se,l,$t,Et,f,E,M,y,T,x,u,a,F,xt,z,Y,o,Ct,Lt]}class Ce extends nt{constructor(e){super(),tt(this,e,wt,vt,Se,{auto:0,challengeurl:18,challengejson:19,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,strings:20,test:16,workers:17,configure:21,reset:22,verify:23},at,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),C()}get challengeurl(){return this.$$.ctx[18]}set challengeurl(e){this.$$set({challengeurl:e}),C()}get challengejson(){return this.$$.ctx[19]}set challengejson(e){this.$$set({challengejson:e}),C()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),C()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),C()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),C()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),C()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),C()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),C()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),C()}get strings(){return this.$$.ctx[20]}set strings(e){this.$$set({strings:e}),C()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),C()}get workers(){return this.$$.ctx[17]}set workers(e){this.$$set({workers:e}),C()}get configure(){return this.$$.ctx[21]}get reset(){return this.$$.ctx[22]}get verify(){return this.$$.ctx[23]}}customElements.define("altcha-widget",rt(Ce,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),N.Altcha=Ce,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})}); diff --git a/e2e/altcha.spec.ts b/e2e/altcha.spec.ts index ff7715f..e4d3a87 100644 --- a/e2e/altcha.spec.ts +++ b/e2e/altcha.spec.ts @@ -1,5 +1,7 @@ import { test, expect } from '@playwright/test'; +const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); + test('should be rendered', async ({ page }) => { await page.goto('./e2e/index.html'); const cmp = page.locator('#test-render .altcha').first(); @@ -22,6 +24,16 @@ test('should be without the footer', async ({ page }) => { expect(await page.locator('#test-hidefooter .altcha-footer').first().count()).toBe(0); }); +test('should show expired error', async ({ page }) => { + await page.goto('./e2e/index.html'); + await delay(100); + expect(await page.locator('#test-expire .altcha-error').first().count()).toBe(0); + await delay(2000); + expect(await page.locator('#test-expire .altcha-error').first().count()).toBe(1); + const cmp = page.locator('#test-expire .altcha').first(); + await expect(cmp).toContainText(/expired/); +}); + test('should set options via configure()', async ({ page }) => { await page.goto('./e2e/index.html'); const cmp = page.locator('#test-configure .altcha').first(); diff --git a/e2e/index.html b/e2e/index.html index 4ce6450..ea37403 100644 --- a/e2e/index.html +++ b/e2e/index.html @@ -1,6 +1,6 @@ - + @@ -33,6 +33,13 @@ > ++++ = 0.8" } }, + "node_modules/husky": { + "version": "9.0.11", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.0.11.tgz", + "integrity": "sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw==", + "dev": true, + "bin": { + "husky": "bin.mjs" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", diff --git a/package.json b/package.json index ddea963..1f7d736 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "preview": "vite preview", "check": "svelte-check --tsconfig ./tsconfig.json", "test": "vitest run tests/helpers.test.ts", - "test:e2e": "playwright test" + "test:e2e": "playwright test", + "prepare": "husky" }, "devDependencies": { "@playwright/test": "^1.41.2", @@ -51,6 +52,7 @@ "body-parser": "^1.20.2", "cors": "^2.8.5", "express": "^4.18.2", + "husky": "^9.0.11", "sass": "^1.71.1", "svelte": "^4.2.11", "svelte-check": "^3.4.6", diff --git a/src/Altcha.svelte b/src/Altcha.svelte index fec92ad..fbcbf9b 100644 --- a/src/Altcha.svelte +++ b/src/Altcha.svelte @@ -22,7 +22,7 @@ export let mockerror: boolean = false; export let strings: string | undefined = undefined; export let test: boolean = false; - export let workers: number = 8; + export let workers: number = navigator.hardwareConcurrency || 8; const dispatch = createEventDispatcher(); const allowedAlgs = ['SHA-256', 'SHA-384', 'SHA-512']; @@ -60,6 +60,7 @@ onMount(() => { log('mounted', ALTCHA_VERSION); + log('workers', workers); if (test) { log('using test mode'); } @@ -255,6 +256,8 @@ } function setExpire(duration: number) { + console.log('>>>') + log('expire', duration) clearTimeout(expireTimeout); if(duration < 1) { expireChallenge(); @@ -302,6 +305,9 @@ if (options.strings) { parsedStrings = options.strings; } + if (options.workers !== void 0) { + workers = +options.workers; + } } export function reset(newState: State = State.UNVERIFIED, err: string | null = null) { diff --git a/src/helpers.ts b/src/helpers.ts index a302c47..8e9ed8d 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -6,9 +6,11 @@ export function ab2hex(ab: ArrayBuffer) { return [...new Uint8Array(ab)].map(x => x.toString(16).padStart(2, '0')).join(''); } -export async function createTestChallenge(max: number = 1e5, algorithm: string = 'SHA-256') { +export async function createTestChallenge(num?: number, algorithm: string = 'SHA-256', max: number = 1e5) { const salt = Date.now().toString(16); - const num = Math.round(Math.random() * max); + if (!num) { + num = Math.round(Math.random() * max); + } const challenge = await hashChallenge(salt, num, algorithm); return { algorithm, diff --git a/src/types.ts b/src/types.ts index 39afdcb..151b677 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,6 +20,7 @@ export interface Configure { name?: string; strings?: Partial ; test?: boolean; + workers?: number; } export interface Solution { diff --git a/tests/helpers.test.ts b/tests/helpers.test.ts index 48b4f29..279a7fb 100644 --- a/tests/helpers.test.ts +++ b/tests/helpers.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, test } from 'vitest'; +import { describe, expect, test, vi } from 'vitest'; import { ab2hex, hashChallenge, createTestChallenge, solveChallenge } from '../src/helpers'; const alg = 'SHA-256'; @@ -37,4 +37,21 @@ describe('solveChallenge', () => { const challenge = await hashChallenge(data.salt, solution!.number, alg); expect(data.challenge).toBe(challenge); }); + + test('should return null if start is greater than random number', async () => { + const data = await createTestChallenge(10, alg); + const solution = await solveChallenge(data.challenge, data.salt, data.algorithm, 100, 20).promise; + expect(solution).toEqual(null); + }); + + test('should abort and return null', async () => { + const data = await createTestChallenge(100, alg); + const { controller, promise } = solveChallenge(data.challenge, data.salt, data.algorithm); + process.nextTick(() => { + controller.abort(); + }); + const solution = await promise; + expect(controller.signal.aborted).toEqual(true) + expect(solution).toEqual(null); + }); }); \ No newline at end of file