med-viewer-sdk 0.1.20 → 0.1.22
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.
|
@@ -13,6 +13,7 @@ export interface ColorAdjustOptions {
|
|
|
13
13
|
adjustments?: ColorAdjustments;
|
|
14
14
|
debounceMs?: number;
|
|
15
15
|
loadMode?: 'async' | 'sync';
|
|
16
|
+
onAdjustmentsChange?: (adjustments: ColorAdjustments) => void;
|
|
16
17
|
}
|
|
17
18
|
export declare class ColorAdjustPlugin {
|
|
18
19
|
private viewer;
|
package/dist/core/Engine.d.ts
CHANGED
|
@@ -86,6 +86,10 @@ export declare class MedViewerEngine {
|
|
|
86
86
|
private mountAnnotorious;
|
|
87
87
|
loadAIMarks(aiBoxes?: AiBoxRect[], showLabel?: boolean): void;
|
|
88
88
|
updateAIMarks(aiBoxes?: AiBoxRect[], showLabel?: boolean): void;
|
|
89
|
+
goToPosition(target: {
|
|
90
|
+
x: number;
|
|
91
|
+
y: number;
|
|
92
|
+
}, animate?: boolean, mag?: number | null): Promise<void>;
|
|
89
93
|
clearAIMarks(): void;
|
|
90
94
|
loadSelectionBox(selections?: SelectionBox[]): void;
|
|
91
95
|
addHandler(event: string, handler: Function): void;
|
|
@@ -13,7 +13,7 @@ export interface SelectionOptions {
|
|
|
13
13
|
startRotated?: boolean;
|
|
14
14
|
startRotatedHeight?: number;
|
|
15
15
|
restrictToImage?: boolean;
|
|
16
|
-
onSelection?: (rect: OpenSeadragon.Rect) => void;
|
|
16
|
+
onSelection?: (rect: OpenSeadragon.Rect, blob: Blob | null) => void;
|
|
17
17
|
onSelectionCanceled?: () => void;
|
|
18
18
|
onSelectionChange?: (rect: OpenSeadragon.Rect) => void;
|
|
19
19
|
onSelectionToggled?: (state: {
|
package/dist/med-viewer-sdk.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AnnoAnnotator } from './core/AnnoAnnotator';
|
|
2
2
|
import { ColorAdjustPlugin, type ColorAdjustOptions } from './core/ColorAdjustPlugin';
|
|
3
3
|
import { MedViewerEngine, type MedEngineOptions } from './core/Engine';
|
|
4
|
+
import type OpenSeadragonType from 'openseadragon';
|
|
5
|
+
import OpenSeadragon from 'openseadragon';
|
|
4
6
|
import { MagnificationPlugin, MagnificationPosition, MagnificationType, type MagnificationOptions } from './core/Magnification';
|
|
5
7
|
import { ScalebarLocation, ScalebarType, type ScalebarOptions } from './core/Scalebar';
|
|
6
8
|
import { SelectionPlugin, type SelectionOptions } from './core/SelectionPlugin';
|
|
7
9
|
import { MedToolbar, ToolbarPosition, type ToolbarOptions } from './core/Toolbar';
|
|
8
|
-
export { AnnoAnnotator, ColorAdjustPlugin, MagnificationPlugin, MagnificationPosition, MagnificationType, MedToolbar, MedViewerEngine, ScalebarLocation, ScalebarType, SelectionPlugin, ToolbarPosition, type ColorAdjustOptions, type MagnificationOptions, type MedEngineOptions, type ScalebarOptions, type SelectionOptions, type ToolbarOptions };
|
|
10
|
+
export { AnnoAnnotator, ColorAdjustPlugin, MagnificationPlugin, MagnificationPosition, MagnificationType, MedToolbar, MedViewerEngine, ScalebarLocation, ScalebarType, SelectionPlugin, ToolbarPosition, OpenSeadragon, type OpenSeadragonType, type ColorAdjustOptions, type MagnificationOptions, type MedEngineOptions, type ScalebarOptions, type SelectionOptions, type ToolbarOptions };
|
package/dist/med-viewer-sdk.mjs
CHANGED
|
@@ -6,6 +6,7 @@ var __publicField = (obj, key, value) => {
|
|
|
6
6
|
};
|
|
7
7
|
var _a, _b, _c, _d, _e;
|
|
8
8
|
import OpenSeadragon from "openseadragon";
|
|
9
|
+
import { default as default2 } from "openseadragon";
|
|
9
10
|
function getDefaultExportFromCjs(x2) {
|
|
10
11
|
return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
|
|
11
12
|
}
|
|
@@ -13156,6 +13157,8 @@ class ColorAdjustPlugin {
|
|
|
13156
13157
|
},
|
|
13157
13158
|
debounceMs: 60,
|
|
13158
13159
|
loadMode: "async",
|
|
13160
|
+
onAdjustmentsChange: () => {
|
|
13161
|
+
},
|
|
13159
13162
|
...options
|
|
13160
13163
|
};
|
|
13161
13164
|
this._adjustments = { ...this.options.adjustments };
|
|
@@ -13207,6 +13210,9 @@ class ColorAdjustPlugin {
|
|
|
13207
13210
|
clearTimeout(this.debounceTimer);
|
|
13208
13211
|
this.debounceTimer = setTimeout(() => {
|
|
13209
13212
|
this.apply();
|
|
13213
|
+
if (this.options.onAdjustmentsChange) {
|
|
13214
|
+
this.options.onAdjustmentsChange(this._adjustments);
|
|
13215
|
+
}
|
|
13210
13216
|
this.debounceTimer = null;
|
|
13211
13217
|
}, this.options.debounceMs);
|
|
13212
13218
|
}
|
|
@@ -13216,6 +13222,9 @@ class ColorAdjustPlugin {
|
|
|
13216
13222
|
reset() {
|
|
13217
13223
|
this._adjustments = { ...this.options.adjustments };
|
|
13218
13224
|
this.apply();
|
|
13225
|
+
if (this.options.onAdjustmentsChange) {
|
|
13226
|
+
this.options.onAdjustmentsChange(this._adjustments);
|
|
13227
|
+
}
|
|
13219
13228
|
}
|
|
13220
13229
|
destroy() {
|
|
13221
13230
|
var _a2;
|
|
@@ -15296,6 +15305,10 @@ class SelectionPlugin {
|
|
|
15296
15305
|
// OpenSeadragonSelection instance
|
|
15297
15306
|
__publicField(this, "options");
|
|
15298
15307
|
this.viewer = viewer;
|
|
15308
|
+
const userOnSelection = options.onSelection;
|
|
15309
|
+
if (options.onSelection) {
|
|
15310
|
+
delete options.onSelection;
|
|
15311
|
+
}
|
|
15299
15312
|
this.options = {
|
|
15300
15313
|
showSelectionControl: true,
|
|
15301
15314
|
showConfirmDenyButtons: true,
|
|
@@ -15351,7 +15364,45 @@ class SelectionPlugin {
|
|
|
15351
15364
|
background: "#4CAF50",
|
|
15352
15365
|
border: "2px solid #4CAF50"
|
|
15353
15366
|
},
|
|
15354
|
-
...options
|
|
15367
|
+
...options,
|
|
15368
|
+
// Override onSelection to provide a blob
|
|
15369
|
+
onSelection: (rect) => {
|
|
15370
|
+
if (!userOnSelection) {
|
|
15371
|
+
return;
|
|
15372
|
+
}
|
|
15373
|
+
try {
|
|
15374
|
+
const viewportRect = this.viewer.viewport.imageToViewportRectangle(rect);
|
|
15375
|
+
const webRect = this.viewer.viewport.viewportToViewerElementRectangle(viewportRect);
|
|
15376
|
+
const pixelDensityRatio = OpenSeadragon.pixelDensityRatio || 1;
|
|
15377
|
+
const { x: x2, y: y2, width, height } = webRect || {};
|
|
15378
|
+
const { canvas } = this.viewer.drawer;
|
|
15379
|
+
const selectionCanvas = document.createElement("canvas");
|
|
15380
|
+
const ctx = selectionCanvas.getContext("2d");
|
|
15381
|
+
if (!ctx) {
|
|
15382
|
+
userOnSelection(rect, null);
|
|
15383
|
+
return;
|
|
15384
|
+
}
|
|
15385
|
+
selectionCanvas.width = width * pixelDensityRatio;
|
|
15386
|
+
selectionCanvas.height = height * pixelDensityRatio;
|
|
15387
|
+
ctx.drawImage(
|
|
15388
|
+
canvas,
|
|
15389
|
+
x2 * pixelDensityRatio,
|
|
15390
|
+
y2 * pixelDensityRatio,
|
|
15391
|
+
width * pixelDensityRatio,
|
|
15392
|
+
height * pixelDensityRatio,
|
|
15393
|
+
0,
|
|
15394
|
+
0,
|
|
15395
|
+
width * pixelDensityRatio,
|
|
15396
|
+
height * pixelDensityRatio
|
|
15397
|
+
);
|
|
15398
|
+
selectionCanvas.toBlob((blob) => {
|
|
15399
|
+
userOnSelection(rect, blob);
|
|
15400
|
+
});
|
|
15401
|
+
} catch (e2) {
|
|
15402
|
+
console.error("[SelectionPlugin] Error creating blob from selection:", e2);
|
|
15403
|
+
userOnSelection(rect, null);
|
|
15404
|
+
}
|
|
15405
|
+
}
|
|
15355
15406
|
};
|
|
15356
15407
|
this.init();
|
|
15357
15408
|
updateOsdTooltips();
|
|
@@ -15501,6 +15552,9 @@ const createAnnoDropdownContent = (engine, hide) => {
|
|
|
15501
15552
|
btn.className = "med-tool-item";
|
|
15502
15553
|
btn.textContent = tItem.label;
|
|
15503
15554
|
btn.onclick = () => {
|
|
15555
|
+
if (engine.selection) {
|
|
15556
|
+
engine.selection.disable();
|
|
15557
|
+
}
|
|
15504
15558
|
if (engine.anno)
|
|
15505
15559
|
engine.anno.setTool(tItem.id, selectedColor);
|
|
15506
15560
|
hide();
|
|
@@ -15523,6 +15577,10 @@ const createColorAdjustDropdownContent = (engine, hide) => {
|
|
|
15523
15577
|
var _a2;
|
|
15524
15578
|
const container = document.createElement("div");
|
|
15525
15579
|
container.className = "med-toolbar-dropdown-inner med-color-adjust-dropdown";
|
|
15580
|
+
if (engine.anno)
|
|
15581
|
+
engine.anno.setEnabled(false);
|
|
15582
|
+
if (engine.selection)
|
|
15583
|
+
engine.selection.disable();
|
|
15526
15584
|
const createSlider = (labelText, id, min, max, step, initialValue, onChange) => {
|
|
15527
15585
|
const section = document.createElement("div");
|
|
15528
15586
|
section.className = "med-toolbar-section";
|
|
@@ -15736,6 +15794,12 @@ const DEFAULT_BUTTONS = [
|
|
|
15736
15794
|
label: t("toolbar.reset"),
|
|
15737
15795
|
onClick: (engine, hide) => {
|
|
15738
15796
|
engine.viewer.viewport.goHome();
|
|
15797
|
+
if (engine.selection) {
|
|
15798
|
+
engine.selection.disable();
|
|
15799
|
+
}
|
|
15800
|
+
if (engine.anno) {
|
|
15801
|
+
engine.anno.setEnabled(false);
|
|
15802
|
+
}
|
|
15739
15803
|
hide();
|
|
15740
15804
|
}
|
|
15741
15805
|
},
|
|
@@ -15757,7 +15821,11 @@ const DEFAULT_BUTTONS = [
|
|
|
15757
15821
|
label: t("toolbar.screenshot"),
|
|
15758
15822
|
onClick: (engine, hide) => {
|
|
15759
15823
|
var _a2;
|
|
15824
|
+
console.log("selection toggleState");
|
|
15760
15825
|
(_a2 = engine.selection) == null ? void 0 : _a2.toggleState();
|
|
15826
|
+
if (engine.anno) {
|
|
15827
|
+
engine.anno.setEnabled(false);
|
|
15828
|
+
}
|
|
15761
15829
|
hide();
|
|
15762
15830
|
}
|
|
15763
15831
|
}
|
|
@@ -16401,6 +16469,38 @@ class MedViewerEngine {
|
|
|
16401
16469
|
updateAIMarks(aiBoxes = [], showLabel = false) {
|
|
16402
16470
|
this.loadAIMarks(aiBoxes, showLabel);
|
|
16403
16471
|
}
|
|
16472
|
+
async goToPosition(target, animate = true, mag = null) {
|
|
16473
|
+
var _a2, _b2, _c2, _d2;
|
|
16474
|
+
const point = this.viewer.viewport.imageToViewportCoordinates(target.x, target.y);
|
|
16475
|
+
if (!point)
|
|
16476
|
+
return;
|
|
16477
|
+
if (!mag) {
|
|
16478
|
+
this.viewer.viewport.panTo(point, animate);
|
|
16479
|
+
return;
|
|
16480
|
+
}
|
|
16481
|
+
const { plugins } = this.options;
|
|
16482
|
+
const config = typeof (plugins == null ? void 0 : plugins.magnification) === "object" ? plugins.magnification : {};
|
|
16483
|
+
if (config.type === "LD") {
|
|
16484
|
+
const tiledImage = this.viewer.world.getItemAt(0);
|
|
16485
|
+
if (!tiledImage)
|
|
16486
|
+
return;
|
|
16487
|
+
const source = this.viewer.source;
|
|
16488
|
+
const width = source.width;
|
|
16489
|
+
source.height;
|
|
16490
|
+
const pixelsPerMeter = typeof (plugins == null ? void 0 : plugins.scalebar) === "object" && ((_a2 = plugins == null ? void 0 : plugins.scalebar) == null ? void 0 : _a2.pixelsPerMeter) ? (_b2 = plugins == null ? void 0 : plugins.scalebar) == null ? void 0 : _b2.pixelsPerMeter : ((_c2 = this.viewer.scalebarInstance) == null ? void 0 : _c2.pixelsPerMeter) || 96;
|
|
16491
|
+
const conversionFactor = 20 * 11e-4 * pixelsPerMeter / width;
|
|
16492
|
+
const targetZoom = mag / conversionFactor;
|
|
16493
|
+
await this.viewer.viewport.zoomTo(targetZoom, point, false);
|
|
16494
|
+
} else {
|
|
16495
|
+
const tiledImage = this.viewer.world.getItemAt(0);
|
|
16496
|
+
if (!tiledImage)
|
|
16497
|
+
return;
|
|
16498
|
+
const baseMag = ((_d2 = this.viewer.source) == null ? void 0 : _d2.max_magnification) || 40;
|
|
16499
|
+
const targetImageZoom = mag / baseMag;
|
|
16500
|
+
const targetViewportZoom = this.viewer.viewport.imageToViewportZoom(targetImageZoom);
|
|
16501
|
+
await this.viewer.viewport.zoomTo(targetViewportZoom, point, false);
|
|
16502
|
+
}
|
|
16503
|
+
}
|
|
16404
16504
|
clearAIMarks() {
|
|
16405
16505
|
const aiBoxesList = Array.from(
|
|
16406
16506
|
document.getElementsByClassName("ld-ai-box")
|
|
@@ -16503,6 +16603,7 @@ export {
|
|
|
16503
16603
|
MagnificationType,
|
|
16504
16604
|
MedToolbar,
|
|
16505
16605
|
MedViewerEngine,
|
|
16606
|
+
default2 as OpenSeadragon,
|
|
16506
16607
|
ScalebarLocation,
|
|
16507
16608
|
ScalebarType,
|
|
16508
16609
|
SelectionPlugin,
|