yui-image-editor 1.0.4 → 1.0.6

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
@@ -1,73 +1,188 @@
1
- # tui-image-editor-demo
2
-
3
- This template should help get you started developing with Vue 3 in Vite.
4
-
5
- ## Recommended IDE Setup
6
-
7
- [VS Code](https://code.visualstudio.com/) + [Vue (Official)](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
8
-
9
- ## Recommended Browser Setup
10
-
11
- - Chromium-based browsers (Chrome, Edge, Brave, etc.):
12
- - [Vue.js devtools](https://chromewebstore.google.com/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd)
13
- - [Turn on Custom Object Formatter in Chrome DevTools](http://bit.ly/object-formatters)
14
- - Firefox:
15
- - [Vue.js devtools](https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/)
16
- - [Turn on Custom Object Formatter in Firefox DevTools](https://fxdx.dev/firefox-devtools-custom-object-formatters/)
17
-
18
- ## Type Support for `.vue` Imports in TS
19
-
20
- TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
21
-
22
- ## Customize configuration
23
-
24
- See [Vite Configuration Reference](https://vite.dev/config/).
25
-
26
- ## Project Setup
27
-
28
- ```sh
29
- npm install
30
- ```
31
-
32
- ### Compile and Hot-Reload for Development
33
-
34
- ```sh
35
- npm run dev
36
- ```
37
-
38
- ### Type-Check, Compile and Minify for Production
39
-
40
- ```sh
41
- npm run build
42
- ```
43
-
44
- ### Run Unit Tests with [Vitest](https://vitest.dev/)
45
-
46
- ```sh
47
- npm run test:unit
48
- ```
49
-
50
- ### Run End-to-End Tests with [Playwright](https://playwright.dev)
51
-
52
- ```sh
53
- # Install browsers for the first run
54
- npx playwright install
55
-
56
- # When testing on CI, must build the project first
57
- npm run build
58
-
59
- # Runs the end-to-end tests
60
- npm run test:e2e
61
- # Runs the tests only on Chromium
62
- npm run test:e2e -- --project=chromium
63
- # Runs the tests of a specific file
64
- npm run test:e2e -- tests/example.spec.ts
65
- # Runs the tests in debug mode
66
- npm run test:e2e -- --debug
67
- ```
68
-
69
- ### Lint with [ESLint](https://eslint.org/)
70
-
71
- ```sh
72
- npm run lint
73
- ```
1
+ cat > README.md << EOF
2
+ # yui-image-editor 图片编辑器组件
3
+ yui-image-editor 是基于 \`tui-image-editor\` 封装的 Vue3 + TypeScript 图片编辑器组件,扩展了专题图编辑专属功能(标题、时间戳、附图标签、对比拉框、标定目标等),支持自定义配置、多语言、主题定制及 A4 尺寸快速切换等能力。
4
+
5
+ ## 一、组件使用指南
6
+ ### 1. 安装依赖
7
+ 确保项目中安装核心依赖:
8
+ \`\`\`bash
9
+ npm install tui-image-editor
10
+ # 若需类型提示,安装对应的类型包(如无官方类型,可自定义)
11
+ npm install -D @types/tui-image-editor
12
+ \`\`\`
13
+
14
+ ### 2. 基础使用
15
+ #### 2.1 2.1 全局引入并注册
16
+ \`\`\`ts
17
+ // 局部引入(推荐)
18
+ import { ImageEditor } from 'yui-image-editor';
19
+ import 'yui-image-editor/dist/yui-image-editor.css';
20
+ const app = createApp(App);
21
+ app.component('ImageEditor', ImageEditor);
22
+ app.mount('#app')
23
+ \`\`\`
24
+
25
+ #### 2.2 局部引入组件
26
+ \`\`\`ts
27
+ import ImageEditor from '@/components/yui-image-editor/index.vue';
28
+ \`\`\`
29
+
30
+ #### 2.3 快速集成
31
+ \`\`\`vue
32
+ <template>
33
+ <div class="container">
34
+ <ImageEditor ref="yuiImageEditor" :editorConfig="editorConfig"></ImageEditor>
35
+ <div @click="updateImage">更换图片</div>
36
+ </div>
37
+ </template>
38
+
39
+ <script setup lang="ts">
40
+ import { onMounted, ref } from 'vue';
41
+ import type { EditorConfig, TuiImageEditor } from "yui-image-editor";
42
+ import mapOverlay from './assets/map-overlay.png';
43
+ import map02Png from './assets/map02.png';
44
+ const yuiImageEditor = ref() //组件实例和方法
45
+ let yuiInstance: TuiImageEditor | null = null // 编辑器内部函数和方法
46
+ const editorConfig: EditorConfig = {
47
+ includeUI: {
48
+ loadImage: {
49
+ path: mapOverlay, // 优先用传入的url
50
+ name: 'mapoverlay'
51
+ },
52
+ initMenu: 'text',
53
+ menuBarPosition: 'left',
54
+ uiSize: {
55
+ width: '100%',
56
+ height: '100%'
57
+ }
58
+ },
59
+ selectionStyle: {
60
+ cornerSize: 20,
61
+ rotatingPointOffset: 70
62
+ },
63
+ usageStatistics: false,
64
+ cssMaxHeight: document.documentElement.clientWidth,
65
+ cssMaxWidth: document.documentElement.clientHeight
66
+ };
67
+ onMounted(async()=>{
68
+ yuiInstance = yuiImageEditor.value.getCoreEditor();
69
+ console.log(yuiImageEditor.value, '===组件实例和方法===')
70
+ console.log(yuiInstance,'===编辑器实例和方法===')
71
+ })
72
+
73
+ const updateImage = async()=>{
74
+ // 修改图片
75
+ const loadImageRes = await yuiImageEditor.value.loadImageFromURL(map02Png,'map02Png')
76
+ console.log(loadImageRes,'===loadImageRes')
77
+ }
78
+ </script>
79
+
80
+ <style scoped>
81
+ .container{
82
+ width: 100%;
83
+ height: 80vh;
84
+ position: relative;
85
+ }
86
+ </style>
87
+ \`\`\`
88
+
89
+ ### 3. Props 说明
90
+ | 名称 | 类型 | 默认值 | 说明 |
91
+ |--------------|--------------|--------------|--------------------------|
92
+ | editorConfig | \`EditorConfig\` | 见核心配置部分 | 编辑器自定义配置,深度合并覆盖默认配置 |
93
+
94
+ ### 4. 事件说明
95
+ | 事件名 | 回调参数类型 | 说明 |
96
+ |-----------------|------------------------------------------------------------------------------|--------------------------|
97
+ | statusChange | \`{ message: string; type: 'success' | 'error' | 'info' }\` | 编辑器操作状态变更(成功/失败/提示) |
98
+ | canvasSizeChange | \`{ width: number; height: number }\` | 画布尺寸变更时触发 |
99
+ | init | \`TuiImageEditor\`(编辑器核心实例) | 编辑器初始化完成时触发 |
100
+
101
+ ### 5. 暴露的方法(通过 ref 调用)
102
+ | 方法名 | 参数 | 返回值 | 说明 |
103
+ |---------------------|---------------------------------------|-------------------------------------|--------------------------|
104
+ | loadImageFromURL | \`imageUrl: string, imageName?: string\` | \`Promise<{ success: boolean; message: string }>\` | 加载指定URL的图片 |
105
+ | getCoreEditor | - | \`TuiImageEditor \| null\` | 获取编辑器核心实例 |
106
+ | addTitle | \`title?: string\`(默认:专题图标题) | \`Promise<void>\` | 添加标题 |
107
+ | addTimestamp | - | \`Promise<void>\` | 添加时间戳 |
108
+ | addFigureLabel | \`title?: string\`(默认:附图) | \`Promise<void>\` | 添加附图标签 |
109
+ | addComparisonBox | - | \`Promise<void>\` | 添加对比拉框 |
110
+ | addCalibrationTarget | - | \`Promise<void>\` | 添加标定目标 |
111
+ | destroy | - | \`void\` | 销毁编辑器(组件卸载时自动调用) |
112
+
113
+ ## 二、组件核心内容
114
+ ### 1. 核心架构
115
+ 组件采用 Vue3 + TypeScript 组合式 API 开发,核心分为 5 个模块:
116
+ \`\`\`
117
+ ├── 配置层:默认配置 + 外部传入配置深度合并
118
+ ├── 实例层:tui-image-editor 核心实例 + 专题图工具实例
119
+ ├── 扩展层:自定义菜单(文本/形状/A4尺寸)+ DOM 操作
120
+ ├── 交互层:鼠标监听 + 状态反馈 + 事件派发
121
+ ├── 生命周期:挂载初始化 + 卸载销毁
122
+ \`\`\`
123
+
124
+ ### 2. 默认配置(可通过 props 覆盖)
125
+ \`\`\`ts
126
+ const defaultConfig: EditorConfig = {
127
+ includeUI: {
128
+ loadImage: {
129
+ path: mapOverlay, // 初始默认图片
130
+ name: 'DefaultImage'
131
+ },
132
+ initMenu: 'icon', // 初始激活菜单
133
+ menuBarPosition: 'left', // 菜单栏位置
134
+ locale: zhLocale, // 中文语言包
135
+ theme: customTheme, // 自定义主题
136
+ uiSize: { width: '100%', height: '100%' } // 编辑器尺寸
137
+ },
138
+ selectionStyle: { // 选中元素样式
139
+ cornerSize: 20,
140
+ rotatingPointOffset: 70
141
+ },
142
+ usageStatistics: true, // 统计开关
143
+ cssMaxHeight: document.documentElement.clientWidth, // 最大高度
144
+ cssMaxWidth: document.documentElement.clientHeight // 最大宽度
145
+ };
146
+ \`\`\`
147
+
148
+ ### 3. 关键扩展功能
149
+ #### 3.1 自定义菜单扩展
150
+ - **文本菜单**:新增「标题」「时间」「附图」按钮,绑定对应添加方法;
151
+ - **形状菜单**:新增「对比拉框」「标定目标」按钮,实现专题图专属形状;
152
+ - **尺寸菜单**:新增「A4-横版」开关,一键切换画布为 A4 横版尺寸(1754*1240)。
153
+
154
+ #### 3.2 专题图工具(SpecialMapTool)
155
+ 封装 \`SpecialMapTool\` 类,基于 tui-image-editor 核心 API 实现专题图专属元素的添加/管理,核心方法:
156
+ - \`addTitle\`:添加带样式的专题图标题;
157
+ - \`addTimestamp\`:添加格式化时间戳;
158
+ - \`addFigureLabel\`:添加附图标签;
159
+ - \`addComparisonBox\`:添加可拖拽/缩放的对比拉框;
160
+ - \`addCalibrationTarget\`:添加标定目标图形。
161
+
162
+ #### 3.3 图片加载封装
163
+ 将原生回调式的 \`loadImageFromURL\` 封装为 Promise 风格,增加前置校验(编辑器实例、URL 非空)和错误分类(跨域/无效URL),便于异步调用和错误处理。
164
+
165
+ #### 3.4 生命周期管理
166
+ - **挂载(onMounted)**:初始化编辑器实例 → 初始化专题图工具 → 扩展菜单 → 绑定鼠标监听 → 派发初始化事件;
167
+ - **卸载(onUnmounted)**:销毁编辑器实例 → 移除事件监听 → 清空工具实例,避免内存泄漏。
168
+
169
+ ### 4. 类型定义(TypeScript)
170
+ 核心类型约束,保证类型安全:
171
+ - \`EditorConfig\`:编辑器配置类型;
172
+ - \`TuiImageEditor\`:编辑器核心实例类型;
173
+ - \`EditorOperationStatus\`:操作状态类型;
174
+ - \`ImageEditorEmits\`:组件派发事件类型;
175
+ - 暴露方法的参数/返回值类型全覆盖。
176
+
177
+ ### 5. 样式与适配
178
+ - 编辑器容器自适应父元素尺寸(宽高 100%);
179
+ - 监听窗口 resize 事件,自动调整编辑器尺寸;
180
+ - 选中元素样式自定义(角标大小、旋转点偏移);
181
+ - 自定义主题(customTheme)覆盖默认样式,适配业务视觉风格。
182
+
183
+ ## 三、注意事项
184
+ 1. 图片加载需注意跨域问题:若加载远程图片,需确保图片服务器配置 CORS;
185
+ 2. 组件卸载时会自动调用 \`destroy\` 方法,手动销毁需通过 ref 调用;
186
+ 3. 自定义配置采用深度合并(deepMerge),可精准覆盖默认配置的任意层级;
187
+ 4. 专题图工具(SpecialMapTool)需依赖 tui-image-editor 实例,初始化失败时会触发 error 状态提示。
188
+ EOF
@@ -1,60 +1,15 @@
1
1
  import { default as YuiImageEditor } from './components/ImageEditor/index';
2
2
  import { YuiImageEditorProps } from './types/component';
3
3
  import { App } from 'vue';
4
- import type * as TuiEditorTypes from '@/types/index';
4
+ export type * from './types/index';
5
5
  declare const ImageEditorComponent: {
6
6
  new (): {
7
7
  $props: YuiImageEditorProps;
8
8
  } & typeof YuiImageEditor;
9
9
  };
10
- export { ImageEditorComponent as ImageEditor, YuiImageEditor };
11
- export type { TuiEditorTypes, YuiImageEditorProps };
10
+ export { ImageEditorComponent as ImageEditor };
12
11
  declare const _default: {
13
12
  install: (app: App) => void;
14
- YuiImageEditor: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
15
- editorConfig: {
16
- type: import('vue').PropType<TuiEditorTypes.EditorConfig>;
17
- default: () => {};
18
- };
19
- }>, {
20
- showStatus: (message: string, type?: "success" | "error" | "info") => void;
21
- updateCanvasSize: () => void;
22
- addTitle: (title?: string) => Promise<void>;
23
- addTimestamp: () => Promise<void>;
24
- addFigureLabel: (title?: string) => Promise<void>;
25
- addComparisonBox: () => Promise<void>;
26
- addCalibrationTarget: () => Promise<void>;
27
- getCoreEditor: () => TuiEditorTypes.TuiImageEditor | null;
28
- loadImageFromURL: (imageUrl: string, imageName?: string) => Promise<{
29
- success: boolean;
30
- message: string;
31
- }>;
32
- destroy: () => void;
33
- }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
34
- init: (editor: TuiEditorTypes.TuiImageEditor) => any;
35
- statusChange: (status: import('./components/ImageEditor/editor.types').EditorOperationStatus | null) => any;
36
- canvasSizeChange: (size: {
37
- width: number;
38
- height: number;
39
- }) => any;
40
- }, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
41
- editorConfig: {
42
- type: import('vue').PropType<TuiEditorTypes.EditorConfig>;
43
- default: () => {};
44
- };
45
- }>> & Readonly<{
46
- onInit?: ((editor: TuiEditorTypes.TuiImageEditor) => any) | undefined;
47
- onStatusChange?: ((status: import('./components/ImageEditor/editor.types').EditorOperationStatus | null) => any) | undefined;
48
- onCanvasSizeChange?: ((size: {
49
- width: number;
50
- height: number;
51
- }) => any) | undefined;
52
- }>, {
53
- editorConfig: TuiEditorTypes.EditorConfig;
54
- }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {
55
- editorContainer: HTMLDivElement;
56
- editorRef: HTMLDivElement;
57
- }, HTMLDivElement>;
58
13
  ImageEditor: new () => {
59
14
  $props: YuiImageEditorProps;
60
15
  } & typeof YuiImageEditor;