med-viewer-sdk 0.1.0 → 0.1.1

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
@@ -46,9 +46,9 @@ MedViewer SDK 是一个强大且灵活的医学图像查看 SDK,它基于 Open
46
46
 
47
47
  ```bash
48
48
  # 假设使用 npm 或 yarn 进行包管理
49
- npm install openseadragon konva # 根据需要添加其他依赖
49
+ npm install openseadragon # 根据需要添加其他依赖
50
50
  # 或
51
- yarn add openseadragon konva
51
+ yarn add openseadragon
52
52
  ```
53
53
 
54
54
  然后,在您的项目中引入 SDK:
@@ -165,6 +165,180 @@ const engine = new MedViewerEngine({
165
165
  });
166
166
  ```
167
167
 
168
+ ### 在 Vue 项目中使用
169
+
170
+ `med-viewer-sdk` 可以在 Vue 2 或 Vue 3 项目中使用。由于 `vue` 是 `med-viewer-sdk` 的一个 `peerDependency`,您需要确保您的项目中已经安装了 `vue`。
171
+
172
+ #### 1. 安装依赖
173
+
174
+ 在您的 Vue 项目中安装 `med-viewer-sdk` 及其 `peerDependencies`。
175
+
176
+ ```bash
177
+ npm install med-viewer-sdk openseadragon vue # 根据您的 Vue 版本安装相应的 Vue 包
178
+ # 或者使用 yarn
179
+ yarn add med-viewer-sdk openseadragon vue
180
+ ```
181
+
182
+ #### 2. 创建 Vue 组件
183
+
184
+ 创建一个 Vue 组件来封装 `MedViewerEngine` 的实例化和生命周期管理。
185
+
186
+ **Vue 3 (Composition API):**
187
+
188
+ ```vue
189
+ <template>
190
+ <div ref="viewerContainer" class="med-viewer-container"></div>
191
+ </template>
192
+
193
+ <script setup lang="ts">
194
+ import { ref, onMounted, onBeforeUnmount } from 'vue';
195
+ import { MedViewerEngine } from 'med-viewer-sdk';
196
+ import OpenSeadragon from 'openseadragon'; // 如果需要 OpenSeadragon 类型
197
+
198
+ const viewerContainer = ref<HTMLElement | null>(null);
199
+ let medViewer: MedViewerEngine | null = null;
200
+
201
+ onMounted(() => {
202
+ if (viewerContainer.value) {
203
+ medViewer = new MedViewerEngine({
204
+ element: viewerContainer.value,
205
+ viewerOptions: {
206
+ id: 'openseadragon-viewer',
207
+ prefixUrl: 'https://openseadragon.github.io/openseadragon/images/',
208
+ tileSources: {
209
+ type: 'image',
210
+ url: 'https://openseadragon.github.io/example-images/duomo/duomo.dzi'
211
+ },
212
+ },
213
+ plugins: {
214
+ toolbar: true,
215
+ selection: true,
216
+ scalebar: {
217
+ type: 'MICROSCOPY',
218
+ location: 'BOTTOM_LEFT',
219
+ color: 'rgb(255, 255, 255)',
220
+ fontColor: 'rgb(255, 255, 255)',
221
+ backgroundColor: 'rgba(0, 0, 0, 0.5)',
222
+ },
223
+ anno: true,
224
+ konva: true,
225
+ colorAdjust: {
226
+ initial: {
227
+ brightness: 1.2,
228
+ contrast: 0.8,
229
+ invert: true,
230
+ }
231
+ }
232
+ }
233
+ });
234
+
235
+ // 可以访问插件并进行操作
236
+ if (medViewer.selection) {
237
+ medViewer.selection.enable();
238
+ medViewer.selection.setSelectionMode('RECTANGLE');
239
+ }
240
+ }
241
+ });
242
+
243
+ onBeforeUnmount(() => {
244
+ if (medViewer) {
245
+ medViewer.destroy();
246
+ medViewer = null;
247
+ }
248
+ });
249
+ </script>
250
+
251
+ <style scoped>
252
+ .med-viewer-container {
253
+ width: 100%;
254
+ height: 80vh; /* 根据需要调整高度 */
255
+ background-color: #000;
256
+ }
257
+ </style>
258
+ ```
259
+
260
+ **Vue 2 (Options API):**
261
+
262
+ ```vue
263
+ <template>
264
+ <div ref="viewerContainer" class="med-viewer-container"></div>
265
+ </template>
266
+
267
+ <script lang="ts">
268
+ import Vue from 'vue';
269
+ import { MedViewerEngine } from 'med-viewer-sdk';
270
+ import OpenSeadragon from 'openseadragon'; // 如果需要 OpenSeadragon 类型
271
+
272
+ export default Vue.extend({
273
+ data() {
274
+ return {
275
+ medViewer: null as MedViewerEngine | null,
276
+ };
277
+ },
278
+ mounted() {
279
+ if (this.$refs.viewerContainer) {
280
+ this.medViewer = new MedViewerEngine({
281
+ element: this.$refs.viewerContainer as HTMLElement,
282
+ viewerOptions: {
283
+ id: 'openseadragon-viewer',
284
+ prefixUrl: 'https://openseadragon.github.io/openseadragon/images/',
285
+ tileSources: {
286
+ type: 'image',
287
+ url: 'https://openseadragon.github.io/example-images/duomo/duomo.dzi'
288
+ },
289
+ },
290
+ plugins: {
291
+ toolbar: true,
292
+ selection: true,
293
+ scalebar: {
294
+ type: 'MICROSCOPY',
295
+ location: 'BOTTOM_LEFT',
296
+ color: 'rgb(255, 255, 255)',
297
+ fontColor: 'rgb(255, 255, 255)',
298
+ backgroundColor: 'rgba(0, 0, 0, 0.5)',
299
+ },
300
+ anno: true,
301
+ konva: true,
302
+ colorAdjust: {
303
+ initial: {
304
+ brightness: 1.2,
305
+ contrast: 0.8,
306
+ invert: true,
307
+ }
308
+ }
309
+ }
310
+ });
311
+
312
+ if (this.medViewer.selection) {
313
+ this.medViewer.selection.enable();
314
+ this.medViewer.selection.setSelectionMode('RECTANGLE');
315
+ }
316
+ }
317
+ },
318
+ beforeDestroy() { // Vue 2 使用 beforeDestroy
319
+ if (this.medViewer) {
320
+ this.medViewer.destroy();
321
+ this.medViewer = null;
322
+ }
323
+ },
324
+ });
325
+ </script>
326
+
327
+ <style scoped>
328
+ .med-viewer-container {
329
+ width: 100%;
330
+ height: 80vh; /* 根据需要调整高度 */
331
+ background-color: #000;
332
+ }
333
+ </style>
334
+ ```
335
+
336
+ #### 3. 注意事项
337
+
338
+ - **CSS 导入**:如果 `med-viewer-sdk` 包含任何 CSS 样式,您可能需要在您的 Vue 项目的入口文件或相关组件中导入它。例如:`import 'med-viewer-sdk/dist/style.css';`
339
+ - **全局样式**:确保 `med-viewer-sdk` 的容器元素有足够的宽高,以便查看器能够正确渲染。
340
+ - **响应式数据**:`MedViewerEngine` 实例本身不是响应式的。如果您需要其内部状态在 Vue 中响应式,您可能需要手动将其属性或方法包装在 Vue 的响应式系统中。
341
+
168
342
 
169
343
  ## 引用方式
170
344