@kitware/vtk.js 26.0.0-beta.1 → 26.0.0-beta.3

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.
Files changed (56) hide show
  1. package/Common/Core/ClassHierarchy.js +6 -11
  2. package/Common/Core/Math/Constants.js +12 -0
  3. package/Common/Core/Math/index.js +48 -29
  4. package/Common/Core/Math.d.ts +34 -4
  5. package/Common/Core/Math.js +2 -1
  6. package/Common/Core/MatrixBuilder.d.ts +13 -2
  7. package/Common/Core/MatrixBuilder.js +14 -2
  8. package/Common/Core/ScalarsToColors.d.ts +1 -3
  9. package/Common/Core/ScalarsToColors.js +1 -1
  10. package/Common/DataModel/BoundingBox.js +7 -7
  11. package/Common/DataModel/EdgeLocator.d.ts +79 -0
  12. package/Common/DataModel/EdgeLocator.js +85 -0
  13. package/Common/DataModel/ImageData.js +2 -50
  14. package/Common/DataModel/IncrementalOctreeNode.d.ts +15 -0
  15. package/Common/DataModel/IncrementalOctreeNode.js +27 -8
  16. package/Common/DataModel/IncrementalOctreePointLocator.js +61 -5
  17. package/Common/DataModel/Polygon.js +2 -2
  18. package/Common/Transform/Transform.js +51 -0
  19. package/Common/Transform.js +3 -1
  20. package/Filters/General/ClipClosedSurface.js +21 -18
  21. package/Filters/General/ContourTriangulator/helper.js +1 -1
  22. package/Filters/General/ImageMarchingCubes.js +5 -22
  23. package/Filters/General/ImageMarchingSquares.js +6 -23
  24. package/Filters/General.js +6 -0
  25. package/Imaging/Core/ImageReslice.js +84 -36
  26. package/Rendering/Core/ColorTransferFunction.d.ts +20 -0
  27. package/Rendering/Core/ColorTransferFunction.js +76 -7
  28. package/Rendering/Core/Prop3D.js +6 -1
  29. package/Rendering/Core/VolumeProperty.js +3 -2
  30. package/Rendering/OpenGL/PolyDataMapper.js +7 -5
  31. package/Rendering/OpenGL/RenderWindow.d.ts +25 -1
  32. package/Rendering/OpenGL/Texture.js +22 -6
  33. package/Rendering/OpenGL/VolumeMapper.js +3 -1
  34. package/Rendering/OpenGL/glsl/vtkVolumeFS.glsl.js +1 -1
  35. package/Rendering/SceneGraph/RenderWindowViewNode.js +8 -2
  36. package/Rendering/SceneGraph/ViewNode.js +11 -0
  37. package/Widgets/Core/AbstractWidget.js +1 -1
  38. package/Widgets/Core/WidgetManager.js +39 -268
  39. package/Widgets/Representations/WidgetRepresentation.js +19 -7
  40. package/Widgets/Widgets3D/EllipseWidget.js +0 -7
  41. package/Widgets/Widgets3D/LabelWidget/behavior.js +0 -7
  42. package/Widgets/Widgets3D/LabelWidget.js +1 -18
  43. package/Widgets/Widgets3D/LineWidget/behavior.js +0 -44
  44. package/Widgets/Widgets3D/LineWidget.js +0 -11
  45. package/Widgets/Widgets3D/PolyLineWidget.js +0 -10
  46. package/Widgets/Widgets3D/RectangleWidget.js +0 -7
  47. package/Widgets/Widgets3D/ShapeWidget.js +1 -1
  48. package/index.d.ts +1 -0
  49. package/macros.d.ts +5 -3
  50. package/macros.js +41 -8
  51. package/package.json +4 -1
  52. package/Filters/General/ClipClosedSurface/ccsEdgeLocator.js +0 -40
  53. package/Widgets/Core/WidgetManager/vdom.js +0 -172
  54. package/Widgets/SVG/SVGLandmarkRepresentation/Constants.js +0 -28
  55. package/Widgets/SVG/SVGLandmarkRepresentation.js +0 -167
  56. package/Widgets/SVG/SVGRepresentation.js +0 -163
@@ -1,13 +1,9 @@
1
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
1
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
3
2
  import Constants from './Constants.js';
4
3
  import macro from '../../../macros.js';
5
4
  import { s as subtract, l as add, m as normalize } from '../../../Common/Core/Math/index.js';
6
5
  import { getNumberOfPlacedHandles, isHandlePlaced, calculateTextPosition, updateTextPosition, getPoint } from './helpers.js';
