@keyblade/tinymce-editor-vue2 0.0.12-alpha.10 → 0.0.12-alpha.12

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 CHANGED
@@ -107,6 +107,38 @@ import { oneTravelImageCheck, oneTravelImageCompressor } from '@keyblade/tinymce
107
107
  // oneTravelImageCompressor: 一码游图片压缩工具
108
108
  ```
109
109
 
110
+ ```typescript
111
+ export async function oneTravelImageCheck(data: File | Blob, options?: {
112
+ imageMaxSize?: number;
113
+ imageAllowedMineType?: string[]
114
+ imageMinWidth?: number;
115
+ imageMinHeight?: number;
116
+ imageMaxWidth?: number;
117
+ imageMaxHeight?: number;
118
+ }): Promise<{
119
+ /** 是否成功 */
120
+ success: boolean;
121
+ /** 处理完成的文件(有可能不需要处理) */
122
+ file?: File | Blob;
123
+ /** 失败 */
124
+ error?: {
125
+ size?: boolean;
126
+ format?: boolean;
127
+ pixel?: boolean;
128
+ message?: string
129
+ }
130
+ }> {}
131
+
132
+ export async function oneTravelImageCompressor(data: File | Blob): Promise<{
133
+ // 文件
134
+ file: File | Blob,
135
+ // 是否经过处理(没有处理的话,会返回原 file 对象)
136
+ hasConversion: boolean;
137
+ success: boolean;
138
+ errorMessage?: string
139
+ }>{}
140
+ ```
141
+
110
142
  ## 三、Api
111
143
  ### 1.全局属性
112
144
  ```typescript
package/es/util.d.ts CHANGED
@@ -20,6 +20,8 @@ export declare function oneTravelImageCheck(data: File | Blob, options?: {
20
20
  pixel?: boolean;
21
21
  message?: string;
22
22
  };
23
+ /** 错误消息 */
24
+ errorMessage?: string;
23
25
  }>;
