@kitware/vtk.js 25.8.0 → 25.8.2

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.
@@ -1,12 +1,12 @@
1
1
  import { vtkObject } from '../../../interfaces' ;
2
2
  import { Nullable } from '../../../types';
3
- import vtkDataArray from '../../Core/DataArray';
3
+ import type vtkDataArray from '../../Core/DataArray';
4
4
 
5
5
  /**
6
6
  *
7
7
  */
8
8
  export interface IFieldDataInitialValues {
9
- arrays?: Array<any>;
9
+ arrays?: vtkDataArray[];
10
10
  copyFieldFlags?: Array<any>;
11
11
  doCopyAllOn?: boolean;
12
12
  doCopyAllOff?: boolean;
@@ -16,7 +16,7 @@ export interface IFieldDataInitialValues {
16
16
  *
17
17
  */
18
18
  interface IArrayWithIndex {
19
- array: any,
19
+ array: vtkDataArray,
20
20
  index: number;
21
21
  }
22
22
 
@@ -75,13 +75,13 @@ export interface vtkFieldData extends vtkObject {
75
75
  /**
76
76
  * Get all arrays.
77
77
  */
78
- getArrays(): any;
78
+ getArrays(): vtkDataArray[];
79
79
 
80
80
  /**
81
81
  *
82
- * @param {any} arraySpec
82
+ * @param {number | string} arraySpec index or name of the array
83
83
  */
84
- getArray(arraySpec: any): void;
84
+ getArray(arraySpec: number | string): Nullable<vtkDataArray>;
85
85
 
86
86
  /**
87
87
  * Get an array by its name.
@@ -99,7 +99,7 @@ export interface vtkFieldData extends vtkObject {
99
99
  * Get an array by its index.
100
100
  * @param {Number} idx The index of the array.
101
101
  */
102
- getArrayByIndex(idx: number): Nullable<any>;
102
+ getArrayByIndex(idx: number): Nullable<vtkDataArray>;
103
103
 
104
104
  /**
105
105
  * Return true if there exists an array with the given arraName. False otherwise.
@@ -76,12 +76,12 @@ export interface vtkWSLinkClient extends vtkObject {
76
76
  * Assign protocols to the client. Those will only be used at connect time and therefore needs to be set before being connected otherwise `registerProtocol` should be used instead.
77
77
  * @returns {Boolean} true if the set method modified the object
78
78
  */
79
- setProtocols(protocols: object): boolean;
79
+ setProtocols(protocols: Record<string, any>): boolean;
80
80
 
81
81
  /**
82
82
  * Get protocols that were either provided in `newInstance` or via its set
83
83
  */
84
- getProtocols(): object;
84
+ getProtocols(): Record<string, any>;
85
85
 
86
86
  /**
87
87
  * Update the list of methods that should be ignore from the busy state monitoring
@@ -130,7 +130,7 @@ export interface vtkWSLinkClient extends vtkObject {
130
130
  /**
131
131
  *
132
132
  */
133
- getRemote(): object;
133
+ getRemote(): Record<string, any>;
134
134
 
135
135
  /**
136
136
  *
@@ -38,16 +38,10 @@ function convert(xx, yy, pb, area) {
38
38
  }
39
39
 
40
40
  var offset = (yy * (area[2] - area[0] + 1) + xx) * 4;
41
- var rgb = [];
42
- rgb[0] = pb[offset];
43
- rgb[1] = pb[offset + 1];
44
- rgb[2] = pb[offset + 2];
45
- var val = rgb[2];
46
- val *= 256;
47
- val += rgb[1];
48
- val *= 256;
49
- val += rgb[0];
50
- return val;
41
+ var r = pb[offset];
42
+ var g = pb[offset + 1];
43
+ var b = pb[offset + 2];
44
+ return (b * 256 + g) * 256 + r;
51
45
  }
52
46
 
53
47
  function getID(low24, high8) {
@@ -271,47 +271,59 @@ function vtkWidgetManager(publicAPI, model) {
271
271
  // --------------------------------------------------------------------------
272
272
 
273
273
 
274
- function updateSelection(_x) {
274
+ function updateSelection(_x, _x2, _x3) {
275
275
  return _updateSelection.apply(this, arguments);
276
276
  }
277
277
 
278
278
  function _updateSelection() {
279
- _updateSelection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref) {
280
- var position, _yield$publicAPI$getS, requestCount, selectedState, representation, widget, i, w;
279
+ _updateSelection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(callData, fromTouchEvent, callID) {
280
+ var position, _yield$publicAPI$getS, requestCount, selectedState, representation, widget, activateHandle, i, w;
281
281
 
282
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
282
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
283
283
  while (1) {
284
- switch (_context2.prev = _context2.next) {
284
+ switch (_context3.prev = _context3.next) {
285
285
  case 0:
286
- position = _ref.position;
287
- model._selectionInProgress = true;
288
- _context2.next = 4;
286
+ activateHandle = function _activateHandle(w) {
287
+ if (fromTouchEvent) {
288
+ // release any previous left button interaction
289
+ model._interactor.invokeLeftButtonRelease(callData);
290
+ }
291
+
292
+ w.activateHandle({
293
+ selectedState: selectedState,
294
+ representation: representation
295
+ });
296
+
297
+ if (fromTouchEvent) {
298
+ // re-trigger the left button press to pick the now-active widget
299
+ model._interactor.invokeLeftButtonPress(callData);
300
+ }
301
+ };
302
+
303
+ position = callData.position;
304
+ _context3.next = 4;
289
305
  return publicAPI.getSelectedDataForXY(position.x, position.y);
290
306
 
291
307
  case 4:
292
- _yield$publicAPI$getS = _context2.sent;
308
+ _yield$publicAPI$getS = _context3.sent;
293
309
  requestCount = _yield$publicAPI$getS.requestCount;
294
310
  selectedState = _yield$publicAPI$getS.selectedState;
295
311
  representation = _yield$publicAPI$getS.representation;
296
312
  widget = _yield$publicAPI$getS.widget;
297
- model._selectionInProgress = false;
298
313
 
299
- if (!requestCount) {
300
- _context2.next = 12;
314
+ if (!(requestCount || callID !== model._currentUpdateSelectionCallID)) {
315
+ _context3.next = 11;
301
316
  break;
302
317
  }
303
318
 
304
- return _context2.abrupt("return");
319
+ return _context3.abrupt("return");
305
320
 
306
- case 12:
321
+ case 11:
307
322
  // Default cursor behavior
308
323
  model._apiSpecificRenderWindow.setCursor(widget ? 'pointer' : 'default');
309
324
 
310
325
  if (model.widgetInFocus === widget && widget.hasFocus()) {
311
- widget.activateHandle({
312
- selectedState: selectedState,
313
- representation: representation
314
- }); // Ken FIXME
326
+ activateHandle(widget); // Ken FIXME
315
327
 
316
328
  model._interactor.render();
317
329
 
@@ -321,10 +333,7 @@ function vtkWidgetManager(publicAPI, model) {
321
333
  w = model.widgets[i];
322
334
 
323
335
  if (w === widget && w.getNestedPickable()) {
324
- w.activateHandle({
325
- selectedState: selectedState,
326
- representation: representation
327
- });
336
+ activateHandle(w);
328
337
  model.activeWidget = w;
329
338
  } else {
330
339
  w.deactivateAllHandles();
@@ -337,43 +346,49 @@ function vtkWidgetManager(publicAPI, model) {
337
346
  model._interactor.render();
338
347
  }
339
348
 
340
- case 14:
349
+ case 13:
341
350
  case "end":
342
- return _context2.stop();
351
+ return _context3.stop();
343
352
  }
344
353
  }
345
- }, _callee2);
354
+ }, _callee3);
346
355
  }));
347
356
  return _updateSelection.apply(this, arguments);
348
357
  }
349
358
 
350
- var handleEvent = function handleEvent(eventName) {
351
- var guard = false;
352
- return function (callData) {
353
- if (guard || model.isAnimating || !model.pickingEnabled || model._selectionInProgress) {
354
- return macro.VOID;
355
- }
359
+ var handleEvent = /*#__PURE__*/function () {
360
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(callData) {
361
+ var fromTouchEvent,
362
+ callID,
363
+ _args = arguments;
364
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
365
+ while (1) {
366
+ switch (_context.prev = _context.next) {
367
+ case 0:
368
+ fromTouchEvent = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
356
369
 
357
- var updatePromise = updateSelection(callData);
358
- macro.measurePromiseExecution(updatePromise, function (elapsed) {
359
- // 100ms is deemed fast enough. Anything higher can degrade usability.
360
- if (elapsed > 100) {
361
- macro.vtkWarningMacro("vtkWidgetManager updateSelection() took ".concat(elapsed, "ms on ").concat(eventName));
362
- }
363
- });
364
- updatePromise.then(function () {
365
- if (model._interactor) {
366
- // re-trigger the event, ignoring our own handler
367
- guard = true;
370
+ if (!(!model.isAnimating && model.pickingEnabled)) {
371
+ _context.next = 6;
372
+ break;
373
+ }
368
374
 
369
- model._interactor["invoke".concat(eventName)](callData);
375
+ callID = Symbol('UpdateSelection');
376
+ model._currentUpdateSelectionCallID = callID;
377
+ _context.next = 6;
378
+ return updateSelection(callData, fromTouchEvent, callID);
370
379
 
371
- guard = false;
380
+ case 6:
381
+ case "end":
382
+ return _context.stop();
383
+ }
372
384
  }
373
- });
374
- return macro.EVENT_ABORT;
385
+ }, _callee);
386
+ }));
387
+
388
+ return function handleEvent(_x4) {
389
+ return _ref.apply(this, arguments);
375
390
  };
376
- };
391
+ }();
377
392
 
