@cornerstonejs/core 1.70.9 → 1.70.11
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/dist/cjs/eventTarget.d.ts +3 -0
- package/dist/cjs/eventTarget.js +31 -0
- package/dist/cjs/eventTarget.js.map +1 -1
- package/dist/cjs/init.js +19 -23
- package/dist/cjs/init.js.map +1 -1
- package/dist/esm/eventTarget.js +31 -0
- package/dist/esm/eventTarget.js.map +1 -1
- package/dist/esm/init.js +19 -23
- package/dist/esm/init.js.map +1 -1
- package/dist/types/eventTarget.d.ts +3 -0
- package/dist/types/eventTarget.d.ts.map +1 -1
- package/dist/types/init.d.ts.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +2 -2
- package/src/eventTarget.ts +59 -0
- package/src/init.ts +22 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/core",
|
|
3
|
-
"version": "1.70.
|
|
3
|
+
"version": "1.70.11",
|
|
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": "
|
|
50
|
+
"gitHead": "134a4a19a878fc7d0615403046bc74ed8564ada0"
|
|
51
51
|
}
|
package/src/eventTarget.ts
CHANGED
|
@@ -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;
|
package/src/init.ts
CHANGED
|
@@ -95,15 +95,16 @@ function _hasNorm16TextureSupport() {
|
|
|
95
95
|
return false;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
98
|
+
function isIOS() {
|
|
99
|
+
if (/iPad|iPhone|iPod/.test(navigator.platform)) {
|
|
100
|
+
return true;
|
|
101
|
+
} else {
|
|
102
|
+
return (
|
|
103
|
+
navigator.maxTouchPoints &&
|
|
104
|
+
navigator.maxTouchPoints > 2 &&
|
|
105
|
+
/MacIntel/.test(navigator.platform)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
/**
|
|
@@ -123,22 +124,18 @@ async function init(configuration = config): Promise<boolean> {
|
|
|
123
124
|
// merge configs
|
|
124
125
|
config = deepMerge(defaultConfig, configuration);
|
|
125
126
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (config.isMobile) {
|
|
127
|
+
if (isIOS()) {
|
|
129
128
|
// iOS devices don't have support for OES_texture_float_linear
|
|
130
129
|
// and thus we should use native data type if we are on iOS
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
);
|
|
141
|
-
}
|
|
130
|
+
config.rendering.useNorm16Texture = _hasNorm16TextureSupport();
|
|
131
|
+
|
|
132
|
+
if (!config.rendering.useNorm16Texture) {
|
|
133
|
+
if (configuration.rendering?.preferSizeOverAccuracy) {
|
|
134
|
+
config.rendering.preferSizeOverAccuracy = true;
|
|
135
|
+
} else {
|
|
136
|
+
console.log(
|
|
137
|
+
'norm16 texture not supported, you can turn on the preferSizeOverAccuracy flag to use native data type, but be aware of the inaccuracy of the rendering in high bits'
|
|
138
|
+
);
|
|
142
139
|
}
|
|
143
140
|
}
|
|
144
141
|
}
|
|
@@ -201,16 +198,11 @@ function setPreferSizeOverAccuracy(status: boolean): void {
|
|
|
201
198
|
* So we should not use float textures on IOS devices.
|
|
202
199
|
*/
|
|
203
200
|
function canRenderFloatTextures(): boolean {
|
|
204
|
-
|
|
205
|
-
if (!isMobile) {
|
|
201
|
+
if (!isIOS()) {
|
|
206
202
|
return true;
|
|
207
203
|
}
|
|
208
204
|
|
|
209
|
-
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return true;
|
|
205
|
+
return false;
|
|
214
206
|
}
|
|
215
207
|
|
|
216
208
|
/**
|