24
26
  /**
25
27
  * 一码游图片压缩
package/es/util.js CHANGED
@@ -1,77 +1,77 @@
1
- import f from "compressorjs";
2
- async function d(n, e) {
1
+ import h from "compressorjs";
2
+ async function y(a, e) {
3
3
  const {
4
- imageMaxSize: i = 30,
5
- imageAllowedMineType: s = ["image/jpg", "image/jpeg", "image/png", "image/bmp", "image/heif", "image/heic", "image/gif", "image/webp"],
6
- imageMinWidth: t = 60,
7
- imageMinHeight: r = 60,
4
+ imageMaxSize: s = 30,
5
+ imageAllowedMineType: r = ["image/jpg", "image/jpeg", "image/png", "image/bmp", "image/heif", "image/heic", "image/gif", "image/webp"],
6
+ imageMinWidth: i = 60,
7
+ imageMinHeight: t = 60,
8
8
  imageMaxWidth: o = 6e3,
9
9
  imageMaxHeight: c = 6e3
10
- } = e || {}, a = n, l = await u(a);
11
- if (a.size > i * 1024 * 1024)
12
- return { success: !1, error: { size: !0 } };
13
- if (!s.includes(a.type))
14
- return { success: !1, error: { format: !0 } };
15
- const m = await g(l);
16
- return m.width < t && m.height < r || m.width > o && m.height > c ? { success: !1, error: { pixel: !0 } } : { success: !0, file: a };
10
+ } = e || {}, n = a, l = await u(n);
11
+ if (n.size > s * 1024 * 1024)
12
+ return { success: !1, error: { size: !0 }, errorMessage: `请上传大小不超过${s}M的图片` };
13
+ if (!r.includes(n.type))
14
+ return { success: !1, error: { format: !0 }, errorMessage: `请上传格式为${r.map((f) => f.toUpperCase()).join("、")}的图片` };
15
+ const g = await m(l);
16
+ return g.width < i && g.height < t || g.width > o && g.height > c ? { success: !1, error: { pixel: !0 }, errorMessage: `请上传像素不低于${i}*${t}且像素不高于${o}*${c}的图片` } : { success: !0, file: n };
17
17
  }
18
- async function y(n) {
18
+ async function b(a) {
19
19
  var c;
20
- let e = n;
21
- const i = await u(e), s = await g(i);
22
- let t = !1;
23
- const r = {};
24
- ["image/heif", "image/heic", "image/webp"].includes(e.type) && (r.convertTypes = [e.type], r.convertSize = 0, t = !0);
20
+ let e = a;
21
+ const s = await u(e), r = await m(s);
22
+ let i = !1;
23
+ const t = {};
24
+ ["image/heif", "image/heic", "image/webp"].includes(e.type) && (t.convertTypes = [e.type], t.convertSize = 0, i = !0);
25
25
  const o = 5 * 1024 * 1024;
26
- if (e.size > o && (r.convertTypes = [e.type], r.convertSize = o, r.maxWidth = s.width * (o / e.size), t = !0), Object.keys(r).length > 0) {
27
- const a = await h(p(i), r);
28
- if (a.success)
29
- e = a.file;
26
+ if (e.size > o && (t.convertTypes = [e.type], t.convertSize = o, t.maxWidth = r.width * (o / e.size), i = !0), Object.keys(t).length > 0) {
27
+ const n = await p(w(s), t);
28
+ if (n.success)
29
+ e = n.file;
30
30
  else
31
- return { file: e, success: !1, hasConversion: t, errorMessage: (c = a.error) == null ? void 0 : c.message };
31
+ return { file: e, success: !1, hasConversion: i, errorMessage: (c = n.error) == null ? void 0 : c.message };
32
32
  }
33
- return { file: e, hasConversion: t, success: !0 };
33
+ return { file: e, hasConversion: i, success: !0 };
34
34
  }
35
- function h(n, e) {
36
- return new Promise((i) => {
37
- new f(n, {
35
+ function p(a, e) {
36
+ return new Promise((s) => {
37
+ new h(a, {
38
38
  ...e,
39
- success: async (s) => {
40
- i({ success: !0, file: s });
39
+ success: async (r) => {
40
+ s({ success: !0, file: r });
41
41
  },
42
- error(s) {
43
- i({ success: !1, error: s });
42
+ error(r) {
43
+ s({ success: !1, error: r });
44
44
  }
45
45
  });
46
46
  });
47
47
  }
48
- function g(n) {
48
+ function m(a) {
49
49
  return new Promise((e) => {
50
- const i = new Image();
51
- i.onload = function() {
52
- e({ width: i.width, height: i.height, image: i });
53
- }, i.src = n;
50
+ const s = new Image();
51
+ s.onload = function() {
52
+ e({ width: s.width, height: s.height, image: s });
53
+ }, s.src = a;
54
54
  });
55
55
  }
56
- function p(n) {
57
- const e = n.split(","), i = e[0].match(/:(.*?);/)[1], s = atob(e[1]);
58
- let t = s.length;
59
- const r = new Uint8Array(t);
60
- for (; t--; )
61
- r[t] = s.charCodeAt(t);
62
- return new Blob([r], { type: i });
56
+ function w(a) {
57
+ const e = a.split(","), s = e[0].match(/:(.*?);/)[1], r = atob(e[1]);
58
+ let i = r.length;
59
+ const t = new Uint8Array(i);
60
+ for (; i--; )
61
+ t[i] = r.charCodeAt(i);
62
+ return new Blob([t], { type: s });
63
63
  }
64
- function u(n) {
65
- return new Promise((e, i) => {
66
- const s = new FileReader();
67
- s.onloadend = () => {
68
- const t = s.result;
69
- e(t);
70
- }, s.onerror = i, s.readAsDataURL(n);
64
+ function u(a) {
65
+ return new Promise((e, s) => {
66
+ const r = new FileReader();
67
+ r.onloadend = () => {
68
+ const i = r.result;
69
+ e(i);
70
+ }, r.onerror = s, r.readAsDataURL(a);
71
71
  });
72
72
  }
73
73
  export {
74
- g as getImagePixel,
75
- d as oneTravelImageCheck,
76
- y as oneTravelImageCompressor
74
+ m as getImagePixel,
75
+ y as oneTravelImageCheck,
76
+ b as oneTravelImageCompressor
77
77
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@keyblade/tinymce-editor-vue2",
3
3
  "description": "KeyBlade Tinymce Editor Vue2",
4
4
  "author": "yangshuai <704807396@qq.com>",
5
- "version": "0.0.12-alpha.10",
5
+ "version": "0.0.12-alpha.12",
6
6
  "private": false,
7
7
  "type": "module",
8
8
  "main": "es/index.js",
@@ -21,6 +21,7 @@
21
21
  ],
22
22
  "dependencies": {
23
23
  "compressorjs": "^1.2.1",
24
+ "image-conversion": "^2.1.1",
24
25
  "vue-global-config": "^0.2.6",
25
26
  "tinymce": "^7.1.0",
26
27
  "element-ui": "^2.15.14"