7
6
 
8
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
-
10
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
7
  var ShapeType = Constants.ShapeType; // Total number of points to place
12
8
 
13
9
  var MAX_POINTS = 2;
@@ -70,44 +66,6 @@ function widgetBehavior(publicAPI, model) {
70
66
  // Text methods
71
67
  // --------------------------------------------------------------------------
72
68
 
73
- /**
74
- * check for handle 2 position in comparison to handle 1 position
75
- * and sets text offset to not overlap on the line representation
76
- */
77
-
78
-
79
- function getOffsetDirectionForTextPosition() {
80
- var pos1 = publicAPI.getHandle(0).getOrigin();
81
- var pos2 = publicAPI.getHandle(1).getOrigin();
82
- var dySign = 1;
83
-
84
- if (pos1 && pos2) {
85
- if (pos1[0] <= pos2[0]) {
86
- dySign = pos1[1] <= pos2[1] ? 1 : -1;
87
- } else {
88
- dySign = pos1[1] <= pos2[1] ? -1 : 1;
89
- }
90
- }
91
-
92
- return dySign;
93
- }
94
- /**
95
- * place SVGText on line according to both handle positions
96
- * which purpose is to never have text representation overlapping
97
- * on PolyLine representation
98
- * */
99
-
100
-
101
- publicAPI.placeText = function () {
102
- var dySign = getOffsetDirectionForTextPosition();
103
-
104
- var textPropsCp = _objectSpread({}, model.representations[3].getTextProps());
105
-
106
- textPropsCp.dy = dySign * Math.abs(textPropsCp.dy);
107
- model.representations[3].setTextProps(textPropsCp);
108
-
109
- model._interactor.render();
110
- };
111
69
 
112
70
  publicAPI.setText = function (text) {
113
71
  model.widgetState.getText().setText(text);
@@ -211,7 +169,6 @@ function widgetBehavior(publicAPI, model) {
211
169
  }
212
170
 
213
171
  if (handleIndex === 1) {
214
- publicAPI.placeText();
215
172
  publicAPI.loseFocus();
216
173
  }
217
174
  }; // --------------------------------------------------------------------------
@@ -289,7 +246,6 @@ function widgetBehavior(publicAPI, model) {
289
246
  if (model._isDragging && publicAPI.isPlaced()) {
290
247
  var wasTextActive = model.widgetState.getText().getActive(); // Recompute offsets
291
248
 
292
- publicAPI.placeText();
293
249
  model.widgetState.deactivate();
294
250
  model.activeState = null;
295
251
 
@@ -5,7 +5,6 @@ import generateState from './LineWidget/state.js';
5
5
  import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
6
6
  import vtkArrowHandleRepresentation from '../Representations/ArrowHandleRepresentation.js';
7
7
  import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
8
- import vtkSVGLandmarkRepresentation from '../SVG/SVGLandmarkRepresentation.js';
9
8
  import vtkPolyLineRepresentation from '../Representations/PolyLineRepresentation.js';
10
9
  import widgetBehavior from './LineWidget/behavior.js';
11
10
  import { Behavior } from '../Representations/WidgetRepresentation/Constants.js';
@@ -107,16 +106,6 @@ function vtkLineWidget(publicAPI, model) {
107
106
  }
108
107
  }
109
108
  }
110
- }, {
111
- builder: vtkSVGLandmarkRepresentation,
112
- initialValues: {
113
- text: '',
114
- textProps: {
115
- dx: 12,
116
- dy: -12
117
- }
118
- },
119
- labels: ['SVGtext']
120
109
  }, {
121
110
  builder: vtkPolyLineRepresentation,
122
111
  labels: ['handle1', 'handle2', 'moveHandle'],
@@ -4,7 +4,6 @@ import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
4
4
  import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
5
5
  import vtkPolyLineRepresentation from '../Representations/PolyLineRepresentation.js';
6
6
  import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
7
- import vtkSVGLandmarkRepresentation from '../SVG/SVGLandmarkRepresentation.js';
8
7
  import widgetBehavior from './PolyLineWidget/behavior.js';
9
8
  import generateState from './PolyLineWidget/state.js';
10
9
  import { ViewTypes } from '../Core/WidgetManager/Constants.js';
@@ -36,15 +35,6 @@ function vtkPolyLineWidget(publicAPI, model) {
36
35
  }, {
37
36
  builder: vtkSphereHandleRepresentation,
38
37
  labels: ['moveHandle']
39
- }, {
40
- builder: vtkSVGLandmarkRepresentation,
41
- initialValues: {
42
- textProps: {
43
- dx: 12,
44
- dy: -12
45
- }
46
- },
47
- labels: ['handles']
48
38
  }, {
49
39
  builder: vtkPolyLineRepresentation,
50
40
  labels: ['handles', 'moveHandle']
@@ -5,7 +5,6 @@ import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
5
5
  import vtkShapeWidget from './ShapeWidget.js';
6
6
  import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
7
7
  import vtkRectangleContextRepresentation from '../Representations/RectangleContextRepresentation.js';
8
- import vtkSVGLandmarkRepresentation from '../SVG/SVGLandmarkRepresentation.js';
9
8
  import widgetBehavior from './RectangleWidget/behavior.js';
10
9
  import generateState from './RectangleWidget/state.js';
11
10
  import { BehaviorCategory, ShapeBehavior } from './ShapeWidget/Constants.js';
@@ -34,12 +33,6 @@ function vtkRectangleWidget(publicAPI, model) {
34
33
  }, {
35
34
  builder: vtkRectangleContextRepresentation,
36
35
  labels: ['rectangleHandle']
37
- }, {
38
- builder: vtkSVGLandmarkRepresentation,
39
- initialValues: {
40
- text: ''
41
- },
42
- labels: ['SVGtext']
43
36
  }];
44
37
  }
