@ivmartel/dwv-react 0.0.0-stage → 0.11.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.
@@ -0,0 +1,1416 @@
1
+ import { createContext as e, forwardRef as t, useCallback as n, useContext as r, useEffect as i, useId as a, useMemo as o, useRef as s, useState as c, useSyncExternalStore as l, version as u } from "react";
2
+ import { alpha as d, styled as f } from "@mui/material/styles";
3
+ import { Alert as p, AppBar as m, Box as h, Button as g, ButtonBase as _, Collapse as v, Dialog as y, IconButton as b, InputAdornment as x, LinearProgress as ee, Link as S, Paper as C, Slide as te, Slider as w, Snackbar as T, Stack as E, Table as D, TableBody as O, TableCell as k, TableContainer as A, TableHead as ne, TableRow as j, TextField as re, Toolbar as ie, Typography as M } from "@mui/material";
4
+ import { AnnotationGroupFactory as N, App as P, AppOptions as F, DicomWriter as ae, DrawController as I, ToolConfig as L, ViewConfig as oe, getDicomTagInfo as se, getDwvVersion as ce, getTagFromKey as le, getUID as ue, getURLsFromKeyValueUri as de, i18n as fe, logger as R } from "dwv";
5
+ import { Fragment as pe, jsx as z, jsxs as B } from "react/jsx-runtime";
6
+ import V from "@mui/icons-material/Search";
7
+ import me from "@mui/icons-material/Straighten";
8
+ import he from "@mui/icons-material/CallMade";
9
+ import ge from "@mui/icons-material/CropLandscape";
10
+ import _e from "@mui/icons-material/RadioButtonUnchecked";
11
+ import ve from "@mui/icons-material/SportsRugby";
12
+ import ye from "@mui/icons-material/SquareFoot";
13
+ import be from "@mui/icons-material/Polyline";
14
+ import xe from "@mui/icons-material/QuestionMark";
15
+ import Se from "@mui/icons-material/Close";
16
+ import Ce from "@mui/icons-material/Refresh";
17
+ import we from "@mui/icons-material/Menu";
18
+ import Te from "@mui/icons-material/Contrast";
19
+ import Ee from "@mui/icons-material/LibraryBooks";
20
+ import De from "@mui/icons-material/Cameraswitch";
21
+ import H from "@mui/icons-material/KeyboardArrowDown";
22
+ import Oe from "@mui/icons-material/ChevronLeft";
23
+ import ke from "@mui/icons-material/ChevronRight";
24
+ import Ae from "@mui/icons-material/Lock";
25
+ import je from "@mui/icons-material/LockOpen";
26
+ import Me from "@mui/icons-material/Save";
27
+ import Ne from "@mui/icons-material/Label";
28
+ import Pe from "@mui/icons-material/LabelOff";
29
+ import Fe from "@mui/icons-material/InfoOutlined";
30
+ import Ie from "@mui/icons-material/Info";
31
+ import Le from "@mui/icons-material/Visibility";
32
+ import Re from "@mui/icons-material/VisibilityOff";
33
+ import ze from "@mui/icons-material/Delete";
34
+ // src/services/overlays.js
35
+ var Be = {
36
+ DOM: [
37
+ {
38
+ tags: ["fileName"],
39
+ pos: "tl"
40
+ },
41
+ {
42
+ tags: ["fileType"],
43
+ pos: "tr"
44
+ },
45
+ {
46
+ tags: ["imageWidth", "imageHeight"],
47
+ pos: "bl",
48
+ format: "RES: {v0}x{v1}"
49
+ },
50
+ {
51
+ event: "wlchange",
52
+ pos: "bl",
53
+ format: "WC: {v0}"
54
+ },
55
+ {
56
+ event: "wlchange",
57
+ pos: "bl",
58
+ format: "WW: {v1}"
59
+ },
60
+ {
61
+ event: "zoomchange",
62
+ pos: "br",
63
+ format: "Z: {v0}",
64
+ precision: "3"
65
+ },
66
+ {
67
+ event: "offsetchange",
68
+ pos: "br",
69
+ format: "Off: {v0},{v1}",
70
+ precision: "round"
71
+ },
72
+ {
73
+ event: "positionchange",
74
+ pos: "br",
75
+ format: "Pos: {v0}"
76
+ },
77
+ {
78
+ event: "positionchange",
79
+ pos: "br",
80
+ format: "Value: {v1}"
81
+ }
82
+ ],
83
+ "*": [
84
+ {
85
+ tags: ["00100010", "00100040"],
86
+ pos: "tl",
87
+ format: "{v0} [{v1}]"
88
+ },
89
+ {
90
+ tags: ["00100030"],
91
+ pos: "tl"
92
+ },
93
+ {
94
+ tags: ["00080070", "00081090"],
95
+ pos: "tr",
96
+ format: "{v0} {v1}"
97
+ },
98
+ {
99
+ tags: ["00080020", "00080030"],
100
+ pos: "tr",
101
+ format: "{v0} {v1}"
102
+ },
103
+ {
104
+ tags: ["00080060"],
105
+ pos: "tr"
106
+ },
107
+ {
108
+ event: "wlchange",
109
+ pos: "bl",
110
+ format: "WC: {v0}",
111
+ precision: "round"
112
+ },
113
+ {
114
+ event: "wlchange",
115
+ pos: "bl",
116
+ format: "WW: {v1}",
117
+ precision: "round"
118
+ },
119
+ {
120
+ event: "zoomchange",
121
+ pos: "br",
122
+ format: "Z: {v0}",
123
+ precision: "3"
124
+ },
125
+ {
126
+ event: "offsetchange",
127
+ pos: "br",
128
+ format: "Off: {v0},{v1}",
129
+ precision: "round"
130
+ },
131
+ {
132
+ event: "positionchange",
133
+ pos: "br",
134
+ format: "Pos: {v0}"
135
+ },
136
+ {
137
+ event: "positionchange",
138
+ pos: "br",
139
+ format: "Value: {v2}"
140
+ }
141
+ ]
142
+ }, Ve = [
143
+ "dataadd",
144
+ "dataremove",
145
+ "drawlayeradd",
146
+ "annotationadd",
147
+ "annotationupdate",
148
+ "annotationremove",
149
+ "annotationselect",
150
+ "tap"
151
+ ], He = class extends EventTarget {
152
+ #e = [
153
+ "Ruler",
154
+ "Arrow",
155
+ "Rectangle",
156
+ "Circle",
157
+ "Ellipse",
158
+ "Protractor",
159
+ "Roi"
160
+ ];
161
+ #t = {
162
+ Scroll: new L(),
163
+ ZoomAndPan: new L(),
164
+ WindowLevel: new L(),
165
+ Draw: new L(this.#e)
166
+ };
167
+ #n = Object.keys(this.#t);
168
+ #r = !1;
169
+ #i = !1;
170
+ #a;
171
+ #o;
172
+ #s;
173
+ #c = new P();
174
+ #l;
175
+ #u = [];
176
+ #d;
177
+ constructor(e) {
178
+ if (super(), !e) throw Error("A viewer id is required.");
179
+ this.#o = e, this.#s = this.getElementId("layerGroup");
180
+ let t = { "*": [new oe(this.#s)] }, n = new F(t);
181
+ n.tools = this.#t, n.overlayConfig = Be, this.#c.init(n), this.#m(), this.#h();
182
+ }
183
+ getViewerId() {
184
+ return this.#o;
185
+ }
186
+ getElementId(e) {
187
+ return `${this.#o}-${e}`;
188
+ }
189
+ getDwvVersion() {
190
+ return ce();
191
+ }
192
+ getToolNames() {
193
+ return this.#n;
194
+ }
195
+ getShapeNames() {
196
+ return this.#e;
197
+ }
198
+ getMetaData() {
199
+ return this.#l;
200
+ }
201
+ #f(e, t) {
202
+ this.dispatchEvent(new CustomEvent(e, { detail: t }));
203
+ }
204
+ #p(e) {
205
+ this.#u = e, this.#f("presetnames", { value: e });
206
+ }
207
+ #m() {
208
+ let e = [], t = 0, n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
209
+ this.#c.addEventListener("loadstart", (i) => {
210
+ this.#d === void 0 && (this.#f("dataready", { value: !1 }), this.#f("dataloaded", { value: !1 })), e = [], t = 0, n.add(i.detail.dataid), r.add(i.detail.dataid);
211
+ }), this.#c.addEventListener("loadprogress", (e) => {
212
+ this.#f("loadprogress", { value: e.detail.loaded });
213
+ }), this.#c.addEventListener("renderend", (e) => {
214
+ if (n.has(e.detail.dataid)) {
215
+ n.delete(e.detail.dataid), this.#d = e.detail.dataid;
216
+ let t = this.#c.getStageController().getViewLayersByDataId(e.detail.dataid)[0].getViewController();
217
+ this.#r = t.canScroll(), this.#i = t.isMonochrome(), this.#p(t.getWindowLevelPresetsNames()), this.#f("dataready", { value: !0 });
218
+ }
219
+ }), this.#c.addEventListener("load", (e) => {
220
+ if (e.detail.dataid === this.#d) {
221
+ this.#l = structuredClone(this.#c.getDataController().get(e.detail.dataid).meta);
222
+ let t = "7FE00010";
223
+ this.#l[t] !== void 0 && delete this.#l[t];
224
+ }
225
+ this.#f("loadprogress", { value: 100 }), this.#f("dataloaded", { value: this.#d !== void 0 });
226
+ }), this.#c.addEventListener("loadend", (i) => {
227
+ if (n.delete(i.detail.dataid), r.delete(i.detail.dataid), e.length !== 0) {
228
+ this.#f("loadprogress", { value: 0 });
229
+ let t = "Load error: " + e[0];
230
+ e.length > 1 && (t += " (+" + (e.length - 1) + " more, check log for details)"), this.#f("error", { value: t }), e = [];
231
+ }
232
+ t &&= (this.#f("loadprogress", { value: 0 }), this.#f("error", { value: "Load was aborted." }), 0);
233
+ });
234
+ let i = (t) => {
235
+ console.error(t.detail.error);
236
+ let n = t.detail.error?.message ?? String(t.detail.error);
237
+ r.size === 0 ? this.#f("error", { value: n }) : e.push(n);
238
+ };
239
+ this.#c.addEventListener("loaderror", i), this.#c.addEventListener("error", i);
240
+ let a = () => {
241
+ ++t;
242
+ };
243
+ this.#c.addEventListener("loadabort", a), this.#c.addEventListener("abort", a);
244
+ }
245
+ #h() {
246
+ this.#c.addEventListener("wlchange", (e) => {
247
+ let t = "manual";
248
+ e.detail.value[2] === t ? (this.#u.includes(t) || this.#p([...this.#u, t]), this.#f("ismanualpreset", { value: !0 })) : this.#f("ismanualpreset", { value: !1 });
249
+ }), this.#c.addEventListener("keydown", (e) => {
250
+ this.#c.defaultOnKeydown(e.detail);
251
+ });
252
+ for (let e of Ve) this.#c.addEventListener(e, (t) => {
253
+ this.#f(e, { ...t.detail });
254
+ });
255
+ }
256
+ getMainLayerGroupDivId() {
257
+ return this.#s;
258
+ }
259
+ getLayerGroupByDivId(e) {
260
+ return this.#c.getStageController().getLayerGroupByDivId(e);
261
+ }
262
+ getDrawLayersByDataId(e) {
263
+ return this.#c.getStageController().getDrawLayersByDataId(e);
264
+ }
265
+ getData(e) {
266
+ return this.#c.getDataController().get(e);
267
+ }
268
+ addToUndoStack = (e) => {
269
+ this.#c.getUndoController().addToUndoStack(e);
270
+ };
271
+ createAnnotationData(e) {
272
+ return this.#c.createAnnotationData(e);
273
+ }
274
+ addAndRenderAnnotationData(e, t, n) {
275
+ this.#c.addAndRenderAnnotationData(e, t, n);
276
+ }
277
+ connect() {
278
+ window.addEventListener("resize", this.#c.onResize);
279
+ }
280
+ disconnect() {
281
+ window.removeEventListener("resize", this.#c.onResize);
282
+ }
283
+ resize() {
284
+ this.#c.onResize();
285
+ }
286
+ loadURLs(e) {
287
+ this.#c.loadURLs(e);
288
+ }
289
+ loadFromUri(e) {
290
+ let t = de(e);
291
+ t && t.length !== 0 && this.#c.loadURLs(t);
292
+ }
293
+ loadFiles(e) {
294
+ this.#c.loadFiles(e);
295
+ }
296
+ canRunTool(e) {
297
+ let t;
298
+ return e === "Scroll" ? t = this.#r : e === "WindowLevel" ? t = this.#i : this.#n.includes(e) ? t = !0 : console.log("Unknwon tool", e), t;
299
+ }
300
+ getFirstRunnableTool() {
301
+ return this.#n.find((e) => this.canRunTool(e));
302
+ }
303
+ applyTool(e, t) {
304
+ this.#c.setTool(e), t !== void 0 && this.#c.setToolFeatures(t);
305
+ let n = this.#c.getStageController().getActiveLayerGroup();
306
+ if (n !== void 0) {
307
+ if (e === "Draw") {
308
+ let e = n.getDrawLayers();
309
+ e.length === 0 ? this.#d !== void 0 && n.setActiveLayerByDataId(this.#d) : n.setActiveLayerByDataId(e.at(-1).getDataId());
310
+ } else this.#d !== void 0 && n.setActiveLayerByDataId(this.#d);
311
+ }
312
+ }
313
+ applyPreset(e) {
314
+ this.#d !== void 0 && this.#c.getStageController().getViewLayersByDataId(this.#d)[0]?.getViewController().setWindowLevelPreset(e);
315
+ }
316
+ toggleOrientation() {
317
+ this.#a === void 0 || this.#a === "axial" ? this.#a = "coronal" : this.#a === "coronal" ? this.#a = "sagittal" : this.#a === "sagittal" && (this.#a = "axial");
318
+ let e = new oe(this.#s);
319
+ e.orientation = this.#a;
320
+ let t = { "*": [e] }, n = this.#c.getStageController();
321
+ n.setDataViewConfigs(t);
322
+ let r = this.#c.getDataController().getDataIds();
323
+ for (let e of r) n.render(e);
324
+ }
325
+ reset() {
326
+ this.#c.getStageController().resetZoomPan();
327
+ }
328
+ }, U = e(), Ue = ({ children: e }) => {
329
+ let t = a(), [n] = c(() => new He(t));
330
+ return i(() => (n.connect(), () => {
331
+ n.disconnect();
332
+ }), [n]), /* @__PURE__ */ z(U.Provider, {
333
+ value: n,
334
+ children: e
335
+ });
336
+ }, W = () => r(U), G = () => {
337
+ let e = W();
338
+ return n((t) => e.getElementId(t), [e]);
339
+ };
340
+ // src/services/AnnotationService.js
341
+ function K(e, t) {
342
+ return {
343
+ id: e.trackingUid,
344
+ label: e.trackingId,
345
+ colour: e.colour,
346
+ factoryName: e.getFactory()?.getName() ?? "unknown",
347
+ canView: e.canView(),
348
+ visible: t,
349
+ quantification: e.quantification
350
+ };
351
+ }
352
+ var We = class {
353
+ #e;
354
+ #t = /* @__PURE__ */ new Map();
355
+ #n = /* @__PURE__ */ new Map();
356
+ #r;
357
+ #i = {
358
+ groups: [],
359
+ selected: void 0
360
+ };
361
+ #a = /* @__PURE__ */ new Set();
362
+ #o = {
363
+ dataadd: (e) => this.#p(e),
364
+ dataremove: (e) => this.#m(e),
365
+ drawlayeradd: (e) => this.#h(e),
366
+ annotationadd: (e) => this.#g(e),
367
+ annotationupdate: (e) => this.#_(e),
368
+ annotationremove: (e) => this.#v(e),
369
+ annotationselect: (e) => this.#y(e),
370
+ tap: (e) => this.#b(e)
371
+ };
372
+ constructor(e) {
373
+ this.#e = e;
374
+ }
375
+ getSnapshot = () => this.#i;
376
+ subscribe = (e) => (this.#a.add(e), () => {
377
+ this.#a.delete(e);
378
+ });
379
+ connect() {
380
+ for (let [e, t] of Object.entries(this.#o)) this.#e.addEventListener(e, t);
381
+ for (let e of this.#t.keys()) {
382
+ let t = this.#s(e);
383
+ t !== void 0 && this.#d(e, t);
384
+ }
385
+ }
386
+ dispose() {
387
+ for (let [e, t] of Object.entries(this.#o)) this.#e.removeEventListener(e, t);
388
+ for (let e of Array.from(this.#n.keys())) this.#f(e);
389
+ }
390
+ getDefaultGroupReference() {
391
+ let e = this.#e.getMainLayerGroupDivId(), t = this.#e.getLayerGroupByDivId(e)?.getActiveViewLayer();
392
+ if (t !== void 0) return {
393
+ refDataId: t.getDataId(),
394
+ divId: e
395
+ };
396
+ }
397
+ addAnnotationGroup(e, t) {
398
+ if (e === void 0 || t === void 0) {
399
+ let n = this.getDefaultGroupReference();
400
+ if (n === void 0) return R.warn("No active view layer to annotate"), !1;
401
+ e ??= n.refDataId, t ??= n.divId;
402
+ }
403
+ let n = this.#e.createAnnotationData(e);
404
+ return this.#e.addAndRenderAnnotationData(n, t, e), !0;
405
+ }
406
+ changeAnnotationColour(e, t, n) {
407
+ let r = this.#s(e), i = r?.find(t);
408
+ i !== void 0 && n !== i.colour && new I(r).updateAnnotationWithCommand(t, { colour: i.colour }, { colour: n }, this.#e.addToUndoStack);
409
+ }
410
+ deleteAnnotation(e, t) {
411
+ let n = this.#s(e);
412
+ n !== void 0 && new I(n).removeAnnotationWithCommand(t, this.#e.addToUndoStack);
413
+ }
414
+ setAnnotationVisibility(e, t, n) {
415
+ let r = this.#e.getDrawLayersByDataId(e);
416
+ for (let e of r) e.setAnnotationVisibility(t, n);
417
+ this.#u(e, t, (e) => ({
418
+ ...e,
419
+ visible: n
420
+ }));
421
+ }
422
+ setLabelsVisibility(e, t) {
423
+ let n = this.#e.getDrawLayersByDataId(e)[0];
424
+ return n === void 0 ? (R.warn(`Cannot find draw layer with id ${e}`), !1) : (n.setLabelsVisibility(t), this.#l(e, (e) => ({
425
+ ...e,
426
+ labelsVisible: t
427
+ })), !0);
428
+ }
429
+ setAnnotationGroupEditable(e, t) {
430
+ this.#s(e)?.setEditable(t);
431
+ }
432
+ gotoAnnotation(e, t) {
433
+ let n = (this.#s(e)?.find(t))?.getCentroid();
434
+ if (n === void 0) {
435
+ R.warn("No centroid for annotation");
436
+ return;
437
+ }
438
+ let r = this.#e.getDrawLayersByDataId(e);
439
+ for (let e of r) e.setCurrentPosition(n), e.highlightAnnotation(t);
440
+ }
441
+ selectAnnotation(e, t) {
442
+ return this.#t.get(e)?.annotations.some((e) => e.id === t) ? ((this.#r?.dataId !== e || this.#r?.annotationId !== t) && (this.#r = {
443
+ dataId: e,
444
+ annotationId: t
445
+ }, this.#c()), !0) : !1;
446
+ }
447
+ clearSelection() {
448
+ this.#r !== void 0 && (this.#r = void 0, this.#c());
449
+ }
450
+ getAnnotationGroupAsDicom(e) {
451
+ let t = this.#s(e);
452
+ if (t === void 0) throw Error(`Cannot find annotation group with id ${e}`);
453
+ let n = new N(), r = ue("SOPInstanceUID"), i = {
454
+ MediaStorageSOPInstanceUID: r,
455
+ SOPInstanceUID: r,
456
+ InstanceNumber: 123,
457
+ SeriesInstanceUID: ue("SeriesInstanceUID"),
458
+ SeriesNumber: 123,
459
+ SeriesDescription: "Annnotation made with dwv"
460
+ }, a = n.toDicom(t, i), o = new ae().getBuffer(a);
461
+ return new Blob([o], { type: "application/dicom" });
462
+ }
463
+ #s(e) {
464
+ return this.#e.getData(e)?.annotationGroup;
465
+ }
466
+ #c() {
467
+ this.#i = {
468
+ groups: Array.from(this.#t.values()),
469
+ selected: this.#r
470
+ };
471
+ for (let e of this.#a) e();
472
+ }
473
+ #l(e, t) {
474
+ let n = this.#t.get(e);
475
+ n !== void 0 && (this.#t.set(e, t(n)), this.#c());
476
+ }
477
+ #u(e, t, n) {
478
+ this.#l(e, (e) => ({
479
+ ...e,
480
+ annotations: e.annotations.map((e) => e.id === t ? n(e) : e)
481
+ }));
482
+ }
483
+ #d(e, t) {
484
+ if (this.#n.has(e)) return;
485
+ let n = (t) => {
486
+ this.#l(e, (e) => ({
487
+ ...e,
488
+ editable: t.detail.data
489
+ }));
490
+ };
491
+ t.addEventListener("annotationgroupeditablechange", n), this.#n.set(e, n);
492
+ }
493
+ #f(e) {
494
+ let t = this.#n.get(e);
495
+ t !== void 0 && (this.#s(e)?.removeEventListener("annotationgroupeditablechange", t), this.#n.delete(e));
496
+ }
497
+ #p(e) {
498
+ let t = e.detail.dataid, n = this.#s(t);
499
+ n !== void 0 && (this.#d(t, n), this.#t.set(t, {
500
+ dataId: t,
501
+ editable: n.isEditable(),
502
+ labelsVisible: !0,
503
+ annotations: n.getList().map((e) => K(e, !0))
504
+ }), this.#c());
505
+ }
506
+ #m(e) {
507
+ let t = e.detail.dataid;
508
+ this.#t.has(t) && (this.#f(t), this.#t.delete(t), this.#r?.dataId === t && (this.#r = void 0), this.#c());
509
+ }
510
+ #h(e) {
511
+ let t = e.detail.dataid, n = this.#s(t);
512
+ n !== void 0 && this.#l(t, (e) => ({
513
+ ...e,
514
+ annotations: n.getList().map((t) => K(t, e.annotations.find((e) => e.id === t.trackingUid)?.visible ?? !0))
515
+ }));
516
+ }
517
+ #g(e) {
518
+ let t = e.detail.data;
519
+ this.#r = void 0, this.#l(e.detail.dataid, (e) => ({
520
+ ...e,
521
+ annotations: [...e.annotations, K(t, !0)]
522
+ }));
523
+ }
524
+ #_(e) {
525
+ let t = e.detail.data;
526
+ this.#u(e.detail.dataid, t.trackingUid, (e) => K(t, e.visible));
527
+ }
528
+ #v(e) {
529
+ let t = e.detail.dataid, n = e.detail.data.trackingUid;
530
+ this.#r?.dataId === t && this.#r?.annotationId === n && (this.#r = void 0), this.#l(t, (e) => ({
531
+ ...e,
532
+ annotations: e.annotations.filter((e) => e.id !== n)
533
+ }));
534
+ }
535
+ #y(e) {
536
+ this.selectAnnotation(e.detail.dataid, e.detail.annotationid);
537
+ }
538
+ #b(e) {
539
+ let t = e.detail.annotations?.[0];
540
+ t !== void 0 && this.selectAnnotation(t.dataid, t.annotationid) || this.clearSelection();
541
+ }
542
+ }, q = e(), Ge = ({ children: e }) => {
543
+ let t = W(), [n] = c(() => new We(t));
544
+ return i(() => (n.connect(), () => {
545
+ n.dispose();
546
+ }), [n]), /* @__PURE__ */ z(q.Provider, {
547
+ value: n,
548
+ children: e
549
+ });
550
+ }, J = () => r(q), Ke = () => {
551
+ let e = J();
552
+ return l(e.subscribe, e.getSnapshot);
553
+ }, qe = "mergeId", Je = (e) => {
554
+ let t = e[qe];
555
+ return Array.isArray(t) ? [...t].sort((e, t) => e.localeCompare(t, void 0, { numeric: !0 })) : [];
556
+ }, Y = (e, t) => t !== void 0 && typeof e == "object" && e && !Array.isArray(e) && !ArrayBuffer.isView(e) && e[t] !== void 0 ? e[t] : e, Ye = (e) => e["00020010"] !== void 0, Xe = (e, t) => (n, r) => (n.push({
557
+ name: r,
558
+ value: Y(e[r].value, t)
559
+ }), n), Ze = (e, t, n) => (r, i) => {
560
+ let a = le(i), o = se(a)?.getName();
561
+ o === void 0 && (o = "x" + a.getKey());
562
+ let s = e[i], c = Y(s.value, t), l = (n ? n + " " : "") + o;
563
+ if (s.vr === "SQ") {
564
+ r.push({
565
+ name: l,
566
+ value: ""
567
+ });
568
+ for (let e = 0; e < c.length; ++e) {
569
+ let i = c[e], a = Object.keys(i).reduce(Ze(i, t, n + "[" + e + "]"), []);
570
+ r = r.concat(a);
571
+ }
572
+ } else s.vr[0] === "O" && c.length > 10 && (c = c.slice(0, 10).toString() + "... (len:" + c.length + ")"), r.push({
573
+ name: l,
574
+ value: c.toString()
575
+ });
576
+ return r;
577
+ }, Qe = (e, t) => {
578
+ let n = Ye(e) ? Ze(e, t, "") : Xe(e, t);
579
+ return Object.keys(e).filter((e) => e !== qe).reduce(n, []);
580
+ }, $e = (e, t) => {
581
+ let n = e["00200013"];
582
+ if (n === void 0) return "";
583
+ let r = Y(n.value, t);
584
+ return String(Array.isArray(r) ? r[0] : r);
585
+ }, et = (e, t) => {
586
+ let n = t.toLowerCase();
587
+ return e.filter((e) => Object.values(e).some((e) => e !== void 0 && String(e).toLowerCase().includes(n)));
588
+ }, tt = ({ data: e }) => {
589
+ let t = o(() => Je(e), [e]), [n, r] = c(0), [i, a] = c(""), s = t[n], l = $e(e, s), u = o(() => et(Qe(e, s), i), [
590
+ e,
591
+ s,
592
+ i
593
+ ]);
594
+ return /* @__PURE__ */ B(h, {
595
+ sx: {
596
+ padding: "10px",
597
+ overflow: "hidden"
598
+ },
599
+ children: [/* @__PURE__ */ B(E, {
600
+ direction: "row",
601
+ spacing: 2,
602
+ children: [/* @__PURE__ */ z(re, {
603
+ type: "search",
604
+ value: i,
605
+ sx: { width: "45%" },
606
+ onChange: (e) => a(e.target.value),
607
+ margin: "normal",
608
+ size: "small",
609
+ slotProps: { input: { startAdornment: /* @__PURE__ */ z(x, {
610
+ position: "start",
611
+ children: /* @__PURE__ */ z(V, {})
612
+ }) } }
613
+ }), /* @__PURE__ */ B(h, {
614
+ sx: {
615
+ width: 300,
616
+ display: "flex",
617
+ alignItems: "center"
618
+ },
619
+ children: [/* @__PURE__ */ z(w, {
620
+ title: "Instance number",
621
+ sx: { margin: "20px" },
622
+ marks: !0,
623
+ min: 0,
624
+ max: Math.max(t.length - 1, 0),
625
+ value: n,
626
+ onChange: (e, t) => r(t)
627
+ }), /* @__PURE__ */ z("div", {
628
+ title: "Instance number",
629
+ children: l
630
+ })]
631
+ })]
632
+ }), /* @__PURE__ */ z(C, {
633
+ sx: {
634
+ width: "100%",
635
+ overflow: "hidden"
636
+ },
637
+ children: /* @__PURE__ */ z(A, {
638
+ sx: { maxHeight: 400 },
639
+ children: /* @__PURE__ */ B(D, {
640
+ stickyHeader: !0,
641
+ children: [/* @__PURE__ */ z(ne, { children: /* @__PURE__ */ B(j, { children: [/* @__PURE__ */ z(k, { children: "Tag" }), /* @__PURE__ */ z(k, { children: "Value" })] }) }), /* @__PURE__ */ z(O, { children: u.map((e, t) => /* @__PURE__ */ B(j, { children: [/* @__PURE__ */ z(k, { children: e.name }), /* @__PURE__ */ z(k, { children: e.value })] }, t)) })]
642
+ })
643
+ })
644
+ })]
645
+ });
646
+ }, nt = {
647
+ ruler: me,
648
+ arrow: he,
649
+ rectangle: ge,
650
+ circle: _e,
651
+ ellipse: ve,
652
+ protractor: ye,
653
+ roi: be
654
+ }, rt = (e, t) => {
655
+ let n = nt[e?.toLowerCase()] ?? xe;
656
+ return /* @__PURE__ */ z(n, { ...t });
657
+ }, it = { appBar: "Header-appBar" }, at = f("div")({ [`& .${it.appBar}`]: { position: "relative" } }), ot = t((e, t) => /* @__PURE__ */ z(te, {
658
+ direction: "up",
659
+ ...e,
660
+ ref: t
661
+ })), st = ({ dialogContainer: e }) => {
662
+ let t = W(), [r, a] = c(0), [o, l] = c(!1), [u] = c(t.getToolNames()), [d] = c(t.getShapeNames()), [f, p] = c(""), [h, _] = c(d[0]), v = s(h), x = n((e, n) => {
663
+ n === void 0 && e === "Draw" && (n = { shapeName: v.current }), t.applyTool(e, n);
664
+ }, [t]), [S, C] = c([]), [te, w] = c(""), [T, E] = c(void 0), [D, O] = c(!1);
665
+ i(() => {
666
+ let e = (e) => {
667
+ let t = e.detail.value;
668
+ a(t);
669
+ }, n = (e) => {
670
+ if (e.detail.value) {
671
+ let e = t.getFirstRunnableTool();
672
+ e !== void 0 && (p(e), x(e));
673
+ }
674
+ }, r = (e) => {
675
+ let n = e.detail.value;
676
+ l(n), E(t.getMetaData());
677
+ }, i = (e) => {
678
+ C(e.detail.value), w(e.detail.value[0]);
679
+ }, o = (e) => {
680
+ e.detail.value && w("manual");
681
+ };
682
+ return t.addEventListener("loadprogress", e), t.addEventListener("dataready", n), t.addEventListener("dataloaded", r), t.addEventListener("presetnames", i), t.addEventListener("ismanualpreset", o), () => {
683
+ t.removeEventListener("loadprogress", e), t.removeEventListener("dataready", n), t.removeEventListener("dataloaded", r), t.removeEventListener("presetnames", i), t.removeEventListener("ismanualpreset", o);
684
+ };
685
+ }, [t, x]);
686
+ let k = (e) => {
687
+ let t;
688
+ return e === "Scroll" ? t = /* @__PURE__ */ z(we, {}) : e === "ZoomAndPan" ? t = /* @__PURE__ */ z(V, {}) : e === "WindowLevel" ? t = /* @__PURE__ */ z(Te, {}) : e === "Draw" && (t = rt(h)), t;
689
+ }, A = (e) => {
690
+ let t = e.currentTarget.value;
691
+ p(t), x(t);
692
+ }, ne = (e) => {
693
+ let t = e.currentTarget.value;
694
+ v.current = t, _(t), p("Draw"), re(t);
695
+ }, j = (e) => {
696
+ let t = e.currentTarget.value;
697
+ w(t), N(t);
698
+ }, re = (e) => {
699
+ x("Draw", { shapeName: e });
700
+ }, N = (e) => {
701
+ t.applyPreset(e);
702
+ }, P = (e) => t.canRunTool(e), F = () => {
703
+ t.toggleOrientation();
704
+ }, ae = () => {
705
+ t.reset();
706
+ }, I = () => {
707
+ O(!0);
708
+ }, L = () => {
709
+ O(!1);
710
+ };
711
+ return /* @__PURE__ */ B(at, {
712
+ className: "header",
713
+ children: [
714
+ /* @__PURE__ */ z(ee, {
715
+ variant: "determinate",
716
+ value: r,
717
+ sx: { width: "100%" }
718
+ }),
719
+ u.map((e) => {
720
+ let t = [/* @__PURE__ */ z("div", {
721
+ className: "toolbar-item",
722
+ children: /* @__PURE__ */ z(g, {
723
+ value: e,
724
+ title: e,
725
+ sx: {
726
+ padding: "6px",
727
+ minWidth: "20px"
728
+ },
729
+ variant: e === f ? "outlined" : "contained",
730
+ disabled: !o || !P(e),
731
+ onClick: A,
732
+ children: k(e)
733
+ }, e)
734
+ }, `${e}-item`)];
735
+ if (e === "WindowLevel") {
736
+ let n = e + "Select";
737
+ t.push(/* @__PURE__ */ B("div", {
738
+ className: "select-wrapper",
739
+ children: [/* @__PURE__ */ z(g, {
740
+ value: n,
741
+ title: n,
742
+ sx: {
743
+ padding: "6px",
744
+ minWidth: "20px"
745
+ },
746
+ variant: "contained",
747
+ disabled: !o || !P(e),
748
+ children: /* @__PURE__ */ z(H, {})
749
+ }, n), /* @__PURE__ */ z("select", {
750
+ value: te,
751
+ onChange: j,
752
+ children: S.map((e) => /* @__PURE__ */ z("option", {
753
+ value: e,
754
+ children: e
755
+ }, e))
756
+ }, "WindowLevelPresetsSelect")]
757
+ }, "wlselect-wrapper"));
758
+ } else if (e === "Draw") {
759
+ let n = e + "Select";
760
+ t.push(/* @__PURE__ */ B("div", {
761
+ className: "select-wrapper",
762
+ children: [/* @__PURE__ */ z(g, {
763
+ value: n,
764
+ title: n,
765
+ sx: {
766
+ padding: "6px",
767
+ minWidth: "20px"
768
+ },
769
+ variant: "contained",
770
+ disabled: !o || !P(e),
771
+ children: /* @__PURE__ */ z(H, {})
772
+ }, n), /* @__PURE__ */ z("select", {
773
+ value: h,
774
+ onChange: ne,
775
+ children: d.map((e) => /* @__PURE__ */ z("option", {
776
+ value: e,
777
+ children: e
778
+ }, e))
779
+ }, "DrawShapeSelect")]
780
+ }, "drawselect-wrapper"));
781
+ }
782
+ return t;
783
+ }),
784
+ /* @__PURE__ */ z("div", {
785
+ className: "toolbar-item",
786
+ children: /* @__PURE__ */ z(g, {
787
+ value: "reset",
788
+ title: "Reset",
789
+ variant: "contained",
790
+ sx: {
791
+ padding: "6px",
792
+ minWidth: "20px"
793
+ },
794
+ disabled: !o,
795
+ onClick: ae,
796
+ children: /* @__PURE__ */ z(Ce, {})
797
+ })
798
+ }, "reset-item"),
799
+ /* @__PURE__ */ z("div", {
800
+ className: "toolbar-item",
801
+ children: /* @__PURE__ */ z(g, {
802
+ value: "toggleOrientation",
803
+ title: "Toggle Orientation",
804
+ variant: "contained",
805
+ sx: {
806
+ padding: "6px",
807
+ minWidth: "20px"
808
+ },
809
+ disabled: !o,
810
+ onClick: F,
811
+ children: /* @__PURE__ */ z(De, {})
812
+ })
813
+ }, "orient-item"),
814
+ /* @__PURE__ */ z("div", {
815
+ className: "toolbar-item",
816
+ children: /* @__PURE__ */ z(g, {
817
+ value: "tags",
818
+ title: "Tags",
819
+ variant: "contained",
820
+ sx: {
821
+ padding: "6px",
822
+ minWidth: "20px"
823
+ },
824
+ disabled: !o,
825
+ onClick: I,
826
+ children: /* @__PURE__ */ z(Ee, {})
827
+ })
828
+ }, "tags-item"),
829
+ /* @__PURE__ */ B(y, {
830
+ open: D,
831
+ onClose: L,
832
+ container: e,
833
+ slots: { transition: ot },
834
+ children: [/* @__PURE__ */ z(m, {
835
+ className: it.appBar,
836
+ position: "sticky",
837
+ children: /* @__PURE__ */ B(ie, { children: [/* @__PURE__ */ z(b, {
838
+ color: "inherit",
839
+ onClick: L,
840
+ "aria-label": "Close",
841
+ children: /* @__PURE__ */ z(Se, {})
842
+ }), /* @__PURE__ */ z(M, {
843
+ variant: "h6",
844
+ color: "inherit",
845
+ children: "DICOM Tags"
846
+ })] })
847
+ }), /* @__PURE__ */ z(tt, { data: T })]
848
+ })
849
+ ]
850
+ });
851
+ }, X = 200, ct = 300, lt = .5, ut = 20, Z = () => Math.max(X, Math.round(window.innerWidth * lt)), dt = (e) => Math.min(Math.max(Math.round(e), X), Z()), ft = (e) => ({
852
+ backgroundColor: e.palette.background.surfaceContainer ?? d(e.palette.text.primary, .12),
853
+ borderLeft: `1px solid ${e.palette.divider}`
854
+ }), pt = f("div")(({ theme: e }) => ft(e)), mt = f("aside")(({ theme: e }) => ({
855
+ "&.open": ft(e),
856
+ "& .resizeHandle:hover, & .resizeHandle:focus-visible, &.resizing .resizeHandle": { backgroundColor: e.palette.primary.main }
857
+ })), ht = f(b)({
858
+ width: 24,
859
+ height: 24,
860
+ padding: 0,
861
+ "& .MuiSvgIcon-root": { fontSize: 18 }
862
+ }), gt = ({ children: e }) => {
863
+ let t = G()("rightPanel"), [n, r] = c(!1), [a, o] = c(ct), [l, u] = c(!1), d = s(null), f = s(!1), p = s(null);
864
+ i(() => {
865
+ f.current && (f.current = !1, d.current?.focus());
866
+ }, [n]);
867
+ let m = () => {
868
+ f.current = !0, r(!n);
869
+ }, h = (e) => {
870
+ e.button === 0 && (e.preventDefault(), e.currentTarget.setPointerCapture(e.pointerId), p.current = {
871
+ x: e.clientX,
872
+ width: a
873
+ }, u(!0));
874
+ }, g = (e) => {
875
+ let t = p.current;
876
+ t !== null && o(dt(t.width + t.x - e.clientX));
877
+ }, _ = (e) => {
878
+ p.current !== null && (e.currentTarget.releasePointerCapture(e.pointerId), p.current = null, u(!1));
879
+ }, v = (e) => {
880
+ let t;
881
+ switch (e.key) {
882
+ case "ArrowLeft":
883
+ t = a + ut;
884
+ break;
885
+ case "ArrowRight":
886
+ t = a - ut;
887
+ break;
888
+ case "Home":
889
+ t = X;
890
+ break;
891
+ case "End":
892
+ t = Z();
893
+ break;
894
+ default: return;
895
+ }
896
+ e.preventDefault(), o(dt(t));
897
+ }, y = /* @__PURE__ */ z(ht, {
898
+ ref: d,
899
+ title: n ? "Close panel" : "Open panel",
900
+ "aria-expanded": n,
901
+ "aria-controls": t,
902
+ onClick: m,
903
+ children: z(n ? ke : Oe, {})
904
+ }), b = "rightPanel";
905
+ return n && (b += " open"), l && (b += " resizing"), /* @__PURE__ */ B(pe, { children: [!n && /* @__PURE__ */ z(pt, {
906
+ className: "rightPanelToggleStrip",
907
+ children: y
908
+ }), /* @__PURE__ */ B(mt, {
909
+ id: t,
910
+ className: b,
911
+ style: { width: n ? a : 0 },
912
+ "aria-hidden": !n,
913
+ inert: !n,
914
+ children: [n && /* @__PURE__ */ z("div", {
915
+ className: "resizeHandle",
916
+ role: "separator",
917
+ tabIndex: 0,
918
+ title: "Resize panel",
919
+ "aria-label": "Resize panel",
920
+ "aria-orientation": "vertical",
921
+ "aria-controls": t,
922
+ "aria-valuenow": a,
923
+ "aria-valuemin": X,
924
+ "aria-valuemax": Z(),
925
+ onPointerDown: h,
926
+ onPointerMove: g,
927
+ onPointerUp: _,
928
+ onPointerCancel: _,
929
+ onKeyDown: v
930
+ }), /* @__PURE__ */ B("div", {
931
+ className: "rightPanelContent",
932
+ style: { width: a },
933
+ children: [/* @__PURE__ */ z("div", {
934
+ className: "rightPanelHeader",
935
+ children: n && y
936
+ }), /* @__PURE__ */ z("div", {
937
+ className: "rightPanelBody",
938
+ children: e
939
+ })]
940
+ })]
941
+ })] });
942
+ }, _t = [
943
+ "min",
944
+ "max",
945
+ "mean",
946
+ "stddev",
947
+ "median",
948
+ "p25",
949
+ "p75"
950
+ ], vt = {
951
+ stddev: "standard deviation",
952
+ surface: "area"
953
+ };
954
+ function yt(e) {
955
+ let t = vt[e.toLowerCase()];
956
+ if (t !== void 0) return t;
957
+ let n = e.match(/^p(\d+)$/);
958
+ return n === null ? e.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase() : `${n[1]}th percentile`;
959
+ }
960
+ var bt = { surface: "area" };
961
+ function xt(e) {
962
+ let t = e.toLowerCase();
963
+ return bt[t] ?? t;
964
+ }
965
+ function St(e, t) {
966
+ let n = Math.abs(e), r = 2;
967
+ n >= 100 ? r = 1 : n !== 0 && n < 1 && (r = 3);
968
+ let i = e.toFixed(r);
969
+ if (t !== void 0) {
970
+ let e = fe.t(t);
971
+ e === void 0 && (e = t), i += e === "°" ? e : ` ${e}`;
972
+ }
973
+ return i;
974
+ }
975
+ function Ct(e, t) {
976
+ if (e === void 0) return [];
977
+ let n = {
978
+ title: t?.geometry ?? "Geometry",
979
+ items: []
980
+ }, r = {
981
+ title: t?.pixelValues ?? "Pixel values",
982
+ items: []
983
+ };
984
+ for (let t of Object.keys(e)) {
985
+ let i = e[t];
986
+ if (i === void 0 || typeof i.value != "number") continue;
987
+ let a = {
988
+ label: yt(t),
989
+ shortLabel: xt(t),
990
+ value: St(i.value, i.unit)
991
+ };
992
+ _t.includes(t.toLowerCase()) ? r.items.push(a) : n.items.push(a);
993
+ }
994
+ return [n, r].filter((e) => e.items.length !== 0);
995
+ }
996
+ // src/components/AnnotationList.jsx
997
+ var wt = (e, t) => `${e}-${t}`, Tt = (e, t) => `annotationgroup${e}-annotation${t}`, Et = (e, t) => {
998
+ let n = document.createElement("a");
999
+ n.href = URL.createObjectURL(e), n.download = t, n.click(), URL.revokeObjectURL(n.href);
1000
+ }, Dt = (e, t) => e.palette.mode === "dark" ? t.light : t.dark, Q = f(b)(({ theme: e }) => ({
1001
+ width: 28,
1002
+ height: 28,
1003
+ padding: 0,
1004
+ "& .MuiSvgIcon-root": { fontSize: 18 },
1005
+ "&[aria-pressed=\"true\"]": {
1006
+ backgroundColor: d(e.palette.primary.main, e.palette.action.activatedOpacity),
1007
+ color: Dt(e, e.palette.primary)
1008
+ }
1009
+ })), Ot = f("input")(({ theme: e }) => ({
1010
+ boxSizing: "border-box",
1011
+ flex: "none",
1012
+ width: 20,
1013
+ height: 20,
1014
+ padding: 0,
1015
+ margin: "0 4px",
1016
+ border: "none",
1017
+ background: "none",
1018
+ cursor: "pointer",
1019
+ appearance: "none",
1020
+ "&:disabled": {
1021
+ cursor: "default",
1022
+ opacity: e.palette.action.disabledOpacity
1023
+ },
1024
+ "&::-webkit-color-swatch-wrapper": { padding: 0 },
1025
+ "&::-webkit-color-swatch": {
1026
+ border: `1px solid ${e.palette.divider}`,
1027
+ borderRadius: 2
1028
+ },
1029
+ "&::-moz-color-swatch": {
1030
+ border: `1px solid ${e.palette.divider}`,
1031
+ borderRadius: 2
1032
+ }
1033
+ })), kt = f("li")(({ theme: e }) => ({
1034
+ listStyle: "none",
1035
+ borderRadius: 4,
1036
+ backgroundColor: e.palette.background.paper,
1037
+ "&:hover": { backgroundImage: `linear-gradient(${d(e.palette.text.primary, .08)}, ${d(e.palette.text.primary, .08)})` },
1038
+ "&.selected": {
1039
+ backgroundColor: d(e.palette.secondary.main, e.palette.action.activatedOpacity),
1040
+ color: Dt(e, e.palette.secondary),
1041
+ ...e.applyStyles("dark", {
1042
+ backgroundColor: e.palette.primary.dark,
1043
+ color: e.palette.text.primary
1044
+ })
1045
+ }
1046
+ })), At = ({ quantification: e }) => {
1047
+ let t = Ct(e);
1048
+ return t.length === 0 ? /* @__PURE__ */ z(M, {
1049
+ variant: "caption",
1050
+ component: "div",
1051
+ sx: { fontStyle: "italic" },
1052
+ children: "No quantification"
1053
+ }) : t.map((e) => /* @__PURE__ */ B(h, {
1054
+ sx: {
1055
+ display: "flex",
1056
+ flexWrap: "wrap",
1057
+ alignItems: "baseline",
1058
+ columnGap: 1
1059
+ },
1060
+ children: [/* @__PURE__ */ z(M, {
1061
+ variant: "caption",
1062
+ component: "div",
1063
+ sx: { fontWeight: "medium" },
1064
+ children: e.title
1065
+ }), /* @__PURE__ */ z(h, {
1066
+ component: "dl",
1067
+ sx: {
1068
+ m: 0,
1069
+ display: "contents"
1070
+ },
1071
+ children: e.items.map((e) => /* @__PURE__ */ B(h, {
1072
+ title: e.label,
1073
+ sx: {
1074
+ display: "flex",
1075
+ alignItems: "baseline",
1076
+ gap: .5
1077
+ },
1078
+ children: [/* @__PURE__ */ z(M, {
1079
+ component: "dt",
1080
+ variant: "caption",
1081
+ color: "textSecondary",
1082
+ sx: {
1083
+ opacity: .7,
1084
+ fontSize: "0.9em"
1085
+ },
1086
+ children: e.shortLabel
1087
+ }), /* @__PURE__ */ z(M, {
1088
+ component: "dd",
1089
+ variant: "caption",
1090
+ sx: { m: 0 },
1091
+ children: e.value
1092
+ })]
1093
+ }, e.label))
1094
+ })]
1095
+ }, e.title));
1096
+ }, jt = ({ dataId: e, editable: t, annotation: n, selected: r, detailsOpen: a, onToggleDetails: o }) => {
1097
+ let c = J(), l = G(), u = s(null);
1098
+ i(() => {
1099
+ r && u.current?.scrollIntoView?.({ block: "nearest" });
1100
+ }, [r]);
1101
+ let d = n.id, f = Tt(e, d), p = l(f), m = l(`qd-${f}`);
1102
+ return /* @__PURE__ */ B(kt, {
1103
+ ref: u,
1104
+ id: p,
1105
+ className: r ? "selected" : void 0,
1106
+ children: [/* @__PURE__ */ B(E, {
1107
+ direction: "row",
1108
+ sx: { alignItems: "center" },
1109
+ children: [/* @__PURE__ */ B(_, {
1110
+ title: "Go to annotation",
1111
+ onClick: () => {
1112
+ c.selectAnnotation(e, d), c.gotoAnnotation(e, d);
1113
+ },
1114
+ sx: {
1115
+ flex: 1,
1116
+ minWidth: 0,
1117
+ justifyContent: "flex-start",
1118
+ gap: 1,
1119
+ pl: 1,
1120
+ py: .5,
1121
+ borderRadius: 1,
1122
+ font: "inherit",
1123
+ color: "inherit"
1124
+ },
1125
+ children: [rt(n.factoryName, { sx: {
1126
+ fontSize: 18,
1127
+ flex: "none"
1128
+ } }), /* @__PURE__ */ z(M, {
1129
+ variant: "body2",
1130
+ noWrap: !0,
1131
+ sx: n.canView ? void 0 : { textDecoration: "line-through" },
1132
+ children: n.label
1133
+ })]
1134
+ }), /* @__PURE__ */ B(E, {
1135
+ direction: "row",
1136
+ sx: {
1137
+ alignItems: "center",
1138
+ flex: "none"
1139
+ },
1140
+ children: [
1141
+ /* @__PURE__ */ z(Q, {
1142
+ title: "Show/hide quantification",
1143
+ "aria-pressed": a,
1144
+ "aria-expanded": a,
1145
+ "aria-controls": m,
1146
+ onClick: o,
1147
+ children: z(a ? Ie : Fe, {})
1148
+ }),
1149
+ /* @__PURE__ */ z(Ot, {
1150
+ type: "color",
1151
+ title: "Change annotation colour",
1152
+ value: n.colour,
1153
+ disabled: !t,
1154
+ onChange: (t) => c.changeAnnotationColour(e, d, t.target.value)
1155
+ }),
1156
+ /* @__PURE__ */ z(Q, {
1157
+ title: "Show/hide annotation",
1158
+ "aria-pressed": !n.visible,
1159
+ onClick: () => c.setAnnotationVisibility(e, d, !n.visible),
1160
+ children: n.visible ? /* @__PURE__ */ z(Le, {}) : /* @__PURE__ */ z(Re, {})
1161
+ }),
1162
+ /* @__PURE__ */ z(Q, {
1163
+ title: "Delete annotation",
1164
+ disabled: !t,
1165
+ onClick: () => c.deleteAnnotation(e, d),
1166
+ children: /* @__PURE__ */ z(ze, {})
1167
+ })
1168
+ ]
1169
+ })]
1170
+ }), /* @__PURE__ */ z(v, {
1171
+ id: m,
1172
+ in: a,
1173
+ children: /* @__PURE__ */ z(h, {
1174
+ sx: {
1175
+ pl: 1,
1176
+ pr: .5,
1177
+ pb: .5
1178
+ },
1179
+ children: /* @__PURE__ */ z(At, { quantification: n.quantification })
1180
+ })
1181
+ })]
1182
+ });
1183
+ }, Mt = ({ group: e, selected: t, openDetails: n, onToggleDetails: r, onError: i }) => {
1184
+ let a = J(), o = e.dataId;
1185
+ return /* @__PURE__ */ B(h, { children: [/* @__PURE__ */ B(E, {
1186
+ direction: "row",
1187
+ sx: {
1188
+ alignItems: "center",
1189
+ pl: 1,
1190
+ py: .5
1191
+ },
1192
+ children: [
1193
+ /* @__PURE__ */ B(M, {
1194
+ variant: "subtitle2",
1195
+ sx: { flex: 1 },
1196
+ noWrap: !0,
1197
+ children: ["group #", o]
1198
+ }),
1199
+ /* @__PURE__ */ z(Q, {
1200
+ title: e.editable ? "Lock group" : "Unlock group",
1201
+ "aria-pressed": !e.editable,
1202
+ onClick: () => a.setAnnotationGroupEditable(o, !e.editable),
1203
+ children: e.editable ? /* @__PURE__ */ z(je, {}) : /* @__PURE__ */ z(Ae, {})
1204
+ }),
1205
+ /* @__PURE__ */ z(Q, {
1206
+ title: "Save annotation group",
1207
+ onClick: () => {
1208
+ try {
1209
+ Et(a.getAnnotationGroupAsDicom(o), `dicom-sr-${o}.dcm`);
1210
+ } catch (e) {
1211
+ console.error(e), i(e.message);
1212
+ }
1213
+ },
1214
+ children: /* @__PURE__ */ z(Me, {})
1215
+ }),
1216
+ /* @__PURE__ */ z(Q, {
1217
+ title: "Show/hide annotation labels",
1218
+ "aria-pressed": !e.labelsVisible,
1219
+ onClick: () => a.setLabelsVisibility(o, !e.labelsVisible),
1220
+ children: e.labelsVisible ? /* @__PURE__ */ z(Ne, {}) : /* @__PURE__ */ z(Pe, {})
1221
+ })
1222
+ ]
1223
+ }), e.annotations.length === 0 ? /* @__PURE__ */ z(M, {
1224
+ variant: "body2",
1225
+ color: "textSecondary",
1226
+ sx: {
1227
+ pl: 1,
1228
+ py: .5,
1229
+ fontStyle: "italic"
1230
+ },
1231
+ children: "No annotation"
1232
+ }) : /* @__PURE__ */ z(E, {
1233
+ component: "ul",
1234
+ spacing: .5,
1235
+ sx: {
1236
+ m: 0,
1237
+ p: 0
1238
+ },
1239
+ children: e.annotations.map((i) => {
1240
+ let a = wt(o, i.id);
1241
+ return /* @__PURE__ */ z(jt, {
1242
+ dataId: o,
1243
+ editable: e.editable,
1244
+ annotation: i,
1245
+ selected: t?.dataId === o && t?.annotationId === i.id,
1246
+ detailsOpen: n.has(a),
1247
+ onToggleDetails: () => r(a)
1248
+ }, a);
1249
+ })
1250
+ })] });
1251
+ }, Nt = () => {
1252
+ let e = Ke(), [t, n] = c(() => /* @__PURE__ */ new Set()), [r, i] = c(void 0), a = (e) => {
1253
+ n((t) => {
1254
+ let n = new Set(t);
1255
+ return n.has(e) ? n.delete(e) : n.add(e), n;
1256
+ });
1257
+ };
1258
+ return /* @__PURE__ */ B(E, {
1259
+ spacing: 1,
1260
+ children: [r && /* @__PURE__ */ z(p, {
1261
+ severity: "warning",
1262
+ onClose: () => i(void 0),
1263
+ children: r
1264
+ }), e.groups.map((n) => /* @__PURE__ */ z(Mt, {
1265
+ group: n,
1266
+ selected: e.selected,
1267
+ openDetails: t,
1268
+ onToggleDetails: a,
1269
+ onError: i
1270
+ }, n.dataId))]
1271
+ });
1272
+ }, Pt = f("div")(), $ = (e) => {
1273
+ e.stopPropagation(), e.preventDefault();
1274
+ }, Ft = () => {
1275
+ let e = W(), [t, n] = c(0), [r, a] = c(!1), [o, l] = c(!1), u = s(null);
1276
+ i(() => {
1277
+ let t = u.current;
1278
+ if (!t || typeof ResizeObserver > "u") return;
1279
+ let n = !0, r = new ResizeObserver(() => {
1280
+ n ? n = !1 : e.resize();
1281
+ });
1282
+ return r.observe(t), () => {
1283
+ r.disconnect();
1284
+ };
1285
+ }, [e]), i(() => {
1286
+ let t = (e) => {
1287
+ n(e.detail.value);
1288
+ }, r = (e) => {
1289
+ a(e.detail.value);
1290
+ };
1291
+ return e.addEventListener("loadprogress", t), e.addEventListener("dataloaded", r), () => {
1292
+ e.removeEventListener("loadprogress", t), e.removeEventListener("dataloaded", r);
1293
+ };
1294
+ }, [e]);
1295
+ let d = (t === 0 || t === 100) && !r, f = (e) => {
1296
+ $(e), l(!0);
1297
+ }, p = (e) => {
1298
+ $(e), l(!1);
1299
+ }, m = (t) => {
1300
+ $(t), l(!1), e.loadFiles(t.dataTransfer.files);
1301
+ }, h = (t) => {
1302
+ t.target && t.target.files && e.loadFiles(t.target.files);
1303
+ }, g = "dropBox dropBoxBorder" + (o ? " hover" : "");
1304
+ return /* @__PURE__ */ B(Pt, {
1305
+ className: "content",
1306
+ children: [/* @__PURE__ */ z("div", {
1307
+ id: e.getMainLayerGroupDivId(),
1308
+ className: "layerGroup",
1309
+ ref: u,
1310
+ onDragOver: $,
1311
+ onDragLeave: $,
1312
+ onDrop: m,
1313
+ children: /* @__PURE__ */ z("div", {
1314
+ className: g,
1315
+ style: { display: d ? "initial" : "none" },
1316
+ onDragOver: f,
1317
+ onDragLeave: p,
1318
+ onDrop: m,
1319
+ children: /* @__PURE__ */ B("p", { children: ["Drag and drop data here or", /* @__PURE__ */ B("label", { children: [/* @__PURE__ */ z("a", {
1320
+ className: "inputFileLink",
1321
+ children: " click here"
1322
+ }), /* @__PURE__ */ z("input", {
1323
+ type: "file",
1324
+ multiple: !0,
1325
+ onChange: h,
1326
+ style: { display: "none" }
1327
+ })] })] })
1328
+ })
1329
+ }), /* @__PURE__ */ z(gt, { children: /* @__PURE__ */ z(Nt, {}) })]
1330
+ });
1331
+ }, It = f("div")(), Lt = () => {
1332
+ let e = {
1333
+ dwv: W().getDwvVersion(),
1334
+ react: u
1335
+ };
1336
+ return /* @__PURE__ */ z(It, {
1337
+ className: "footer",
1338
+ children: /* @__PURE__ */ z("p", {
1339
+ className: "legend",
1340
+ children: /* @__PURE__ */ B(M, {
1341
+ variant: "caption",
1342
+ children: [
1343
+ "Powered by ",
1344
+ /* @__PURE__ */ z(S, {
1345
+ href: "https://github.com/ivmartel/dwv",
1346
+ title: "dwv on github",
1347
+ color: "inherit",
1348
+ children: "dwv"
1349
+ }),
1350
+ " ",
1351
+ e.dwv,
1352
+ " and ",
1353
+ /* @__PURE__ */ z(S, {
1354
+ href: "https://github.com/facebook/react",
1355
+ title: "react on github",
1356
+ color: "inherit",
1357
+ children: "React"
1358
+ }),
1359
+ " ",
1360
+ e.react
1361
+ ]
1362
+ })
1363
+ })
1364
+ });
1365
+ }, Rt = f("div")(), zt = (e) => e ? e.split(/\s+/).filter((e) => e) : [], Bt = ({ uri: e, urls: t, loadFromWindowLocation: n = !1, showLegend: r = !1 }) => {
1366
+ let a = W(), [o, l] = c(void 0), u = zt(t).join(" "), d = s(null), f = s(void 0);
1367
+ i(() => {
1368
+ let t = u ? u.split(" ") : [];
1369
+ f.current === void 0 ? (f.current = {
1370
+ uri: e,
1371
+ urlsKey: u
1372
+ }, e ? a.loadFromUri(e) : t.length === 0 ? n && window.location.search && a.loadFromUri(window.location.href) : a.loadURLs(t)) : (e !== f.current.uri && (f.current.uri = e, e && a.loadFromUri(e)), u !== f.current.urlsKey && (f.current.urlsKey = u, t.length !== 0 && a.loadURLs(t)));
1373
+ }, [
1374
+ a,
1375
+ e,
1376
+ u,
1377
+ n
1378
+ ]), i(() => {
1379
+ let e = (e) => {
1380
+ l(e.detail.value);
1381
+ };
1382
+ return a.addEventListener("error", e), () => {
1383
+ a.removeEventListener("error", e);
1384
+ };
1385
+ }, [a]);
1386
+ let m = (e, t) => {
1387
+ t !== "clickaway" && l(void 0);
1388
+ };
1389
+ return /* @__PURE__ */ B(Rt, {
1390
+ className: "dwv",
1391
+ ref: d,
1392
+ children: [
1393
+ /* @__PURE__ */ z(st, { dialogContainer: () => d.current }),
1394
+ /* @__PURE__ */ z(Ft, { className: "content" }),
1395
+ r && /* @__PURE__ */ z(Lt, {}),
1396
+ /* @__PURE__ */ z(T, {
1397
+ open: o !== void 0,
1398
+ autoHideDuration: 6e3,
1399
+ onClose: m,
1400
+ anchorOrigin: {
1401
+ vertical: "bottom",
1402
+ horizontal: "center"
1403
+ },
1404
+ children: /* @__PURE__ */ z(p, {
1405
+ severity: "error",
1406
+ variant: "filled",
1407
+ onClose: m,
1408
+ children: o
1409
+ })
1410
+ })
1411
+ ]
1412
+ });
1413
+ }, Vt = (e) => /* @__PURE__ */ z(Ue, { children: /* @__PURE__ */ z(Ge, { children: /* @__PURE__ */ z(Bt, { ...e }) }) });
1414
+ export { Vt as DwvViewer };
1415
+
1416
+ //# sourceMappingURL=index.js.map