med-viewer-sdk 0.1.20 → 0.1.21
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;
|
|
@@ -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.mjs
CHANGED
|
@@ -13156,6 +13156,8 @@ class ColorAdjustPlugin {
|
|
|
13156
13156
|
},
|
|
13157
13157
|
debounceMs: 60,
|
|
13158
13158
|
loadMode: "async",
|
|
13159
|
+
onAdjustmentsChange: () => {
|
|
13160
|
+
},
|
|
13159
13161
|
...options
|
|
13160
13162
|
};
|
|
13161
13163
|
this._adjustments = { ...this.options.adjustments };
|
|
@@ -13207,6 +13209,9 @@ class ColorAdjustPlugin {
|
|
|
13207
13209
|
clearTimeout(this.debounceTimer);
|
|
13208
13210
|
this.debounceTimer = setTimeout(() => {
|
|
13209
13211
|
this.apply();
|
|
13212
|
+
if (this.options.onAdjustmentsChange) {
|
|
13213
|
+
this.options.onAdjustmentsChange(this._adjustments);
|
|
13214
|
+
}
|
|
13210
13215
|
this.debounceTimer = null;
|
|
13211
13216
|
}, this.options.debounceMs);
|
|
13212
13217
|
}
|
|
@@ -13216,6 +13221,9 @@ class ColorAdjustPlugin {
|
|
|
13216
13221
|
reset() {
|
|
13217
13222
|
this._adjustments = { ...this.options.adjustments };
|
|
13218
13223
|
this.apply();
|
|
13224
|
+
if (this.options.onAdjustmentsChange) {
|
|
13225
|
+
this.options.onAdjustmentsChange(this._adjustments);
|
|
13226
|
+
}
|
|
13219
13227
|
}
|
|
13220
13228
|
destroy() {
|
|
13221
13229
|
var _a2;
|
|
@@ -15296,6 +15304,10 @@ class SelectionPlugin {
|
|
|
15296
15304
|
// OpenSeadragonSelection instance
|
|
15297
15305
|
__publicField(this, "options");
|
|
15298
15306
|
this.viewer = viewer;
|
|
15307
|
+
const userOnSelection = options.onSelection;
|
|
15308
|
+
if (options.onSelection) {
|
|
15309
|
+
delete options.onSelection;
|
|
15310
|
+
}
|
|
15299
15311
|
this.options = {
|
|
15300
15312
|
showSelectionControl: true,
|
|
15301
15313
|
showConfirmDenyButtons: true,
|
|
@@ -15351,7 +15363,45 @@ class SelectionPlugin {
|
|
|
15351
15363
|
background: "#4CAF50",
|
|
15352
15364
|
border: "2px solid #4CAF50"
|
|
15353
15365
|
},
|
|
15354
|
-
...options
|
|
15366
|
+
...options,
|
|
15367
|
+
// Override onSelection to provide a blob
|
|
15368
|
+
onSelection: (rect) => {
|
|
15369
|
+
if (!userOnSelection) {
|
|
15370
|
+
return;
|
|
15371
|
+
}
|
|
15372
|
+
try {
|
|
15373
|
+
const viewportRect = this.viewer.viewport.imageToViewportRectangle(rect);
|
|
15374
|
+
const webRect = this.viewer.viewport.viewportToViewerElementRectangle(viewportRect);
|
|
15375
|
+
const pixelDensityRatio = OpenSeadragon.pixelDensityRatio || 1;
|
|
15376
|
+
const { x: x2, y: y2, width, height } = webRect || {};
|
|
15377
|
+
const { canvas } = this.viewer.drawer;
|
|
15378
|
+
const selectionCanvas = document.createElement("canvas");
|
|
15379
|
+
const ctx = selectionCanvas.getContext("2d");
|
|
15380
|
+
if (!ctx) {
|
|
15381
|
+
userOnSelection(rect, null);
|
|
15382
|
+
return;
|
|
15383
|
+
}
|
|
15384
|
+
selectionCanvas.width = width * pixelDensityRatio;
|
|
15385
|
+
selectionCanvas.height = height * pixelDensityRatio;
|
|
15386
|
+
ctx.drawImage(
|
|
15387
|
+
canvas,
|
|
15388
|
+
x2 * pixelDensityRatio,
|
|
15389
|
+
y2 * pixelDensityRatio,
|
|
15390
|
+
width * pixelDensityRatio,
|
|
15391
|
+
height * pixelDensityRatio,
|
|
15392
|
+
0,
|
|
15393
|
+
0,
|
|
15394
|
+
width * pixelDensityRatio,
|
|
15395
|
+
height * pixelDensityRatio
|
|
15396
|
+
);
|
|
15397
|
+
selectionCanvas.toBlob((blob) => {
|
|
15398
|
+
userOnSelection(rect, blob);
|
|
15399
|
+
});
|
|
15400
|
+
} catch (e2) {
|
|
15401
|
+
console.error("[SelectionPlugin] Error creating blob from selection:", e2);
|
|
15402
|
+
userOnSelection(rect, null);
|
|
15403
|
+
}
|
|
15404
|
+
}
|
|
15355
15405
|
};
|
|
15356
15406
|
this.init();
|
|
15357
15407
|
updateOsdTooltips();
|
|
@@ -15501,6 +15551,9 @@ const createAnnoDropdownContent = (engine, hide) => {
|
|
|
15501
15551
|
btn.className = "med-tool-item";
|
|
15502
15552
|
btn.textContent = tItem.label;
|
|
15503
15553
|
btn.onclick = () => {
|
|
15554
|
+
if (engine.selection) {
|
|
15555
|
+
engine.selection.disable();
|
|
15556
|
+
}
|
|
15504
15557
|
if (engine.anno)
|
|
15505
15558
|
engine.anno.setTool(tItem.id, selectedColor);
|
|
15506
15559
|
hide();
|
|
@@ -15523,6 +15576,10 @@ const createColorAdjustDropdownContent = (engine, hide) => {
|
|
|
15523
15576
|
var _a2;
|
|
15524
15577
|
const container = document.createElement("div");
|
|
15525
15578
|
container.className = "med-toolbar-dropdown-inner med-color-adjust-dropdown";
|
|
15579
|
+
if (engine.anno)
|
|
15580
|
+
engine.anno.setEnabled(false);
|
|
15581
|
+
if (engine.selection)
|
|
15582
|
+
engine.selection.disable();
|
|
15526
15583
|
const createSlider = (labelText, id, min, max, step, initialValue, onChange) => {
|
|
15527
15584
|
const section = document.createElement("div");
|
|
15528
15585
|
section.className = "med-toolbar-section";
|
|
@@ -15736,6 +15793,12 @@ const DEFAULT_BUTTONS = [
|
|
|
15736
15793
|
label: t("toolbar.reset"),
|
|
15737
15794
|
onClick: (engine, hide) => {
|
|
15738
15795
|
engine.viewer.viewport.goHome();
|
|
15796
|
+
if (engine.selection) {
|
|
15797
|
+
engine.selection.disable();
|
|
15798
|
+
}
|
|
15799
|
+
if (engine.anno) {
|
|
15800
|
+
engine.anno.setEnabled(false);
|
|
15801
|
+
}
|
|
15739
15802
|
hide();
|
|
15740
15803
|
}
|
|
15741
15804
|
},
|
|
@@ -15758,6 +15821,9 @@ const DEFAULT_BUTTONS = [
|
|
|
15758
15821
|
onClick: (engine, hide) => {
|
|
15759
15822
|
var _a2;
|
|
15760
15823
|
(_a2 = engine.selection) == null ? void 0 : _a2.toggleState();
|
|
15824
|
+
if (engine.anno) {
|
|
15825
|
+
engine.anno.setEnabled(false);
|
|
15826
|
+
}
|
|
15761
15827
|
hide();
|
|
15762
15828
|
}
|
|
15763
15829
|
}
|