@cornerstonejs/core 1.70.8 → 1.70.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "1.70.8",
3
+ "version": "1.70.10",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "types": "dist/types/index.d.ts",
@@ -47,5 +47,5 @@
47
47
  "type": "individual",
48
48
  "url": "https://ohif.org/donate"
49
49
  },
50
- "gitHead": "5a76e12669c559dbfae16854f17687f6705d6397"
50
+ "gitHead": "65604450273a4e7eee6203a83863e2b9674c4263"
51
51
  }
@@ -3,13 +3,16 @@
3
3
  */
4
4
  class CornerstoneEventTarget implements EventTarget {
5
5
  private listeners;
6
+ private debouncedListeners;
6
7
 
7
8
  constructor() {
8
9
  this.listeners = {};
10
+ this.debouncedListeners = {};
9
11
  }
10
12
 
11
13
  public reset() {
12
14
  this.listeners = {};
15
+ this.debouncedListeners = {};
13
16
  }
14
17
 
15
18
  public addEventListenerOnce(type, callback) {
@@ -39,6 +42,62 @@ class CornerstoneEventTarget implements EventTarget {
39
42
  this.listeners[type].push(callback);
40
43
  }
41
44
 
45
+ /**
46
+ * Adds a debounced event listener to the event target.
47
+ *
48
+ * @param type - The type of the event to listen for.
49
+ * @param callback - The callback function to be executed when the event is triggered.
50
+ * @param delay - The delay in milliseconds before the callback is invoked after the last event.
51
+ */
52
+ public addEventListenerDebounced(type, callback, delay) {
53
+ // Ensure the dictionary for the type exists
54
+ this.debouncedListeners[type] = this.debouncedListeners[type] || {};
55
+ const debouncedCallbacks = this.debouncedListeners[type];
56
+
57
+ // Check if there's already a debounced version of this callback registered
58
+ if (!debouncedCallbacks[callback]) {
59
+ const handle = (event) => {
60
+ // Clear any existing timeout to reset the debounce timer
61
+ if (debouncedCallbacks[callback]) {
62
+ clearTimeout(debouncedCallbacks[callback].timeoutId);
63
+ }
64
+
65
+ // Set a new timeout
66
+ debouncedCallbacks[callback].timeoutId = setTimeout(() => {
67
+ callback.call(this, event);
68
+ }, delay);
69
+ };
70
+
71
+ // Store the handle and initial timeoutId (null initially)
72
+ debouncedCallbacks[callback] = {
73
+ original: callback,
74
+ handle,
75
+ timeoutId: null,
76
+ };
77
+
78
+ // Register the debounced handler
79
+ this.addEventListener(type, handle);
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Removes a debounced event listener from the event target.
85
+ *
86
+ * @param type - The type of the event.
87
+ * @param callback - The callback function to be removed.
88
+ */
89
+ public removeEventListenerDebounced(type, callback) {
90
+ if (
91
+ this.debouncedListeners[type] &&
92
+ this.debouncedListeners[type][callback]
93
+ ) {
94
+ const debounced = this.debouncedListeners[type][callback];
95
+ this.removeEventListener(type, debounced.handle);
96
+ clearTimeout(debounced.timeoutId);
97
+ delete this.debouncedListeners[type][callback];
98
+ }
99
+ }
100
+
42
101
  public removeEventListener(type, callback) {
43
102
  if (!this.listeners[type]) {
44
103
  return;
@@ -56,7 +56,7 @@ type ColormapModifiedEventDetail = {
56
56
  colormap: ColormapPublic;
57
57
  /** Unique ID for the volume in the cache */
58
58
  volumeId?: string;
59
- }
59
+ };
60
60
 
61
61
  /**
62
62
  * DISPLAY_AREA_MODIFIED Event's data
@@ -119,6 +119,10 @@ type ImageVolumeModifiedEventDetail = {
119
119
  imageVolume: IImageVolume;
120
120
  /** FrameOfReferenceUID where the volume belongs to */
121
121
  FrameOfReferenceUID: string;
122
+ /** number of frames */
123
+ numberOfFrames: number;
124
+ /** framesProcessed */
125
+ framesProcessed: number;
122
126
  };
123
127
 
124
128
  /**