@syhr/sy-graph 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 ADDED
@@ -0,0 +1,173 @@
1
+ # @syhr/sy-graph
2
+
3
+ 一个基于 Meta2D 的平面图形配置工具 Vue 3 组件库。
4
+
5
+ ## 特性
6
+
7
+ - 🎨 基于 Meta2D 的强大图形编辑能力
8
+ - 🔧 支持多种图形类型和图表
9
+ - 📱 响应式设计,支持移动端
10
+ - 🎯 TypeScript 支持
11
+ - 📦 多种模块格式支持(ES、UMD、CommonJS)
12
+ - 🔌 Vue 3 插件化架构
13
+ - 🛡️ 安全的全局属性处理,避免 $t 等变量冲突
14
+
15
+ ## 安装
16
+
17
+ ```bash
18
+ npm install @syhr/sy-graph
19
+ ```
20
+
21
+ ### Peer Dependencies
22
+
23
+ 确保你的项目已安装以下 peer dependencies:
24
+
25
+ ```bash
26
+ npm install vue@^3.0.0 element-plus@^2.0.0 @meta2d/core@^1.0.0 @meta2d/svg@^1.0.0 @meta2d/utils@^1.0.0
27
+ ```
28
+
29
+ ## 使用
30
+
31
+ ### 全局注册(推荐)
32
+
33
+ ```javascript
34
+ import { createApp } from 'vue';
35
+ import SyGraph from '@syhr/sy-graph';
36
+ import '@syhr/sy-graph/style';
37
+
38
+ const app = createApp(App);
39
+ app.use(SyGraph);
40
+ app.mount('#app');
41
+ ```
42
+
43
+ ### 局部使用
44
+
45
+ ```javascript
46
+ import { SyGraph } from '@syhr/sy-graph';
47
+ import '@syhr/sy-graph/style';
48
+
49
+ export default {
50
+ components: {
51
+ SyGraph,
52
+ },
53
+ };
54
+ ```
55
+
56
+ ### 在模板中使用
57
+
58
+ ```vue
59
+ <template>
60
+ <div>
61
+ <SyGraph :url="graphUrl" :local="false" :show-map="true" @loaded="handleLoaded" @graph-event="handleGraphEvent" />
62
+ </div>
63
+ </template>
64
+
65
+ <script setup>
66
+ import { ref } from 'vue';
67
+
68
+ const graphUrl = ref('path/to/your/graph.json');
69
+
70
+ const handleLoaded = (stage) => {
71
+ console.log('Graph loaded:', stage);
72
+ };
73
+
74
+ const handleGraphEvent = (event) => {
75
+ console.log('Graph event:', event);
76
+ };
77
+ </script>
78
+ ```
79
+
80
+ ## Props
81
+
82
+ | 属性 | 类型 | 默认值 | 说明 |
83
+ | --------- | ------- | ------ | ------------------ |
84
+ | url | String | '' | 图纸数据 URL |
85
+ | local | Boolean | false | 是否为本地数据 |
86
+ | planeData | Object | null | 直接传入的图纸数据 |
87
+ | planeId | String | '' | 图纸 ID |
88
+ | showMap | Boolean | false | 是否显示地图 |
89
+ | isFactory | Boolean | false | 是否为工厂模式 |
90
+
91
+ ## Events
92
+
93
+ | 事件名 | 说明 | 参数 |
94
+ | ----------- | -------------- | ------------------ |
95
+ | loaded | 图纸加载完成 | stage: Meta2D 实例 |
96
+ | graph-event | 图纸自定义事件 | event: 事件对象 |
97
+
98
+ ## 方法
99
+
100
+ 通过 ref 获取组件实例后可调用以下方法:
101
+
102
+ - `changeVisibleByLevel(level, isStrict)` - 切换显示层级
103
+ - `batchUpdatePen(dataList)` - 批量更新图元
104
+ - `setValue(pen, render)` - 设置图元属性
105
+ - `getAllPens()` - 获取所有图元
106
+ - `getStage()` - 获取 Meta2D 实例
107
+
108
+ ## TypeScript 支持
109
+
110
+ 本包提供完整的 TypeScript 类型声明:
111
+
112
+ ```typescript
113
+ import type { SyGraphProps, SyGraphInstance } from '@syhr/sy-graph';
114
+
115
+ // 组件 ref 类型
116
+ const graphRef = ref<SyGraphInstance>();
117
+
118
+ // Props 类型
119
+ const props: SyGraphProps = {
120
+ url: 'path/to/graph.json',
121
+ showMap: true,
122
+ };
123
+ ```
124
+
125
+ ## 浏览器支持
126
+
127
+ - Chrome >= 60
128
+ - Firefox >= 60
129
+ - Safari >= 12
130
+ - Edge >= 79
131
+
132
+ ## 开发
133
+
134
+ ```bash
135
+ # 安装依赖
136
+ npm install
137
+
138
+ # 开发模式
139
+ npm run dev
140
+
141
+ # 构建库
142
+ npm run build:lib
143
+
144
+ # 构建类型
145
+ npm run build:types
146
+
147
+ # 完整构建
148
+ npm run build:all
149
+
150
+ # 类型检查
151
+ npm run type-check
152
+
153
+ # 代码检查
154
+ npm run lint
155
+ ```
156
+
157
+ ## 许可证
158
+
159
+ [MIT](LICENSE)
160
+
161
+ ## 更新日志
162
+
163
+ 查看 [CHANGELOG.md](CHANGELOG.md) 了解详细的更新记录。
164
+
165
+ ## 贡献
166
+
167
+ 欢迎提交 Issue 和 Pull Request。
168
+
169
+ ## 相关链接
170
+
171
+ - [Meta2D 官方文档](https://meta2d.com)
172
+ - [Vue 3 文档](https://vuejs.org)
173
+ - [Element Plus 文档](https://element-plus.org)
package/lib/style.css ADDED
@@ -0,0 +1 @@
1
+ .meta2d-editor[data-v-664781e2]{position:relative;width:100%;height:100%}.meta2d-editor[data-v-664781e2] .stage.value-map{position:absolute;top:1.04vw;right:.52vw;z-index:200}.meta2d-editor .toolbox[data-v-664781e2]{position:absolute;display:none;width:5.21vw;height:1.56vw;background:red;z-index:10000}.preview-container[data-v-c09e5d6b]{position:relative;width:100%;height:100%}.preview-container .back-btn[data-v-c09e5d6b]{position:absolute;bottom:.52vw;right:.52vw;z-index:1000}