378
393
  function updateWidgetForRender(w) {
379
394
  w.updateRepresentationForRender(model.renderingType);
@@ -389,42 +404,42 @@ function vtkWidgetManager(publicAPI, model) {
389
404
  model.widgets.forEach(updateWidgetForRender);
390
405
  }
391
406
 
392
- function captureBuffers(_x2, _x3, _x4, _x5) {
407
+ function captureBuffers(_x5, _x6, _x7, _x8) {
393
408
  return _captureBuffers.apply(this, arguments);
394
409
  }
395
410
 
396
411
  function _captureBuffers() {
397
- _captureBuffers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(x1, y1, x2, y2) {
398
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
412
+ _captureBuffers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(x1, y1, x2, y2) {
413
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
399
414
  while (1) {
400
- switch (_context3.prev = _context3.next) {
415
+ switch (_context4.prev = _context4.next) {
401
416
  case 0:
402
417
  if (!model._captureInProgress) {
403
- _context3.next = 2;
418
+ _context4.next = 2;
404
419
  break;
405
420
  }
406
421
 
407
- return _context3.abrupt("return");
422
+ return _context4.abrupt("return");
408
423
 
409
424
  case 2:
410
425
  model._captureInProgress = true;
411
426
  renderPickingBuffer();
412
427
  model._capturedBuffers = null;
413
- _context3.next = 7;
428
+ _context4.next = 7;
414
429
  return model._selector.getSourceDataAsync(model._renderer, x1, y1, x2, y2);
415
430
 
416
431
  case 7:
417
- model._capturedBuffers = _context3.sent;
432
+ model._capturedBuffers = _context4.sent;
418
433
  model.previousSelectedData = null;
419
434
  renderFrontBuffer();
420
435
  model._captureInProgress = false;
421
436
 
422
437
  case 11:
423
438
  case "end":
424
- return _context3.stop();
439
+ return _context4.stop();
425
440
  }
426
441
  }
427
- }, _callee3);
442
+ }, _callee4);
428
443
  }));