45
38
  }; // --------------------------------------------------------------------------
@@ -12,7 +12,7 @@ function vtkShapeWidget(publicAPI, model) {
12
12
 
13
13
  var superClass = _objectSpread({}, publicAPI);
14
14
 
15
- model.methodsToLink = ['scaleInPixels', 'textProps', 'fontProperties'];
15
+ model.methodsToLink = ['scaleInPixels'];
16
16
 
17
17
  publicAPI.setManipulator = function (manipulator) {
18
18
  superClass.setManipulator(manipulator);
package/index.d.ts CHANGED
@@ -26,6 +26,7 @@
26
26
  /// <reference path="./Common/DataModel/DataSet.d.ts" />
27
27
  /// <reference path="./Common/DataModel/DataSetAttributes/FieldData.d.ts" />
28
28
  /// <reference path="./Common/DataModel/DataSetAttributes.d.ts" />
29
+ /// <reference path="./Common/DataModel/EdgeLocator.d.ts" />
29
30
  /// <reference path="./Common/DataModel/ITKHelper.d.ts" />
30
31
  /// <reference path="./Common/DataModel/ImageData.d.ts" />
31
32
  /// <reference path="./Common/DataModel/IncrementalOctreeNode.d.ts" />
package/macros.d.ts CHANGED
@@ -172,17 +172,19 @@ export function get(publicAPI: object, model: object, fieldNames: Array<string>)
172
172
  * @param publicAPI object on which public methods get attached to
173
173
  * @param model object on which protected fields are stored
174
174
  * @param fieldNames list of fields available in model that we want to expose as set{FieldName} methods on the publicAPI
175
+ * * Can be a string (the name of the field to expose) or an object (e.g. {type:enum, name: {FieldName}, enum: FieldEnum}).
175
176
  */
176
- export function set(publicAPI: object, model: object, fields: Array<string>): void;
177
+ export function set(publicAPI: object, model: object, fields: Array<string|object>): void;
177
178
 
178
179
  /**
179
180
  * Add setter+getter methods to the provided publicAPI
180
181
  *
181
182
  * @param publicAPI object on which public methods get attached to
182
183
  * @param model object on which protected fields are stored
183
- * @param fieldNames list of fields available in model that we want to expose as set{FieldName}+get{FieldName} methods on the publicAPI
184
+ * @param fieldNames list of fields available in model that we want to expose as set{FieldName}+get{FieldName} methods on the publicAPI.
185
+ * Can be a string (the name of the field to expose) or an object (e.g. {type:enum, name: {FieldName}, enum: FieldEnum}).
184
186
  */
185
- export function setGet(publicAPI: object, model: object, fields: Array<string>): void;
187
+ export function setGet(publicAPI: object, model: object, fields: Array<string|object>): void;
186
188
 
187
189
  /**
188
190
  * Add getter methods to the provided publicAPI for arrays.
package/macros.js CHANGED
@@ -3,6 +3,7 @@ import _typeof from '@babel/runtime/helpers/typeof';
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
5
5
  import _construct from '@babel/runtime/helpers/construct';
6
+ import DeepEqual from 'fast-deep-equal';
6
7
  import vtk, { vtkGlobal } from './vtk.js';
7
8
  import ClassHierarchy from './Common/Core/ClassHierarchy.js';
8
9
 
@@ -233,7 +234,13 @@ function obj() {
233
234
  if (!('classHierarchy' in model)) {
234
235
  model.classHierarchy = new ClassHierarchy('vtkObject');
235
236
  } else if (!(model.classHierarchy instanceof ClassHierarchy)) {
236
- model.classHierarchy = ClassHierarchy.from(model.classHierarchy);
237
+ var hierarchy = new ClassHierarchy();
238
+
239
+ for (var i = 0; i < model.classHierarchy.length; i++) {
240
+ hierarchy.push(model.classHierarchy[i]);
241
+ }
242
+
243
+ model.classHierarchy = hierarchy;
237
244
  }
238
245
 
239
246
  function off(index) {
@@ -437,12 +444,25 @@ function obj() {
437
444
  // getXXX: add getters
438
445
  // ----------------------------------------------------------------------------
439
446
 
447
+ var objectGetterMap = {
448
+ object: function object(publicAPI, model, field) {
449
+ return function getter() {
450
+ return _objectSpread({}, model[field.name]);
451
+ };
452
+ }
453
+ };
440
454
  function get(publicAPI, model, fieldNames) {
441
455
  fieldNames.forEach(function (field) {
442
456
  if (_typeof(field) === 'object') {
443
- publicAPI["get".concat(_capitalize(field.name))] = function () {
444
- return model[field.name];
445
- };
457
+ var getter = objectGetterMap[field.type];
458
+
459
+ if (getter) {
460
+ publicAPI["get".concat(_capitalize(field.name))] = getter(publicAPI, model, field);
461
+ } else {
462
+ publicAPI["get".concat(_capitalize(field.name))] = function () {
463
+ return model[field.name];
464
+ };
465
+ }
446
466
  } else {
447
467
  publicAPI["get".concat(_capitalize(field))] = function () {
448
468
  return model[field];
@@ -491,6 +511,17 @@ var objectSetterMap = {
491
511
  vtkErrorMacro("Set Enum with invalid argument (String/Number) ".concat(field, ", ").concat(value));
492
512
  throw new TypeError('Set Enum with invalid argument (String/Number)');
493
513
  };
514
+ },
515
+ object: function object(publicAPI, model, field) {
516
+ return function (value) {
517
+ if (!DeepEqual(model[field.name], value)) {
518
+ model[field.name] = value;
519
+ publicAPI.modified();
520
+ return true;
521
+ }
522
+
523
+ return false;
524
+ };
494
525
  }
495
526
  };
496
527
 
@@ -549,7 +580,7 @@ function setGet(publicAPI, model, fieldNames) {
549
580
  function getArray(publicAPI, model, fieldNames) {
550
581
  fieldNames.forEach(function (field) {
551
582
  publicAPI["get".concat(_capitalize(field))] = function () {
552
- return model[field] ? [].concat(model[field]) : model[field];
583
+ return model[field] ? Array.from(model[field]) : model[field];
553
584
  };
554
585
 
555
586
  publicAPI["get".concat(_capitalize(field), "ByReference")] = function () {
@@ -607,9 +638,11 @@ function setArray(publicAPI, model, fieldNames, size) {
607
638
  }
608
639
  }
609
640
 
610
- changeDetected = model[field] == null || model[field].some(function (item, index) {
611
- return item !== array[index];
612
- }) || model[field].length !== array.length;
641
+ changeDetected = model[field] == null || model[field].length !== array.length;
642
+
643
+ for (var i = 0; !changeDetected && i < array.length; ++i) {
644
+ changeDetected = model[field][i] !== array[i];
645
+ }
613
646
 
614
647
  if (changeDetected && needCopy) {
615
648
  array = Array.from(array);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "26.0.0-beta.1",
3
+ "version": "26.0.0-beta.3",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",
@@ -33,6 +33,7 @@
33
33
  "@babel/runtime": "7.17.9",
34
34
  "commander": "9.2.0",
35
35
  "d3-scale": "4.0.2",
36
+ "fast-deep-equal": "^3.1.3",
36
37
  "fflate": "0.7.3",
37
38
  "gl-matrix": "3.4.3",
38
39
  "globalthis": "1.0.3",
@@ -112,6 +113,7 @@
112
113
  "rollup-plugin-svgo": "1.1.0",
113
114
  "rollup-plugin-web-worker-loader": "1.6.1",
114
115
  "semantic-release": "19.0.3",
116
+ "snabbdom": "^3.5.1",
115
117
  "string-replace-loader": "3.1.0",
116
118
  "style-loader": "3.3.1",
117
119
  "tape": "5.5.3",
@@ -140,6 +142,7 @@
140
142
  "doc:publish": "kw-doc -c ./Documentation/config.js -mp",
141
143
  "doc:generate-api": "node ./Documentation/generate-api-docs.js",
142
144
  "example": "node ./Utilities/ExampleRunner/example-runner-cli.js -c ./Documentation/config.js",
145
+ "example:webgpu": "cross-env WEBGPU=1 NO_WEBGL=1 node ./Utilities/ExampleRunner/example-runner-cli.js -c ./Documentation/config.js",
143
146
  "dev:esm": "npm run build:esm -- -w",
144
147
  "dev:umd": "webpack --watch --config webpack.dev.js --progress",
145
148
  "build": "npm run build:release",
@@ -1,40 +0,0 @@
1
- import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
2
- import _createClass from '@babel/runtime/helpers/createClass';
3
-
4
- var CCSEdgeLocator = /*#__PURE__*/function () {
5
- function CCSEdgeLocator() {
6
- _classCallCheck(this, CCSEdgeLocator);
7
-
8
- this._edgeMap = new Map();
9
- }
10
-
11
- _createClass(CCSEdgeLocator, [{
12
- key: "initialize",
13
- value: function initialize() {
14
- this._edgeMap.clear();
15
- }
16
- }, {
17
- key: "insertUniqueEdge",
18
- value: function insertUniqueEdge(i0, i1) {
19
- // Generate key, which is unique, since we order the edges
20
- var key = i1 < i0 ? "".concat(i1, "-").concat(i0) : "".concat(i0, "-").concat(i1);
21
-
22
- var node = this._edgeMap.get(key);
23
-
24
- if (!node) {
25
- // Didn't find key, so add a new edge entry
26
- node = {
27
- edgeId: -1
28
- };
29
-
30
- this._edgeMap.set(key, node);
31
- }
32
-
33
- return node;
34
- }
35
- }]);
36
-
37
- return CCSEdgeLocator;
38
- }();
39
-
40
- export { CCSEdgeLocator as default };
@@ -1,172 +0,0 @@
1
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
-
3
- var SVG_XMLNS = 'http://www.w3.org/2000/svg';
4
-
5
- function attrDelta(oldObj, newObj) {
6
- var set = [];
7
- var remove = [];
8
- var oldKeysArray = Object.keys(oldObj);
9
- var newKeysArray = Object.keys(newObj);
10
- var oldKeys = new Set(oldKeysArray);
11
- var newKeys = new Set(newKeysArray);
12
-
13
- for (var i = 0; i < oldKeysArray.length; i++) {
14
- var key = oldKeysArray[i];
15
-
16
- if (newKeys.has(key)) {
17
- if (oldObj[key] !== newObj[key]) {
18
- set.push([key, newObj[key]]);
19
- }
20
- } else {
21
- remove.push(key);
22
- }
23
- }
24
-
25
- for (var _i = 0; _i < newKeysArray.length; _i++) {
26
- var _key = newKeysArray[_i];
27
-
28
- if (!oldKeys.has(_key)) {
29
- set.push([_key, newObj[_key]]);
30
- }
31
- }
32
-
33
- return [set, remove];
34
- }
35
-
36
- function render(vnode) {
37
- var node = document.createElementNS(SVG_XMLNS, vnode.name);
38
- var keys = Object.keys(vnode.attrs);
39
-
40
- for (var i = 0; i < keys.length; i++) {
41
- var key = keys[i];
42
- node.setAttribute(key, vnode.attrs[key]);
43
- } // TODO: support removing event listener (e.g. use snabbdom)
44
-
45
-
46
- Object.keys(vnode.eventListeners).forEach(function (key) {
47
- node.addEventListener(key, vnode.eventListeners[key]);
48
- });
49
-
50
- if (vnode.textContent) {
51
- node.textContent = vnode.textContent;
52
- } else {
53
- for (var _i2 = 0; _i2 < vnode.children.length; _i2++) {
54
- node.appendChild(render(vnode.children[_i2]));
55
- }
56
- }
57
-
58
- return node;
59
- }
60
- /**
61
- * Returns a set of patch functions to be applied to a document node.
62
- *
63
- * Patch functions must return the effective result node.
64
- */
65
-
66
- function diff(oldVTree, newVTree) {
67
- if (newVTree.textContent !== null && newVTree.children.length) {
68
- throw new Error('Tree cannot have both children and textContent!');
69
- }
70
-
71
- if (!oldVTree) {
72
- return [function () {
73
- return render(newVTree);
74
- }];
75
- }
76
-
77
- if (!newVTree) {
78
- return [function (node) {
79
- return node.remove();
80
- }];
81
- }
82
-
83
- if (oldVTree.name !== newVTree.name) {
84
- return [function (node) {
85
- var newNode = render(newVTree);
86
- node.replaceWith(newNode);
87
- return newNode;
88
- }];
89
- }
90
-
91
- var patchFns = [];
92
-
93
- var _attrDelta = attrDelta(oldVTree.attrs, newVTree.attrs),
94
- _attrDelta2 = _slicedToArray(_attrDelta, 2),
95
- attrsSet = _attrDelta2[0],
96
- attrsRemove = _attrDelta2[1];
97
-
98
- if (attrsSet.length || attrsRemove.length) {
99
- patchFns.push(function (node) {
100
- for (var i = 0; i < attrsSet.length; i++) {
101
- var _attrsSet$i = _slicedToArray(attrsSet[i], 2),
102
- name = _attrsSet$i[0],
103
- value = _attrsSet$i[1];
104
-
105
- node.setAttribute(name, value);
106
- }
107
-
108
- for (var _i3 = 0; _i3 < attrsRemove.length; _i3++) {
109
- var _name = attrsRemove[_i3];
110
- node.removeAttribute(_name);
111
- }
112
-
113
- return node;
114
- });
115
- }
116
-
117
- if (oldVTree.textContent !== newVTree.textContent && newVTree.textContent !== null) {
118
- patchFns.push(function (node) {
119
- node.textContent = newVTree.textContent;
120
- return node;
121
- });
122
- }
123
-
124
- if (newVTree.textContent === null) {
125
- var min = Math.min(oldVTree.children.length, newVTree.children.length);
126
-
127
- var _loop = function _loop(i) {
128
- var childPatches = diff(oldVTree.children[i], newVTree.children[i]);
129
- patchFns.push(function (node) {
130
- for (var p = 0; p < childPatches.length; p++) {
131
- childPatches[p](node.children[i]);
132
- }
133
-
134
- return node;
135
- });
136
- };
137
-
138
- for (var i = 0; i < min; i++) {
139
- _loop(i);
140
- }
141
-
142
- if (oldVTree.children.length < newVTree.children.length) {
143
- var _loop2 = function _loop2(_i4) {
144
- patchFns.push(function (node) {
145
- node.appendChild(render(newVTree.children[_i4]));
146
- return node;
147
- });
148
- };
149
-
150
- for (var _i4 = min; _i4 < newVTree.children.length; _i4++) {
151
- _loop2(_i4);
152
- }
153
- } else {
154
- var _loop3 = function _loop3(_i5) {
155
- patchFns.push(function (node) {
156
- node.children[_i5].remove();
157
-
158
- return node;
159
- });
160
- };
161
-
162
- // always delete nodes in reverse
163
- for (var _i5 = oldVTree.children.length - 1; _i5 >= min; _i5--) {
164
- _loop3(_i5);
165
- }
166
- }
167
- }
168
-
169
- return patchFns;
170
- }
171
-
172
- export { diff, render };
@@ -1,28 +0,0 @@
1
- var VerticalTextAlignment = {
2
- TOP: 'TOP',
3
- BOTTOM: 'BOTTOM',
4
- MIDDLE: 'MIDDLE'
5
- };
6
- /**
7
- * fontSize can be a number or a string representing a size in px
8
- * @param {Number|String} fontSize
9
- * @returns Number representing the fontSize in pixels
10
- */
11
-
12
- function fontSizeToPixels(fontProperties) {
13
- var defaultFontSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 16;
14
-
15
- if (fontProperties != null && fontProperties.fontSize) {
16
- if (typeof fontProperties.fontSize === 'string') {
17
- if (fontProperties.fontSize.slice(-2) === 'px') {
18
- return window.devicePixelRatio * parseInt(fontProperties.fontSize, 10);
19
- }
20
- }
21
-
22
- return window.devicePixelRatio * fontProperties.fontSize;
23
- }
24
-
25
- return window.devicePixelRatio * defaultFontSize;
26
- }
27
-
28
- export { VerticalTextAlignment, VerticalTextAlignment as default, fontSizeToPixels };