uni-image-editor 1.0.0
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 +98 -0
- package/components/edit-graffiti-config.vue +151 -0
- package/components/edit-text-config.vue +112 -0
- package/components/image-clipper/image-clipper.vue +1009 -0
- package/components/image-clipper/img/photo.svg +19 -0
- package/components/image-clipper/img/rotate.svg +15 -0
- package/components/image-clipper/index.scss +184 -0
- package/components/image-clipper/utils.js +280 -0
- package/components/input-text-modal.vue +431 -0
- package/image-editor.vue +971 -0
- package/js/const.js +242 -0
- package/js/editor.js +1179 -0
- package/js/utils.js +316 -0
- package/package.json +29 -0
package/js/const.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: msc 864078729@qq.com
|
|
3
|
+
* @Date: 4024-04-26 09:35:49
|
|
4
|
+
* @LastEditors: msc 862078729@qq.com
|
|
5
|
+
* @LastEditTime: 2024-06-17 09:44:26
|
|
6
|
+
* @FilePath: \code\components\image-editor\js\const.js
|
|
7
|
+
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// 定义图片编辑器支持的编辑类型
|
|
11
|
+
export const IMG_EDITOR_EDIT_TYPE = {
|
|
12
|
+
graffiti: "graffiti", // 涂鸦
|
|
13
|
+
text: "text", // 文字
|
|
14
|
+
cut: "cut", // 裁剪
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// 定义图片编辑器可用的工具类型
|
|
18
|
+
export const IMG_EDITOR_TOOL_TYPE = {
|
|
19
|
+
graffiti: "graffiti", // 涂鸦
|
|
20
|
+
text: "text", // 文字
|
|
21
|
+
cut: "cut", // 裁剪
|
|
22
|
+
redo: "redo", // 重做
|
|
23
|
+
repeal: "repeal", // 撤销
|
|
24
|
+
clear: "clear", // 清空
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// 定义图片编辑器工具类型的中文描述
|
|
28
|
+
export const IMG_EDITOR_TOOL_TYPE_TEXT = {
|
|
29
|
+
[IMG_EDITOR_TOOL_TYPE.graffiti]: "涂鸦",
|
|
30
|
+
[IMG_EDITOR_TOOL_TYPE.text]: "文字",
|
|
31
|
+
[IMG_EDITOR_TOOL_TYPE.cut]: "裁剪",
|
|
32
|
+
[IMG_EDITOR_TOOL_TYPE.redo]: "重做",
|
|
33
|
+
[IMG_EDITOR_TOOL_TYPE.repeal]: "撤销",
|
|
34
|
+
[IMG_EDITOR_TOOL_TYPE.clear]: "清空",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// 能取消的操作,如文本、涂鸦,开始时不删除撤销的步骤吗,确认后再删除对应的步骤
|
|
38
|
+
export const CAN_CANCEL_EDIT_TYPE = [
|
|
39
|
+
IMG_EDITOR_EDIT_TYPE.cut,
|
|
40
|
+
IMG_EDITOR_EDIT_TYPE.text,
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
// 定义涂鸦功能中可用的形状类型
|
|
44
|
+
export const IMG_EDITOR_GRAFFITI_SHAPE_TYPE = {
|
|
45
|
+
curve: "curve", // 曲线
|
|
46
|
+
line: "line", // 直线
|
|
47
|
+
rect: "rect", // 矩形
|
|
48
|
+
circle: "circle", // 圆形
|
|
49
|
+
hollowRect: "hollowRect", // 空心矩形
|
|
50
|
+
hollowCircle: "hollowCircle", // 空心圆形
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// 定义图片编辑器在处理或渲染图片时使用的数据类型
|
|
54
|
+
export const IMG_EDITOR_RENDER_TYPE = {
|
|
55
|
+
img: "img", // 图片
|
|
56
|
+
data: "data", // 数据(可能指图片数据的某种表示形式,如Base64编码的字符串)
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const DEFAULT_TOOLS_CONFIGS = [
|
|
60
|
+
// 涂鸦工具配置对象
|
|
61
|
+
{
|
|
62
|
+
// 工具名称,对应 IMG_EDITOR_TOOL_TYPE 中的 graffiti
|
|
63
|
+
name: IMG_EDITOR_TOOL_TYPE.graffiti,
|
|
64
|
+
// 图标类名
|
|
65
|
+
icon: "icon-tuya",
|
|
66
|
+
// 默认颜色
|
|
67
|
+
color: "#000000",
|
|
68
|
+
// 图标大小
|
|
69
|
+
iconSize: 40,
|
|
70
|
+
// 工具提示文本,根据工具类型从 IMG_EDITOR_TOOL_TYPE_TEXT 中获取
|
|
71
|
+
text: IMG_EDITOR_TOOL_TYPE_TEXT[IMG_EDITOR_TOOL_TYPE.graffiti],
|
|
72
|
+
// 激活时的颜色
|
|
73
|
+
activeColor: "#2979ff",
|
|
74
|
+
// 文本大小(尽管这个属性在涂鸦工具配置中可能并不直接用到,但保持与其他工具配置的一致性)
|
|
75
|
+
textSize: 24,
|
|
76
|
+
// 涂鸦配置对象
|
|
77
|
+
graffitiConfigs: {
|
|
78
|
+
// 可选颜色列表
|
|
79
|
+
colors: ["#ff0000", "#1c9d02", "#000000", "#006ce6", "#efaa03", "#ccc"],
|
|
80
|
+
// 可用形状列表
|
|
81
|
+
shapes: [
|
|
82
|
+
// 曲线
|
|
83
|
+
{ icon: "icon-tuxiang-biaojiquxian-01", name: "curve" },
|
|
84
|
+
// 直线
|
|
85
|
+
{ icon: "icon-zhixian1", name: "line" },
|
|
86
|
+
// 空心圆
|
|
87
|
+
{ icon: "icon-xingzhuang-tuoyuanxing", name: "hollowCircle" },
|
|
88
|
+
// 实心圆
|
|
89
|
+
{ icon: "icon-circle", name: "circle" },
|
|
90
|
+
// 空心矩形
|
|
91
|
+
{ icon: "icon-16gl-square", name: "hollowRect" },
|
|
92
|
+
// 实心矩形
|
|
93
|
+
{ icon: "icon-16gf-square", name: "rect" },
|
|
94
|
+
],
|
|
95
|
+
// 线条粗细可选值列表
|
|
96
|
+
roughs: [2, 4, 6, 8, 10, 12],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
// 文本工具配置对象
|
|
100
|
+
{
|
|
101
|
+
// 工具名称,对应 IMG_EDITOR_TOOL_TYPE 中的 text
|
|
102
|
+
name: IMG_EDITOR_TOOL_TYPE.text,
|
|
103
|
+
// 图标类名
|
|
104
|
+
icon: "icon-wenzi",
|
|
105
|
+
// 默认颜色
|
|
106
|
+
color: "#000000",
|
|
107
|
+
// 图标大小
|
|
108
|
+
iconSize: 40,
|
|
109
|
+
// 文本大小
|
|
110
|
+
textSize: 24,
|
|
111
|
+
// 工具提示文本,根据工具类型从 IMG_EDITOR_TOOL_TYPE_TEXT 中获取
|
|
112
|
+
text: IMG_EDITOR_TOOL_TYPE_TEXT[IMG_EDITOR_TOOL_TYPE.text],
|
|
113
|
+
// 激活时的颜色
|
|
114
|
+
activeColor: "#2979ff",
|
|
115
|
+
// 文本配置对象
|
|
116
|
+
textConfigs: {
|
|
117
|
+
// 可选颜色列表
|
|
118
|
+
colors: ["#ff0000", "#1c9d02", "#000000", "#006ce6", "#efaa03", "#ccc"],
|
|
119
|
+
// 文本大小可选值列表
|
|
120
|
+
sizes: [12, 14, 16, 18, 20, 22],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
// 裁剪工具配置
|
|
124
|
+
{
|
|
125
|
+
// 工具名称,对应 IMG_EDITOR_TOOL_TYPE 中的 cut
|
|
126
|
+
name: IMG_EDITOR_TOOL_TYPE.cut,
|
|
127
|
+
// 图标类名
|
|
128
|
+
icon: "icon-caijian",
|
|
129
|
+
// 默认颜色
|
|
130
|
+
color: "#000000",
|
|
131
|
+
// 文本大小(尽管这个属性可能并不直接用于图标工具,但保持与其他工具配置的一致性)
|
|
132
|
+
textSize: 24,
|
|
133
|
+
// 图标大小
|
|
134
|
+
iconSize: 40,
|
|
135
|
+
// 工具提示文本,根据工具类型从 IMG_EDITOR_TOOL_TYPE_TEXT 中获取
|
|
136
|
+
text: IMG_EDITOR_TOOL_TYPE_TEXT[IMG_EDITOR_TOOL_TYPE.cut],
|
|
137
|
+
// 激活时的颜色
|
|
138
|
+
activeColor: "#2979ff",
|
|
139
|
+
},
|
|
140
|
+
// 撤销操作工具配置
|
|
141
|
+
{
|
|
142
|
+
// 工具名称,对应 IMG_EDITOR_TOOL_TYPE 中的 repeal
|
|
143
|
+
name: IMG_EDITOR_TOOL_TYPE.repeal,
|
|
144
|
+
// 图标类名(注意:通常撤销操作图标可能不是 "icon-chexiao1",这里仅为示例)
|
|
145
|
+
icon: "icon-chexiao1", // 建议使用更合适的撤销图标类名,如 "icon-undo"
|
|
146
|
+
// 默认颜色
|
|
147
|
+
color: "#000000",
|
|
148
|
+
// 图标大小
|
|
149
|
+
iconSize: 40,
|
|
150
|
+
// 文本大小(同样可能不直接用于图标工具)
|
|
151
|
+
textSize: 24,
|
|
152
|
+
// 工具提示文本,根据工具类型从 IMG_EDITOR_TOOL_TYPE_TEXT 中获取
|
|
153
|
+
text: IMG_EDITOR_TOOL_TYPE_TEXT[IMG_EDITOR_TOOL_TYPE.repeal],
|
|
154
|
+
// 激活时的颜色
|
|
155
|
+
activeColor: "#2979ff",
|
|
156
|
+
},
|
|
157
|
+
// 重做操作工具配置
|
|
158
|
+
{
|
|
159
|
+
// 工具名称,对应 IMG_EDITOR_TOOL_TYPE 中的 redo
|
|
160
|
+
name: IMG_EDITOR_TOOL_TYPE.redo,
|
|
161
|
+
// 图标类名(注意:通常重做操作图标不是 "icon-chexiao1",这里仅为示例)
|
|
162
|
+
icon: "icon-chexiao1", // 建议使用更合适的重做图标类名,如 "icon-redo"
|
|
163
|
+
// 默认颜色
|
|
164
|
+
color: "#000000",
|
|
165
|
+
// 图标大小
|
|
166
|
+
iconSize: 40,
|
|
167
|
+
// 文本大小(同样可能不直接用于图标工具)
|
|
168
|
+
textSize: 24,
|
|
169
|
+
// 工具提示文本,根据工具类型从 IMG_EDITOR_TOOL_TYPE_TEXT 中获取
|
|
170
|
+
text: IMG_EDITOR_TOOL_TYPE_TEXT[IMG_EDITOR_TOOL_TYPE.redo],
|
|
171
|
+
// 激活时的颜色
|
|
172
|
+
activeColor: "#2979ff",
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
// 清除工具配置
|
|
176
|
+
{
|
|
177
|
+
// 工具名称,对应 IMG_EDITOR_TOOL_TYPE 中的 clear
|
|
178
|
+
name: IMG_EDITOR_TOOL_TYPE.clear,
|
|
179
|
+
// 图标类名
|
|
180
|
+
icon: "icon-qingkong",
|
|
181
|
+
// 默认颜色
|
|
182
|
+
color: "#000000",
|
|
183
|
+
// 图标大小
|
|
184
|
+
iconSize: 40,
|
|
185
|
+
// 文本大小(同样可能不直接用于图标工具)
|
|
186
|
+
textSize: 24,
|
|
187
|
+
// 工具提示文本,根据工具类型从 IMG_EDITOR_TOOL_TYPE_TEXT 中获取
|
|
188
|
+
text: IMG_EDITOR_TOOL_TYPE_TEXT[IMG_EDITOR_TOOL_TYPE.clear],
|
|
189
|
+
// 激活时的颜色
|
|
190
|
+
activeColor: "#2979ff",
|
|
191
|
+
},
|
|
192
|
+
];
|
|
193
|
+
|
|
194
|
+
// 文本输入框模态框的输入框默认宽度
|
|
195
|
+
export const INPUT_TEXT_MODAL_INPUT_DEFAULT_WIDTH = 150;
|
|
196
|
+
|
|
197
|
+
// 文本输入框模态框的输入框默认高度
|
|
198
|
+
export const INPUT_TEXT_MODAL_INPUT_DEFAULT_HEIGHT = 60;
|
|
199
|
+
|
|
200
|
+
// 文本输入框模态框的拉伸类型,定义了四个方向
|
|
201
|
+
export const INPUT_TEXT_MODAL_STRETCH_TYPE = {
|
|
202
|
+
topLeft: "top-left", // 左上角
|
|
203
|
+
topRight: "top-right", // 右上角
|
|
204
|
+
bottomRight: "bottom-right", // 右下角
|
|
205
|
+
bottomLeft: "bottom-left", // 左下角
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// 文本输入框模态框的拉伸图标配置数组,与拉伸类型一一对应
|
|
209
|
+
export const INPUT_TEXT_MODAL_STRETCH_ICONS_CONFIGS = [
|
|
210
|
+
{
|
|
211
|
+
// 左上角的拉伸图标类名
|
|
212
|
+
icon: "iconfont icon-lashen stretch-icon stretch-icon-top-left",
|
|
213
|
+
// 对应的拉伸类型
|
|
214
|
+
name: INPUT_TEXT_MODAL_STRETCH_TYPE.topLeft,
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
// 右上角的拉伸图标类名
|
|
218
|
+
icon: "iconfont icon-lashen stretch-icon stretch-icon-top-right",
|
|
219
|
+
// 对应的拉伸类型
|
|
220
|
+
name: INPUT_TEXT_MODAL_STRETCH_TYPE.topRight,
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
// 右下角的拉伸图标类名
|
|
224
|
+
icon: "iconfont icon-lashen stretch-icon stretch-icon-bottom-right",
|
|
225
|
+
// 对应的拉伸类型
|
|
226
|
+
name: INPUT_TEXT_MODAL_STRETCH_TYPE.bottomRight,
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
// 左下角的拉伸图标类名
|
|
230
|
+
icon: "iconfont icon-lashen stretch-icon stretch-icon-bottom-left",
|
|
231
|
+
// 对应的拉伸类型
|
|
232
|
+
name: INPUT_TEXT_MODAL_STRETCH_TYPE.bottomLeft,
|
|
233
|
+
},
|
|
234
|
+
];
|
|
235
|
+
|
|
236
|
+
// 转化网络图片到本地的方式
|
|
237
|
+
export const CONVERT_IMG_NET_TO_LOCAL_TYPE = {
|
|
238
|
+
// 通过canvas转化
|
|
239
|
+
canvas: 'canvas',
|
|
240
|
+
// 通过uni.download下载转化
|
|
241
|
+
download:'download'
|
|
242
|
+
}
|