@cornerstonejs/core 4.17.2 → 4.17.4

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.
@@ -131,15 +131,39 @@ class ContextPoolRenderingEngine extends BaseRenderingEngine {
131
131
  }
132
132
  }
133
133
  _resizeVTKViewports(vtkDrivenViewports, keepCamera = true, immediate = true) {
134
- const canvasesDrivenByVtkJs = vtkDrivenViewports.map((vp) => {
135
- return getOrCreateCanvas(vp.element);
136
- });
137
- canvasesDrivenByVtkJs.forEach((canvas) => {
138
- const devicePixelRatio = window.devicePixelRatio || 1;
139
- canvas.width = canvas.clientWidth * devicePixelRatio;
140
- canvas.height = canvas.clientHeight * devicePixelRatio;
141
- });
142
- if (canvasesDrivenByVtkJs.length) {
134
+ const devicePixelRatio = window.devicePixelRatio || 1;
135
+ const viewportsNeedingResize = [];
136
+ for (const vp of vtkDrivenViewports) {
137
+ const canvas = getOrCreateCanvas(vp.element);
138
+ const displayedWidth = Math.round(canvas.clientWidth * devicePixelRatio);
139
+ const displayedHeight = Math.round(canvas.clientHeight * devicePixelRatio);
140
+ if (displayedWidth === 0 || displayedHeight === 0) {
141
+ continue;
142
+ }
143
+ const renderedWidth = canvas.width;
144
+ const renderedHeight = canvas.height;
145
+ if (displayedWidth === renderedWidth &&
146
+ displayedHeight === renderedHeight) {
147
+ continue;
148
+ }
149
+ viewportsNeedingResize.push(vp);
150
+ }
151
+ if (viewportsNeedingResize.length === 0) {
152
+ return;
153
+ }
154
+ if (this._animationFrameSet) {
155
+ return;
156
+ }
157
+ for (const vp of viewportsNeedingResize) {
158
+ const canvas = getOrCreateCanvas(vp.element);
159
+ const displayedWidth = Math.round(canvas.clientWidth * devicePixelRatio);
160
+ const displayedHeight = Math.round(canvas.clientHeight * devicePixelRatio);
161
+ const targetWidth = Math.max(VIEWPORT_MIN_SIZE, displayedWidth);
162
+ const targetHeight = Math.max(VIEWPORT_MIN_SIZE, displayedHeight);
163
+ vp.sWidth = targetWidth;
164
+ vp.sHeight = targetHeight;
165
+ }
166
+ if (vtkDrivenViewports.length) {
143
167
  this._resize(vtkDrivenViewports);
144
168
  }
145
169
  vtkDrivenViewports.forEach((vp) => {
@@ -181,6 +205,10 @@ class ContextPoolRenderingEngine extends BaseRenderingEngine {
181
205
  return eventDetail;
182
206
  }
183
207
  _renderViewportWithContext(viewport, offscreenMultiRenderWindow, offScreenCanvasContainer) {
208
+ if (viewport.canvas.clientWidth === 0 ||
209
+ viewport.canvas.clientHeight === 0) {
210
+ return;
211
+ }
184
212
  if (viewport.sWidth < VIEWPORT_MIN_SIZE ||
185
213
  viewport.sHeight < VIEWPORT_MIN_SIZE) {
186
214
  console.warn('Viewport is too small', viewport.sWidth, viewport.sHeight);
@@ -210,8 +238,8 @@ class ContextPoolRenderingEngine extends BaseRenderingEngine {
210
238
  const renderer = offscreenMultiRenderWindow.getRenderer(viewport.id);
211
239
  const contextIndex = this.contextPool.getContextIndexForViewport(viewport.id);
212
240
  const maxSize = this.contextPool.getMaxSizeForContext(contextIndex);
213
- const viewportWidth = viewport.canvas.width;
214
- const viewportHeight = viewport.canvas.height;
241
+ const viewportWidth = viewport.sWidth;
242
+ const viewportHeight = viewport.sHeight;
215
243
  const xEnd = Math.min(1, viewportWidth / maxSize.width);
216
244
  const yEnd = Math.min(1, viewportHeight / maxSize.height);
217
245
  renderer.setViewport(0, 0, xEnd, yEnd);
@@ -245,7 +273,7 @@ class ContextPoolRenderingEngine extends BaseRenderingEngine {
245
273
  if (contextIndex === undefined) {
246
274
  return;
247
275
  }
248
- const maxSizeChanged = this.contextPool.updateViewportSize(viewport.id, viewport.canvas.width, viewport.canvas.height);
276
+ const maxSizeChanged = this.contextPool.updateViewportSize(viewport.id, viewport.sWidth, viewport.sHeight);
249
277
  if (!maxSizeChanged) {
250
278
  return;
251
279
  }
@@ -260,7 +288,14 @@ class ContextPoolRenderingEngine extends BaseRenderingEngine {
260
288
  }
261
289
  _copyToOnscreenCanvas(viewport, offScreenCanvas) {
262
290
  const { element, canvas, id: viewportId, renderingEngineId, suppressEvents, } = viewport;
263
- const { width: dWidth, height: dHeight } = canvas;
291
+ const dWidth = viewport.sWidth;
292
+ const dHeight = viewport.sHeight;
293
+ if (canvas.width !== dWidth ||
294
+ (canvas.height !== dHeight && dWidth >= 1 && dHeight >= 1)) {
295
+ canvas.width = dWidth;
296
+ canvas.height = dHeight;
297
+ canvas.style.aspectRatio = `${dWidth} / ${dHeight}`;
298
+ }
264
299
  const onScreenContext = canvas.getContext('2d');
265
300
  const contextIndex = this.contextPool.getContextIndexForViewport(viewportId);
266
301
  const maxSize = this.contextPool.getMaxSizeForContext(contextIndex);
@@ -279,10 +314,8 @@ class ContextPoolRenderingEngine extends BaseRenderingEngine {
279
314
  for (const viewport of viewportsDrivenByVtkJs) {
280
315
  viewport.sx = 0;
281
316
  viewport.sy = 0;
282
- viewport.sWidth = viewport.canvas.width;
283
- viewport.sHeight = viewport.canvas.height;
284
317
  const contextIndex = this.contextPool.getContextIndexForViewport(viewport.id);
285
- const maxSizeChanged = this.contextPool.updateViewportSize(viewport.id, viewport.canvas.width, viewport.canvas.height);
318
+ const maxSizeChanged = this.contextPool.updateViewportSize(viewport.id, viewport.sWidth, viewport.sHeight);
286
319
  if (maxSizeChanged) {
287
320
  contextsToResize.add(contextIndex);
288
321
  }
@@ -290,8 +323,8 @@ class ContextPoolRenderingEngine extends BaseRenderingEngine {
290
323
  const { context: offscreenMultiRenderWindow } = contextData;
291
324
  const renderer = offscreenMultiRenderWindow.getRenderer(viewport.id);
292
325
  const maxSize = this.contextPool.getMaxSizeForContext(contextIndex);
293
- const xEnd = Math.min(1, viewport.canvas.width / maxSize.width);
294
- const yEnd = Math.min(1, viewport.canvas.height / maxSize.height);
326
+ const xEnd = Math.min(1, viewport.sWidth / maxSize.width);
327
+ const yEnd = Math.min(1, viewport.sHeight / maxSize.height);
295
328
  renderer.setViewport(0, 0, xEnd, yEnd);
296
329
  }
297
330
  contextsToResize.forEach((contextIndex) => {
@@ -43,8 +43,11 @@ export function getOrCreateCanvas(element) {
43
43
  const devicePixelRatio = window.devicePixelRatio || 1;
44
44
  const width = Math.ceil(rect.width * devicePixelRatio);
45
45
  const height = Math.ceil(rect.height * devicePixelRatio);
46
- canvas.width = width;
47
- canvas.height = height;
46
+ if (width > 0 && height > 0) {
47
+ canvas.width = width;
48
+ canvas.height = height;
49
+ canvas.style.aspectRatio = `${width} / ${height}`;
50
+ }
48
51
  return canvas;
49
52
  }
50
53
  export default getOrCreateCanvas;
@@ -1 +1 @@
1
- export declare const version = "4.17.2";
1
+ export declare const version = "4.17.4";
@@ -1 +1 @@
1
- export const version = '4.17.2';
1
+ export const version = '4.17.4';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "4.17.2",
3
+ "version": "4.17.4",
4
4
  "description": "Cornerstone3D Core",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/esm/index.d.ts",
@@ -97,5 +97,5 @@
97
97
  "type": "individual",
98
98
  "url": "https://ohif.org/donate"
99
99
  },
100
- "gitHead": "1bf66a49411068a5351010e818f5a4ea3916434a"
100
+ "gitHead": "3664bf4622c54d790aa3684f42967448a1bddea3"
101
101
  }