magtool 1.2.1 → 1.2.3

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.
@@ -0,0 +1,194 @@
1
+ const y = (e) => {
2
+ const { age: t } = e || {};
3
+ let s, o;
4
+ if (t != null && t.included) {
5
+ const { minAge: n, maxAge: r } = t.included[0] || {};
6
+ n ? s = n : s = "all", r ? o = r : o = "all";
7
+ }
8
+ return o === "all" ? s === "all" ? "All" : `${s}~65+` : `${s}~${o}`;
9
+ }, P = (e, t) => e === "all" ? null : t === 65 ? {
10
+ included: [
11
+ {
12
+ minAge: e
13
+ }
14
+ ]
15
+ } : {
16
+ included: [
17
+ {
18
+ minAge: e,
19
+ maxAge: t
20
+ }
21
+ ]
22
+ }, C = (e) => {
23
+ const { gender: t } = e || {};
24
+ return t != null && t.included ? t.included[0] : null;
25
+ }, R = { useAgeFormat: y, useAgeValue: P, useGenderFormat: C }, A = (e) => new Promise((t, s) => {
26
+ const o = new Image();
27
+ o.src = window.$getType(e) === "String" ? e : URL.createObjectURL(e), o.onload = () => t(o), o.onerror = () => s(new Error("Could not load image"));
28
+ }), I = (e) => new Promise((t, s) => {
29
+ const o = document.createElement("video");
30
+ o.preload = "metadata", window.$getType(e) === "String" ? o.src = e : o.src = URL.createObjectURL(e), o.onloadedmetadata = () => {
31
+ window.URL.revokeObjectURL(e), console.info([o]), t(o);
32
+ };
33
+ }), M = ({ type: e = "csv", data: t, name: s }) => {
34
+ let o = document.createElement("a");
35
+ if (e === "csv") {
36
+ const r = new Blob(["\uFEFF" + t], {
37
+ type: "text/csv,charset=UTF-8"
38
+ });
39
+ o.href = URL.createObjectURL(r);
40
+ }
41
+ let n = new MouseEvent("click");
42
+ o.download = s || "download", o.dispatchEvent(n), (e === "csv" || e === "video") && URL.revokeObjectURL(o.url), o = null, n = null;
43
+ }, T = { loadImage: A, loadVideo: I, download: M }, j = ({ table: e, key: t, form: s, value: o, cb: n = () => {
44
+ } }) => {
45
+ const r = e.getSelectionRows();
46
+ r.length > 1 ? (e.clearSelection(), e.toggleRowSelection(r[1], "selected"), s[o] = r[1][t]) : r.length === 1 && (s[o] = r[0][t]), n();
47
+ }, E = (e = {}) => {
48
+ let { sortable: t = !0, empty: s = !1, mmp: o = !1 } = e, n = window.$map.asa.asaMetric.all;
49
+ o && (n = n.concat(window.$map.asa.mmpMetric.all));
50
+ const r = n.map((l, w) => ({
51
+ label: l.label,
52
+ prop: l.value,
53
+ width: l.width,
54
+ sortable: t,
55
+ type: l.type,
56
+ align: l.align,
57
+ visible: l.visible,
58
+ formatter: l.formatter
59
+ }));
60
+ return r.unshift({
61
+ label: "Currency",
62
+ prop: "currency",
63
+ width: 80,
64
+ align: "right"
65
+ }), r;
66
+ }, S = () => ({
67
+ label: "-"
68
+ }), U = ({ columns: e, data: t, currency: s = "", channel: o = "" }) => {
69
+ if (!t.length || !e.length)
70
+ return [];
71
+ const n = {
72
+ spend: {
73
+ prop: "spend",
74
+ prefix: s,
75
+ format: (a) => window.$fa(a, 2)
76
+ },
77
+ taps: {
78
+ prop: "taps",
79
+ format: (a) => window.$fa(a, 0)
80
+ },
81
+ installs: {
82
+ prop: "installs",
83
+ format: (a) => window.$fa(a, 0)
84
+ },
85
+ impressions: {
86
+ prop: "impressions",
87
+ format: (a) => window.$fa(a, 0)
88
+ },
89
+ mmpInstalls: {
90
+ prop: "mmpInstalls",
91
+ format: (a) => window.$fa(a, 0)
92
+ },
93
+ mmpCPI: {
94
+ prop: "mmpCPI",
95
+ format: (a) => window.$fa(a, 2)
96
+ },
97
+ IPM: {
98
+ prop: "IPM",
99
+ format: (a) => window.$fa(a, 2)
100
+ },
101
+ revenue: {
102
+ prop: "revenue",
103
+ format: (a) => window.$fa(a, 2)
104
+ }
105
+ }, r = [], l = {
106
+ avgCPT: {},
107
+ avgCPA: {},
108
+ avgCPM: {},
109
+ cr: {},
110
+ ttr: {},
111
+ IPM: {},
112
+ mmpInstalls: {},
113
+ mmpCPI: {}
114
+ };
115
+ e.forEach((a, i) => {
116
+ l[a.property] && (l[a.property].i = i);
117
+ const u = n[a.property];
118
+ if (u) {
119
+ u.i = i;
120
+ let m = window.$bigNumber(0);
121
+ t.forEach(($) => {
122
+ m = m.plus($[a.property] || 0);
123
+ }), m = m.toNumber(), u.total = m, r.push(m);
124
+ } else
125
+ r.push("");
126
+ }), Object.keys(n).forEach((a) => {
127
+ const i = n[a];
128
+ i.format && r[i.i] && (r[i.i] = i.format(r[i.i]));
129
+ });
130
+ const f = n.taps.total ? window.$fa(n.spend.total / n.taps.total) : "0.00";
131
+ r[l.avgCPT.i] = f;
132
+ const g = n.installs.total ? window.$fa(n.spend.total / n.installs.total) : "0.00";
133
+ if (r[l.avgCPA.i] = g, l.avgCPM.i !== void 0) {
134
+ const a = n.impressions.total ? window.$fa(n.spend.total / (n.impressions.total / 1e3)) : "0.00";
135
+ r[l.avgCPM.i] = a;
136
+ }
137
+ const h = n.taps.total ? window.$fa(n.installs.total / n.taps.total * 100) : "0.00";
138
+ r[l.cr.i] = h;
139
+ const v = n.impressions.total ? window.$fa(n.taps.total / n.impressions.total * 100) : "0.00";
140
+ r[l.ttr.i] = v;
141
+ const b = n.impressions.total ? window.$fa(n.installs.total * 1e3 / n.impressions.total) : "0.00";
142
+ return r[l.IPM.i] = b, r;
143
+ }, L = (e) => {
144
+ const t = window.$map.asa.allMetric.obj;
145
+ return Object.keys(e).forEach((s) => {
146
+ const o = e[s];
147
+ t[s] && (e[`${s}Format`] = window.$fu({ prop: s, value: o, currency: !1, obj: t }));
148
+ }), e;
149
+ }, O = ({ columns: e, data: t }, s) => e.length && t.length ? e.map((n) => {
150
+ let r = s[n.property] === void 0 ? "" : s[n.property];
151
+ if (r !== "")
152
+ try {
153
+ r = window.$fa(r, window.$map.asa.allMetric.obj[n.property].precision);
154
+ } catch {
155
+ }
156
+ return r;
157
+ }) : [], F = { useSingleSelect: j, useColumn: E, useEmptyColumn: S, useRemoteSummary: O, useSummary: U, useFormat: L }, x = (e, t = 88) => {
158
+ const s = document.querySelector("html"), { scrollTop: o } = s, n = e.getBoundingClientRect();
159
+ s.scrollTo({
160
+ top: o + n.y - t,
161
+ behavior: "smooth"
162
+ });
163
+ }, k = { pageScrollTo: x }, c = [];
164
+ let d = 0;
165
+ const p = function(e) {
166
+ c.forEach((t) => {
167
+ if (t.time === void 0 || t.lastTime === 0 || e - t.lastTime >= t.time) {
168
+ t.cb(e), t.lastTime = e;
169
+ return;
170
+ }
171
+ }), c.length && window.requestAnimationFrame(p);
172
+ }, q = function(e, t = 1e3) {
173
+ return d++, c.push({
174
+ cb: e,
175
+ time: t,
176
+ lastTime: 0,
177
+ id: d
178
+ }), c.length === 1 && window.requestAnimationFrame(p), d;
179
+ }, B = function(e) {
180
+ for (let t = 0; t < c.length; t++)
181
+ if (c[t].id === e) {
182
+ c.splice(t, 1);
183
+ break;
184
+ }
185
+ }, N = { useRaf: q, clearRaf: B }, V = {
186
+ ...R,
187
+ ...T,
188
+ ...F,
189
+ ...k,
190
+ ...N
191
+ };
192
+ export {
193
+ V as default
194
+ };
package/dist/index.js CHANGED
@@ -1,23 +1,22 @@
1
- import o from "moment";
2
- import { c as m } from "./cps.js";
3
- import { d as a } from "./util.js";
4
- import { d as n } from "./directive.js";
5
- import { p } from "./store.js";
1
+ import t from "moment";
2
+ import { d as m } from "./util.js";
3
+ import { d as a } from "./directive.js";
4
+ import n from "./store.js";
6
5
  /* empty css */
