med-viewer-sdk 0.1.11 → 0.1.13

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.
@@ -1,174 +1,169 @@
1
- import OpenSeadragon from "openseadragon";
2
- import { t } from "../i18n/i18n";
3
- import "../plugins/openseadragon-selection.js";
4
- import selectionRest from "@/assets/icons/selection_rest.png";
5
- import selectionGroup from "@/assets/icons/selection_grouphover.png";
6
- import selectionHover from "@/assets/icons/selection_hover.png";
7
- import selectionDown from "@/assets/icons/selection_pressed.png";
8
- import selectionConfirmRest from "@/assets/icons/selection_confirm_rest.png";
9
- import selectionConfirmGroup from "@/assets/icons/selection_confirm_grouphover.png";
10
- import selectionConfirmHover from "@/assets/icons/selection_confirm_hover.png";
11
- import selectionConfirmDown from "@/assets/icons/selection_confirm_pressed.png";
12
- import selectionCancelRest from "@/assets/icons/selection_cancel_rest.png";
13
- import selectionCancelGroup from "@/assets/icons/selection_cancel_grouphover.png";
14
- import selectionCancelHover from "@/assets/icons/selection_cancel_hover.png";
15
- import selectionCancelDown from "@/assets/icons/selection_cancel_pressed.png";
1
+ import OpenSeadragon from 'openseadragon'
2
+ import { t } from '../i18n/i18n'
3
+ import '../plugins/openseadragon-selection.js'
4
+ import selectionRest from '@/assets/icons/selection_rest.png'
5
+ import selectionGroup from '@/assets/icons/selection_grouphover.png'
6
+ import selectionHover from '@/assets/icons/selection_hover.png'
7
+ import selectionDown from '@/assets/icons/selection_pressed.png'
8
+ import selectionConfirmRest from '@/assets/icons/selection_confirm_rest.png'
9
+ import selectionConfirmGroup from '@/assets/icons/selection_confirm_grouphover.png'
10
+ import selectionConfirmHover from '@/assets/icons/selection_confirm_hover.png'
11
+ import selectionConfirmDown from '@/assets/icons/selection_confirm_pressed.png'
12
+ import selectionCancelRest from '@/assets/icons/selection_cancel_rest.png'
13
+ import selectionCancelGroup from '@/assets/icons/selection_cancel_grouphover.png'
14
+ import selectionCancelHover from '@/assets/icons/selection_cancel_hover.png'
15
+ import selectionCancelDown from '@/assets/icons/selection_cancel_pressed.png'
16
16
 
17
17
  // 最简单的办法:直接向 OSD 的字符串库注入翻译
18
- OpenSeadragon.setString("Tooltips.SelectionToggle", t("selection.toggle")); // 切换选择
19
- OpenSeadragon.setString("Tooltips.SelectionConfirm", t("selection.confirm")); // 确认选择
20
- OpenSeadragon.setString("Tooltips.SelectionCancel", t("selection.cancel")); // 取消选择
18
+ OpenSeadragon.setString('Tooltips.SelectionToggle', t('selection.toggle')) // 切换选择
19
+ OpenSeadragon.setString('Tooltips.SelectionConfirm', t('selection.confirm')) // 确认选择
20
+ OpenSeadragon.setString('Tooltips.SelectionCancel', t('selection.cancel')) // 取消选择
21
21
 
