@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 +32 -0
- package/es/util.d.ts +2 -0
- package/es/util.js +54 -54
- package/package.json +2 -1
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
package/es/util.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import
|
|
2
|
-
async function
|
|
1
|
+
import h from "compressorjs";
|
|
2
|
+
async function y(a, e) {
|
|
3
3
|
const {
|
|
4
|
-
imageMaxSize:
|
|
5
|
-
imageAllowedMineType:
|
|
6
|
-
imageMinWidth:
|
|
7
|
-
imageMinHeight:
|
|
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 || {},
|
|
11
|
-
if (
|
|
12
|
-
return { success: !1, error: { size: !0 } };
|
|
13
|
-
if (!
|
|
14
|
-
return { success: !1, error: { format: !0 } };
|
|
15
|
-
const
|
|
16
|
-
return
|
|
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
|
|
18
|
+
async function b(a) {
|
|
19
19
|
var c;
|
|
20
|
-
let e =
|
|
21
|
-
const
|
|
22
|
-
let
|
|
23
|
-
const
|
|
24
|
-
["image/heif", "image/heic", "image/webp"].includes(e.type) && (
|
|
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 && (
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
e =
|
|
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:
|
|
31
|
+
return { file: e, success: !1, hasConversion: i, errorMessage: (c = n.error) == null ? void 0 : c.message };
|
|
32
32
|
}
|
|
33
|
-
return { file: e, hasConversion:
|
|
33
|
+
return { file: e, hasConversion: i, success: !0 };
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
return new Promise((
|
|
37
|
-
new
|
|
35
|
+
function p(a, e) {
|
|
36
|
+
return new Promise((s) => {
|
|
37
|
+
new h(a, {
|
|
38
38
|
...e,
|
|
39
|
-
success: async (
|
|
40
|
-
|
|
39
|
+
success: async (r) => {
|
|
40
|
+
s({ success: !0, file: r });
|
|
41
41
|
},
|
|
42
|
-
error(
|
|
43
|
-
|
|
42
|
+
error(r) {
|
|
43
|
+
s({ success: !1, error: r });
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function m(a) {
|
|
49
49
|
return new Promise((e) => {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
e({ width:
|
|
53
|
-
},
|
|
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
|
|
57
|
-
const e =
|
|
58
|
-
let
|
|
59
|
-
const
|
|
60
|
-
for (;
|
|
61
|
-
|
|
62
|
-
return new Blob([
|
|
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(
|
|
65
|
-
return new Promise((e,
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
e(
|
|
70
|
-
},
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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.
|
|
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"
|