7
- const u = (_, r) => {
8
- _.use(a).use(n);
9
- let e;
10
- if (r.storeChips)
6
+ const w = (o, e) => {
7
+ o.use(m).use(a);
8
+ let s;
9
+ if (e.storeChips)
11
10
  try {
12
- const { store: t, pinia: i } = p(r.storeChips);
13
- e = t, _.provide("store", t).use(i);
11
+ const { store: _, pinia: i } = n(e.storeChips);
12
+ s = _, o.provide("store", _).use(i);
14
13
  } catch {
15
14
  throw new Error(
16
15
  "piniaStore error, storeChips must be an Object source from import.meta.globa"
17
16
  );
18
17
  }
19
- const s = localStorage.getItem("lang");
20
- return s && s.includes("cn") && o.locale("zh-cn", {
18
+ const r = localStorage.getItem("lang");
19
+ r && r.includes("cn") && t.locale("zh-cn", {
21
20
  months: "一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split(
22
21
  "_"
23
22
  ),
@@ -27,11 +26,8 @@ const u = (_, r) => {
27
26
  weekdays: "星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),
28
27
  weekdaysShort: "周日_周一_周二_周三_周四_周五_周六".split("_"),
29
28
  weekdaysMin: "日_一_二_三_四_五_六".split("_")
30
- }), window.$m = o, window.$moment = o, {
31
- composition: m,
32
- store: e
33
- };
29
+ }), window.$m = t, window.$moment = t;
34
30
  };
35
31
  export {
36
- u as default
32
+ w as default
37
33
  };
package/dist/store.js CHANGED
@@ -1,11 +1,11 @@
1
- import { createPinia as a, defineStore as c } from "pinia";
2
- const r = a(), s = (e) => {
1
+ import { createPinia as o, defineStore as c } from "pinia";
2
+ const r = o(), s = (e) => {
3
3
  const t = {};
4
- return Object.keys(e).forEach((n) => {
5
- const o = n.match(/chip\/(\S*).js/)[1];
6
- t[o] = c(o, e[n].default);
4
+ return Object.keys(e).forEach((a) => {
5
+ const n = a.match(/chip\/(\S*).js/)[1];
6
+ t[n] = c(n, e[a].default);
7
7
  }), { pinia: r, store: t };
8
8
  };
9
9
  export {
10
- s as p
10
+ s as default
11
11
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "magtool",
3
3
  "packageManager": "yarn@4.4.1",
4
- "version": "1.2.1",
4
+ "version": "1.2.3",
5
5
  "author": "magxl",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -12,16 +12,8 @@
12
12
  "require": "./dist/index.js"
13
13
  },
14
14
  "./cps": {
15
- "import": "./dist/cps.js",
16
- "require": "./dist/cps.js"
17
- },
18
- "./directive": {
19
- "import": "./dist/directive.js",
20
- "require": "./dist/directive.js"
21
- },
22
- "./util": {
23
- "import": "./dist/util.js",
24
- "require": "./dist/util.js"
15
+ "import": "./dist/composition.js",
16
+ "require": "./dist/composition.js"
25
17
  },
26
18
  "./store": {
27
19
  "import": "./dist/store.js",
package/dist/cps.js DELETED
@@ -1,171 +0,0 @@
1
- const $ = (t) => {
2
- const { age: o } = t || {};
3
- let s, n;
4
- if (o != null && o.included) {
5
- const { minAge: e, maxAge: r } = o.included[0] || {};
6
- e ? s = e : s = "all", r ? n = r : n = "all";
7
- }
8
- return n === "all" ? s === "all" ? "All" : `${s}~65+` : `${s}~${n}`;
9
- }, b = (t, o) => t === "all" ? null : o === 65 ? {
10
- included: [
11
- {
12
- minAge: t
13
- }
14
- ]
15
- } : {
16
- included: [
17
- {
18
- minAge: t,
19
- maxAge: o
20
- }
21
- ]
22
- }, h = (t) => {
23
- const { gender: o } = t || {};
24
- return o != null && o.included ? o.included[0] : null;
25
- }, y = { useAgeFormat: $, useAgeValue: b, useGenderFormat: h }, P = (t) => new Promise((o, s) => {
26
- const n = new Image();
27
- n.src = window.$getType(t) === "String" ? t : URL.createObjectURL(t), n.onload = () => o(n), n.onerror = () => s(new Error("Could not load image"));
28
- }), C = (t) => new Promise((o, s) => {
29
- const n = document.createElement("video");
30
- n.preload = "metadata", window.$getType(t) === "String" ? n.src = t : n.src = URL.createObjectURL(t), n.onloadedmetadata = () => {
31
- window.URL.revokeObjectURL(t), console.info([n]), o(n);
32
- };
33
- }), M = ({ type: t = "csv", data: o, name: s }) => {
34
- let n = document.createElement("a");
35
- if (t === "csv") {
36
- const r = new Blob(["\uFEFF" + o], {
37
- type: "text/csv,charset=UTF-8"
38
- });
39
- n.href = URL.createObjectURL(r);
40
- }
41
- let e = new MouseEvent("click");
42
- n.download = s || "download", n.dispatchEvent(e), (t === "csv" || t === "video") && URL.revokeObjectURL(n.url), n = null, e = null;
43
- }, R = { loadImage: P, loadVideo: C, download: M }, A = ({ table: t, key: o, form: s, value: n, cb: e = () => {
44
- } }) => {
45
- const r = t.getSelectionRows();
46
- r.length > 1 ? (t.clearSelection(), t.toggleRowSelection(r[1], "selected"), s[n] = r[1][o]) : r.length === 1 && (s[n] = r[0][o]), e();
47
- }, I = (t = {}) => {
48
- let { sortable: o = !0, empty: s = !1, mmp: n = !1 } = t, e = window.$map.asa.asaMetric.all;
49
- n && (e = e.concat(window.$map.asa.mmpMetric.all));
50
- const r = e.map((l, u) => ({
51
- label: l.label,
52
- prop: l.value,
53
- width: l.width,
54
- sortable: o,
55
- type: l.type,
56
- align: l.align,
57
- visible: l.visible,
58
- formatter: l.formatter
59
- }));
60
- return r.unshift({
61
- label: "Currency",
62
- prop: "currency",
63
- width: 80,
64
- align: "right"
65
- }), r;
66
- }, j = () => ({
67
- label: "-"
68
- }), S = ({ columns: t, data: o, currency: s = "", channel: n = "" }) => {
69
- if (!o.length || !t.length)
70
- return [];
71
- const e = {
72
- spend: {
73
- prop: "spend",
74
- prefix: s,
75
- format: (a) => window.$fa(a, 2)
76
- },
77
- taps: {
78
- prop: "taps",
79
- format: (a) => window.$fa(a, 0)
80
- },
81
- installs: {
82
- prop: "installs",
83
- format: (a) => window.$fa(a, 0)
84
- },
85
- impressions: {
86
- prop: "impressions",
87
- format: (a) => window.$fa(a, 0)
88
- },
89
- mmpInstalls: {
90
- prop: "mmpInstalls",
91
- format: (a) => window.$fa(a, 0)
92
- },
93
- mmpCPI: {
94
- prop: "mmpCPI",
95
- format: (a) => window.$fa(a, 2)
96
- },
97
- IPM: {
98
- prop: "IPM",
99
- format: (a) => window.$fa(a, 2)
100
- },
101
- revenue: {
102
- prop: "revenue",
103
- format: (a) => window.$fa(a, 2)
104
- }
105
- }, r = [], l = {
106
- avgCPT: {},
107
- avgCPA: {},
108
- avgCPM: {},
109
- cr: {},
110
- ttr: {},
111
- IPM: {},
112
- mmpInstalls: {},
113
- mmpCPI: {}
114
- };
115
- t.forEach((a, i) => {
116
- l[a.property] && (l[a.property].i = i);
117
- const m = e[a.property];
118
- if (m) {
119
- m.i = i;
120
- let c = window.$bigNumber(0);
121
- o.forEach((v) => {
122
- c = c.plus(v[a.property] || 0);
123
- }), c = c.toNumber(), m.total = c, r.push(c);
124
- } else
125
- r.push("");
126
- }), Object.keys(e).forEach((a) => {
127
- const i = e[a];
128
- i.format && r[i.i] && (r[i.i] = i.format(r[i.i]));
129
- });
130
- const p = e.taps.total ? window.$fa(e.spend.total / e.taps.total) : "0.00";
131
- r[l.avgCPT.i] = p;
132
- const d = e.installs.total ? window.$fa(e.spend.total / e.installs.total) : "0.00";
133
- if (r[l.avgCPA.i] = d, l.avgCPM.i !== void 0) {
134
- const a = e.impressions.total ? window.$fa(e.spend.total / (e.impressions.total / 1e3)) : "0.00";
135
- r[l.avgCPM.i] = a;
136
- }
137
- const f = e.taps.total ? window.$fa(e.installs.total / e.taps.total * 100) : "0.00";
138
- r[l.cr.i] = f;
139
- const w = e.impressions.total ? window.$fa(e.taps.total / e.impressions.total * 100) : "0.00";
140
- r[l.ttr.i] = w;
141
- const g = e.impressions.total ? window.$fa(e.installs.total * 1e3 / e.impressions.total) : "0.00";
142
- return r[l.IPM.i] = g, r;
143
- }, U = (t) => {
144
- const o = window.$map.asa.allMetric.obj;
145
- return Object.keys(t).forEach((s) => {
146
- const n = t[s];
147
- o[s] && (t[`${s}Format`] = window.$fu({ prop: s, value: n, currency: !1, obj: o }));
148
- }), t;
149
- }, E = ({ columns: t, data: o }, s) => t.length && o.length ? t.map((e) => {
150
- let r = s[e.property] === void 0 ? "" : s[e.property];
151
- if (r !== "")
152
- try {
153
- r = window.$fa(r, window.$map.asa.allMetric.obj[e.property].precision);
154
- } catch {
155
- }
156
- return r;
157
- }) : [], L = { useSingleSelect: A, useColumn: I, useEmptyColumn: j, useRemoteSummary: E, useSummary: S, useFormat: U }, T = (t, o = 88) => {
158
- const s = document.querySelector("html"), { scrollTop: n } = s, e = t.getBoundingClientRect();
159
- s.scrollTo({
160
- top: n + e.y - o,
161
- behavior: "smooth"
162
- });
163
- }, O = { pageScrollTo: T }, x = {
164
- ...y,
165
- ...R,
166
- ...L,
167
- ...O
168
- };
169
- export {
170
- x as c
171
- };