22
22
  export interface SelectionOptions {
23
- element?: HTMLElement | null;
24
- showSelectionControl?: boolean;
25
- toggleButton?: HTMLElement | null;
26
- showConfirmDenyButtons?: boolean;
27
- styleConfirmDenyButtons?: boolean;
28
- returnPixelCoordinates?: boolean;
29
- keyboardShortcut?: string;
30
- rect?: OpenSeadragon.Rect | null;
31
- allowRotation?: boolean;
32
- startRotated?: boolean;
33
- startRotatedHeight?: number;
34
- restrictToImage?: boolean;
35
- onSelection?: (rect: OpenSeadragon.Rect) => void;
36
- onSelectionCanceled?: () => void;
37
- onSelectionChange?: (rect: OpenSeadragon.Rect) => void;
38
- onSelectionToggled?: (state: { enabled: boolean }) => void;
39
- prefixUrl?: string | null;
23
+ element?: HTMLElement | null
24
+ showSelectionControl?: boolean
25
+ toggleButton?: HTMLElement | null
26
+ showConfirmDenyButtons?: boolean
27
+ styleConfirmDenyButtons?: boolean
28
+ returnPixelCoordinates?: boolean
29
+ keyboardShortcut?: string
30
+ rect?: OpenSeadragon.Rect | null
31
+ allowRotation?: boolean
32
+ startRotated?: boolean
33
+ startRotatedHeight?: number
34
+ restrictToImage?: boolean
35
+ onSelection?: (rect: OpenSeadragon.Rect) => void
36
+ onSelectionCanceled?: () => void
37
+ onSelectionChange?: (rect: OpenSeadragon.Rect) => void
38
+ onSelectionToggled?: (state: { enabled: boolean }) => void
39
+ prefixUrl?: string | null
40
40
  navImages?: {
41
41
  selection: {
42
- REST: string;
43
- GROUP: string;
44
- HOVER: string;
45
- DOWN: string;
46
- };
42
+ REST: string
43
+ GROUP: string
44
+ HOVER: string
45
+ DOWN: string
46
+ }
47
47
  selectionConfirm: {
48
- REST: string;
49
- GROUP: string;
50
- HOVER: string;
51
- DOWN: string;
52
- };
48
+ REST: string
49
+ GROUP: string
50
+ HOVER: string
51
+ DOWN: string
52
+ }
53
53
  selectionCancel: {
54
- REST: string;
55
- GROUP: string;
56
- HOVER: string;
57
- DOWN: string;
58
- };
59
- };
54
+ REST: string
55
+ GROUP: string
56
+ HOVER: string
57
+ DOWN: string
58
+ }
59
+ }
60
60
  borderStyle?: {
61
- width: string;
62
- color: string;
63
- };
61
+ width: string
62
+ color: string
63
+ }
64
64
  handleStyle?: {
65
- top: string;
66
- left: string;
67
- width: string;
68
- height: string;
69
- margin: string;
70
- background: string;
71
- border: string;
72
- };
65
+ top: string
66
+ left: string
67
+ width: string
68
+ height: string
69
+ margin: string
70
+ background: string
71
+ border: string
72
+ }
73
73
  cornersStyle?: {
74
- width: string;
75
- height: string;
76
- background: string;
77
- border: string;
78
- };
74
+ width: string
75
+ height: string
76
+ background: string
77
+ border: string
78
+ }
79
79
  }
80
80
 
81
81
  export class SelectionPlugin {
82
- private viewer: OpenSeadragon.Viewer;
83
- private selection: any; // OpenSeadragonSelection instance
84
- private options: SelectionOptions;
82
+ private viewer: OpenSeadragon.Viewer
83
+ private selection: any // OpenSeadragonSelection instance
84
+ private options: SelectionOptions
85
85
 
86
86
  constructor(viewer: OpenSeadragon.Viewer, options: SelectionOptions = {}) {
87
- this.viewer = viewer;
87
+ this.viewer = viewer
88
88
  this.options = {
89
89
  showSelectionControl: true,
90
90
  showConfirmDenyButtons: true,
91
91
  styleConfirmDenyButtons: true,
92
92
  returnPixelCoordinates: true,
93
- keyboardShortcut: "c",
93
+ keyboardShortcut: 'c',
94
94
  allowRotation: true,
95
95
  startRotated: false,
96
96
  restrictToImage: false,
97
- prefixUrl: "",
97
+ prefixUrl: '',
98
98
  navImages: {
99
99
  selection: {
100
100
  REST: selectionRest,
101
101
  GROUP: selectionGroup,
102
102
  HOVER: selectionHover,
103
- DOWN: selectionDown,
103
+ DOWN: selectionDown
104
104
  },
105
105
  selectionConfirm: {
106
106
  REST: selectionConfirmRest,
107
107
  GROUP: selectionConfirmGroup,
108
108
  HOVER: selectionConfirmHover,
109
- DOWN: selectionConfirmDown,
109
+ DOWN: selectionConfirmDown
110
110
  },
111
111
  selectionCancel: {
112
112
  REST: selectionCancelRest,
113
113
  GROUP: selectionCancelGroup,
114
114
  HOVER: selectionCancelHover,
115
- DOWN: selectionCancelDown,
116
- },
115
+ DOWN: selectionCancelDown
116
+ }
117
117
  },
118
118
  borderStyle: {
119
- width: "2px", // 稍微加粗,更有质感
119
+ width: '2px', // 稍微加粗,更有质感
120
120
 
121
- color: "#4CAF50", // 使用经典的“激活蓝”
121
+ color: '#4CAF50' // 使用经典的“激活蓝”
122
122
  },
123
123
 
124
124
  handleStyle: {
125
- top: "50%",
126
- left: "50%",
127
- width: "10px", // 增大触点,方便鼠标点击
128
- height: "10px",
129
- margin: "-6px 0 0 -6px",
130
- background: "#4CAF50", // 白色背景
131
- border: "2px solid #4CAF50", // 蓝色边框
125
+ top: '50%',
126
+ left: '50%',
127
+ width: '10px', // 增大触点,方便鼠标点击
128
+ height: '10px',
129
+ margin: '-6px 0 0 -6px',
130
+ background: '#4CAF50', // 白色背景
131
+ border: '2px solid #4CAF50' // 蓝色边框
132
132
  },
133
-
134
133
 
135
134
  cornersStyle: {
136
- width: "12px", // 角部手柄稍微比边部大一点
137
- height: "12px",
138
- background: "#4CAF50",
139
- border: "2px solid #4CAF50",
135
+ width: '12px', // 角部手柄稍微比边部大一点
136
+ height: '12px',
137
+ background: '#4CAF50',
138
+ border: '2px solid #4CAF50'
140
139
  },
141
140
 
142
- ...options,
143
- };
141
+ ...options
142
+ }
144
143
 