429
444
  return _captureBuffers.apply(this, arguments);
430
445
  }
@@ -480,9 +495,21 @@ function vtkWidgetManager(publicAPI, model) {
480
495
  model.isAnimating = false;
481
496
  publicAPI.renderWidgets();
482
497
  }));
483
- subscriptions.push(model._interactor.onMouseMove(handleEvent('MouseMove')));
484
- subscriptions.push(model._interactor.onLeftButtonPress(handleEvent('LeftButtonPress'), // stay after widgets, but before default of 0
485
- WIDGET_PRIORITY / 2));
498
+ subscriptions.push(model._interactor.onMouseMove(function (eventData) {
499
+ handleEvent(eventData);
500
+ return macro.VOID;
501
+ })); // must be handled after widgets, hence the given priority.
502
+
503
+ subscriptions.push(model._interactor.onLeftButtonPress(function (eventData) {
504
+ var deviceType = eventData.deviceType;
505
+ var touchEvent = deviceType === 'touch' || deviceType === 'pen'; // only try selection if the left button press is from touch.
506
+
507
+ if (touchEvent) {
508
+ handleEvent(eventData, touchEvent);
509
+ }
510
+
511
+ return macro.VOID;
512
+ }, WIDGET_PRIORITY / 2));
486
513
  publicAPI.modified();
