altcha 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -50
- package/dist/altcha.d.ts +24 -5
- package/dist/altcha.js +972 -824
- package/dist/altcha.umd.cjs +2 -2
- package/dist_external/altcha.d.ts +24 -5
- package/dist_external/altcha.js +1009 -861
- package/dist_external/altcha.umd.cjs +2 -2
- package/dist_external/worker.js +1 -1
- package/dist_plugins/analytics.d.ts +1 -0
- package/dist_plugins/analytics.js +290 -0
- package/dist_plugins/analytics.umd.cjs +1 -0
- package/dist_plugins/obfuscation.d.ts +1 -0
- package/dist_plugins/obfuscation.js +138 -0
- package/dist_plugins/obfuscation.umd.cjs +1 -0
- package/dist_plugins/upload.d.ts +1 -0
- package/dist_plugins/upload.js +458 -0
- package/dist_plugins/upload.umd.cjs +4 -0
- package/package.json +39 -22
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(m,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(m=typeof globalThis<"u"?globalThis:m||self,v(m.altcha={}))})(this,function(m){"use strict";var kn=Object.defineProperty;var Lt=m=>{throw TypeError(m)};var pn=(m,v,A)=>v in m?kn(m,v,{enumerable:!0,configurable:!0,writable:!0,value:A}):m[v]=A;var j=(m,v,A)=>pn(m,typeof v!="symbol"?v+"":v,A),It=(m,v,A)=>v.has(m)||Lt("Cannot "+A);var $=(m,v,A)=>(It(m,v,"read from private field"),A?A.call(m):v.get(m)),le=(m,v,A)=>v.has(m)?Lt("Cannot add the same private member more than once"):v instanceof WeakSet?v.add(m):v.set(m,A),xt=(m,v,A,de)=>(It(m,v,"write to private field"),de?de.call(m,A):v.set(m,A),A);var ue,he,we,_e,ye,ve;var v=typeof document<"u"?document.currentScript:null;function A(){}function de(i){return i()}function He(){return Object.create(null)}function ge(i){i.forEach(de)}function $e(i){return typeof i=="function"}function Tt(i,e){return i!=i?e==e:i!==e||i&&typeof i=="object"||typeof i=="function"}function Rt(i){return Object.keys(i).length===0}function L(i,e){i.appendChild(e)}function V(i,e,t){i.insertBefore(e,t||null)}function D(i){i.parentNode&&i.parentNode.removeChild(i)}function R(i){return document.createElement(i)}function z(i){return document.createElementNS("http://www.w3.org/2000/svg",i)}function qe(i){return document.createTextNode(i)}function K(){return qe(" ")}function Ft(){return qe("")}function De(i,e,t,r){return i.addEventListener(e,t,r),()=>i.removeEventListener(e,t,r)}function f(i,e,t){t==null?i.removeAttribute(e):i.getAttribute(e)!==t&&i.setAttribute(e,t)}function St(i){return Array.from(i.childNodes)}function Ze(i,e,t){i.classList.toggle(e,!!t)}function Mt(i,e,{bubbles:t=!1,cancelable:r=!1}={}){return new CustomEvent(i,{detail:e,bubbles:t,cancelable:r})}function Dt(i){const e={};return i.childNodes.forEach(t=>{e[t.slot||"default"]=!0}),e}let me;function be(i){me=i}function Ne(){if(!me)throw new Error("Function called outside component initialization");return me}function Nt(i){Ne().$$.on_mount.push(i)}function jt(i){Ne().$$.on_destroy.push(i)}function Vt(){const i=Ne();return(e,t,{cancelable:r=!1}={})=>{const o=i.$$.callbacks[e];if(o){const s=Mt(e,t,{cancelable:r});return o.slice().forEach(u=>{u.call(i,s)}),!s.defaultPrevented}return!0}}const fe=[],Ce=[];let ae=[];const Ye=[],Ge=Promise.resolve();let je=!1;function Je(){je||(je=!0,Ge.then(k))}function Ut(){return Je(),Ge}function Ve(i){ae.push(i)}const Ue=new Set;let ce=0;function k(){if(ce!==0)return;const i=me;do{try{for(;ce<fe.length;){const e=fe[ce];ce++,be(e),Pt(e.$$)}}catch(e){throw fe.length=0,ce=0,e}for(be(null),fe.length=0,ce=0;Ce.length;)Ce.pop()();for(let e=0;e<ae.length;e+=1){const t=ae[e];Ue.has(t)||(Ue.add(t),t())}ae.length=0}while(fe.length);for(;Ye.length;)Ye.pop()();je=!1,Ue.clear(),be(i)}function Pt(i){if(i.fragment!==null){i.update(),ge(i.before_update);const e=i.dirty;i.dirty=[-1],i.fragment&&i.fragment.p(i.ctx,e),i.after_update.forEach(Ve)}}function Bt(i){const e=[],t=[];ae.forEach(r=>i.indexOf(r)===-1?e.push(r):t.push(r)),t.forEach(r=>r()),ae=e}const Ot=new Set;function Ht(i,e){i&&i.i&&(Ot.delete(i),i.i(e))}function $t(i,e,t){const{fragment:r,after_update:o}=i.$$;r&&r.m(e,t),Ve(()=>{const s=i.$$.on_mount.map(de).filter($e);i.$$.on_destroy?i.$$.on_destroy.push(...s):ge(s),i.$$.on_mount=[]}),o.forEach(Ve)}function qt(i,e){const t=i.$$;t.fragment!==null&&(Bt(t.after_update),ge(t.on_destroy),t.fragment&&t.fragment.d(e),t.on_destroy=t.fragment=null,t.ctx=[])}function Zt(i,e){i.$$.dirty[0]===-1&&(fe.push(i),Je(),i.$$.dirty.fill(0)),i.$$.dirty[e/31|0]|=1<<e%31}function Yt(i,e,t,r,o,s,u=null,a=[-1]){const l=me;be(i);const c=i.$$={fragment:null,ctx:[],props:s,update:A,not_equal:o,bound:He(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(l?l.$$.context:[])),callbacks:He(),dirty:a,skip_bound:!1,root:e.target||l.$$.root};u&&u(c.root);let q=!1;if(c.ctx=t?t(i,e.props||{},(w,Z,...Y)=>{const G=Y.length?Y[0]:Z;return c.ctx&&o(c.ctx[w],c.ctx[w]=G)&&(!c.skip_bound&&c.bound[w]&&c.bound[w](G),q&&Zt(i,w)),Z}):[],c.update(),q=!0,ge(c.before_update),c.fragment=r?r(c.ctx):!1,e.target){if(e.hydrate){const w=St(e.target);c.fragment&&c.fragment.l(w),w.forEach(D)}else c.fragment&&c.fragment.c();e.intro&&Ht(i.$$.fragment),$t(i,e.target,e.anchor),k()}be(l)}let Xe;typeof HTMLElement=="function"&&(Xe=class extends HTMLElement{constructor(e,t,r){super();j(this,"$$ctor");j(this,"$$s");j(this,"$$c");j(this,"$$cn",!1);j(this,"$$d",{});j(this,"$$r",!1);j(this,"$$p_d",{});j(this,"$$l",{});j(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=t,r&&this.attachShadow({mode:"open"})}addEventListener(e,t,r){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(t),this.$$c){const o=this.$$c.$on(e,t);this.$$l_u.set(t,o)}super.addEventListener(e,t,r)}removeEventListener(e,t,r){if(super.removeEventListener(e,t,r),this.$$c){const o=this.$$l_u.get(t);o&&(o(),this.$$l_u.delete(t))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(s){return()=>{let u;return{c:function(){u=R("slot"),s!=="default"&&f(u,"name",s)},m:function(c,q){V(c,u,q)},d:function(c){c&&D(u)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const t={},r=Dt(this);for(const s of this.$$s)s in r&&(t[s]=[e(s)]);for(const s of this.attributes){const u=this.$$g_p(s.name);u in this.$$d||(this.$$d[u]=Ae(u,s.value,this.$$p_d,"toProp"))}for(const s in this.$$p_d)!(s in this.$$d)&&this[s]!==void 0&&(this.$$d[s]=this[s],delete this[s]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:t,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const s in this.$$p_d)if(this.$$d[s]=this.$$c.$$.ctx[this.$$c.$$.props[s]],this.$$p_d[s].reflect){const u=Ae(s,this.$$d[s],this.$$p_d,"toAttribute");u==null?this.removeAttribute(this.$$p_d[s].attribute||s):this.setAttribute(this.$$p_d[s].attribute||s,u)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const s in this.$$l)for(const u of this.$$l[s]){const a=this.$$c.$on(s,u);this.$$l_u.set(u,a)}this.$$l={}}}attributeChangedCallback(e,t,r){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Ae(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&&(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(t=>this.$$p_d[t].attribute===e||!this.$$p_d[t].attribute&&t.toLowerCase()===e)||e}});function Ae(i,e,t,r){var s;const o=(s=t[i])==null?void 0:s.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!r||!t[i])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 Gt(i,e,t,r,o,s){let u=class extends Xe{constructor(){super(i,t,o),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(u.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(l){var c;l=Ae(a,l,e),this.$$d[a]=l,(c=this.$$c)==null||c.$set({[a]:l})}})}),r.forEach(a=>{Object.defineProperty(u.prototype,a,{get(){var l;return(l=this.$$c)==null?void 0:l[a]}})}),i.element=u,u}class Jt{constructor(){j(this,"$$");j(this,"$$set")}$destroy(){qt(this,1),this.$destroy=A}$on(e,t){if(!$e(t))return A;const r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(t),()=>{const o=r.indexOf(t);o!==-1&&r.splice(o,1)}}$set(e){this.$$set&&!Rt(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Xt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Xt);const Wt=new TextEncoder;function zt(i){return[...new Uint8Array(i)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function Kt(i,e="SHA-256",t=1e5){const r=Date.now().toString(16);i||(i=Math.round(Math.random()*t));const o=await We(r,i,e);return{algorithm:e,challenge:o,salt:r,signature:""}}async function We(i,e,t){return zt(await crypto.subtle.digest(t.toUpperCase(),Wt.encode(i+e)))}function Qt(i,e,t="SHA-256",r=1e6,o=0){const s=new AbortController,u=Date.now();return{promise:(async()=>{for(let l=o;l<=r;l+=1){if(s.signal.aborted)return null;if(await We(e,l,t)===i)return{number:l,took:Date.now()-u}}return null})(),controller:s}}function ze(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}class en{constructor(e){j(this,"beaconUrl",null);j(this,"error",null);j(this,"loadTime",Date.now());j(this,"submitTime",null);j(this,"startTime",null);j(this,"viewTimeThresholdMs",1500);le(this,ue,{});le(this,he,null);le(this,we,this.onFormChange.bind(this));le(this,_e,this.onFormFocus.bind(this));le(this,ye,this.onFormSubmit.bind(this));le(this,ve,this.onUnload.bind(this));this.elForm=e,window.addEventListener("unload",$(this,ve)),this.elForm.addEventListener("change",$(this,we)),this.elForm.addEventListener("focusin",$(this,_e)),this.elForm.addEventListener("submit",$(this,ye))}data(){const e=Object.entries($(this,ue));return{correction:e.length&&e.filter(([t,r])=>r>1).length/e.length||0,dropoff:!this.submitTime&&!this.error&&$(this,he)?$(this,he):null,error:this.error,mobile:this.isMobile(),start:this.startTime,submit:this.submitTime,tz:ze()}}dataAsBase64(){try{return btoa(JSON.stringify(this.data()))}catch(e){console.error("failed to encode ALTCHA session data to base64",e)}return""}destroy(){window.removeEventListener("unload",$(this,ve)),this.elForm.removeEventListener("change",$(this,we)),this.elForm.removeEventListener("focusin",$(this,_e)),this.elForm.removeEventListener("submit",$(this,ye))}end(){this.submitTime||(this.submitTime=Date.now())}getFieldName(e,t=40){const r=e.getAttribute("data-group-label"),o=e.getAttribute("name")||e.getAttribute("aria-label");return((r?r+": ":"")+o).slice(0,t)}isMobile(){const e="userAgentData"in navigator&&navigator.userAgentData?navigator.userAgentData:{};return"mobile"in e?e.mobile===!0:/Mobi/i.test(window.navigator.userAgent)}isInput(e){return["INPUT","SELECT","TEXTAREA"].includes(e.tagName)}onFormFieldChange(e){const t=this.getFieldName(e);t&&this.trackFieldChange(t)}onFormChange(e){const t=e.target;t&&this.isInput(t)&&this.onFormFieldChange(t)}onFormFocus(e){const t=e.target;if(this.startTime||this.start(),t&&this.isInput(t)){const r=this.getFieldName(t);r&&xt(this,he,r)}}onFormSubmit(){this.end()}onUnload(){this.loadTime<=Date.now()-this.viewTimeThresholdMs&&!this.submitTime&&this.sendBeacon()}async sendBeacon(){if(this.beaconUrl&&"sendBeacon"in navigator)try{navigator.sendBeacon(new URL(this.beaconUrl,location.origin),JSON.stringify(this.data()))}catch{}}start(){this.startTime=Date.now()}trackError(e){this.error=e===null?null:String(e)}trackFieldChange(e){$(this,ue)[e]=($(this,ue)[e]||0)+1}}ue=new WeakMap,he=new WeakMap,we=new WeakMap,_e=new WeakMap,ye=new WeakMap,ve=new WeakMap;var b=(i=>(i.ERROR="error",i.VERIFIED="verified",i.VERIFYING="verifying",i.UNVERIFIED="unverified",i.EXPIRED="expired",i))(b||{});function Ke(i){let e,t,r;return{c(){e=z("svg"),t=z("path"),r=z("path"),f(t,"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"),f(t,"fill","currentColor"),f(t,"opacity",".25"),f(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"),f(r,"fill","currentColor"),f(r,"class","altcha-spinner"),f(e,"width","24"),f(e,"height","24"),f(e,"viewBox","0 0 24 24"),f(e,"xmlns","http://www.w3.org/2000/svg")},m(o,s){V(o,e,s),L(e,t),L(e,r)},d(o){o&&D(e)}}}function tn(i){let e,t=i[13].label+"",r;return{c(){e=R("label"),f(e,"for",r=i[4]+"_checkbox")},m(o,s){V(o,e,s),e.innerHTML=t},p(o,s){s[0]&8192&&t!==(t=o[13].label+"")&&(e.innerHTML=t),s[0]&16&&r!==(r=o[4]+"_checkbox")&&f(e,"for",r)},d(o){o&&D(e)}}}function nn(i){let e,t=i[13].verifying+"";return{c(){e=R("span")},m(r,o){V(r,e,o),e.innerHTML=t},p(r,o){o[0]&8192&&t!==(t=r[13].verifying+"")&&(e.innerHTML=t)},d(r){r&&D(e)}}}function rn(i){let e,t=i[13].verified+"",r,o,s,u,a=i[11]&&Qe(i);return{c(){e=R("span"),r=K(),o=R("input"),s=K(),a&&a.c(),u=Ft(),f(o,"type","hidden"),f(o,"name",i[4]),o.value=i[6]},m(l,c){V(l,e,c),e.innerHTML=t,V(l,r,c),V(l,o,c),V(l,s,c),a&&a.m(l,c),V(l,u,c)},p(l,c){c[0]&8192&&t!==(t=l[13].verified+"")&&(e.innerHTML=t),c[0]&16&&f(o,"name",l[4]),c[0]&64&&(o.value=l[6]),l[11]?a?a.p(l,c):(a=Qe(l),a.c(),a.m(u.parentNode,u)):a&&(a.d(1),a=null)},d(l){l&&(D(e),D(r),D(o),D(s),D(u)),a&&a.d(l)}}}function Qe(i){let e;return{c(){e=R("input"),f(e,"type","hidden"),f(e,"name","__session"),e.value=i[12]},m(t,r){V(t,e,r)},p(t,r){r[0]&4096&&(e.value=t[12])},d(t){t&&D(e)}}}function et(i){let e,t,r,o,s,u,a;return{c(){e=R("div"),t=R("a"),r=z("svg"),o=z("path"),s=z("path"),u=z("path"),f(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"),f(o,"fill","currentColor"),f(s,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),f(s,"fill","currentColor"),f(u,"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"),f(u,"fill","currentColor"),f(r,"width","22"),f(r,"height","22"),f(r,"viewBox","0 0 20 20"),f(r,"fill","none"),f(r,"xmlns","http://www.w3.org/2000/svg"),f(t,"href",ot),f(t,"target","_blank"),f(t,"class","altcha-logo"),f(t,"aria-label",a=i[13].ariaLinkLabel)},m(l,c){V(l,e,c),L(e,t),L(t,r),L(r,o),L(r,s),L(r,u)},p(l,c){c[0]&8192&&a!==(a=l[13].ariaLinkLabel)&&f(t,"aria-label",a)},d(l){l&&D(e)}}}function tt(i){let e,t,r,o;function s(l,c){return l[7]===b.EXPIRED?sn:on}let u=s(i),a=u(i);return{c(){e=R("div"),t=z("svg"),r=z("path"),o=K(),a.c(),f(r,"stroke-linecap","round"),f(r,"stroke-linejoin","round"),f(r,"d","M6 18L18 6M6 6l12 12"),f(t,"width","14"),f(t,"height","14"),f(t,"xmlns","http://www.w3.org/2000/svg"),f(t,"fill","none"),f(t,"viewBox","0 0 24 24"),f(t,"stroke-width","1.5"),f(t,"stroke","currentColor"),f(e,"class","altcha-error")},m(l,c){V(l,e,c),L(e,t),L(t,r),L(e,o),a.m(e,null)},p(l,c){u===(u=s(l))&&a?a.p(l,c):(a.d(1),a=u(l),a&&(a.c(),a.m(e,null)))},d(l){l&&D(e),a.d()}}}function on(i){let e,t=i[13].error+"";return{c(){e=R("div"),f(e,"title",i[5])},m(r,o){V(r,e,o),e.innerHTML=t},p(r,o){o[0]&8192&&t!==(t=r[13].error+"")&&(e.innerHTML=t),o[0]&32&&f(e,"title",r[5])},d(r){r&&D(e)}}}function sn(i){let e,t=i[13].expired+"";return{c(){e=R("div"),f(e,"title",i[5])},m(r,o){V(r,e,o),e.innerHTML=t},p(r,o){o[0]&8192&&t!==(t=r[13].expired+"")&&(e.innerHTML=t),o[0]&32&&f(e,"title",r[5])},d(r){r&&D(e)}}}function nt(i){let e,t,r=i[13].footer+"";return{c(){e=R("div"),t=R("div"),f(e,"class","altcha-footer")},m(o,s){V(o,e,s),L(e,t),t.innerHTML=r},p(o,s){s[0]&8192&&r!==(r=o[13].footer+"")&&(t.innerHTML=r)},d(o){o&&D(e)}}}function it(i){let e;return{c(){e=R("div"),f(e,"class","altcha-anchor-arrow")},m(t,r){V(t,e,r),i[41](e)},p:A,d(t){t&&D(e),i[41](null)}}}function ln(i){let e,t,r,o,s,u,a,l,c,q,w,Z,Y,G,Q,_=i[7]===b.VERIFYING&&Ke();function te(d,p){return d[7]===b.VERIFIED?rn:d[7]===b.VERIFYING?nn:tn}let ee=te(i),P=ee(i),F=(i[3]!==!0||i[14])&&et(i),N=(i[5]||i[7]===b.EXPIRED)&&tt(i),I=i[13].footer&&(i[2]!==!0||i[14])&&nt(i),S=i[1]&&it(i);return{c(){e=R("div"),t=R("div"),_&&_.c(),r=K(),o=R("div"),s=R("input"),l=K(),c=R("div"),P.c(),q=K(),F&&F.c(),w=K(),N&&N.c(),Z=K(),I&&I.c(),Y=K(),S&&S.c(),f(s,"type","checkbox"),f(s,"id",u=i[4]+"_checkbox"),s.required=a=i[0]!=="onsubmit",f(o,"class","altcha-checkbox"),Ze(o,"altcha-hidden",i[7]===b.VERIFYING),f(c,"class","altcha-label"),f(t,"class","altcha-main"),f(e,"class","altcha"),f(e,"data-state",i[7]),f(e,"data-floating",i[1])},m(d,p){V(d,e,p),L(e,t),_&&_.m(t,null),L(t,r),L(t,o),L(o,s),s.checked=i[8],L(t,l),L(t,c),P.m(c,null),L(t,q),F&&F.m(t,null),L(e,w),N&&N.m(e,null),L(e,Z),I&&I.m(e,null),L(e,Y),S&&S.m(e,null),i[42](e),G||(Q=[De(s,"change",i[40]),De(s,"change",i[15]),De(s,"invalid",i[16])],G=!0)},p(d,p){d[7]===b.VERIFYING?_||(_=Ke(),_.c(),_.m(t,r)):_&&(_.d(1),_=null),p[0]&16&&u!==(u=d[4]+"_checkbox")&&f(s,"id",u),p[0]&1&&a!==(a=d[0]!=="onsubmit")&&(s.required=a),p[0]&256&&(s.checked=d[8]),p[0]&128&&Ze(o,"altcha-hidden",d[7]===b.VERIFYING),ee===(ee=te(d))&&P?P.p(d,p):(P.d(1),P=ee(d),P&&(P.c(),P.m(c,null))),d[3]!==!0||d[14]?F?F.p(d,p):(F=et(d),F.c(),F.m(t,null)):F&&(F.d(1),F=null),d[5]||d[7]===b.EXPIRED?N?N.p(d,p):(N=tt(d),N.c(),N.m(e,Z)):N&&(N.d(1),N=null),d[13].footer&&(d[2]!==!0||d[14])?I?I.p(d,p):(I=nt(d),I.c(),I.m(e,Y)):I&&(I.d(1),I=null),d[1]?S?S.p(d,p):(S=it(d),S.c(),S.m(e,null)):S&&(S.d(1),S=null),p[0]&128&&f(e,"data-state",d[7]),p[0]&2&&f(e,"data-floating",d[1])},i:A,o:A,d(d){d&&D(e),_&&_.d(),P.d(),F&&F.d(),N&&N.d(),I&&I.d(),S&&S.d(),i[42](null),G=!1,ge(Q)}}}const rt="Visit Altcha.org",ot="https://altcha.org/";function st(i){return JSON.parse(i)}function fn(i,e,t){var Ct,At;let r,o,s,u,{analytics:a=!1}=e,{auto:l=void 0}=e,{beaconurl:c=void 0}=e,{blockspam:q=void 0}=e,{challengeurl:w=void 0}=e,{challengejson:Z=void 0}=e,{debug:Y=!1}=e,{delay:G=0}=e,{expire:Q=void 0}=e,{floating:_=void 0}=e,{floatinganchor:te=void 0}=e,{floatingoffset:ee=void 0}=e,{hidefooter:P=!1}=e,{hidelogo:F=!1}=e,{name:N="altcha"}=e,{maxnumber:I=1e6}=e,{mockerror:S=!1}=e,{refetchonexpire:d=!0}=e,{spamfilter:p=!1}=e,{strings:Le=void 0}=e,{test:J=!1}=e,{verifyurl:ie=void 0}=e,{workers:Ee=Math.min(16,navigator.hardwareConcurrency||8)}=e,{workerurl:Ie=void 0}=e;const Pe=Vt(),ft=["SHA-256","SHA-384","SHA-512"],at=(At=(Ct=document.documentElement.lang)==null?void 0:Ct.split("-"))==null?void 0:At[0];let ne=!1,x,re=null,xe=null,g=null,Te=null,X=null,oe=null,B=null,ct=null,O=b.UNVERIFIED;jt(()=>{g&&(g.removeEventListener("submit",ht),g.removeEventListener("reset",dt),g.removeEventListener("focusin",ut),g=null),B&&B.destroy(),X&&(clearTimeout(X),X=null),document.removeEventListener("click",_t),document.removeEventListener("scroll",yt),window.removeEventListener("resize",Et)}),Nt(()=>{C("mounted","0.7.0"),C("workers",Ee),J&&C("using test mode"),Q&&Re(Q),l!==void 0&&C("auto",l),_!==void 0&&kt(_),g=x.closest("form"),g&&(g.addEventListener("submit",ht,{capture:!0}),g.addEventListener("reset",dt),l==="onfocus"&&g.addEventListener("focusin",ut)),a&&bt(),l==="onload"&&se(),r&&(P||F)&&C("Attributes hidefooter and hidelogo ignored because usage with free API Keys require attribution.")});function C(...n){(Y||n.some(h=>h instanceof Error))&&console[n[0]instanceof Error?"error":"log"]("ALTCHA",...n)}function ut(n){O===b.UNVERIFIED&&se()}function ht(n){g&&B&&O===b.VERIFIED&&(B.end(),t(12,ct=B.dataAsBase64())),g&&l==="onsubmit"&&(O===b.UNVERIFIED?(n.preventDefault(),n.stopPropagation(),se().then(()=>{g==null||g.requestSubmit()})):O!==b.VERIFIED&&(n.preventDefault(),n.stopPropagation(),O===b.VERIFYING&&vt()))}function dt(){Fe()}function gt(n,h){return btoa(JSON.stringify({algorithm:n.algorithm,challenge:n.challenge,number:h.number,salt:n.salt,signature:n.signature,test:J?!0:void 0,took:h.took}))}function mt(n){if(!n.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(n.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!ft.includes(n.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${ft.join(", ")}`);if(!n.challenge||n.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!n.salt||n.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function an(){var n;if(S)throw C("mocking error"),new Error("Mocked error.");if(o)return C("using provided json data"),o;if(J)return C("generating test challenge",{test:J}),Kt(typeof J!="boolean"?+J:void 0);{if(!w&&g){const E=g.getAttribute("action");E!=null&&E.includes("/form/")&&t(17,w=E+"/altcha")}if(!w)throw new Error("Attribute challengeurl not set.");C("fetching challenge from",w);const h=await fetch(w,{headers:p?{"x-altcha-spam-filter":"1"}:{}});if(h.status!==200)throw new Error(`Server responded with ${h.status}.`);const y=h.headers.get("Expires"),M=h.headers.get("X-Altcha-Config"),H=await h.json(),U=new URLSearchParams((n=H.salt.split("?"))==null?void 0:n[1]),W=U.get("expires")||U.get("expire");if(W){const E=new Date(+W*1e3),T=isNaN(E.getTime())?0:E.getTime()-Date.now();T>0&&Re(T)}if(M)try{const E=JSON.parse(M);E&&typeof E=="object"&&(E.verifyurl&&(E.verifyurl=new URL(E.verifyurl,new URL(w)).toString()),pt(E))}catch(E){C("unable to configure from X-Altcha-Config",E)}if(!Q&&(y!=null&&y.length)){const E=Date.parse(y);if(E){const T=E-Date.now();T>0&&Re(T)}}return H}}function bt(){if(!B)if(g){if(C("analytics enabled"),t(11,B=new en(g)),c===void 0){const n=g.getAttribute("action");n&&t(19,c=n+"/beacon")}t(11,B.beaconUrl=c||null,B)}else C("analytics cannot be enabled - form element not found")}function wt(){w&&d&&O===b.VERIFIED?se():Fe(b.EXPIRED,u.expired)}async function cn(n){let h=null;if("Worker"in window){try{h=await un(n.challenge,n.salt,n.algorithm,n.maxnumber)}catch(y){C(y)}if((h==null?void 0:h.number)!==void 0)return{data:n,solution:h}}return{data:n,solution:await Qt(n.challenge,n.salt,n.algorithm,n.maxnumber||I).promise}}async function un(n,h,y,M=typeof J=="number"?J:I,H=Math.ceil(Ee)){const U=[];H=Math.min(16,Math.max(1,H));for(let T=0;T<H;T++)U.push(createAltchaWorker(Ie));const W=Math.ceil(M/H),E=await Promise.all(U.map((T,Oe)=>{const ke=Oe*W;return new Promise(Se=>{T.addEventListener("message",Me=>{if(Me.data)for(const pe of U)pe!==T&&pe.postMessage({type:"abort"});Se(Me.data)}),T.postMessage({payload:{alg:y,challenge:n,max:ke+W,salt:h,start:ke},type:"work"})})}));for(const T of U)T.terminate();return E.find(T=>!!T)||null}function hn(){[b.UNVERIFIED,b.ERROR,b.EXPIRED].includes(O)?p&&(g==null?void 0:g.reportValidity())===!1?t(8,ne=!1):se():t(8,ne=!0)}function _t(n){const h=n.target;_&&h&&!x.contains(h)&&O===b.VERIFIED&&t(9,x.style.display="none",x)}function yt(){_&&Be()}function vt(){O===b.VERIFYING&&u.waitAlert&&alert(u.waitAlert)}function dn(n){B&&B.trackError(Te)}function gn(n){_&&O!==b.UNVERIFIED&&requestAnimationFrame(()=>{Be()})}function Et(){_&&Be()}function Re(n){C("expire",n),X&&(clearTimeout(X),X=null),n<1?wt():X=setTimeout(wt,n)}function kt(n){C("floating",n),_!==n&&(t(9,x.style.left="",x),t(9,x.style.top="",x)),t(1,_=n===!0||n===""?"auto":n===!1||n==="false"?void 0:_),_?(l||t(0,l="onsubmit"),document.addEventListener("scroll",yt),document.addEventListener("click",_t),window.addEventListener("resize",Et)):l==="onsubmit"&&t(0,l=void 0)}function mn(n){var y;const h=g==null?void 0:g.querySelector(typeof n=="string"?`input[name="${n}"]`:'input[type="email"]:not([data-no-spamfilter])');return((y=h==null?void 0:h.value)==null?void 0:y.slice(h.value.indexOf("@")))||void 0}function bn(n){return[...(g==null?void 0:g.querySelectorAll(n!=null&&n.length?n.map(y=>`input[name="${y}"]`).join(", "):'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])'))||[]].reduce((y,M)=>{const H=M.name,U=M.value;return H&&U&&(y[H]=/\n/.test(U)?U.replace(new RegExp("(?<!\\r)\\n","g"),`\r
|
|
2
|
-
`):U),y},{})}async function wn(n){if(!ie)throw new Error("Attribute verifyurl not set.");C("requesting server verification from",ie);const h={payload:n};if(p){const{blockedCountries:H,classifier:U,disableRules:W,email:E,expectedLanguages:T,expectedCountries:Oe,fields:ke,ipAddress:Se,text:Me,timeZone:pe}=_n();h.blockedCountries=H,h.classifier=U,h.disableRules=W,h.email=E===!1?void 0:mn(E),h.expectedCountries=Oe,h.expectedLanguages=T||(at?[at]:void 0),h.fields=ke===!1?void 0:bn(ke),h.ipAddress=Se===!1?void 0:Se||"auto",h.text=Me,h.timeZone=pe===!1?void 0:pe||ze()}const y=await fetch(ie,{body:JSON.stringify(h),headers:{"content-type":"application/json"},method:"POST"});if(y.status!==200)throw new Error(`Server responded with ${y.status}.`);const M=await y.json();if(M!=null&&M.payload&&t(6,oe=M.payload),Pe("serververification",M),q&&M.classification==="BAD")throw new Error("SpamFilter returned negative classification.")}function _n(){return p==="ipAddress"?{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:!1,expectedCountries:void 0,expectedLanguages:void 0,fields:!1,ipAddress:void 0,text:void 0,timeZone:void 0}:typeof p=="object"?p:{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:void 0,expectedCountries:void 0,expectedLanguages:void 0,fields:void 0,ipAddress:void 0,text:void 0,timeZone:void 0}}function Be(n=20){if(x)if(xe||(xe=(te?document.querySelector(te):g==null?void 0:g.querySelector('input[type="submit"], button[type="submit"], button:not([type="button"]):not([type="reset"])'))||g),xe){const h=parseInt(ee,10)||12,y=xe.getBoundingClientRect(),M=x.getBoundingClientRect(),H=document.documentElement.clientHeight,U=document.documentElement.clientWidth,W=_==="auto"?y.bottom+M.height+h+n>H:_==="top",E=Math.max(n,Math.min(U-n-M.width,y.left+y.width/2-M.width/2));if(W?t(9,x.style.top=`${y.top-(M.height+h)}px`,x):t(9,x.style.top=`${y.bottom+h}px`,x),t(9,x.style.left=`${E}px`,x),x.setAttribute("data-floating",W?"top":"bottom"),re){const T=re.getBoundingClientRect();t(10,re.style.left=y.left-E+y.width/2-T.width/2+"px",re)}}else C("unable to find floating anchor element")}function pt(n){n.analytics&&(t(18,a=n.analytics),bt()),n.auto!==void 0&&(t(0,l=n.auto),l==="onload"&&se()),n.beaconurl&&(t(19,c=n.beaconurl),B&&t(11,B.beaconUrl=c,B)),n.floatinganchor!==void 0&&t(23,te=n.floatinganchor),n.delay!==void 0&&t(21,G=n.delay),n.floatingoffset!==void 0&&t(24,ee=n.floatingoffset),n.floating!==void 0&&kt(n.floating),n.expire!==void 0&&(Re(n.expire),t(22,Q=n.expire)),n.challenge&&(mt(n.challenge),o=n.challenge),n.challengeurl!==void 0&&t(17,w=n.challengeurl),n.debug!==void 0&&t(20,Y=!!n.debug),n.hidefooter!==void 0&&t(2,P=!!n.hidefooter),n.hidelogo!==void 0&&t(3,F=!!n.hidelogo),n.maxnumber!==void 0&&t(25,I=+n.maxnumber),n.mockerror!==void 0&&t(26,S=!!n.mockerror),n.name!==void 0&&t(4,N=n.name),n.refetchonexpire!==void 0&&t(27,d=!!n.refetchonexpire),n.spamfilter!==void 0&&t(28,p=typeof n.spamfilter=="object"?n.spamfilter:!!n.spamfilter),n.strings&&t(39,s=n.strings),n.test!==void 0&&t(29,J=typeof n.test=="number"?n.test:!!n.test),n.verifyurl!==void 0&&t(30,ie=n.verifyurl),n.workers!==void 0&&t(31,Ee=+n.workers),n.workerurl!==void 0&&t(32,Ie=n.workerurl)}function Fe(n=b.UNVERIFIED,h=null){X&&(clearTimeout(X),X=null),t(8,ne=!1),t(5,Te=h),t(6,oe=null),t(7,O=n)}async function se(){return Fe(b.VERIFYING),await new Promise(n=>setTimeout(n,G||0)),an().then(n=>(mt(n),C("challenge",n),cn(n))).then(({data:n,solution:h})=>{if(C("solution",h),(h==null?void 0:h.number)!==void 0){if(ie)return wn(gt(n,h));t(6,oe=gt(n,h)),C("payload",oe)}else throw C("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."),new Error("Unexpected result returned.")}).then(()=>{Ut().then(()=>{t(7,O=b.VERIFIED),t(8,ne=!0),C("verified"),Pe("verified",{payload:oe})})}).catch(n=>{C(n),t(7,O=b.ERROR),t(8,ne=!1),t(5,Te=n.message)})}function yn(){ne=this.checked,t(8,ne)}function vn(n){Ce[n?"unshift":"push"](()=>{re=n,t(10,re)})}function En(n){Ce[n?"unshift":"push"](()=>{x=n,t(9,x)})}return i.$$set=n=>{"analytics"in n&&t(18,a=n.analytics),"auto"in n&&t(0,l=n.auto),"beaconurl"in n&&t(19,c=n.beaconurl),"blockspam"in n&&t(33,q=n.blockspam),"challengeurl"in n&&t(17,w=n.challengeurl),"challengejson"in n&&t(34,Z=n.challengejson),"debug"in n&&t(20,Y=n.debug),"delay"in n&&t(21,G=n.delay),"expire"in n&&t(22,Q=n.expire),"floating"in n&&t(1,_=n.floating),"floatinganchor"in n&&t(23,te=n.floatinganchor),"floatingoffset"in n&&t(24,ee=n.floatingoffset),"hidefooter"in n&&t(2,P=n.hidefooter),"hidelogo"in n&&t(3,F=n.hidelogo),"name"in n&&t(4,N=n.name),"maxnumber"in n&&t(25,I=n.maxnumber),"mockerror"in n&&t(26,S=n.mockerror),"refetchonexpire"in n&&t(27,d=n.refetchonexpire),"spamfilter"in n&&t(28,p=n.spamfilter),"strings"in n&&t(35,Le=n.strings),"test"in n&&t(29,J=n.test),"verifyurl"in n&&t(30,ie=n.verifyurl),"workers"in n&&t(31,Ee=n.workers),"workerurl"in n&&t(32,Ie=n.workerurl)},i.$$.update=()=>{i.$$.dirty[0]&131072&&t(14,r=!!(w!=null&&w.includes(".altcha.org"))&&!!(w!=null&&w.includes("apiKey=ckey_"))),i.$$.dirty[1]&8&&(o=Z?st(Z):void 0),i.$$.dirty[1]&16&&t(39,s=Le?st(Le):{}),i.$$.dirty[1]&256&&t(13,u={ariaLinkLabel:rt,error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by <a href="${ot}" target="_blank" aria-label="${s.ariaLinkLabel||rt}">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...s}),i.$$.dirty[0]&192&&Pe("statechange",{payload:oe,state:O}),i.$$.dirty[0]&32&&dn(),i.$$.dirty[0]&128&&gn()},[l,_,P,F,N,Te,oe,O,ne,x,re,B,ct,u,r,hn,vt,w,a,c,Y,G,Q,te,ee,I,S,d,p,J,ie,Ee,Ie,q,Z,Le,pt,Fe,se,s,yn,vn,En]}class lt extends Jt{constructor(e){super(),Yt(this,e,fn,ln,Tt,{analytics:18,auto:0,beaconurl:19,blockspam:33,challengeurl:17,challengejson:34,debug:20,delay:21,expire:22,floating:1,floatinganchor:23,floatingoffset:24,hidefooter:2,hidelogo:3,name:4,maxnumber:25,mockerror:26,refetchonexpire:27,spamfilter:28,strings:35,test:29,verifyurl:30,workers:31,workerurl:32,configure:36,reset:37,verify:38},null,[-1,-1,-1])}get analytics(){return this.$$.ctx[18]}set analytics(e){this.$$set({analytics:e}),k()}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),k()}get beaconurl(){return this.$$.ctx[19]}set beaconurl(e){this.$$set({beaconurl:e}),k()}get blockspam(){return this.$$.ctx[33]}set blockspam(e){this.$$set({blockspam:e}),k()}get challengeurl(){return this.$$.ctx[17]}set challengeurl(e){this.$$set({challengeurl:e}),k()}get challengejson(){return this.$$.ctx[34]}set challengejson(e){this.$$set({challengejson:e}),k()}get debug(){return this.$$.ctx[20]}set debug(e){this.$$set({debug:e}),k()}get delay(){return this.$$.ctx[21]}set delay(e){this.$$set({delay:e}),k()}get expire(){return this.$$.ctx[22]}set expire(e){this.$$set({expire:e}),k()}get floating(){return this.$$.ctx[1]}set floating(e){this.$$set({floating:e}),k()}get floatinganchor(){return this.$$.ctx[23]}set floatinganchor(e){this.$$set({floatinganchor:e}),k()}get floatingoffset(){return this.$$.ctx[24]}set floatingoffset(e){this.$$set({floatingoffset:e}),k()}get hidefooter(){return this.$$.ctx[2]}set hidefooter(e){this.$$set({hidefooter:e}),k()}get hidelogo(){return this.$$.ctx[3]}set hidelogo(e){this.$$set({hidelogo:e}),k()}get name(){return this.$$.ctx[4]}set name(e){this.$$set({name:e}),k()}get maxnumber(){return this.$$.ctx[25]}set maxnumber(e){this.$$set({maxnumber:e}),k()}get mockerror(){return this.$$.ctx[26]}set mockerror(e){this.$$set({mockerror:e}),k()}get refetchonexpire(){return this.$$.ctx[27]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),k()}get spamfilter(){return this.$$.ctx[28]}set spamfilter(e){this.$$set({spamfilter:e}),k()}get strings(){return this.$$.ctx[35]}set strings(e){this.$$set({strings:e}),k()}get test(){return this.$$.ctx[29]}set test(e){this.$$set({test:e}),k()}get verifyurl(){return this.$$.ctx[30]}set verifyurl(e){this.$$set({verifyurl:e}),k()}get workers(){return this.$$.ctx[31]}set workers(e){this.$$set({workers:e}),k()}get workerurl(){return this.$$.ctx[32]}set workerurl(e){this.$$set({workerurl:e}),k()}get configure(){return this.$$.ctx[36]}get reset(){return this.$$.ctx[37]}get verify(){return this.$$.ctx[38]}}customElements.define("altcha-widget",Gt(lt,{analytics:{type:"Boolean"},auto:{},beaconurl:{},blockspam:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},delay:{},expire:{},floating:{},floatinganchor:{},floatingoffset:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},spamfilter:{type:"Boolean"},strings:{},test:{type:"Boolean"},verifyurl:{},workers:{},workerurl:{}},[],["configure","reset","verify"],!1)),globalThis.createAltchaWorker=i=>new Worker(new URL(i||"./worker.js",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:v&&v.src||new URL("altcha.umd.cjs",document.baseURI).href)),m.Altcha=lt,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function($,H){typeof exports=="object"&&typeof module<"u"?H(exports):typeof define=="function"&&define.amd?define(["exports"],H):($=typeof globalThis<"u"?globalThis:$||self,H($.altcha={}))})(this,function($){"use strict";var Rn=Object.defineProperty;var Ln=($,H,z)=>H in $?Rn($,H,{enumerable:!0,configurable:!0,writable:!0,value:z}):$[H]=z;var Y=($,H,z)=>Ln($,typeof H!="symbol"?H+"":H,z);var H=typeof document<"u"?document.currentScript:null;function z(){}function xt(n,e){for(const t in e)n[t]=e[t];return n}function Fe(n){return n()}function Ne(){return Object.create(null)}function ge(n){n.forEach(Fe)}function je(n){return typeof n=="function"}function At(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function It(n){return Object.keys(n).length===0}function Rt(n,e,t,i){if(n){const o=Ve(n,e,t,i);return n[0](o)}}function Ve(n,e,t,i){return n[1]&&i?xt(t.ctx.slice(),n[1](i(e))):t.ctx}function Lt(n,e,t,i){if(n[2]&&i){const o=n[2](i(t));if(e.dirty===void 0)return o;if(typeof o=="object"){const l=[],s=Math.max(e.dirty.length,o.length);for(let h=0;h<s;h+=1)l[h]=e.dirty[h]|o[h];return l}return e.dirty|o}return e.dirty}function St(n,e,t,i,o,l){if(o){const s=Ve(e,t,i,l);n.p(s,o)}}function Tt(n){if(n.ctx.length>32){const e=[],t=n.ctx.length/32;for(let i=0;i<t;i++)e[i]=-1;return e}return-1}function R(n,e){n.appendChild(e)}function U(n,e,t){n.insertBefore(e,t||null)}function j(n){n.parentNode&&n.parentNode.removeChild(n)}function M(n){return document.createElement(n)}function K(n){return document.createElementNS("http://www.w3.org/2000/svg",n)}function Dt(n){return document.createTextNode(n)}function Q(){return Dt(" ")}function Le(n,e,t,i){return n.addEventListener(e,t,i),()=>n.removeEventListener(e,t,i)}function c(n,e,t){t==null?n.removeAttribute(e):n.getAttribute(e)!==t&&n.setAttribute(e,t)}function Pt(n){return Array.from(n.childNodes)}function Ue(n,e,t){n.classList.toggle(e,!!t)}function Mt(n,e,{bubbles:t=!1,cancelable:i=!1}={}){return new CustomEvent(n,{detail:e,bubbles:t,cancelable:i})}function Ft(n){const e={};return n.childNodes.forEach(t=>{e[t.slot||"default"]=!0}),e}let me;function be(n){me=n}function Se(){if(!me)throw new Error("Function called outside component initialization");return me}function Nt(n){Se().$$.on_mount.push(n)}function jt(n){Se().$$.on_destroy.push(n)}function Vt(){const n=Se();return(e,t,{cancelable:i=!1}={})=>{const o=n.$$.callbacks[e];if(o){const l=Mt(e,t,{cancelable:i});return o.slice().forEach(s=>{s.call(n,l)}),!l.defaultPrevented}return!0}}const ce=[],Ce=[];let ue=[];const He=[],Oe=Promise.resolve();let Te=!1;function $e(){Te||(Te=!0,Oe.then(p))}function Ut(){return $e(),Oe}function De(n){ue.push(n)}const Pe=new Set;let ae=0;function p(){if(ae!==0)return;const n=me;do{try{for(;ae<ce.length;){const e=ce[ae];ae++,be(e),Ht(e.$$)}}catch(e){throw ce.length=0,ae=0,e}for(be(null),ce.length=0,ae=0;Ce.length;)Ce.pop()();for(let e=0;e<ue.length;e+=1){const t=ue[e];Pe.has(t)||(Pe.add(t),t())}ue.length=0}while(ce.length);for(;He.length;)He.pop()();Te=!1,Pe.clear(),be(n)}function Ht(n){if(n.fragment!==null){n.update(),ge(n.before_update);const e=n.dirty;n.dirty=[-1],n.fragment&&n.fragment.p(n.ctx,e),n.after_update.forEach(De)}}function Ot(n){const e=[],t=[];ue.forEach(i=>n.indexOf(i)===-1?e.push(i):t.push(i)),t.forEach(i=>i()),ue=e}const xe=new Set;let $t;function Be(n,e){n&&n.i&&(xe.delete(n),n.i(e))}function Bt(n,e,t,i){if(n&&n.o){if(xe.has(n))return;xe.add(n),$t.c.push(()=>{xe.delete(n)}),n.o(e)}}function qt(n,e,t){const{fragment:i,after_update:o}=n.$$;i&&i.m(e,t),De(()=>{const l=n.$$.on_mount.map(Fe).filter(je);n.$$.on_destroy?n.$$.on_destroy.push(...l):ge(l),n.$$.on_mount=[]}),o.forEach(De)}function Zt(n,e){const t=n.$$;t.fragment!==null&&(Ot(t.after_update),ge(t.on_destroy),t.fragment&&t.fragment.d(e),t.on_destroy=t.fragment=null,t.ctx=[])}function Gt(n,e){n.$$.dirty[0]===-1&&(ce.push(n),$e(),n.$$.dirty.fill(0)),n.$$.dirty[e/31|0]|=1<<e%31}function Yt(n,e,t,i,o,l,s=null,h=[-1]){const d=me;be(n);const u=n.$$={fragment:null,ctx:[],props:l,update:z,not_equal:o,bound:Ne(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(d?d.$$.context:[])),callbacks:Ne(),dirty:h,skip_bound:!1,root:e.target||d.$$.root};s&&s(u.root);let A=!1;if(u.ctx=t?t(n,e.props||{},(b,X,...B)=>{const q=B.length?B[0]:X;return u.ctx&&o(u.ctx[b],u.ctx[b]=q)&&(!u.skip_bound&&u.bound[b]&&u.bound[b](q),A&&Gt(n,b)),X}):[],u.update(),A=!0,ge(u.before_update),u.fragment=i?i(u.ctx):!1,e.target){if(e.hydrate){const b=Pt(e.target);u.fragment&&u.fragment.l(b),b.forEach(j)}else u.fragment&&u.fragment.c();e.intro&&Be(n.$$.fragment),qt(n,e.target,e.anchor),p()}be(d)}let qe;typeof HTMLElement=="function"&&(qe=class extends HTMLElement{constructor(e,t,i){super();Y(this,"$$ctor");Y(this,"$$s");Y(this,"$$c");Y(this,"$$cn",!1);Y(this,"$$d",{});Y(this,"$$r",!1);Y(this,"$$p_d",{});Y(this,"$$l",{});Y(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=t,i&&this.attachShadow({mode:"open"})}addEventListener(e,t,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(t),this.$$c){const o=this.$$c.$on(e,t);this.$$l_u.set(t,o)}super.addEventListener(e,t,i)}removeEventListener(e,t,i){if(super.removeEventListener(e,t,i),this.$$c){const o=this.$$l_u.get(t);o&&(o(),this.$$l_u.delete(t))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(l){return()=>{let s;return{c:function(){s=M("slot"),l!=="default"&&c(s,"name",l)},m:function(u,A){U(u,s,A)},d:function(u){u&&j(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const t={},i=Ft(this);for(const l of this.$$s)l in i&&(t[l]=[e(l)]);for(const l of this.attributes){const s=this.$$g_p(l.name);s in this.$$d||(this.$$d[s]=Ae(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:t,$$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=Ae(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 h=this.$$c.$on(l,s);this.$$l_u.set(s,h)}this.$$l={}}}attributeChangedCallback(e,t,i){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Ae(e,i,this.$$p_d,"toProp"),(o=this.$$c)==null||o.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{!this.$$cn&&this.$$c&&(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(t=>this.$$p_d[t].attribute===e||!this.$$p_d[t].attribute&&t.toLowerCase()===e)||e}});function Ae(n,e,t,i){var l;const o=(l=t[n])==null?void 0:l.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!t[n])return e;if(i==="toAttribute")switch(o){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function Wt(n,e,t,i,o,l){let s=class extends qe{constructor(){super(n,t,o),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(h=>(e[h].attribute||h).toLowerCase())}};return Object.keys(e).forEach(h=>{Object.defineProperty(s.prototype,h,{get(){return this.$$c&&h in this.$$c?this.$$c[h]:this.$$d[h]},set(d){var u;d=Ae(h,d,e),this.$$d[h]=d,(u=this.$$c)==null||u.$set({[h]:d})}})}),i.forEach(h=>{Object.defineProperty(s.prototype,h,{get(){var d;return(d=this.$$c)==null?void 0:d[h]}})}),n.element=s,s}class Xt{constructor(){Y(this,"$$");Y(this,"$$set")}$destroy(){Zt(this,1),this.$destroy=z}$on(e,t){if(!je(t))return z;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(t),()=>{const o=i.indexOf(t);o!==-1&&i.splice(o,1)}}$set(e){this.$$set&&!It(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Jt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Jt);const Ze=new TextEncoder;function zt(n){return[...new Uint8Array(n)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function Kt(n,e="SHA-256",t=1e5){const i=Date.now().toString(16);n||(n=Math.round(Math.random()*t));const o=await Ge(i,n,e);return{algorithm:e,challenge:o,salt:i,signature:""}}async function Ge(n,e,t){return zt(await crypto.subtle.digest(t.toUpperCase(),Ze.encode(n+e)))}function Qt(n,e,t="SHA-256",i=1e6,o=0){const l=new AbortController,s=Date.now();return{promise:(async()=>{for(let d=o;d<=i;d+=1){if(l.signal.aborted)return null;if(await Ge(e,d,t)===n)return{number:d,took:Date.now()-s}}return null})(),controller:l}}function en(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}function tn(n){const e=atob(n),t=new Uint8Array(e.length);for(let i=0;i<e.length;i++)t[i]=e.charCodeAt(i);return t}function nn(n,e=12){const t=new Uint8Array(e);for(let i=0;i<e;i++)t[i]=n%256,n=Math.floor(n/256);return t}async function rn(n,e="",t=1e6,i=0){const o="AES-GCM",l=new AbortController,s=Date.now(),h=async()=>{for(let A=i;A<=t;A+=1){if(l.signal.aborted||!d||!u)return null;try{const b=await crypto.subtle.decrypt({name:o,iv:nn(A)},d,u);if(b)return{clearText:new TextDecoder().decode(b),took:Date.now()-s}}catch{}}return null};let d=null,u=null;try{u=tn(n);const A=await crypto.subtle.digest("SHA-256",Ze.encode(e));d=await crypto.subtle.importKey("raw",A,o,!1,["decrypt"])}catch{return{promise:Promise.reject(),controller:l}}return{promise:h(),controller:l}}var g=(n=>(n.ERROR="error",n.VERIFIED="verified",n.VERIFYING="verifying",n.UNVERIFIED="unverified",n.EXPIRED="expired",n))(g||{});function Ye(n){let e,t,i;return{c(){e=K("svg"),t=K("path"),i=K("path"),c(t,"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(t,"fill","currentColor"),c(t,"opacity",".25"),c(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(i,"fill","currentColor"),c(i,"class","altcha-spinner"),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){U(o,e,l),R(e,t),R(e,i)},d(o){o&&j(e)}}}function on(n){let e,t=n[11].label+"",i;return{c(){e=M("label"),c(e,"for",i=n[4]+"_checkbox")},m(o,l){U(o,e,l),e.innerHTML=t},p(o,l){l[0]&2048&&t!==(t=o[11].label+"")&&(e.innerHTML=t),l[0]&16&&i!==(i=o[4]+"_checkbox")&&c(e,"for",i)},d(o){o&&j(e)}}}function ln(n){let e,t=n[11].verifying+"";return{c(){e=M("span")},m(i,o){U(i,e,o),e.innerHTML=t},p(i,o){o[0]&2048&&t!==(t=i[11].verifying+"")&&(e.innerHTML=t)},d(i){i&&j(e)}}}function sn(n){let e,t=n[11].verified+"",i,o;return{c(){e=M("span"),i=Q(),o=M("input"),c(o,"type","hidden"),c(o,"name",n[4]),o.value=n[6]},m(l,s){U(l,e,s),e.innerHTML=t,U(l,i,s),U(l,o,s)},p(l,s){s[0]&2048&&t!==(t=l[11].verified+"")&&(e.innerHTML=t),s[0]&16&&c(o,"name",l[4]),s[0]&64&&(o.value=l[6])},d(l){l&&(j(e),j(i),j(o))}}}function We(n){let e,t,i,o,l,s,h;return{c(){e=M("div"),t=M("a"),i=K("svg"),o=K("path"),l=K("path"),s=K("path"),c(o,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(o,"fill","currentColor"),c(l,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(l,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(i,"width","22"),c(i,"height","22"),c(i,"viewBox","0 0 20 20"),c(i,"fill","none"),c(i,"xmlns","http://www.w3.org/2000/svg"),c(t,"href",Qe),c(t,"target","_blank"),c(t,"class","altcha-logo"),c(t,"aria-label",h=n[11].ariaLinkLabel)},m(d,u){U(d,e,u),R(e,t),R(t,i),R(i,o),R(i,l),R(i,s)},p(d,u){u[0]&2048&&h!==(h=d[11].ariaLinkLabel)&&c(t,"aria-label",h)},d(d){d&&j(e)}}}function Xe(n){let e,t,i,o;function l(d,u){return d[7]===g.EXPIRED?cn:fn}let s=l(n),h=s(n);return{c(){e=M("div"),t=K("svg"),i=K("path"),o=Q(),h.c(),c(i,"stroke-linecap","round"),c(i,"stroke-linejoin","round"),c(i,"d","M6 18L18 6M6 6l12 12"),c(t,"width","14"),c(t,"height","14"),c(t,"xmlns","http://www.w3.org/2000/svg"),c(t,"fill","none"),c(t,"viewBox","0 0 24 24"),c(t,"stroke-width","1.5"),c(t,"stroke","currentColor"),c(e,"class","altcha-error")},m(d,u){U(d,e,u),R(e,t),R(t,i),R(e,o),h.m(e,null)},p(d,u){s===(s=l(d))&&h?h.p(d,u):(h.d(1),h=s(d),h&&(h.c(),h.m(e,null)))},d(d){d&&j(e),h.d()}}}function fn(n){let e,t=n[11].error+"";return{c(){e=M("div"),c(e,"title",n[5])},m(i,o){U(i,e,o),e.innerHTML=t},p(i,o){o[0]&2048&&t!==(t=i[11].error+"")&&(e.innerHTML=t),o[0]&32&&c(e,"title",i[5])},d(i){i&&j(e)}}}function cn(n){let e,t=n[11].expired+"";return{c(){e=M("div"),c(e,"title",n[5])},m(i,o){U(i,e,o),e.innerHTML=t},p(i,o){o[0]&2048&&t!==(t=i[11].expired+"")&&(e.innerHTML=t),o[0]&32&&c(e,"title",i[5])},d(i){i&&j(e)}}}function Je(n){let e,t,i=n[11].footer+"";return{c(){e=M("div"),t=M("div"),c(e,"class","altcha-footer")},m(o,l){U(o,e,l),R(e,t),t.innerHTML=i},p(o,l){l[0]&2048&&i!==(i=o[11].footer+"")&&(t.innerHTML=i)},d(o){o&&j(e)}}}function ze(n){let e;return{c(){e=M("div"),c(e,"class","altcha-anchor-arrow")},m(t,i){U(t,e,i),n[48](e)},p:z,d(t){t&&j(e),n[48](null)}}}function un(n){let e,t,i,o,l,s,h,d,u,A,b,X,B,q,T,L,ee;const te=n[46].default,N=Rt(te,n,n[45],null);let D=n[7]===g.VERIFYING&&Ye();function ne(a,y){return a[7]===g.VERIFIED?sn:a[7]===g.VERIFYING?ln:on}let W=ne(n),V=W(n),k=(n[3]!==!0||n[12])&&We(n),P=(n[5]||n[7]===g.EXPIRED)&&Xe(n),S=n[11].footer&&(n[2]!==!0||n[12])&&Je(n),E=n[1]&&ze(n);return{c(){N&&N.c(),e=Q(),t=M("div"),i=M("div"),D&&D.c(),o=Q(),l=M("div"),s=M("input"),u=Q(),A=M("div"),V.c(),b=Q(),k&&k.c(),X=Q(),P&&P.c(),B=Q(),S&&S.c(),q=Q(),E&&E.c(),c(s,"type","checkbox"),c(s,"id",h=n[4]+"_checkbox"),s.required=d=n[0]!=="onsubmit"&&(!n[1]||n[0]!=="off"),c(l,"class","altcha-checkbox"),Ue(l,"altcha-hidden",n[7]===g.VERIFYING),c(A,"class","altcha-label"),c(i,"class","altcha-main"),c(t,"class","altcha"),c(t,"data-state",n[7]),c(t,"data-floating",n[1])},m(a,y){N&&N.m(a,y),U(a,e,y),U(a,t,y),R(t,i),D&&D.m(i,null),R(i,o),R(i,l),R(l,s),s.checked=n[8],R(i,u),R(i,A),V.m(A,null),R(i,b),k&&k.m(i,null),R(t,X),P&&P.m(t,null),R(t,B),S&&S.m(t,null),R(t,q),E&&E.m(t,null),n[49](t),T=!0,L||(ee=[Le(s,"change",n[47]),Le(s,"change",n[13]),Le(s,"invalid",n[14])],L=!0)},p(a,y){N&&N.p&&(!T||y[1]&16384)&&St(N,te,a,a[45],T?Lt(te,a[45],y,null):Tt(a[45]),null),a[7]===g.VERIFYING?D||(D=Ye(),D.c(),D.m(i,o)):D&&(D.d(1),D=null),(!T||y[0]&16&&h!==(h=a[4]+"_checkbox"))&&c(s,"id",h),(!T||y[0]&3&&d!==(d=a[0]!=="onsubmit"&&(!a[1]||a[0]!=="off")))&&(s.required=d),y[0]&256&&(s.checked=a[8]),(!T||y[0]&128)&&Ue(l,"altcha-hidden",a[7]===g.VERIFYING),W===(W=ne(a))&&V?V.p(a,y):(V.d(1),V=W(a),V&&(V.c(),V.m(A,null))),a[3]!==!0||a[12]?k?k.p(a,y):(k=We(a),k.c(),k.m(i,null)):k&&(k.d(1),k=null),a[5]||a[7]===g.EXPIRED?P?P.p(a,y):(P=Xe(a),P.c(),P.m(t,B)):P&&(P.d(1),P=null),a[11].footer&&(a[2]!==!0||a[12])?S?S.p(a,y):(S=Je(a),S.c(),S.m(t,q)):S&&(S.d(1),S=null),a[1]?E?E.p(a,y):(E=ze(a),E.c(),E.m(t,null)):E&&(E.d(1),E=null),(!T||y[0]&128)&&c(t,"data-state",a[7]),(!T||y[0]&2)&&c(t,"data-floating",a[1])},i(a){T||(Be(N,a),T=!0)},o(a){Bt(N,a),T=!1},d(a){a&&(j(e),j(t)),N&&N.d(a),D&&D.d(),V.d(),k&&k.d(),P&&P.d(),S&&S.d(),E&&E.d(),n[49](null),L=!1,ge(ee)}}}const Ke="Visit Altcha.org",Qe="https://altcha.org/";function et(n){return JSON.parse(n)}function an(n,e,t){var vt,kt;let i,o,l,s,{$$slots:h={},$$scope:d}=e,{auto:u=void 0}=e,{blockspam:A=void 0}=e,{challengeurl:b=void 0}=e,{challengejson:X=void 0}=e,{debug:B=!1}=e,{delay:q=0}=e,{expire:T=void 0}=e,{floating:L=void 0}=e,{floatinganchor:ee=void 0}=e,{floatingoffset:te=void 0}=e,{hidefooter:N=!1}=e,{hidelogo:D=!1}=e,{name:ne="altcha"}=e,{maxnumber:W=1e6}=e,{mockerror:V=!1}=e,{obfuscated:k=void 0}=e,{plugins:P=void 0}=e,{refetchonexpire:S=!0}=e,{spamfilter:E=!1}=e,{strings:a=void 0}=e,{test:y=!1}=e,{verifyurl:re=void 0}=e,{workers:he=Math.min(16,navigator.hardwareConcurrency||8)}=e,{workerurl:ye=void 0}=e;const _e=Vt(),nt=["SHA-256","SHA-384","SHA-512"],rt=(kt=(vt=document.documentElement.lang)==null?void 0:vt.split("-"))==null?void 0:kt[0];let le=!1,C,se=null,de=null,_=null,we=null,J=null,fe=null,ie=[],x=g.UNVERIFIED;jt(()=>{hn(),_&&(_.removeEventListener("submit",ct),_.removeEventListener("reset",ut),_.removeEventListener("focusin",ft),_=null),J&&(clearTimeout(J),J=null),document.removeEventListener("click",lt),document.removeEventListener("scroll",st),window.removeEventListener("resize",ht)}),Nt(()=>{v("mounted","0.9.0"),v("workers",he),yn(),v("plugins",ie.length?ie.map(r=>r.constructor.pluginName).join(", "):"none"),y&&v("using test mode"),T&&Re(T),u!==void 0&&v("auto",u),L!==void 0&&dt(L),_=C.closest("form"),_&&(_.addEventListener("submit",ct,{capture:!0}),_.addEventListener("reset",ut),u==="onfocus"&&_.addEventListener("focusin",ft)),u==="onload"&&(k?pe():oe()),i&&(N||D)&&v("Attributes hidefooter and hidelogo ignored because usage with free API Keys requires attribution."),requestAnimationFrame(()=>{_e("load")})});function it(r,f){return btoa(JSON.stringify({algorithm:r.algorithm,challenge:r.challenge,number:f.number,salt:r.salt,signature:r.signature,test:y?!0:void 0,took:f.took}))}function hn(){for(const r of ie)r.destroy()}function ot(){b&&S&&x===g.VERIFIED?oe():Ee(g.EXPIRED,s.expired)}async function dn(){var r;if(V)throw v("mocking error"),new Error("Mocked error.");if(o)return v("using provided json data"),o;if(y)return v("generating test challenge",{test:y}),Kt(typeof y!="boolean"?+y:void 0);{if(!b&&_){const w=_.getAttribute("action");w!=null&&w.includes("/form/")&&t(15,b=w+"/altcha")}if(!b)throw new Error("Attribute challengeurl not set.");v("fetching challenge from",b);const f=await fetch(b,{headers:E?{"x-altcha-spam-filter":"1"}:{}});if(f.status!==200)throw new Error(`Server responded with ${f.status}.`);const m=f.headers.get("Expires"),I=f.headers.get("X-Altcha-Config"),Z=await f.json(),O=new URLSearchParams((r=Z.salt.split("?"))==null?void 0:r[1]),F=O.get("expires")||O.get("expire");if(F){const w=new Date(+F*1e3),G=isNaN(w.getTime())?0:w.getTime()-Date.now();G>0&&Re(G)}if(I)try{const w=JSON.parse(I);w&&typeof w=="object"&&(w.verifyurl&&(w.verifyurl=new URL(w.verifyurl,new URL(b)).toString()),bt(w))}catch(w){v("unable to configure from X-Altcha-Config",w)}if(!T&&(m!=null&&m.length)){const w=Date.parse(m);if(w){const G=w-Date.now();G>0&&Re(G)}}return Z}}function gn(r){var m;const f=_==null?void 0:_.querySelector(typeof r=="string"?`input[name="${r}"]`:'input[type="email"]:not([data-no-spamfilter])');return((m=f==null?void 0:f.value)==null?void 0:m.slice(f.value.indexOf("@")))||void 0}function mn(){return E==="ipAddress"?{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:!1,expectedCountries:void 0,expectedLanguages:void 0,fields:!1,ipAddress:void 0,text:void 0,timeZone:void 0}:typeof E=="object"?E:{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:void 0,expectedCountries:void 0,expectedLanguages:void 0,fields:void 0,ipAddress:void 0,text:void 0,timeZone:void 0}}function bn(r){return[...(_==null?void 0:_.querySelectorAll(r!=null&&r.length?r.map(m=>`input[name="${m}"]`).join(", "):'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])'))||[]].reduce((m,I)=>{const Z=I.name,O=I.value;return Z&&O&&(m[Z]=/\n/.test(O)?O.replace(new RegExp("(?<!\\r)\\n","g"),`\r
|
|
2
|
+
`):O),m},{})}function yn(){const r=P!==void 0?P.split(","):void 0;for(const f of globalThis.altchaPlugins)(!r||r.includes(f.pluginName))&&ie.push(new f({el:C,clarify:pe,dispatch:_e,getConfiguration:yt,getFloatingAnchor:_t,getState:wt,log:v,reset:Ee,solve:mt,setState:Et,setFloatingAnchor:pt,verify:oe}))}function v(...r){(B||r.some(f=>f instanceof Error))&&console[r[0]instanceof Error?"error":"log"]("ALTCHA",`[name=${ne}]`,...r)}function _n(){[g.UNVERIFIED,g.ERROR,g.EXPIRED].includes(x)?E&&(_==null?void 0:_.reportValidity())===!1?t(8,le=!1):k?pe():oe():t(8,le=!0)}function lt(r){const f=r.target;L&&f&&!C.contains(f)&&(x===g.VERIFIED||u==="off"&&x===g.UNVERIFIED)&&t(9,C.style.display="none",C)}function st(){L&&x!==g.UNVERIFIED&&Ie()}function wn(r){for(const f of ie)typeof f.onErrorChange=="function"&&f.onErrorChange(we)}function ft(r){x===g.UNVERIFIED&&oe()}function ct(r){_&&u==="onsubmit"?x===g.UNVERIFIED?(r.preventDefault(),r.stopPropagation(),oe().then(()=>{_==null||_.requestSubmit()})):x!==g.VERIFIED&&(r.preventDefault(),r.stopPropagation(),x===g.VERIFYING&&at()):_&&L&&u==="off"&&x===g.UNVERIFIED&&(r.preventDefault(),r.stopPropagation(),t(9,C.style.display="block",C),Ie())}function ut(){Ee()}function at(){x===g.VERIFYING&&s.waitAlert&&alert(s.waitAlert)}function pn(r){for(const f of ie)typeof f.onStateChange=="function"&&f.onStateChange(x);L&&x!==g.UNVERIFIED&&requestAnimationFrame(()=>{Ie()}),t(8,le=x===g.VERIFIED)}function ht(){L&&Ie()}function Ie(r=20){if(C)if(de||(de=(ee?document.querySelector(ee):_==null?void 0:_.querySelector('input[type="submit"], button[type="submit"], button:not([type="button"]):not([type="reset"])'))||_),de){const f=parseInt(te,10)||12,m=de.getBoundingClientRect(),I=C.getBoundingClientRect(),Z=document.documentElement.clientHeight,O=document.documentElement.clientWidth,F=L==="auto"?m.bottom+I.height+f+r>Z:L==="top",w=Math.max(r,Math.min(O-r-I.width,m.left+m.width/2-I.width/2));if(F?t(9,C.style.top=`${m.top-(I.height+f)}px`,C):t(9,C.style.top=`${m.bottom+f}px`,C),t(9,C.style.left=`${w}px`,C),C.setAttribute("data-floating",F?"top":"bottom"),se){const G=se.getBoundingClientRect();t(10,se.style.left=m.left-w+m.width/2-G.width/2+"px",se)}}else v("unable to find floating anchor element")}async function En(r){if(!re)throw new Error("Attribute verifyurl not set.");v("requesting server verification from",re);const f={payload:r};if(E){const{blockedCountries:Z,classifier:O,disableRules:F,email:w,expectedLanguages:G,expectedCountries:Me,fields:ve,ipAddress:ke,text:In,timeZone:Ct}=mn();f.blockedCountries=Z,f.classifier=O,f.disableRules=F,f.email=w===!1?void 0:gn(w),f.expectedCountries=Me,f.expectedLanguages=G||(rt?[rt]:void 0),f.fields=ve===!1?void 0:bn(ve),f.ipAddress=ke===!1?void 0:ke||"auto",f.text=In,f.timeZone=Ct===!1?void 0:Ct||en()}const m=await fetch(re,{body:JSON.stringify(f),headers:{"content-type":"application/json"},method:"POST"});if(m.status!==200)throw new Error(`Server responded with ${m.status}.`);const I=await m.json();if(I!=null&&I.payload&&t(6,fe=I.payload),_e("serververification",I),A&&I.classification==="BAD")throw new Error("SpamFilter returned negative classification.")}function Re(r){v("expire",r),J&&(clearTimeout(J),J=null),r<1?ot():J=setTimeout(ot,r)}function dt(r){v("floating",r),L!==r&&(t(9,C.style.left="",C),t(9,C.style.top="",C)),t(1,L=r===!0||r===""?"auto":r===!1||r==="false"?void 0:L),L?(u||t(0,u="onsubmit"),document.addEventListener("scroll",st),document.addEventListener("click",lt),window.addEventListener("resize",ht)):u==="onsubmit"&&t(0,u=void 0)}function gt(r){if(!r.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(r.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!nt.includes(r.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${nt.join(", ")}`);if(!r.challenge||r.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!r.salt||r.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function mt(r){let f=null;if("Worker"in window){try{f=await vn(r,r.maxnumber)}catch(m){v(m)}if((f==null?void 0:f.number)!==void 0||"obfuscated"in r)return{data:r,solution:f}}if("obfuscated"in r){const m=await rn(r.obfuscated,r.key,r.maxnumber);return{data:r,solution:await m.promise}}return{data:r,solution:await Qt(r.challenge,r.salt,r.algorithm,r.maxnumber||W).promise}}async function vn(r,f=typeof y=="number"?y:W,m=Math.ceil(he)){const I=[];m=Math.min(16,Math.max(1,m));for(let F=0;F<m;F++)I.push(altchaCreateWorker(ye));const Z=Math.ceil(f/m),O=await Promise.all(I.map((F,w)=>{const G=w*Z;return new Promise(Me=>{F.addEventListener("message",ve=>{if(ve.data)for(const ke of I)ke!==F&&ke.postMessage({type:"abort"});Me(ve.data)}),F.postMessage({payload:r,max:G+Z,start:G,type:"work"})})}));for(const F of I)F.terminate();return O.find(F=>!!F)||null}async function pe(){if(!k){t(7,x=g.ERROR);return}const r=ie.find(f=>f.constructor.pluginName==="obfuscation");if(!r||!("clarify"in r)){t(7,x=g.ERROR),v("Plugin `obfuscation` not found. Import `altcha/plugins/obfuscation` to load it.");return}if("clarify"in r&&typeof r.clarify=="function")return r.clarify()}function bt(r){r.obfuscated!==void 0&&t(24,k=r.obfuscated),r.auto!==void 0&&(t(0,u=r.auto),u==="onload"&&(k?pe():oe())),r.blockspam!==void 0&&t(16,A=!!r.blockspam),r.floatinganchor!==void 0&&t(20,ee=r.floatinganchor),r.delay!==void 0&&t(18,q=r.delay),r.floatingoffset!==void 0&&t(21,te=r.floatingoffset),r.floating!==void 0&&dt(r.floating),r.expire!==void 0&&(Re(r.expire),t(19,T=r.expire)),r.challenge&&(gt(r.challenge),o=r.challenge),r.challengeurl!==void 0&&t(15,b=r.challengeurl),r.debug!==void 0&&t(17,B=!!r.debug),r.hidefooter!==void 0&&t(2,N=!!r.hidefooter),r.hidelogo!==void 0&&t(3,D=!!r.hidelogo),r.maxnumber!==void 0&&t(22,W=+r.maxnumber),r.mockerror!==void 0&&t(23,V=!!r.mockerror),r.name!==void 0&&t(4,ne=r.name),r.refetchonexpire!==void 0&&t(25,S=!!r.refetchonexpire),r.spamfilter!==void 0&&t(26,E=typeof r.spamfilter=="object"?r.spamfilter:!!r.spamfilter),r.strings&&t(44,l=r.strings),r.test!==void 0&&t(27,y=typeof r.test=="number"?r.test:!!r.test),r.verifyurl!==void 0&&t(28,re=r.verifyurl),r.workers!==void 0&&t(29,he=+r.workers),r.workerurl!==void 0&&t(30,ye=r.workerurl)}function yt(){return{auto:u,blockspam:A,challengeurl:b,debug:B,delay:q,expire:T,floating:L,floatinganchor:ee,floatingoffset:te,hidefooter:N,hidelogo:D,name:ne,maxnumber:W,mockerror:V,obfuscated:k,refetchonexpire:S,spamfilter:E,strings:s,test:y,verifyurl:re,workers:he,workerurl:ye}}function _t(){return de}function kn(r){return ie.find(f=>f.constructor.pluginName===r)}function wt(){return x}function Ee(r=g.UNVERIFIED,f=null){J&&(clearTimeout(J),J=null),t(8,le=!1),t(5,we=f),t(6,fe=null),t(7,x=r)}function pt(r){de=r}function Et(r,f=null){t(7,x=r),t(5,we=f)}async function oe(){return Ee(g.VERIFYING),await new Promise(r=>setTimeout(r,q||0)),dn().then(r=>(gt(r),v("challenge",r),mt(r))).then(({data:r,solution:f})=>{if(v("solution",f),"challenge"in r&&f&&!("clearText"in f))if((f==null?void 0:f.number)!==void 0){if(re)return En(it(r,f));t(6,fe=it(r,f)),v("payload",fe)}else throw v("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."),new Error("Unexpected result returned.")}).then(()=>{Ut().then(()=>{t(7,x=g.VERIFIED),v("verified"),_e("verified",{payload:fe})})}).catch(r=>{v(r),t(7,x=g.ERROR),t(5,we=r.message)})}function Cn(){le=this.checked,t(8,le)}function xn(r){Ce[r?"unshift":"push"](()=>{se=r,t(10,se)})}function An(r){Ce[r?"unshift":"push"](()=>{C=r,t(9,C)})}return n.$$set=r=>{"auto"in r&&t(0,u=r.auto),"blockspam"in r&&t(16,A=r.blockspam),"challengeurl"in r&&t(15,b=r.challengeurl),"challengejson"in r&&t(31,X=r.challengejson),"debug"in r&&t(17,B=r.debug),"delay"in r&&t(18,q=r.delay),"expire"in r&&t(19,T=r.expire),"floating"in r&&t(1,L=r.floating),"floatinganchor"in r&&t(20,ee=r.floatinganchor),"floatingoffset"in r&&t(21,te=r.floatingoffset),"hidefooter"in r&&t(2,N=r.hidefooter),"hidelogo"in r&&t(3,D=r.hidelogo),"name"in r&&t(4,ne=r.name),"maxnumber"in r&&t(22,W=r.maxnumber),"mockerror"in r&&t(23,V=r.mockerror),"obfuscated"in r&&t(24,k=r.obfuscated),"plugins"in r&&t(32,P=r.plugins),"refetchonexpire"in r&&t(25,S=r.refetchonexpire),"spamfilter"in r&&t(26,E=r.spamfilter),"strings"in r&&t(33,a=r.strings),"test"in r&&t(27,y=r.test),"verifyurl"in r&&t(28,re=r.verifyurl),"workers"in r&&t(29,he=r.workers),"workerurl"in r&&t(30,ye=r.workerurl),"$$scope"in r&&t(45,d=r.$$scope)},n.$$.update=()=>{n.$$.dirty[0]&32768&&t(12,i=!!(b!=null&&b.includes(".altcha.org"))&&!!(b!=null&&b.includes("apiKey=ckey_"))),n.$$.dirty[1]&1&&(o=X?et(X):void 0),n.$$.dirty[1]&4&&t(44,l=a?et(a):{}),n.$$.dirty[1]&8192&&t(11,s={ariaLinkLabel:Ke,error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by <a href="${Qe}" target="_blank" aria-label="${l.ariaLinkLabel||Ke}">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),n.$$.dirty[0]&192&&_e("statechange",{payload:fe,state:x}),n.$$.dirty[0]&32&&wn(),n.$$.dirty[0]&128&&pn()},[u,L,N,D,ne,we,fe,x,le,C,se,s,i,_n,at,b,A,B,q,T,ee,te,W,V,k,S,E,y,re,he,ye,X,P,a,pe,bt,yt,_t,kn,wt,Ee,pt,Et,oe,l,d,h,Cn,xn,An]}class tt extends Xt{constructor(e){super(),Yt(this,e,an,un,At,{auto:0,blockspam:16,challengeurl:15,challengejson:31,debug:17,delay:18,expire:19,floating:1,floatinganchor:20,floatingoffset:21,hidefooter:2,hidelogo:3,name:4,maxnumber:22,mockerror:23,obfuscated:24,plugins:32,refetchonexpire:25,spamfilter:26,strings:33,test:27,verifyurl:28,workers:29,workerurl:30,clarify:34,configure:35,getConfiguration:36,getFloatingAnchor:37,getPlugin:38,getState:39,reset:40,setFloatingAnchor:41,setState:42,verify:43},null,[-1,-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),p()}get blockspam(){return this.$$.ctx[16]}set blockspam(e){this.$$set({blockspam:e}),p()}get challengeurl(){return this.$$.ctx[15]}set challengeurl(e){this.$$set({challengeurl:e}),p()}get challengejson(){return this.$$.ctx[31]}set challengejson(e){this.$$set({challengejson:e}),p()}get debug(){return this.$$.ctx[17]}set debug(e){this.$$set({debug:e}),p()}get delay(){return this.$$.ctx[18]}set delay(e){this.$$set({delay:e}),p()}get expire(){return this.$$.ctx[19]}set expire(e){this.$$set({expire:e}),p()}get floating(){return this.$$.ctx[1]}set floating(e){this.$$set({floating:e}),p()}get floatinganchor(){return this.$$.ctx[20]}set floatinganchor(e){this.$$set({floatinganchor:e}),p()}get floatingoffset(){return this.$$.ctx[21]}set floatingoffset(e){this.$$set({floatingoffset:e}),p()}get hidefooter(){return this.$$.ctx[2]}set hidefooter(e){this.$$set({hidefooter:e}),p()}get hidelogo(){return this.$$.ctx[3]}set hidelogo(e){this.$$set({hidelogo:e}),p()}get name(){return this.$$.ctx[4]}set name(e){this.$$set({name:e}),p()}get maxnumber(){return this.$$.ctx[22]}set maxnumber(e){this.$$set({maxnumber:e}),p()}get mockerror(){return this.$$.ctx[23]}set mockerror(e){this.$$set({mockerror:e}),p()}get obfuscated(){return this.$$.ctx[24]}set obfuscated(e){this.$$set({obfuscated:e}),p()}get plugins(){return this.$$.ctx[32]}set plugins(e){this.$$set({plugins:e}),p()}get refetchonexpire(){return this.$$.ctx[25]}set refetchonexpire(e){this.$$set({refetchonexpire:e}),p()}get spamfilter(){return this.$$.ctx[26]}set spamfilter(e){this.$$set({spamfilter:e}),p()}get strings(){return this.$$.ctx[33]}set strings(e){this.$$set({strings:e}),p()}get test(){return this.$$.ctx[27]}set test(e){this.$$set({test:e}),p()}get verifyurl(){return this.$$.ctx[28]}set verifyurl(e){this.$$set({verifyurl:e}),p()}get workers(){return this.$$.ctx[29]}set workers(e){this.$$set({workers:e}),p()}get workerurl(){return this.$$.ctx[30]}set workerurl(e){this.$$set({workerurl:e}),p()}get clarify(){return this.$$.ctx[34]}get configure(){return this.$$.ctx[35]}get getConfiguration(){return this.$$.ctx[36]}get getFloatingAnchor(){return this.$$.ctx[37]}get getPlugin(){return this.$$.ctx[38]}get getState(){return this.$$.ctx[39]}get reset(){return this.$$.ctx[40]}get setFloatingAnchor(){return this.$$.ctx[41]}get setState(){return this.$$.ctx[42]}get verify(){return this.$$.ctx[43]}}customElements.define("altcha-widget",Wt(tt,{auto:{},blockspam:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},delay:{},expire:{},floating:{},floatinganchor:{},floatingoffset:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},obfuscated:{},plugins:{},refetchonexpire:{type:"Boolean"},spamfilter:{type:"Boolean"},strings:{},test:{type:"Boolean"},verifyurl:{},workers:{},workerurl:{}},["default"],["clarify","configure","getConfiguration","getFloatingAnchor","getPlugin","getState","reset","setFloatingAnchor","setState","verify"],!1)),globalThis.altchaCreateWorker=n=>new Worker(new URL(n||"./worker.js",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:H&&H.src||new URL("altcha.umd.cjs",document.baseURI).href)),globalThis.altchaPlugins=globalThis.altchaPlugins||[],$.Altcha=tt,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
|
package/dist_external/worker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";const f=new TextEncoder;function
|
|
1
|
+
(function(){"use strict";const f=new TextEncoder;function p(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}async function w(e,t,r){return p(await crypto.subtle.digest(r.toUpperCase(),f.encode(e+t)))}function b(e,t,r="SHA-256",n=1e6,s=0){const o=new AbortController,a=Date.now();return{promise:(async()=>{for(let c=s;c<=n;c+=1){if(o.signal.aborted)return null;if(await w(t,c,r)===e)return{number:c,took:Date.now()-a}}return null})(),controller:o}}function h(e){const t=atob(e),r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}function g(e,t=12){const r=new Uint8Array(t);for(let n=0;n<t;n++)r[n]=e%256,e=Math.floor(e/256);return r}async function m(e,t="",r=1e6,n=0){const s="AES-GCM",o=new AbortController,a=Date.now(),l=async()=>{for(let u=n;u<=r;u+=1){if(o.signal.aborted||!c||!y)return null;try{const d=await crypto.subtle.decrypt({name:s,iv:g(u)},c,y);if(d)return{clearText:new TextDecoder().decode(d),took:Date.now()-a}}catch{}}return null};let c=null,y=null;try{y=h(e);const u=await crypto.subtle.digest("SHA-256",f.encode(t));c=await crypto.subtle.importKey("raw",u,s,!1,["decrypt"])}catch{return{promise:Promise.reject(),controller:o}}return{promise:l(),controller:o}}let i;onmessage=async e=>{const{type:t,payload:r,start:n,max:s}=e.data;let o=null;if(t==="abort")i==null||i.abort(),i=void 0;else if(t==="work"){if("obfuscated"in r){const{key:a,obfuscated:l}=r||{};o=await m(l,a,s,n)}else{const{algorithm:a,challenge:l,salt:c}=r||{};o=b(l,c,a,s,n)}i=o.controller,o.promise.then(a=>{self.postMessage(a&&{...a,worker:!0})})}}})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'altcha/analytics';
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
var y = Object.defineProperty;
|
|
2
|
+
var p = (s) => {
|
|
3
|
+
throw TypeError(s);
|
|
4
|
+
};
|
|
5
|
+
var C = (s, t, e) => t in s ? y(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
6
|
+
var l = (s, t, e) => C(s, typeof t != "symbol" ? t + "" : t, e), F = (s, t, e) => t.has(s) || p("Cannot " + e);
|
|
7
|
+
var i = (s, t, e) => (F(s, t, "read from private field"), e ? e.call(s) : t.get(s)), r = (s, t, e) => t.has(s) ? p("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(s) : t.set(s, e), T = (s, t, e, n) => (F(s, t, "write to private field"), n ? n.call(s, e) : t.set(s, e), e), E = (s, t, e) => (F(s, t, "access private method"), e);
|
|
8
|
+
new TextEncoder();
|
|
9
|
+
function L() {
|
|
10
|
+
try {
|
|
11
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
12
|
+
} catch {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class v {
|
|
16
|
+
/**
|
|
17
|
+
* Constructs a new instance of the Plugin.
|
|
18
|
+
*
|
|
19
|
+
* @param {PluginContext} context - The context provided to the plugin, containing necessary configurations and dependencies.
|
|
20
|
+
*/
|
|
21
|
+
constructor(t) {
|
|
22
|
+
this.context = t;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Registers a plugin class in the global `altchaPlugins` array.
|
|
26
|
+
* Ensures the plugin is added only once.
|
|
27
|
+
*
|
|
28
|
+
* @param {new(context: PluginContext) => Plugin} cls - The plugin class to register.
|
|
29
|
+
*/
|
|
30
|
+
static register(t) {
|
|
31
|
+
typeof globalThis.altchaPlugins != "object" && (globalThis.altchaPlugins = []), globalThis.altchaPlugins.includes(t) || globalThis.altchaPlugins.push(t);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Clean up resources when the plugin is destroyed.
|
|
35
|
+
* Override this method in subclasses to implement custom destruction logic.
|
|
36
|
+
*/
|
|
37
|
+
destroy() {
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Callback triggered when an error changes.
|
|
41
|
+
* Override this method in subclasses to handle error state changes.
|
|
42
|
+
*
|
|
43
|
+
* @param {string | null} err - The error message or `null` if there's no error.
|
|
44
|
+
*/
|
|
45
|
+
onErrorChange(t) {
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Callback triggered when the plugin state changes.
|
|
49
|
+
* Override this method in subclasses to handle state changes.
|
|
50
|
+
*
|
|
51
|
+
* @param {State} state - The new state of the plugin.
|
|
52
|
+
*/
|
|
53
|
+
onStateChange(t) {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A distinct name of the plugin. Every plugin must have it's own name.
|
|
58
|
+
*/
|
|
59
|
+
l(v, "pluginName");
|
|
60
|
+
var o, a, m, f, w;
|
|
61
|
+
class A extends v {
|
|
62
|
+
/**
|
|
63
|
+
* Creates an instance of PluginAnalytics.
|
|
64
|
+
*
|
|
65
|
+
* @param {PluginContext} context - The context object containing plugin configurations.
|
|
66
|
+
*/
|
|
67
|
+
constructor(e) {
|
|
68
|
+
super(e);
|
|
69
|
+
r(this, f);
|
|
70
|
+
// HTML form element associated with the plugin
|
|
71
|
+
r(this, o);
|
|
72
|
+
// Session instance for tracking analytics data
|
|
73
|
+
r(this, a);
|
|
74
|
+
// Bound method for form submission handling
|
|
75
|
+
r(this, m, E(this, f, w).bind(this));
|
|
76
|
+
if (T(this, o, this.context.el.closest("form")), i(this, o)) {
|
|
77
|
+
let n = i(this, o).getAttribute("data-beacon-url");
|
|
78
|
+
const h = i(this, o).getAttribute("action");
|
|
79
|
+
!n && h && (n = h + "/beacon"), i(this, o).addEventListener("submit", i(this, m)), T(this, a, new N(i(this, o), n));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Destroys the plugin instance, removing event listeners and cleaning up the session.
|
|
84
|
+
*/
|
|
85
|
+
destroy() {
|
|
86
|
+
var e, n;
|
|
87
|
+
(e = i(this, o)) == null || e.removeEventListener("submit", i(this, m)), (n = i(this, a)) == null || n.destroy();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Tracks errors by forwarding them to the session instance.
|
|
91
|
+
*
|
|
92
|
+
* @param {string | null} err - The error message, or `null` if no error exists.
|
|
93
|
+
*/
|
|
94
|
+
onErrorChange(e) {
|
|
95
|
+
var n;
|
|
96
|
+
(n = i(this, a)) == null || n.trackError(e);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
o = new WeakMap(), a = new WeakMap(), m = new WeakMap(), f = new WeakSet(), /**
|
|
100
|
+
* Handles form submission events, appending session data to the form if applicable.
|
|
101
|
+
*/
|
|
102
|
+
w = function() {
|
|
103
|
+
var e;
|
|
104
|
+
if (i(this, a) && !i(this, a).submitTime) {
|
|
105
|
+
i(this, a).end();
|
|
106
|
+
const n = i(this, a).dataAsBase64();
|
|
107
|
+
this.context.dispatch("session", n);
|
|
108
|
+
const h = document.createElement("input");
|
|
109
|
+
h.type = "hidden", h.name = "__session", h.value = n, (e = i(this, o)) == null || e.appendChild(h);
|
|
110
|
+
}
|
|
111
|
+
}, l(A, "pluginName", "analytics");
|
|
112
|
+
var c, u, d, g, b;
|
|
113
|
+
class N {
|
|
114
|
+
/**
|
|
115
|
+
* Creates a new Session instance.
|
|
116
|
+
*
|
|
117
|
+
* @param {HTMLFormElement} elForm - The form element being tracked.
|
|
118
|
+
* @param {string | null} [beaconUrl=null] - The URL to send analytics data to.
|
|
119
|
+
*/
|
|
120
|
+
constructor(t, e = null) {
|
|
121
|
+
// Error message associated with the session
|
|
122
|
+
l(this, "error", null);
|
|
123
|
+
// Timestamp when the form was loaded
|
|
124
|
+
l(this, "loadTime", Date.now());
|
|
125
|
+
// Timestamp when the form was submitted
|
|
126
|
+
l(this, "submitTime", null);
|
|
127
|
+
// Timestamp when the user started interacting with the form
|
|
128
|
+
l(this, "startTime", null);
|
|
129
|
+
// Minimum time in milliseconds required to consider the form "viewed"
|
|
130
|
+
l(this, "viewTimeThresholdMs", 1500);
|
|
131
|
+
// Tracks the number of changes made to each form field
|
|
132
|
+
r(this, c, {});
|
|
133
|
+
// Name of the last input field focused by the user
|
|
134
|
+
r(this, u, null);
|
|
135
|
+
// Bound method for handling form change events
|
|
136
|
+
r(this, d, this.onFormChange.bind(this));
|
|
137
|
+
// Bound method for handling form focus events
|
|
138
|
+
r(this, g, this.onFormFocus.bind(this));
|
|
139
|
+
// Bound method for handling the unload event
|
|
140
|
+
r(this, b, this.onUnload.bind(this));
|
|
141
|
+
this.elForm = t, this.beaconUrl = e, window.addEventListener("unload", i(this, b)), this.elForm.addEventListener("change", i(this, d)), this.elForm.addEventListener("focusin", i(this, g));
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Collects and returns analytics data about the form interaction.
|
|
145
|
+
*
|
|
146
|
+
* @returns {Record<string, unknown>} - An object containing analytics data.
|
|
147
|
+
*/
|
|
148
|
+
data() {
|
|
149
|
+
const t = Object.entries(i(this, c));
|
|
150
|
+
return {
|
|
151
|
+
correction: t.length && t.filter(([e, n]) => n > 1).length / t.length || 0,
|
|
152
|
+
dropoff: !this.submitTime && !this.error && i(this, u) ? i(this, u) : null,
|
|
153
|
+
error: this.error,
|
|
154
|
+
mobile: this.isMobile(),
|
|
155
|
+
start: this.startTime,
|
|
156
|
+
submit: this.submitTime,
|
|
157
|
+
tz: L()
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Encodes the session data as a base64 string.
|
|
162
|
+
*
|
|
163
|
+
* @returns {string} - The base64-encoded session data.
|
|
164
|
+
*/
|
|
165
|
+
dataAsBase64() {
|
|
166
|
+
try {
|
|
167
|
+
return btoa(JSON.stringify(this.data()));
|
|
168
|
+
} catch (t) {
|
|
169
|
+
console.error("failed to encode ALTCHA session data to base64", t);
|
|
170
|
+
}
|
|
171
|
+
return "";
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Destroys the session, removing event listeners.
|
|
175
|
+
*/
|
|
176
|
+
destroy() {
|
|
177
|
+
window.removeEventListener("unload", i(this, b)), this.elForm.removeEventListener("change", i(this, d)), this.elForm.removeEventListener("focusin", i(this, g));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Marks the session as ended by recording the submission time.
|
|
181
|
+
*/
|
|
182
|
+
end() {
|
|
183
|
+
this.submitTime || (this.submitTime = Date.now());
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Retrieves the name of a form field, including a group label if available.
|
|
187
|
+
*
|
|
188
|
+
* @param {HTMLInputElement} el - The input element.
|
|
189
|
+
* @param {number} [maxLength=40] - The maximum length of the field name.
|
|
190
|
+
* @returns {string} - The field name, truncated to `maxLength` if necessary.
|
|
191
|
+
*/
|
|
192
|
+
getFieldName(t, e = 40) {
|
|
193
|
+
const n = t.getAttribute("data-group-label"), h = t.getAttribute("name") || t.getAttribute("aria-label");
|
|
194
|
+
return ((n ? n + ": " : "") + h).slice(0, e);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Determines if the current device is a mobile device.
|
|
198
|
+
*
|
|
199
|
+
* @returns {boolean} - `true` if the device is mobile, otherwise `false`.
|
|
200
|
+
*/
|
|
201
|
+
isMobile() {
|
|
202
|
+
const t = "userAgentData" in navigator && navigator.userAgentData ? navigator.userAgentData : {};
|
|
203
|
+
return "mobile" in t ? t.mobile === !0 : /Mobi/i.test(window.navigator.userAgent);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Checks if a given element is an input element (input, select, or textarea).
|
|
207
|
+
*
|
|
208
|
+
* @param {HTMLElement} el - The element to check.
|
|
209
|
+
* @returns {boolean} - `true` if the element is an input, otherwise `false`.
|
|
210
|
+
*/
|
|
211
|
+
isInput(t) {
|
|
212
|
+
return ["INPUT", "SELECT", "TEXTAREA"].includes(t.tagName);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Tracks changes to a specific form field.
|
|
216
|
+
*
|
|
217
|
+
* @param {HTMLInputElement} el - The input element that changed.
|
|
218
|
+
*/
|
|
219
|
+
onFormFieldChange(t) {
|
|
220
|
+
const e = this.getFieldName(t);
|
|
221
|
+
e && this.trackFieldChange(e);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Handles form change events, tracking changes to input fields.
|
|
225
|
+
*
|
|
226
|
+
* @param {Event} ev - The change event.
|
|
227
|
+
*/
|
|
228
|
+
onFormChange(t) {
|
|
229
|
+
const e = t.target;
|
|
230
|
+
e && this.isInput(e) && this.onFormFieldChange(e);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Handles form focus events, marking the session start time and tracking the last focused field.
|
|
234
|
+
*
|
|
235
|
+
* @param {FocusEvent} ev - The focus event.
|
|
236
|
+
*/
|
|
237
|
+
onFormFocus(t) {
|
|
238
|
+
const e = t.target;
|
|
239
|
+
if (this.startTime || this.start(), e && this.isInput(e)) {
|
|
240
|
+
const n = this.getFieldName(e);
|
|
241
|
+
n && T(this, u, n);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Handles the window unload event, sending a beacon with session data if the form was viewed but not submitted.
|
|
246
|
+
*/
|
|
247
|
+
onUnload() {
|
|
248
|
+
this.loadTime <= Date.now() - this.viewTimeThresholdMs && !this.submitTime && this.sendBeacon();
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Sends a beacon with session data to the specified beacon URL.
|
|
252
|
+
*/
|
|
253
|
+
async sendBeacon() {
|
|
254
|
+
if (this.beaconUrl && "sendBeacon" in navigator)
|
|
255
|
+
try {
|
|
256
|
+
navigator.sendBeacon(
|
|
257
|
+
new URL(this.beaconUrl, location.origin),
|
|
258
|
+
JSON.stringify(this.data())
|
|
259
|
+
);
|
|
260
|
+
} catch {
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Marks the session as started by recording the start time.
|
|
265
|
+
*/
|
|
266
|
+
start() {
|
|
267
|
+
this.startTime = Date.now();
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Tracks an error associated with the session.
|
|
271
|
+
*
|
|
272
|
+
* @param {string | null} err - The error message, or `null` if no error exists.
|
|
273
|
+
*/
|
|
274
|
+
trackError(t) {
|
|
275
|
+
this.error = t === null ? null : String(t);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Tracks a change to a specific form field.
|
|
279
|
+
*
|
|
280
|
+
* @param {string} name - The name of the form field.
|
|
281
|
+
*/
|
|
282
|
+
trackFieldChange(t) {
|
|
283
|
+
i(this, c)[t] = (i(this, c)[t] || 0) + 1;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
c = new WeakMap(), u = new WeakMap(), d = new WeakMap(), g = new WeakMap(), b = new WeakMap();
|
|
287
|
+
v.register(A);
|
|
288
|
+
export {
|
|
289
|
+
A as PluginAnalytics
|
|
290
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(e=typeof globalThis<"u"?globalThis:e||self,i(e["[name]"]={}))})(this,function(e){"use strict";var N=Object.defineProperty;var A=e=>{throw TypeError(e)};var S=(e,i,o)=>i in e?N(e,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[i]=o;var c=(e,i,o)=>S(e,typeof i!="symbol"?i+"":i,o),y=(e,i,o)=>i.has(e)||A("Cannot "+o);var s=(e,i,o)=>(y(e,i,"read from private field"),o?o.call(e):i.get(e)),l=(e,i,o)=>i.has(e)?A("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(e):i.set(e,o),v=(e,i,o,d)=>(y(e,i,"write to private field"),d?d.call(e,o):i.set(e,o),o),w=(e,i,o)=>(y(e,i,"access private method"),o);var a,h,b,F,C,m,g,f,T,p;new TextEncoder;function i(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}class o{constructor(t){this.context=t}static register(t){typeof globalThis.altchaPlugins!="object"&&(globalThis.altchaPlugins=[]),globalThis.altchaPlugins.includes(t)||globalThis.altchaPlugins.push(t)}destroy(){}onErrorChange(t){}onStateChange(t){}}c(o,"pluginName");class d extends o{constructor(n){super(n);l(this,F);l(this,a);l(this,h);l(this,b,w(this,F,C).bind(this));if(v(this,a,this.context.el.closest("form")),s(this,a)){let r=s(this,a).getAttribute("data-beacon-url");const u=s(this,a).getAttribute("action");!r&&u&&(r=u+"/beacon"),s(this,a).addEventListener("submit",s(this,b)),v(this,h,new L(s(this,a),r))}}destroy(){var n,r;(n=s(this,a))==null||n.removeEventListener("submit",s(this,b)),(r=s(this,h))==null||r.destroy()}onErrorChange(n){var r;(r=s(this,h))==null||r.trackError(n)}}a=new WeakMap,h=new WeakMap,b=new WeakMap,F=new WeakSet,C=function(){var n;if(s(this,h)&&!s(this,h).submitTime){s(this,h).end();const r=s(this,h).dataAsBase64();this.context.dispatch("session",r);const u=document.createElement("input");u.type="hidden",u.name="__session",u.value=r,(n=s(this,a))==null||n.appendChild(u)}},c(d,"pluginName","analytics");class L{constructor(t,n=null){c(this,"error",null);c(this,"loadTime",Date.now());c(this,"submitTime",null);c(this,"startTime",null);c(this,"viewTimeThresholdMs",1500);l(this,m,{});l(this,g,null);l(this,f,this.onFormChange.bind(this));l(this,T,this.onFormFocus.bind(this));l(this,p,this.onUnload.bind(this));this.elForm=t,this.beaconUrl=n,window.addEventListener("unload",s(this,p)),this.elForm.addEventListener("change",s(this,f)),this.elForm.addEventListener("focusin",s(this,T))}data(){const t=Object.entries(s(this,m));return{correction:t.length&&t.filter(([n,r])=>r>1).length/t.length||0,dropoff:!this.submitTime&&!this.error&&s(this,g)?s(this,g):null,error:this.error,mobile:this.isMobile(),start:this.startTime,submit:this.submitTime,tz:i()}}dataAsBase64(){try{return btoa(JSON.stringify(this.data()))}catch(t){console.error("failed to encode ALTCHA session data to base64",t)}return""}destroy(){window.removeEventListener("unload",s(this,p)),this.elForm.removeEventListener("change",s(this,f)),this.elForm.removeEventListener("focusin",s(this,T))}end(){this.submitTime||(this.submitTime=Date.now())}getFieldName(t,n=40){const r=t.getAttribute("data-group-label"),u=t.getAttribute("name")||t.getAttribute("aria-label");return((r?r+": ":"")+u).slice(0,n)}isMobile(){const t="userAgentData"in navigator&&navigator.userAgentData?navigator.userAgentData:{};return"mobile"in t?t.mobile===!0:/Mobi/i.test(window.navigator.userAgent)}isInput(t){return["INPUT","SELECT","TEXTAREA"].includes(t.tagName)}onFormFieldChange(t){const n=this.getFieldName(t);n&&this.trackFieldChange(n)}onFormChange(t){const n=t.target;n&&this.isInput(n)&&this.onFormFieldChange(n)}onFormFocus(t){const n=t.target;if(this.startTime||this.start(),n&&this.isInput(n)){const r=this.getFieldName(n);r&&v(this,g,r)}}onUnload(){this.loadTime<=Date.now()-this.viewTimeThresholdMs&&!this.submitTime&&this.sendBeacon()}async sendBeacon(){if(this.beaconUrl&&"sendBeacon"in navigator)try{navigator.sendBeacon(new URL(this.beaconUrl,location.origin),JSON.stringify(this.data()))}catch{}}start(){this.startTime=Date.now()}trackError(t){this.error=t===null?null:String(t)}trackFieldChange(t){s(this,m)[t]=(s(this,m)[t]||0)+1}}m=new WeakMap,g=new WeakMap,f=new WeakMap,T=new WeakMap,p=new WeakMap,o.register(d),e.PluginAnalytics=d,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'altcha/obfuscation';
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
var D = Object.defineProperty;
|
|
2
|
+
var B = (t) => {
|
|
3
|
+
throw TypeError(t);
|
|
4
|
+
};
|
|
5
|
+
var V = (t, e, i) => e in t ? D(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
|
|
6
|
+
var f = (t, e, i) => V(t, typeof e != "symbol" ? e + "" : e, i), b = (t, e, i) => e.has(t) || B("Cannot " + i);
|
|
7
|
+
var p = (t, e, i) => (b(t, e, "read from private field"), i ? i.call(t) : e.get(t)), g = (t, e, i) => e.has(t) ? B("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i);
|
|
8
|
+
var E = (t, e, i) => (b(t, e, "access private method"), i);
|
|
9
|
+
class y {
|
|
10
|
+
/**
|
|
11
|
+
* Constructs a new instance of the Plugin.
|
|
12
|
+
*
|
|
13
|
+
* @param {PluginContext} context - The context provided to the plugin, containing necessary configurations and dependencies.
|
|
14
|
+
*/
|
|
15
|
+
constructor(e) {
|
|
16
|
+
this.context = e;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Registers a plugin class in the global `altchaPlugins` array.
|
|
20
|
+
* Ensures the plugin is added only once.
|
|
21
|
+
*
|
|
22
|
+
* @param {new(context: PluginContext) => Plugin} cls - The plugin class to register.
|
|
23
|
+
*/
|
|
24
|
+
static register(e) {
|
|
25
|
+
typeof globalThis.altchaPlugins != "object" && (globalThis.altchaPlugins = []), globalThis.altchaPlugins.includes(e) || globalThis.altchaPlugins.push(e);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Clean up resources when the plugin is destroyed.
|
|
29
|
+
* Override this method in subclasses to implement custom destruction logic.
|
|
30
|
+
*/
|
|
31
|
+
destroy() {
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Callback triggered when an error changes.
|
|
35
|
+
* Override this method in subclasses to handle error state changes.
|
|
36
|
+
*
|
|
37
|
+
* @param {string | null} err - The error message or `null` if there's no error.
|
|
38
|
+
*/
|
|
39
|
+
onErrorChange(e) {
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Callback triggered when the plugin state changes.
|
|
43
|
+
* Override this method in subclasses to handle state changes.
|
|
44
|
+
*
|
|
45
|
+
* @param {State} state - The new state of the plugin.
|
|
46
|
+
*/
|
|
47
|
+
onStateChange(e) {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A distinct name of the plugin. Every plugin must have it's own name.
|
|
52
|
+
*/
|
|
53
|
+
f(y, "pluginName");
|
|
54
|
+
var l = /* @__PURE__ */ ((t) => (t.ERROR = "error", t.VERIFIED = "verified", t.VERIFYING = "verifying", t.UNVERIFIED = "unverified", t.EXPIRED = "expired", t))(l || {}), r, a, I, x;
|
|
55
|
+
class v extends y {
|
|
56
|
+
/**
|
|
57
|
+
* Creates an instance of PluginObfuscation.
|
|
58
|
+
*
|
|
59
|
+
* @param {PluginContext} context - The context object containing plugin configurations.
|
|
60
|
+
*/
|
|
61
|
+
constructor(i) {
|
|
62
|
+
var n, o;
|
|
63
|
+
super(i);
|
|
64
|
+
g(this, a);
|
|
65
|
+
// The button element associated with revealing the obfuscated data
|
|
66
|
+
f(this, "elButton");
|
|
67
|
+
// Bound method for handling button click events
|
|
68
|
+
g(this, r, E(this, a, I).bind(this));
|
|
69
|
+
const s = i.el;
|
|
70
|
+
this.elButton = ((n = s.parentElement) == null ? void 0 : n.querySelector("[data-clarify-button]")) || ((o = s.parentElement) == null ? void 0 : o.querySelector("button, a")), this.elButton && this.elButton.addEventListener("click", p(this, r));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Destroys the plugin instance, removing event listeners.
|
|
74
|
+
*/
|
|
75
|
+
destroy() {
|
|
76
|
+
this.elButton && this.elButton.removeEventListener("click", p(this, r));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Handles the clarification process by decrypting the obfuscated data and rendering the clear text.
|
|
80
|
+
*/
|
|
81
|
+
async clarify() {
|
|
82
|
+
const {
|
|
83
|
+
el: i,
|
|
84
|
+
getConfiguration: s,
|
|
85
|
+
getFloatingAnchor: n,
|
|
86
|
+
setFloatingAnchor: o,
|
|
87
|
+
reset: d,
|
|
88
|
+
solve: P,
|
|
89
|
+
setState: m
|
|
90
|
+
} = this.context, { delay: C, floating: F, maxnumber: T, obfuscated: R } = s();
|
|
91
|
+
if (this.elButton && !n() && o(this.elButton), !R) {
|
|
92
|
+
m(l.ERROR);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
d(l.VERIFYING), await new Promise((h) => setTimeout(h, C || 0));
|
|
96
|
+
const [k, N] = R.split("?");
|
|
97
|
+
let c = new URLSearchParams(N || "").get("key") || void 0;
|
|
98
|
+
if (c) {
|
|
99
|
+
const h = c.match(/^\(prompt:?(.*)\)$/);
|
|
100
|
+
h && (c = prompt(h[1] || "Enter Key:") || void 0);
|
|
101
|
+
}
|
|
102
|
+
const { solution: u } = await P({
|
|
103
|
+
obfuscated: k,
|
|
104
|
+
key: c,
|
|
105
|
+
maxnumber: T
|
|
106
|
+
});
|
|
107
|
+
u && "clearText" in u ? (E(this, a, x).call(this, u.clearText), m(l.VERIFIED), this.context.dispatch("cleartext", u.clearText), F && i && (i.style.display = "none")) : m(l.ERROR, "Unable to decrypt data.");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
r = new WeakMap(), a = new WeakSet(), /**
|
|
111
|
+
* Handles the button click event, triggering the clarification process.
|
|
112
|
+
*
|
|
113
|
+
* @param {Event} ev - The click event.
|
|
114
|
+
*/
|
|
115
|
+
I = function(i) {
|
|
116
|
+
i.preventDefault();
|
|
117
|
+
const { auto: s } = this.context.getConfiguration();
|
|
118
|
+
s === "off" || this.clarify();
|
|
119
|
+
}, /**
|
|
120
|
+
* Renders the clear text data by creating an appropriate element (e.g., a link or text node).
|
|
121
|
+
*
|
|
122
|
+
* @param {string} clearText - The decrypted clear text data to render.
|
|
123
|
+
*/
|
|
124
|
+
x = function(i) {
|
|
125
|
+
var o;
|
|
126
|
+
const s = i.match(/^(mailto|tel|sms|https?):/);
|
|
127
|
+
let n;
|
|
128
|
+
if (s) {
|
|
129
|
+
const [d] = i.slice(i.indexOf(":") + 1).replace(/^\/\//, "").split("?");
|
|
130
|
+
n = document.createElement("a"), n.href = i, n.innerHTML = d;
|
|
131
|
+
} else
|
|
132
|
+
n = document.createTextNode(i);
|
|
133
|
+
this.elButton && n && (this.elButton.after(n), (o = this.elButton.parentElement) == null || o.removeChild(this.elButton));
|
|
134
|
+
}, f(v, "pluginName", "obfuscation");
|
|
135
|
+
y.register(v);
|
|
136
|
+
export {
|
|
137
|
+
v as PluginObfuscation
|
|
138
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e["[name]"]={}))})(this,function(e){"use strict";var D=Object.defineProperty;var v=e=>{throw TypeError(e)};var V=(e,t,i)=>t in e?D(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var p=(e,t,i)=>V(e,typeof t!="symbol"?t+"":t,i),x=(e,t,i)=>t.has(e)||v("Cannot "+i);var E=(e,t,i)=>(x(e,t,"read from private field"),i?i.call(e):t.get(e)),b=(e,t,i)=>t.has(e)?v("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i);var R=(e,t,i)=>(x(e,t,"access private method"),i);var u,c,I,P;class t{constructor(l){this.context=l}static register(l){typeof globalThis.altchaPlugins!="object"&&(globalThis.altchaPlugins=[]),globalThis.altchaPlugins.includes(l)||globalThis.altchaPlugins.push(l)}destroy(){}onErrorChange(l){}onStateChange(l){}}p(t,"pluginName");var i=(s=>(s.ERROR="error",s.VERIFIED="verified",s.VERIFYING="verifying",s.UNVERIFIED="unverified",s.EXPIRED="expired",s))(i||{});class m extends t{constructor(n){var o,r;super(n);b(this,c);p(this,"elButton");b(this,u,R(this,c,I).bind(this));const a=n.el;this.elButton=((o=a.parentElement)==null?void 0:o.querySelector("[data-clarify-button]"))||((r=a.parentElement)==null?void 0:r.querySelector("button, a")),this.elButton&&this.elButton.addEventListener("click",E(this,u))}destroy(){this.elButton&&this.elButton.removeEventListener("click",E(this,u))}async clarify(){const{el:n,getConfiguration:a,getFloatingAnchor:o,setFloatingAnchor:r,reset:g,solve:T,setState:y}=this.context,{delay:C,floating:F,maxnumber:k,obfuscated:B}=a();if(this.elButton&&!o()&&r(this.elButton),!B){y(i.ERROR);return}g(i.VERIFYING),await new Promise(d=>setTimeout(d,C||0));const[N,O]=B.split("?");let h=new URLSearchParams(O||"").get("key")||void 0;if(h){const d=h.match(/^\(prompt:?(.*)\)$/);d&&(h=prompt(d[1]||"Enter Key:")||void 0)}const{solution:f}=await T({obfuscated:N,key:h,maxnumber:k});f&&"clearText"in f?(R(this,c,P).call(this,f.clearText),y(i.VERIFIED),this.context.dispatch("cleartext",f.clearText),F&&n&&(n.style.display="none")):y(i.ERROR,"Unable to decrypt data.")}}u=new WeakMap,c=new WeakSet,I=function(n){n.preventDefault();const{auto:a}=this.context.getConfiguration();a==="off"||this.clarify()},P=function(n){var r;const a=n.match(/^(mailto|tel|sms|https?):/);let o;if(a){const[g]=n.slice(n.indexOf(":")+1).replace(/^\/\//,"").split("?");o=document.createElement("a"),o.href=n,o.innerHTML=g}else o=document.createTextNode(n);this.elButton&&o&&(this.elButton.after(o),(r=this.elButton.parentElement)==null||r.removeChild(this.elButton))},p(m,"pluginName","obfuscation"),t.register(m),e.PluginObfuscation=m,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|