145
- this.init();
144
+ this.init()
146
145
  }
147
146
 
148
147
  private init(): void {
149
148
  // 等待 viewer 初始化完成
150
- this.viewer.addOnceHandler("open", () => {
151
- this.setupSelection();
152
- });
149
+ this.viewer.addOnceHandler('open', () => {
150
+ this.setupSelection()
151
+ })
153
152
  }
154
153
  private setupSelection(): void {
155
154
  try {
156
155
  // 检查是否有 selection 插件
157
- if (typeof (this.viewer as any).selection !== "function") {
156
+ if (typeof (this.viewer as any).selection !== 'function') {
158
157
  console.warn(
159
- "OpenSeadragonSelection plugin not found. Please include openseadragonselection.js",
160
- );
161
- return;
158
+ 'OpenSeadragonSelection plugin not found. Please include openseadragonselection.js'
159
+ )
160
+ return
162
161
  }
163
162
 
164
163
  // 初始化 selection
165
- this.selection = (this.viewer as any).selection(this.options);
166
-
164
+ this.selection = (this.viewer as any).selection(this.options)
167
165
  } catch (error) {
168
- console.error(
169
- "[SelectionPlugin] Failed to initialize selection plugin:",
170
- error,
171
- );
166
+ console.error('[SelectionPlugin] Failed to initialize selection plugin:', error)
172
167
  }
173
168
  }
174
169
 
