altcha 2.2.2 → 2.2.4

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.
@@ -1,28 +1,24 @@
1
- var N = Object.defineProperty;
2
- var B = (t) => {
3
- throw TypeError(t);
4
- };
5
- var O = (t, e, i) => e in t ? N(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
6
- var f = (t, e, i) => O(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 {
1
+ class h {
10
2
  /**
11
3
  * Constructs a new instance of the Plugin.
12
4
  *
13
5
  * @param {PluginContext} context - The context provided to the plugin, containing necessary configurations and dependencies.
14
6
  */
15
- constructor(e) {
16
- this.context = e;
7
+ constructor(t) {
8
+ this.context = t;
17
9
  }
10
+ /**
11
+ * A distinct name of the plugin. Every plugin must have it's own name.
12
+ */
13
+ static pluginName;
18
14
  /**
19
15
  * Registers a plugin class in the global `altchaPlugins` array.
20
16
  * Ensures the plugin is added only once.
21
17
  *
22
18
  * @param {new(context: PluginContext) => Plugin} cls - The plugin class to register.
23
19
  */
24
- static register(e) {
25
- typeof globalThis.altchaPlugins != "object" && (globalThis.altchaPlugins = []), globalThis.altchaPlugins.includes(e) || globalThis.altchaPlugins.push(e);
20
+ static register(t) {
21
+ typeof globalThis.altchaPlugins != "object" && (globalThis.altchaPlugins = []), globalThis.altchaPlugins.includes(t) || globalThis.altchaPlugins.push(t);
26
22
  }
27
23
  /**
28
24
  * Clean up resources when the plugin is destroyed.
@@ -36,7 +32,7 @@ class y {
36
32
  *
37
33
  * @param {string | null} err - The error message or `null` if there's no error.
38
34
  */
39
- onErrorChange(e) {
35
+ onErrorChange(t) {
40
36
  }
41
37
  /**
42
38
  * Callback triggered when the plugin state changes.
@@ -44,95 +40,90 @@ class y {
44
40
  *
45
41
  * @param {State} state - The new state of the plugin.
46
42
  */
47
- onStateChange(e) {
43
+ onStateChange(t) {
48
44
  }
49
45
  }
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.CODE = "code", 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 {
46
+ var s = /* @__PURE__ */ ((e) => (e.CODE = "code", e.ERROR = "error", e.VERIFIED = "verified", e.VERIFYING = "verifying", e.UNVERIFIED = "unverified", e.EXPIRED = "expired", e))(s || {});
47
+ class R extends h {
48
+ static pluginName = "obfuscation";
49
+ // The button element associated with revealing the obfuscated data
50
+ elButton;
51
+ // Bound method for handling button click events
52
+ #t = this.#e.bind(this);
56
53
  /**
57
54
  * Creates an instance of PluginObfuscation.
58
55
  *
59
56
  * @param {PluginContext} context - The context object containing plugin configurations.
60
57
  */
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));
58
+ constructor(t) {
59
+ super(t);
60
+ const i = t.el;
61
+ this.elButton = i.parentElement?.querySelector("[data-clarify-button]") || i.parentElement?.querySelector("button, a"), this.elButton && this.elButton.addEventListener("click", this.#t);
71
62
  }
72
63
  /**
73
64
  * Destroys the plugin instance, removing event listeners.
74
65
  */
75
66
  destroy() {
76
- this.elButton && this.elButton.removeEventListener("click", p(this, r));
67
+ this.elButton && this.elButton.removeEventListener("click", this.#t);
77
68
  }
78
69
  /**
79
70
  * Handles the clarification process by decrypting the obfuscated data and rendering the clear text.
80
71
  */
81
72
  async clarify() {
82
73
  const {
83
- el: i,
84
- getConfiguration: s,
74
+ el: t,
75
+ getConfiguration: i,
85
76
  getFloatingAnchor: n,
86
- setFloatingAnchor: o,
87
- reset: d,
88
- solve: C,
89
- setState: m
90
- } = this.context, { delay: P, floating: F, maxnumber: T, obfuscated: R } = s();
91
- if (this.elButton && !n() && o(this.elButton), !R) {
92
- m(l.ERROR);
77
+ setFloatingAnchor: r,
78
+ reset: f,
79
+ solve: d,
80
+ setState: c
81
+ } = this.context, { delay: g, floating: m, maxnumber: p, obfuscated: u } = i();
82
+ if (this.elButton && !n() && r(this.elButton), !u) {
83
+ c(s.ERROR);
93
84
  return;
94
85
  }
95
- d(l.VERIFYING), await new Promise((h) => setTimeout(h, P || 0));
96
- const [k, D] = R.split("?");
97
- let c = new URLSearchParams(D || "").get("key") || void 0;
98
- if (c) {
99
- const h = c.match(/^\(prompt:?(.*)\)$/);
100
- h && (c = prompt(h[1] || "Enter Key:") || void 0);
86
+ f(s.VERIFYING), await new Promise((l) => setTimeout(l, g || 0));
87
+ const [E, y] = u.split("?");
88
+ let o = new URLSearchParams(y || "").get("key") || void 0;
89
+ if (o) {
90
+ const l = o.match(/^\(prompt:?(.*)\)$/);
91
+ l && (o = prompt(l[1] || "Enter Key:") || void 0);
101
92
  }
102
- const { solution: u } = await C({
103
- obfuscated: k,
104
- key: c,
105
- maxnumber: T
93
+ const { solution: a } = await d({
94
+ obfuscated: E,
95
+ key: o,
96
+ maxnumber: p
106
97
  });
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.");
98
+ a && "clearText" in a ? (this.#i(a.clearText), c(s.VERIFIED), this.context.dispatch("cleartext", a.clearText), m && t && (t.style.display = "none")) : c(s.ERROR, "Unable to decrypt data.");
99
+ }
100
+ /**
101
+ * Handles the button click event, triggering the clarification process.
102
+ *
103
+ * @param {Event} ev - The click event.
104
+ */
105
+ #e(t) {
106
+ t.preventDefault();
107
+ const { auto: i } = this.context.getConfiguration();
108
+ i === "off" || this.clarify();
109
+ }
110
+ /**
111
+ * Renders the clear text data by creating an appropriate element (e.g., a link or text node).
112
+ *
113
+ * @param {string} clearText - The decrypted clear text data to render.
114
+ */
115
+ #i(t) {
116
+ const i = t.match(/^(mailto|tel|sms|https?):/);
117
+ let n;
118
+ if (i) {
119
+ const [r] = t.slice(t.indexOf(":") + 1).replace(/^\/\//, "").split("?");
120
+ n = document.createElement("a"), n.href = t, n.innerHTML = r;
121
+ } else
122
+ n = document.createTextNode(t);
123
+ this.elButton && n && (this.elButton.after(n), this.elButton.parentElement?.removeChild(this.elButton));
108
124
  }
109
125
  }
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);
126
+ h.register(R);
136
127
  export {
137
- v as PluginObfuscation
128
+ R as PluginObfuscation
138
129
  };
@@ -1 +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 N=Object.defineProperty;var v=e=>{throw TypeError(e)};var V=(e,t,i)=>t in e?N(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 y=(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.CODE="code",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",y(this,u))}destroy(){this.elButton&&this.elButton.removeEventListener("click",y(this,u))}async clarify(){const{el:n,getConfiguration:a,getFloatingAnchor:o,setFloatingAnchor:r,reset:g,solve:T,setState:E}=this.context,{delay:C,floating:F,maxnumber:O,obfuscated:B}=a();if(this.elButton&&!o()&&r(this.elButton),!B){E(i.ERROR);return}g(i.VERIFYING),await new Promise(d=>setTimeout(d,C||0));const[k,D]=B.split("?");let h=new URLSearchParams(D||"").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:k,key:h,maxnumber:O});f&&"clearText"in f?(R(this,c,P).call(this,f.clearText),E(i.VERIFIED),this.context.dispatch("cleartext",f.clearText),F&&n&&(n.style.display="none")):E(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"})});
1
+ (function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o["[name]"]={}))})(this,function(o){"use strict";class s{constructor(t){this.context=t}static pluginName;static register(t){typeof globalThis.altchaPlugins!="object"&&(globalThis.altchaPlugins=[]),globalThis.altchaPlugins.includes(t)||globalThis.altchaPlugins.push(t)}destroy(){}onErrorChange(t){}onStateChange(t){}}var a=(e=>(e.CODE="code",e.ERROR="error",e.VERIFIED="verified",e.VERIFYING="verifying",e.UNVERIFIED="unverified",e.EXPIRED="expired",e))(a||{});class h extends s{static pluginName="obfuscation";elButton;#t=this.#e.bind(this);constructor(t){super(t);const i=t.el;this.elButton=i.parentElement?.querySelector("[data-clarify-button]")||i.parentElement?.querySelector("button, a"),this.elButton&&this.elButton.addEventListener("click",this.#t)}destroy(){this.elButton&&this.elButton.removeEventListener("click",this.#t)}async clarify(){const{el:t,getConfiguration:i,getFloatingAnchor:n,setFloatingAnchor:u,reset:p,solve:m,setState:f}=this.context,{delay:g,floating:E,maxnumber:y,obfuscated:d}=i();if(this.elButton&&!n()&&u(this.elButton),!d){f(a.ERROR);return}p(a.VERIFYING),await new Promise(c=>setTimeout(c,g||0));const[b,R]=d.split("?");let l=new URLSearchParams(R||"").get("key")||void 0;if(l){const c=l.match(/^\(prompt:?(.*)\)$/);c&&(l=prompt(c[1]||"Enter Key:")||void 0)}const{solution:r}=await m({obfuscated:b,key:l,maxnumber:y});r&&"clearText"in r?(this.#i(r.clearText),f(a.VERIFIED),this.context.dispatch("cleartext",r.clearText),E&&t&&(t.style.display="none")):f(a.ERROR,"Unable to decrypt data.")}#e(t){t.preventDefault();const{auto:i}=this.context.getConfiguration();i==="off"||this.clarify()}#i(t){const i=t.match(/^(mailto|tel|sms|https?):/);let n;if(i){const[u]=t.slice(t.indexOf(":")+1).replace(/^\/\//,"").split("?");n=document.createElement("a"),n.href=t,n.innerHTML=u}else n=document.createTextNode(t);this.elButton&&n&&(this.elButton.after(n),this.elButton.parentElement?.removeChild(this.elButton))}}s.register(h),o.PluginObfuscation=h,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});