magtool 1.0.9 → 1.1.2

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.
Files changed (2) hide show
  1. package/dist/util.js +89 -92
  2. package/package.json +2 -2
package/dist/util.js CHANGED
@@ -1,166 +1,163 @@
1
1
  const j = (c) => {
2
2
  window.$getLang = () => localStorage.getItem("lang");
3
- const u = (e = {}) => {
4
- const { alpha: t, name: o } = e, n = ["blue", "red", "orange", "green", "pink", "yellow", "purple", "primary", "dark"], r = ["", 1, 3, 5, 7];
5
- return `${o || n[parseInt(Math.random() * n.length)]}${t === 0 ? "" : r[parseInt(Math.random() * r.length)]}`;
3
+ const w = (e = {}) => {
4
+ const { alpha: o, name: t } = e, n = ["blue", "red", "orange", "green", "pink", "yellow", "purple", "primary", "dark"], r = ["", 1, 3, 5, 7];
5
+ return `${t || n[parseInt(Math.random() * n.length)]}${o === 0 ? "" : r[parseInt(Math.random() * r.length)]}`;
6
6
  };
7
- window.$randomColor = u, window.$rc = u, c.config.globalProperties.$rc = u, window.$rn = (e, t = 0) => {
8
- let o = parseInt(Math.random() * e);
9
- return o += t, o;
7
+ window.$randomColor = w, window.$rc = w, c.config.globalProperties.$rc = w, window.$rn = (e, o = 0) => {
8
+ let t = parseInt(Math.random() * e);
9
+ return t += o, t;
10
10
  }, window.$elc = (e = {}) => {
11
- let { i: t = 0, color: o } = e;
11
+ let { i: o = 0, color: t } = e;
12
12
  const n = window.global.config.color;
13
- return o = o || n[t], { type: "linear", x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: o + "FF" }, { offset: 1, color: o + "00" }] };
13
+ return t = t || n[o], { type: "linear", x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: t + "FF" }, { offset: 1, color: t + "00" }] };
14
14
  }, window.$egc = (e = {}) => {
15
- let { i: t = 0, color: o } = e;
15
+ let { i: o = 0, color: t } = e;
16
16
  const n = window.global.config.color;
17
- return o = o || n[t], { type: "radial", x: 0.1, y: 0.5, r: 1, colorStops: [{ offset: 0, color: o + "00" }, { offset: 1, color: o + "FF" }] };
18
- }, window.$fd = (e, t) => {
19
- let o = [];
20
- for (let n = 0; n < e; n++) o.push(t(n));
21
- return o;
17
+ return t = t || n[o], { type: "radial", x: 0.1, y: 0.5, r: 1, colorStops: [{ offset: 0, color: t + "00" }, { offset: 1, color: t + "FF" }] };
18
+ }, window.$fd = (e, o) => {
19
+ let t = [];
20
+ for (let n = 0; n < e; n++) t.push(o(n));
21
+ return t;
22
22
  }, c.config.globalProperties.$setTimeout = function(e = () => {
23
- }, t) {
23
+ }, o) {
24
24
  this.timer && (clearTimeout(this.timer), this.timer = null), this.timer = setTimeout(() => {
25
25
  e(), clearTimeout(this.timer);
26
- }, t);
26
+ }, o);
27
27
  };