@@ -177,7 +172,7 @@ export class SelectionPlugin {
177
172
  */
178
173
  enable(): void {
179
174
  if (this.selection) {
180
- this.selection.enable();
175
+ this.selection.enable()
181
176
  }
182
177
  }
183
178
 
@@ -186,7 +181,7 @@ export class SelectionPlugin {
186
181
  */
187
182
  disable(): void {
188
183
  if (this.selection) {
189
- this.selection.disable();
184
+ this.selection.disable()
190
185
  }
191
186
  }
192
187
 
@@ -195,7 +190,7 @@ export class SelectionPlugin {
195
190
  */
196
191
  toggleState(): void {
197
192
  if (this.selection) {
198
- this.selection.toggleState();
193
+ this.selection.toggleState()
199
194
  }
200
195
  }
201
196
 
@@ -204,9 +199,9 @@ export class SelectionPlugin {
204
199
  */
205
200
  getSelection(): OpenSeadragon.Rect | null {
206
201
  if (this.selection) {
207
- return this.selection.getSelection();
202
+ return this.selection.getSelection()
208
203
  }
209
- return null;
204
+ return null
210
205
  }
211
206
 
212
207
  /**
@@ -214,7 +209,7 @@ export class SelectionPlugin {
214
209
  */
215
210
  setSelection(rect: OpenSeadragon.Rect): void {
216
211
  if (this.selection) {
217
- this.selection.setSelection(rect);
212
+ this.selection.setSelection(rect)
218
213
  }
219
214
  }
220
215
 
@@ -223,7 +218,7 @@ export class SelectionPlugin {
223
218
  */
224
219
  clearSelection(): void {
225
220
  if (this.selection) {
226
- this.selection.clearSelection();
221
+ this.selection.clearSelection()
227
222
  }
228
223
  }
229
224
 
@@ -232,9 +227,9 @@ export class SelectionPlugin {
232
227
  */
233
228
  isEnabled(): boolean {
234
229
  if (this.selection) {
235
- return this.selection.isEnabled();
230
+ return this.selection.isEnabled()
236
231
  }
237
- return false;
232
+ return false
238
233
  }
239
234
 
240
235
  /**
@@ -242,8 +237,7 @@ export class SelectionPlugin {
242
237
  */
243
238
  destroy(): void {
244
239
  if (this.selection) {
245
- this.selection.destroy();
246
- this.selection = null;
240
+ this.selection = null
247
241
  }
248
242
  }
249
243
  }
package/src/i18n/i18n.ts CHANGED
@@ -1,7 +1,7 @@
1
- export type Locale = 'zh-CN' | 'en-US';
1
+ export type Locale = 'zh-CN' | 'en-US'
2
2
 
3
3
  export interface I18nDict {
4
- [key: string]: string | I18nDict;
4
+ [key: string]: string | I18nDict
5
5
  }
6
6
 
7
7
  const dicts: Record<Locale, I18nDict> = {
@@ -20,19 +20,18 @@ const dicts: Record<Locale, I18nDict> = {
20
20
  colorAdjust: '颜色调整',
21
21
  screenshot: '截图设置',
22
22
  brightness: '亮度',
23
- contrast: '对比度',
24
- saturation: '饱和度',
25
- gamma: '伽马',
26
- hue: '色相',
27
- invert: '反色',
28
- sepia: '怀旧',
29
- greyscale: '灰度',
30
-
23
+ contrast: '对比度',
24
+ saturation: '饱和度',
25
+ gamma: '伽马',
26
+ hue: '色相',
27
+ invert: '反色',
28
+ sepia: '怀旧',
29
+ greyscale: '灰度'
31
30
  },
32
31
  selection: {
33
32
  toggle: '切换选择',
34
33
  confirm: '确认选择',
35
- cancel: '取消选择',
34
+ cancel: '取消选择'
36
35
  },
37
36
  annotation: {
38
37
  length: '长度',
@@ -43,9 +42,8 @@ const dicts: Record<Locale, I18nDict> = {
43
42
  remark: '备注',
44
43
  radius: '半径',
45
44
  majorAxis: '长轴',
46
- minorAxis: '短轴',
47
-
48
- },
45
+ minorAxis: '短轴'
46
+ }
49
47
  },
50
48
  'en-US': {
51
49
  toolbar: {
@@ -61,19 +59,19 @@ const dicts: Record<Locale, I18nDict> = {
61
59
  annoSettings: 'Annotation Settings',
62
60
  colorAdjust: 'Color Adjust',
63
61
  screenshot: 'Screenshot Settings',
64
- brightness: 'Brightness',
65
- contrast: 'Contrast',
66
- saturation: 'Saturation',
67
- gamma: 'Gamma',
68
- hue: 'Hue',
69
- invert: 'Invert',
70
- sepia: 'Sepia',
71
- greyscale: 'Greyscale',
62
+ brightness: 'Brightness',
63
+ contrast: 'Contrast',
64
+ saturation: 'Saturation',
65
+ gamma: 'Gamma',
66
+ hue: 'Hue',
67
+ invert: 'Invert',
68
+ sepia: 'Sepia',
69
+ greyscale: 'Greyscale'
72
70
  },
73
71
  selection: {
74
72
  toggle: 'Toggle Selection',
75
73
  confirm: 'Confirm Selection',
76
- cancel: 'Cancel Selection',
74
+ cancel: 'Cancel Selection'
77
75
  },
78
76
  annotation: {
79
77
  length: 'Length',
@@ -84,23 +82,23 @@ const dicts: Record<Locale, I18nDict> = {
84
82
  remark: 'Remark',
85
83
  radius: 'Radius',
86
84
  majorAxis: 'Major Axis',
87
- minorAxis: 'Minor Axis',
88
- },
89
- },
90
- };
85
+ minorAxis: 'Minor Axis'
86
+ }
87
+ }
88
+ }
91
89
 
92
- let currentLocale: Locale = 'zh-CN';
90
+ let currentLocale: Locale = 'zh-CN'
93
91
 
94
92
  export function setLocale(locale: Locale) {
95
- currentLocale = locale;
93
+ currentLocale = locale
96
94
  }
97
95
 
98
96
  export function t(path: string): string {
99
- const keys = path.split('.');
100
- let value: any = dicts[currentLocale];
97
+ const keys = path.split('.')
98
+ let value: any = dicts[currentLocale]
101
99
  for (const k of keys) {
102
- value = value?.[k];
103
- if (!value) return path;
100
+ value = value?.[k]
101
+ if (!value) return path
104
102
  }
105
- return typeof value === 'string' ? value : path;
103
+ return typeof value === 'string' ? value : path
106
104
  }
package/src/index.ts CHANGED
@@ -1,52 +1,45 @@
1
- import { MedViewerEngine, type MedEngineOptions } from "./core/Engine";
2
- import {
3
- type ScalebarOptions,
4
- ScalebarType,
5
- ScalebarLocation
6
- } from "./core/Scalebar";
7
- import { AnnoAnnotator } from "./core/AnnoAnnotator";
8
- import { MedToolbar, ToolbarPosition, type ToolbarOptions } from "./core/Toolbar";
9
- import { SelectionPlugin, type SelectionOptions } from "./core/SelectionPlugin";
10
- import {
11
- ColorAdjustPlugin,
12
- type ColorAdjustOptions,
13
- } from "./core/ColorAdjustPlugin";
1
+ import { AnnoAnnotator } from './core/AnnoAnnotator'
2
+ import { ColorAdjustPlugin, type ColorAdjustOptions } from './core/ColorAdjustPlugin'
3
+ import { MedViewerEngine, type MedEngineOptions } from './core/Engine'
14
4
  import {
15
5
  MagnificationPlugin,
16
6
  MagnificationPosition,
17
7
  MagnificationType,
18
- type MagnificationOptions,
19
- } from "./core/Magnification";
8
+ type MagnificationOptions
9
+ } from './core/Magnification'
10
+ import { ScalebarLocation, ScalebarType, type ScalebarOptions } from './core/Scalebar'
11
+ import { SelectionPlugin, type SelectionOptions } from './core/SelectionPlugin'
12
+ import { MedToolbar, ToolbarPosition, type ToolbarOptions } from './core/Toolbar'
20
13
 
21
14
  // 1. 导出供模块化开发使用 (Vue/React/Vite)
22
15
  export {
23
- MedViewerEngine,
24
- type MedEngineOptions,
25
16
  AnnoAnnotator,
26
- MedToolbar,
27
- ToolbarPosition,
28
- type ToolbarOptions,
29
- SelectionPlugin,
30
- type SelectionOptions,
31
17
  ColorAdjustPlugin,
32
- type ColorAdjustOptions,
33
18
  MagnificationPlugin,
34
19
  MagnificationPosition,
35
20
  MagnificationType,
21
+ MedToolbar,
22
+ MedViewerEngine,
23
+ ScalebarLocation,
24
+ ScalebarType,
25
+ SelectionPlugin,
26
+ ToolbarPosition,
27
+ type ColorAdjustOptions,
36
28
  type MagnificationOptions,
29
+ type MedEngineOptions,
37
30
  type ScalebarOptions,
38
- ScalebarType,
39
- ScalebarLocation,
40
- };
31
+ type SelectionOptions,
32
+ type ToolbarOptions
33
+ }
41
34
 
42
35
  // 2. 导出供原生 HTML 全局变量使用 (window.MedViewerSDK)
43
- if (typeof window !== "undefined") {
44
- (window as any).MedViewerSDK = {
36
+ if (typeof window !== 'undefined') {
37
+ ;(window as any).MedViewerSDK = {
45
38
  MedViewerEngine,
46
39
  AnnoAnnotator,
47
40
  MedToolbar,
48
41
  SelectionPlugin,
49
42
  ColorAdjustPlugin,
50
- MagnificationPlugin,
51
- };
43
+ MagnificationPlugin
44
+ }
52
45
  }