487
514
 
488
515
  if (model.pickingEnabled) {
@@ -564,16 +591,16 @@ function vtkWidgetManager(publicAPI, model) {
564
591
  };
565
592
 
566
593
  publicAPI.getSelectedDataForXY = /*#__PURE__*/function () {
567
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(x, y) {
594
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(x, y) {
568
595
  var i, widget, hoveredSVGReps, selection, capturedRegion;
569
- return _regeneratorRuntime.wrap(function _callee$(_context) {
596
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
570
597
  while (1) {
571
- switch (_context.prev = _context.next) {
598
+ switch (_context2.prev = _context2.next) {
572
599
  case 0:
573
600
  model.selections = null;
574
601
 
575
602
  if (!model.pickingEnabled) {
576
- _context.next = 24;
603
+ _context2.next = 24;
577
604
  break;
578
605
  }
579
606
 
@@ -581,7 +608,7 @@ function vtkWidgetManager(publicAPI, model) {
581
608
 
582
609
  case 3:
583
610
  if (!(i < model.widgets.length)) {
584
- _context.next = 16;
611
+ _context2.next = 16;
585
612
  break;
586
613
  }
587
614
 
@@ -591,7 +618,7 @@ function vtkWidgetManager(publicAPI, model) {
591
618
  });
592
619
 
593
620
  if (!hoveredSVGReps.length) {
594
- _context.next = 13;
621
+ _context2.next = 13;
595
622
  break;
596
623
  }
597
624
 
@@ -600,20 +627,20 @@ function vtkWidgetManager(publicAPI, model) {
600
627
  selection.getProperties().widget = widget;
601
628
  selection.getProperties().representation = hoveredSVGReps[0];
602
629
  model.selections = [selection];
603
- return _context.abrupt("return", publicAPI.getSelectedData());
630
+ return _context2.abrupt("return", publicAPI.getSelectedData());
604
631
 
605
632
  case 13:
606
633
  ++i;
607
- _context.next = 3;
634
+ _context2.next = 3;
608
635
  break;
609
636
 
610
637
  case 16:
611
638
  if (!(!model._capturedBuffers || model.captureOn === CaptureOn.MOUSE_MOVE)) {
612
- _context.next = 19;
639
+ _context2.next = 19;
613
640
  break;
614
641
  }
615
642
 
616
- _context.next = 19;
643
+ _context2.next = 19;
617
644
  return captureBuffers(x, y, x, y);
618
645
 
619
646
  case 19:
@@ -621,28 +648,28 @@ function vtkWidgetManager(publicAPI, model) {
621
648
  capturedRegion = model._capturedBuffers.area;
622
649
 
623
650
  if (!(x < capturedRegion[0] || x > capturedRegion[2] || y < capturedRegion[1] || y > capturedRegion[3])) {
624
- _context.next = 23;
651
+ _context2.next = 23;
625
652
  break;
626
653
  }
627
654
 
628
- _context.next = 23;
655
+ _context2.next = 23;
629
656
  return captureBuffers(x, y, x, y);
630
657
 
631
658
  case 23:
632
659
  model.selections = model._capturedBuffers.generateSelection(x, y, x, y);
633
660
 
634
661
  case 24:
635
- return _context.abrupt("return", publicAPI.getSelectedData());
662
+ return _context2.abrupt("return", publicAPI.getSelectedData());
636
663
 
637
664
  case 25:
638
665
  case "end":
639
- return _context.stop();
666
+ return _context2.stop();
640
667
  }
641
668
  }
642
- }, _callee);
669
+ }, _callee2);
643
670
  }));
644
671
 
645
- return function (_x6, _x7) {
672
+ return function (_x9, _x10) {
646
673
  return _ref2.apply(this, arguments);
647
674
  };
648
675
  }();
@@ -791,6 +818,7 @@ function vtkWidgetManager(publicAPI, model) {
791
818
  var DEFAULT_VALUES = {
792
819
  // _camera: null,
793
820
  // _selector: null,
821
+ // _currentUpdateSelectionCallID: null,
794
822
  viewId: null,
795
823
  widgets: [],
796
824
  renderer: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "25.8.0",
3
+ "version": "25.8.2",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",