28
- const g = (e) => e.substr(0, 1).toUpperCase() + e.substr(1, e.length).toLowerCase();
29
- c.config.globalProperties.$toUpperCamel = g, window.$toUpperCamel = g;
30
- const m = (e, t = 2) => {
31
- const o = window.$getType(e);
28
+ const u = (e) => e.substr(0, 1).toUpperCase() + e.substr(1, e.length).toLowerCase();
29
+ c.config.globalProperties.$toUpperCamel = u, window.$toUpperCamel = u;
30
+ const g = (e, o = 2) => {
31
+ const t = window.$getType(e);
32
32
  let n;
33
- o === "Number" ? (e = e.toFixed(t), n = String(e), e = String(Math.abs(e))) : o === "String" && (n = e, e = String(Math.abs(Number(e))));
33
+ t === "Number" ? (e = e.toFixed(o), n = String(e), e = String(Math.abs(e))) : t === "String" && (n = e, e = String(Math.abs(Number(e))));
34
34
  const r = e.split(".");
35
35
  let i = r[0].split("");
36
36
  i = i.reverse();
37
37
  let p = [];
38
- i.forEach((l, w) => {
39
- w !== 0 && w % 3 == 0 && p.push(","), p.push(l);
38
+ i.forEach((T, y) => {
39
+ y !== 0 && y % 3 == 0 && p.push(","), p.push(T);
40
40
  });
41
- let s = p.reverse().join("");
42
- return window.$getType(t) === "Number" && t > 0 && (s += ".", r[1] ? s += r[1].padEnd(t, 0).substr(0, t) : s += "0".padEnd(t, "0")), Number(n) !== Number(e) ? `-${s}` : s;
41
+ let l = p.reverse().join("");
42
+ return window.$getType(o) === "Number" && o > 0 && (l += ".", r[1] ? l += r[1].padEnd(o, 0).substr(0, o) : l += "0".padEnd(o, "0")), Number(n) !== Number(e) ? `-${l}` : l;
43
43
  };
44
- window.$fa = m, c.config.globalProperties.$fa = m;
45
- const $ = ({ prop: e, currency: t, value: o, obj: n = window.$map.asa.asaMetric.allObj }) => {
44
+ window.$fa = g, c.config.globalProperties.$fa = g;
45
+ const f = ({ prop: e, currency: o, value: t, obj: n = window.$map.asa.asaMetric.allObj }) => {
46
46
  const r = n[e];
47
- return r.unit === "currency" ? t ? `${t} ${window.$fa(o, r == null ? void 0 : r.precision)}` : window.$fa(o, r == null ? void 0 : r.precision) : r.unit === "%" ? `${window.$fa(o, r == null ? void 0 : r.precision)}%` : window.$fa(o, r == null ? void 0 : r.precision);
47
+ return r.unit === "currency" ? o ? `${o} ${window.$fa(t, r == null ? void 0 : r.precision)}` : window.$fa(t, r == null ? void 0 : r.precision) : r.unit === "%" ? `${window.$fa(t, r == null ? void 0 : r.precision)}%` : window.$fa(t, r == null ? void 0 : r.precision);
48
48
  };
49
- window.$fu2 = $, c.config.globalProperties.$fu2 = $;
50
- const b = (e = () => {
51
- }, t = 2) => {
52
- let o = null;
49
+ window.$fu2 = f, c.config.globalProperties.$fu2 = f;
50
+ const m = (e = () => {
51
+ }, o = 2) => {
52
+ let t = null;
53
53
  return new Promise((n, r) => {
54
- o = setTimeout(() => {
55
- e(n, r), clearTimeout(o), n(!0);
56
- }, 100 * t);
54
+ t = setTimeout(() => {
55
+ e(n, r), clearTimeout(t), n(!0);
56
+ }, 100 * o);
57
57
  });
58
58
  };
59
- window.$pm = b, window.$promise = b;
60
- const h = (e = () => {
61
- }, t = 500) => {
62
- let o;
59
+ window.$pm = m, window.$promise = m;
60
+ const $ = (e = () => {
61
+ }, o = 500) => {
62
+ let t;
63
63
  return function(...n) {
64
- o && clearTimeout(o), o = setTimeout(() => {
64
+ t && clearTimeout(t), t = setTimeout(() => {
65
65
  e.apply(this, n);
66
- }, t);
66
+ }, o);
67
67
  };
68
68
  };
69
- window.$db = h, window.$debounce = h, Number.prototype.toFixedNumber = function(e) {
69
+ window.$db = $, window.$debounce = $, Number.prototype.toFixedNumber = function(e) {
70
70
  return Number(this.toFixed(e));
71
71
  }, Array.prototype.filter1 = function(e) {
72
72
  if (!e || typeof e != "function") throw new Error(e + " is not a function");
73
- let t, o;
73
+ let o, t;
74
74
  for (let n = 0; n < this.length; n++) if (e(this[n], n, this)) {
75
- o = n, t = this[n];
75
+ t = n, o = this[n];
76
76
  break;
77
77
  }
78
- return { index: o, data: t };
78
+ return { index: t, data: o };
79
79
  }, window.$getType = (e) => Object.prototype.toString.call(e).slice(8, -1);
80
- const y = (e, t) => {
80
+ const b = (e, o) => {
81
81
  if (!e) return;
82
- const o = window.$l("Copied");
82
+ const t = window.$l("Copied");
83
83
  let n;
84
- if (n = t ? window.$getType(t) !== "Boolean" ? `${o} ${t}: ${e}` : `${o}: ${e}` : o, navigator.clipboard && window.isSecureContext) navigator.clipboard.writeText(e).then(() => {
85
- c.config.globalProperties.$message.success({ message: n, center: !0, duration: 0 });
84
+ if (n = o ? window.$getType(o) !== "Boolean" ? `${t} ${o}: ${e}` : `${t}: ${e}` : t, navigator.clipboard && window.isSecureContext) navigator.clipboard.writeText(e).then(() => {
85
+ c.config.globalProperties.$message.success({ message: n, center: !0, duration: 5e3 });
86
86
  });
87
87
  else {
88
88
  let r = document.createElement("textarea");
89
- r.value = e, r.style.position = "fixed", r.style.opacity = 0, document.body.appendChild(r), r.select(), document.execCommand("Copy"), r.remove(), c.config.globalProperties.$message.success({ message: n, center: !0, duration: 0 });
89
+ r.value = e, r.style.position = "fixed", r.style.opacity = 0, document.body.appendChild(r), r.select(), document.execCommand("Copy"), r.remove(), c.config.globalProperties.$message.success({ message: n, center: !0, duration: 5e3 });
90
90
  }
91
91
  };
92
- window.$copy = y, c.config.globalProperties.$copy = y, window.$sc = (e) => e < 1e3 ? e : e < 1e6 ? parseInt(e / 1e3) + "K" : parseInt(e / 1e6) + "M";
93
- const T = { cpa: "avgCPA", cpt: "avgCPT" };
94
- window.$nr = (e, t = T) => {
95
- const o = t[e.name];
96
- o && (e.name = o);
97
- }, window.$nro = (e, t) => (Object.keys(e).forEach((o) => {
98
- objMap[o] && (e[objMap[o]] = e[o], delete e[o]);
92
+ window.$copy = b, c.config.globalProperties.$copy = b, window.$sc = (e) => e < 1e3 ? e : e < 1e6 ? parseInt(e / 1e3) + "K" : parseInt(e / 1e6) + "M";
93
+ const v = { cpa: "avgCPA", cpt: "avgCPT" };
94
+ window.$nr = (e, o = v) => {
95
+ const t = o[e.name];
96
+ t && (e.name = t);
97
+ }, window.$nro = (e, o) => (Object.keys(e).forEach((t) => {
98
+ objMap[t] && (e[objMap[t]] = e[t], delete e[t]);
99
99
  }), e), window.$pc = (e) => {
100
- let t = 0;
101
- return Object.keys(e).forEach((o) => {
102
- (window.$getType(e[o]) === "Array" && e[o].length !== 0 || e[o]) && t++;
103
- }), t;
100
+ let o = 0;
101
+ return Object.keys(e).forEach((t) => {
102
+ (window.$getType(e[t]) === "Array" && e[t].length !== 0 || e[t]) && o++;
103
+ }), o;
104
104
  };
105
- const d = (e = "info", t) => {
105
+ const s = (e = "info", o) => {
106
106
  e === "success" && (e = "info");
107
107
  };
108
108
  window.$console = { info: (...e) => {
109
- d("info");
109
+ s("info");
110
110
  }, log: (...e) => {
111
- d("log");
111
+ s("log");
112
112
  }, error: (...e) => {
113
- d("error");
113
+ s("error");
114
114
  }, warn: (...e) => {
115
- d("warn");
115
+ s("warn");
116
116
  }, success: (...e) => {
117
- d("success");
118
- } }, window.$loadImage = (e) => new Promise((t, o) => {
117
+ s("success");
118
+ } }, window.$loadImage = (e) => new Promise((o, t) => {
119
119
  const n = new Image();
120
- n.src = window.$getType(e) === "String" ? e : URL.createObjectURL(e), n.onload = () => t(n), n.onerror = () => o(new Error("Could not load image"));
121
- }), window.$loadVideo = (e) => new Promise((t, o) => {
120
+ n.src = window.$getType(e) === "String" ? e : URL.createObjectURL(e), n.onload = () => o(n), n.onerror = () => t(new Error("Could not load image"));
121
+ }), window.$loadVideo = (e) => new Promise((o, t) => {
122
122
  const n = document.createElement("video");
123
123
  n.preload = "metadata", window.$getType(e) === "String" ? n.src = e : n.src = URL.createObjectURL(e), n.onloadedmetadata = () => {
124
- window.URL.revokeObjectURL(e), t(n);
124
+ window.URL.revokeObjectURL(e), o(n);
125
125
  };
126
126
  });
127
- const v = (e) => {
127
+ const h = (e) => {
128
128
  if (e && window.$getType(e) === "Object") {
129
- const t = {};
130
- return Object.keys(e).forEach((o) => {
131
- const n = e[o];
129
+ const o = {};
130
+ return Object.keys(e).forEach((t) => {
131
+ const n = e[t];
132
132
  switch (window.$getType(n)) {
133
133
  case "Object":
134
- Object.keys(n) !== 0 && (t[o] = n);
134
+ Object.keys(n) !== 0 && (o[t] = n);
135
135
  break;
136
136
  case "Array":
137
- n.length !== 0 && (t[o] = n);
137
+ n.length !== 0 && (o[t] = n);
138
138
  break;
139
139
  case "String":
140
- n && (t[o] = n.toLowerCase());
140
+ n && (o[t] = n.toLowerCase());
141
141
  break;
142
142
  default:
143
- [void 0, null, ""].indexOf(n) === -1 && (t[o] = n);
143
+ [void 0, null, ""].indexOf(n) === -1 && (o[t] = n);
144
144
  }
145
- }), t;
145
+ }), o;
146
146
  }
147
147
  };
148
- window.$removeEmptyParams = v, window.$rep = v;
149
- let a = null, f = null;
148
+ window.$removeEmptyParams = h, window.$rep = h;
149
+ let a = null, d = null;
150
150
  window.$download = async (e) => {
151
- let { type: t = "img", url: o, name: n, data: r } = e;
152
- if (a = document.createElement("a"), t === "csv") {
151
+ let { type: o = "img", url: t, name: n, data: r } = e;
152
+ if (a = document.createElement("a"), o === "csv") {
153
153
  const i = new Blob(["\uFEFF" + r], { type: "text/csv,charset=UTF-8" });
154
154
  a.href = URL.createObjectURL(i);
155
- } else if (t === "video" || t === "excel") {
156
- const { access_token: i, scope: p, token_type: s } = store.launch().login.info, l = {};
157
- t === "excel" && (l.method = l.method || "GET", l.headers = { [p]: `${s} ${i}` }), await fetch(o, l).then((w) => w.blob()).then((w) => {
158
- a.href = URL.createObjectURL(w);
159
- });
160
- } else (t = "table") ? await fetch(o).then((i) => i.blob()).then((i) => {
155
+ } else o === "video" || o === "excel" ? await fetch(t, e).then((i) => i.blob()).then((i) => {
161
156
  a.href = URL.createObjectURL(i);
162
- }) : a.href = o;
163
- f = new MouseEvent("click"), a.download = n || "download", a.dispatchEvent(f), t !== "csv" && t !== "video" || URL.revokeObjectURL(a.url), a = null, f = null;
157
+ }) : (o = "table") ? await fetch(t).then((i) => i.blob()).then((i) => {
158
+ a.href = URL.createObjectURL(i);
159
+ }) : a.href = t;
160
+ d = new MouseEvent("click"), a.download = n || "download", a.dispatchEvent(d), o !== "csv" && o !== "video" || URL.revokeObjectURL(a.url), a = null, d = null;
164
161
  };
165
162
  };
166
163
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "magtool",
3
3
  "packageManager": "yarn@4.4.1",
4
- "version": "1.0.9",
4
+ "version": "1.1.2",
5
5
  "author": "magxl",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -35,7 +35,7 @@
35
35
  "dist/*"
36
36
  ],
37
37
  "dependencies": {
38
- "magtool": "^1.0.8",
38
+ "magtool": "^1.0.9",
39
39
  "moment": "^2.30.1",
40
40
  "pinia": "^3.0.0",
41
41
  "vue": "^3.3.4"