redhotmagma-visualization 1.28.4 → 1.29.0

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 (88) hide show
  1. package/AlignTargetProvider.js +129 -0
  2. package/CommonUtils/Deferred.js +135 -0
  3. package/CommonUtils/Observable.js +126 -0
  4. package/CommonUtils/PropertyObserver.js +61 -0
  5. package/CommonUtils/SyncCurrentFunction.js +59 -0
  6. package/CommonUtils/SyncObservableEvent.js +19 -0
  7. package/CommonUtils/pointerEvent.js +415 -0
  8. package/Constants.js +23 -0
  9. package/DevApp.js +1049 -0
  10. package/ExposedModules.js +26 -0
  11. package/FallbackVisualization.js +26 -0
  12. package/PrintingEffects/ColorEmbossingEffect.js +58 -0
  13. package/PrintingEffects/DomingEffect.js +150 -0
  14. package/PrintingEffects/EmbossingEffect.js +65 -0
  15. package/PrintingEffects/EmbroideryEffect.js +541 -0
  16. package/PrintingEffects/EngravingEffect.js +65 -0
  17. package/PrintingEffects/PrintingEffects.js +117 -0
  18. package/PrintingEffects/PrintingEffectsUtils.js +53 -0
  19. package/PrintingEffects/resources/embroidery_multiply.jpg +0 -0
  20. package/PrintingEffects/resources/embroidery_screen.jpg +0 -0
  21. package/README.md +11 -4
  22. package/React/ReactBase.js +111 -0
  23. package/Three/Controls/OrbitControls.js +745 -0
  24. package/Three/Exporters/glTFExporter.js +48 -0
  25. package/Three/Loaders/ColladaLoader.js +2916 -0
  26. package/Three/Loaders/MTLLoader.js +449 -0
  27. package/Three/Loaders/OBJLoader.js +548 -0
  28. package/Three/Three2D.js +1790 -0
  29. package/Three/Three2DLayers.js +504 -0
  30. package/Three/Three3D.js +1412 -0
  31. package/Three/Three3DScene.js +1432 -0
  32. package/Three/ThreeBase.js +724 -0
  33. package/Utils/DesignArea/getDesignAreaCanvasSize.js +32 -0
  34. package/Utils/TextureBuilder/createTextureBuilder.js +334 -0
  35. package/Utils/TextureBuilder/textureBuilderFunctions.js +87 -0
  36. package/Utils/alignToElement.js +58 -0
  37. package/Utils/createAlphaMapFromAlphaChannel.js +50 -0
  38. package/Utils/createCache.js +46 -0
  39. package/Utils/createCanvas.js +29 -0
  40. package/Utils/createImageRepository.js +124 -0
  41. package/Utils/disposeMaterial.js +41 -0
  42. package/Utils/getImageSize.js +15 -0
  43. package/Utils/imagePreloader.js +76 -0
  44. package/Utils/initTextureCanvas.js +49 -0
  45. package/Utils/isMobileDevice.js +19 -0
  46. package/Utils/optimizeTextureImage.js +73 -0
  47. package/Utils/rememberCameraViewOffset.js +21 -0
  48. package/Utils/removeObject.js +22 -0
  49. package/Utils/restrictCameraMovement.js +45 -0
  50. package/Utils/setOrthographicCameraSize.js +16 -0
  51. package/Utils/updateFitSizeToElement.js +39 -0
  52. package/VisualizationContainer.js +279 -0
  53. package/VisualizationInterface.js +298 -0
  54. package/VisualizationProvider.js +38 -0
  55. package/__mocks__/exportedSample.svg +45 -0
  56. package/index.js +16 -0
  57. package/package.json +10 -70
  58. package/scripts/cpPublic.js +9 -12
  59. package/scripts/cpPublicLocal.js +30 -0
  60. package/src/CommonUtils/Observable.js +1 -0
  61. package/src/CommonUtils/pointerEvent.js +2 -1
  62. package/src/DevApp.js +2 -1
  63. package/src/FallbackVisualization.js +1 -5
  64. package/src/PrintingEffects/DomingEffect.js +1 -0
  65. package/src/PrintingEffects/EmbroideryEffect.js +3 -2
  66. package/src/React/ReactBase.js +1 -1
  67. package/src/Three/Controls/OrbitControls.js +2 -0
  68. package/src/Three/Loaders/ColladaLoader.js +111 -294
  69. package/src/Three/Loaders/MTLLoader.js +2 -0
  70. package/src/Three/Loaders/OBJLoader.js +2 -0
  71. package/src/Three/Three2D.js +18 -11
  72. package/src/Three/Three3D.js +9 -1
  73. package/src/Three/ThreeBase.js +14 -2
  74. package/src/Utils/DesignArea/getDesignAreaCanvasSize.js +1 -0
  75. package/src/Utils/TextureBuilder/createTextureBuilder.js +2 -0
  76. package/src/Utils/imagePreloader.js +1 -0
  77. package/src/Utils/initTextureCanvas.js +3 -0
  78. package/src/Utils/isMobileDevice.js +2 -0
  79. package/src/Utils/optimizeTextureImage.js +1 -0
  80. package/src/VisualizationContainer.js +3 -1
  81. package/src/VisualizationInterface.js +10 -1
  82. package/visualizationAdapterCreator.js +76 -0
  83. package/babel.config.js +0 -41
  84. package/scripts/cpPath.js +0 -151
  85. package/scripts/moveLibToPackageRoot.js +0 -44
  86. package/scripts/utils/fileSystem.js +0 -69
  87. package/scripts/utils/process.js +0 -19
  88. package/tsconfig.json +0 -22
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = exports.VisualizationContainerSwitch = exports.VisualizationContainer = void 0;
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
+
14
+ var _cssElementQueries = require("css-element-queries");
15
+
16
+ var _VisualizationProvider = require("./VisualizationProvider");
17
+
18
+ var _VisualizationInterface = require("./VisualizationInterface");
19
+
20
+ var _AlignTargetProvider = require("./AlignTargetProvider");
21
+
22
+ var _alignToElement = require("./Utils/alignToElement");
23
+
24
+ var _updateFitSizeToElement = require("./Utils/updateFitSizeToElement");
25
+
26
+ var _Constants = require("./Constants");
27
+
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
29
+
30
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
31
+
32
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
33
+
34
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
35
+
36
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
37
+
38
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
39
+
40
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
41
+
42
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
43
+
44
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
45
+
46
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
47
+
48
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
49
+
50
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
51
+
52
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
53
+
54
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
55
+
56
+ var defaultContainerStyle = {
57
+ position: "absolute",
58
+ top: 0,
59
+ left: 0,
60
+ width: "100%",
61
+ height: "100%",
62
+ overflow: "hidden"
63
+ };
64
+ /**
65
+ * Component for the Three.js visualization
66
+ * Responsibilities:
67
+ * - renders the placeholder for the THREE.js visualization
68
+ * - adds the Three instance to the placeholder, initializes the controls
69
+ * - loads the current model and starts the animation
70
+ * - will handle probably the positioning of the 3D component
71
+ */
72
+
73
+ var VisualizationContainer = /*#__PURE__*/function (_React$Component) {
74
+ _inherits(VisualizationContainer, _React$Component);
75
+
76
+ var _super = _createSuper(VisualizationContainer);
77
+
78
+ function VisualizationContainer() {
79
+ var _this;
80
+
81
+ _classCallCheck(this, VisualizationContainer);
82
+
83
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
84
+ args[_key] = arguments[_key];
85
+ }
86
+
87
+ _this = _super.call.apply(_super, [this].concat(args));
88
+
89
+ _defineProperty(_assertThisInitialized(_this), "state", {
90
+ loading: false,
91
+ broken: false
92
+ });
93
+
94
+ _defineProperty(_assertThisInitialized(_this), "setLoading", function (loading) {
95
+ _this.setState({
96
+ loading: loading
97
+ });
98
+ });
99
+
100
+ _defineProperty(_assertThisInitialized(_this), "onSizeChange", function (size) {
101
+ var _this$props = _this.props,
102
+ visualization = _this$props.visualization,
103
+ alignTargetElement = _this$props.alignTargetElement;
104
+
105
+ if (!visualization.isInitialized()) {
106
+ return;
107
+ }
108
+
109
+ visualization.setSize(size);
110
+
111
+ if (alignTargetElement && alignTargetElement.clientWidth > 0 && alignTargetElement.clientHeight > 0) {
112
+ (0, _alignToElement.alignToElement)(visualization, alignTargetElement);
113
+ (0, _updateFitSizeToElement.updateFitSizeToElement)(visualization, alignTargetElement).updateCameraPosition({
114
+ animate: visualization.isAnimating() || !!alignTargetElement
115
+ });
116
+ }
117
+
118
+ visualization.render();
119
+ });
120
+
121
+ _defineProperty(_assertThisInitialized(_this), "containerRef", /*#__PURE__*/_react["default"].createRef());
122
+
123
+ return _this;
124
+ }
125
+
126
+ _createClass(VisualizationContainer, [{
127
+ key: "componentDidMount",
128
+ value: function componentDidMount() {
129
+ var visualization = this.props.visualization;
130
+
131
+ if (!visualization) {
132
+ // eslint-disable-next-line no-console
133
+ console.warn("Visualization component is not provided! Visualization will not be rendered.");
134
+ return;
135
+ }
136
+
137
+ if (!(visualization instanceof _VisualizationInterface.VisualizationInterface)) {
138
+ throw new Error('The provided "three" prop should always be a subclass of VisualizationInterface!');
139
+ }
140
+
141
+ this.initResizeSensor();
142
+ this.updateVisualization();
143
+ }
144
+ }, {
145
+ key: "componentDidUpdate",
146
+ value: function componentDidUpdate(prevProps) {
147
+ this.updateVisualization(prevProps);
148
+ }
149
+ }, {
150
+ key: "initResizeSensor",
151
+ value: function initResizeSensor() {
152
+ var container = this.containerRef.current;
153
+ this.resizeSensor = new _cssElementQueries.ResizeSensor(container, this.onSizeChange);
154
+ }
155
+ }, {
156
+ key: "updateVisualization",
157
+ value: function updateVisualization() {
158
+ var prevProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
159
+ var _this$props2 = this.props,
160
+ visualization = _this$props2.visualization,
161
+ alignTargetElement = _this$props2.alignTargetElement;
162
+ var container = this.containerRef.current;
163
+
164
+ if (visualization !== prevProps.visualization) {
165
+ if (prevProps.visualization) {
166
+ prevProps.visualization.dispose();
167
+ }
168
+
169
+ if (visualization.isInitialized()) {
170
+ // Three is already initialized, just add it to the current container instead of reloading it completely
171
+ visualization.addToContainer(container);
172
+ } else {
173
+ this.initVisualization(container);
174
+ } // init resize sensor if it's not done in the componentDidUpdate
175
+
176
+
177
+ !this.resizeSensor && this.initResizeSensor();
178
+ }
179
+
180
+ if (alignTargetElement && alignTargetElement !== prevProps.alignTargetElement || visualization && visualization !== prevProps.visualization) {
181
+ (0, _alignToElement.alignToElement)(visualization, alignTargetElement);
182
+ (0, _updateFitSizeToElement.updateFitSizeToElement)(visualization, alignTargetElement).updateCameraPosition({
183
+ animate: visualization.isAnimating() || !!prevProps.alignTargetElement
184
+ });
185
+ visualization.render();
186
+ }
187
+ }
188
+ }, {
189
+ key: "componentWillUnmount",
190
+ value: function componentWillUnmount() {
191
+ var _this$props3 = this.props,
192
+ autoDispose = _this$props3.autoDispose,
193
+ visualization = _this$props3.visualization;
194
+ autoDispose && visualization.dispose();
195
+ this.resizeSensor && this.resizeSensor.detach();
196
+ }
197
+ }, {
198
+ key: "initVisualization",
199
+ value: function initVisualization(container) {
200
+ var _this2 = this;
201
+
202
+ var visualization = this.props.visualization;
203
+ visualization.init(container);
204
+ visualization.observable.on(_Constants.EventTypes.LoadError, function (_ref) {
205
+ var screenshot = _ref.data.screenshot;
206
+ return !screenshot && _this2.setState({
207
+ broken: true
208
+ });
209
+ });
210
+ visualization.observable.on(_Constants.EventTypes.LoadFinished, function (_ref2) {
211
+ var screenshot = _ref2.data.screenshot;
212
+ return !screenshot && _this2.setState({
213
+ broken: false
214
+ });
215
+ });
216
+ }
217
+ }, {
218
+ key: "render",
219
+ value: function render() {
220
+ var _this$props4 = this.props,
221
+ className = _this$props4.className,
222
+ ProgressComponent = _this$props4.ProgressComponent,
223
+ BrokenComponent = _this$props4.BrokenComponent;
224
+ var broken = this.state.broken;
225
+
226
+ var style = _objectSpread(_objectSpread({}, className ? {} : defaultContainerStyle), broken && BrokenComponent && {
227
+ display: "none"
228
+ });
229
+
230
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(ProgressComponent, {
231
+ loading: this.props.isLoading
232
+ }), /*#__PURE__*/_react["default"].createElement("div", {
233
+ className: "".concat(className || ""),
234
+ style: style,
235
+ ref: this.containerRef
236
+ }), broken && BrokenComponent && /*#__PURE__*/_react["default"].createElement(BrokenComponent, null));
237
+ }
238
+ }]);
239
+
240
+ return VisualizationContainer;
241
+ }(_react["default"].Component);
242
+
243
+ exports.VisualizationContainer = VisualizationContainer;
244
+
245
+ _defineProperty(VisualizationContainer, "propTypes", {
246
+ visualization: _propTypes["default"].instanceOf(_VisualizationInterface.VisualizationInterface).isRequired,
247
+ autoDispose: _propTypes["default"].bool,
248
+ alignTargetElement: _propTypes["default"].instanceOf(Element)
249
+ });
250
+
251
+ _defineProperty(VisualizationContainer, "defaultProps", {
252
+ ProgressComponent: function ProgressComponent(_ref3) {
253
+ var loading = _ref3.loading;
254
+ return loading ? /*#__PURE__*/_react["default"].createElement("div", null, "Loading component...") : null;
255
+ },
256
+ autoDispose: false,
257
+ alignTargetElement: null
258
+ });
259
+
260
+ var VisualizationContainerSwitch = function VisualizationContainerSwitch(props) {
261
+ // eslint-disable-next-line react/prop-types
262
+ var visualization = props.visualization,
263
+ VisualizationContainerComponent = props.VisualizationContainerComponent,
264
+ FallbackComponent = props.FallbackComponent;
265
+ var Component = visualization ? VisualizationContainerComponent : FallbackComponent;
266
+ return /*#__PURE__*/_react["default"].createElement(Component, props);
267
+ };
268
+
269
+ exports.VisualizationContainerSwitch = VisualizationContainerSwitch;
270
+ VisualizationContainerSwitch.defaultProps = {
271
+ VisualizationContainerComponent: VisualizationContainer,
272
+ FallbackComponent: function FallbackComponent() {
273
+ return null;
274
+ }
275
+ };
276
+
277
+ var _default = (0, _AlignTargetProvider.withCurrentTarget)((0, _VisualizationProvider.withVisualization)(VisualizationContainerSwitch));
278
+
279
+ exports["default"] = _default;
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VisualizationInterface = void 0;
7
+
8
+ var _Observable = _interopRequireDefault(require("./CommonUtils/Observable"));
9
+
10
+ var _Constants = require("./Constants");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+
14
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
15
+
16
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
17
+
18
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
19
+
20
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
+
22
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
23
+
24
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
25
+
26
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
+
28
+ var VisualizationInterface = /*#__PURE__*/function () {
29
+ function VisualizationInterface() {
30
+ var _this = this;
31
+
32
+ var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
33
+
34
+ _classCallCheck(this, VisualizationInterface);
35
+
36
+ _defineProperty(this, "_basePath", "");
37
+
38
+ _defineProperty(this, "_itemPath", "");
39
+
40
+ _defineProperty(this, "_materialVariantPath", "");
41
+
42
+ _defineProperty(this, "_isInitialized", false);
43
+
44
+ _defineProperty(this, "_screenshottingInProgress", false);
45
+
46
+ _defineProperty(this, "observable", new _Observable["default"](this));
47
+
48
+ _defineProperty(this, "dispatchErrorEvent", function (data) {
49
+ _this.observable.dispatch(_Constants.EventTypes.Error, data);
50
+ });
51
+
52
+ _defineProperty(this, "onLoadError", function (url) {
53
+ var errorMessage = "Could not load file: ".concat(url); // eslint-disable-next-line no-console
54
+
55
+ console.error(errorMessage);
56
+
57
+ _this.observable.dispatch(_Constants.EventTypes.LoadError, {
58
+ url: url,
59
+ screenshot: !!_this._screenshottingInProgress
60
+ });
61
+ });
62
+
63
+ _defineProperty(this, "onLoadStart", function () {
64
+ return _this.observable.dispatch(_Constants.EventTypes.LoadStart, {
65
+ screenshot: !!_this._screenshottingInProgress
66
+ });
67
+ });
68
+
69
+ _defineProperty(this, "onLoadFinished", function () {
70
+ return _this.observable.dispatch(_Constants.EventTypes.LoadFinished, {
71
+ screenshot: !!_this._screenshottingInProgress
72
+ });
73
+ });
74
+
75
+ if (cfg.basePath) {
76
+ this.setBasePath(cfg.basePath);
77
+ }
78
+ }
79
+ /**
80
+ * Initializes the visualization
81
+ * This function is called from the container component.
82
+ * It provides the opportunity to add any visualization element to the container, and do initial setup if needed.
83
+ * @param {HTMLElement} [container=<div>]
84
+ * @param {boolean} [useDefaultSetup]
85
+ */
86
+ // eslint-disable-next-line no-unused-vars
87
+
88
+
89
+ _createClass(VisualizationInterface, [{
90
+ key: "init",
91
+ value: function init(container, useDefaultSetup) {}
92
+ /**
93
+ * Adds the visualization element to the container
94
+ * This function is called from the container component, when the visualization is already initialized.
95
+ * (see isInitialized method below)
96
+ * This function should add the visualization element to the container, and do other updates if needed.
97
+ * @param container
98
+ */
99
+ // eslint-disable-next-line no-unused-vars
100
+
101
+ }, {
102
+ key: "addToContainer",
103
+ value: function addToContainer(container) {}
104
+ }, {
105
+ key: "isInitialized",
106
+ value: function isInitialized() {
107
+ return this._isInitialized;
108
+ }
109
+ /**
110
+ * Sets the base path for loading models
111
+ * @see getModelPaths
112
+ * @param {string} path
113
+ */
114
+
115
+ }, {
116
+ key: "setBasePath",
117
+ value: function setBasePath(path) {
118
+ this._basePath = path;
119
+ }
120
+ /**
121
+ * Sets the item path for loading models
122
+ * @see getModelPaths
123
+ * @param {string} path
124
+ */
125
+
126
+ }, {
127
+ key: "setItemPath",
128
+ value: function setItemPath(path) {
129
+ this._itemPath = path;
130
+ }
131
+ }, {
132
+ key: "updateItemPath",
133
+ value: function updateItemPath(path) {
134
+ this.setItemPath(path);
135
+ return this.loadModel();
136
+ }
137
+ /**
138
+ * Sets the material variant path for loading models
139
+ * @see getModelPaths
140
+ * @param {string} path
141
+ */
142
+
143
+ }, {
144
+ key: "setMaterialVariantPath",
145
+ value: function setMaterialVariantPath(path) {
146
+ this._materialVariantPath = path;
147
+ }
148
+ }, {
149
+ key: "updateMaterialVariantPath",
150
+ value: function updateMaterialVariantPath(path) {
151
+ this.setMaterialVariantPath(path);
152
+ return this.updateMaterial();
153
+ }
154
+ /**
155
+ * A helper function to split the given relative url to path and fileName parts
156
+ * @param {string|{path: string, fileName: string}} value
157
+ * @returns {{path: string, fileName: string}}
158
+ */
159
+
160
+ }, {
161
+ key: "getPathAndFileName",
162
+ value: function getPathAndFileName(value) {
163
+ if (_typeof(value) === "object" && value.path && value.fileName) {
164
+ return value;
165
+ } else if (typeof value === "string") {
166
+ var matches = value.match(/(.*\/)?([^/]+)$/);
167
+
168
+ if (matches) {
169
+ return {
170
+ path: matches[1],
171
+ fileName: matches[2]
172
+ };
173
+ }
174
+
175
+ throw new Error("Could not match path and filename for the string: '".concat(value, "', is it a valid path?"));
176
+ }
177
+
178
+ throw new Error("Unknown path value type given in getPathAndFileName. " + "It should be a string or an object { path, fileName }");
179
+ }
180
+ /**
181
+ * Sets the canvas size
182
+ * @param {number} width
183
+ * @param {number} height
184
+ * @param {boolean} rerender
185
+ */
186
+ // eslint-disable-next-line no-unused-vars
187
+
188
+ }, {
189
+ key: "setSize",
190
+ value: function setSize(_ref) {
191
+ var width = _ref.width,
192
+ height = _ref.height;
193
+ var rerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
194
+ }
195
+ /**
196
+ * Loads the model from the pre-configured paths
197
+ * Implement this function to load resources and add them to the visualization.
198
+ * @see updateItemPath
199
+ * @see setItemPath
200
+ */
201
+
202
+ }, {
203
+ key: "loadModel",
204
+ value: function loadModel() {}
205
+ /**
206
+ * Updates the material on the model
207
+ * Implement this function to load a material and apply it on the visualization object.
208
+ * @see updateMaterialVariantPath
209
+ * @see setMaterialVariantPath
210
+ */
211
+
212
+ }, {
213
+ key: "updateMaterial",
214
+ value: function updateMaterial() {}
215
+ /**
216
+ * Handle updates of design area list if needed in the custom implementation
217
+ */
218
+ // eslint-disable-next-line no-unused-vars
219
+
220
+ }, {
221
+ key: "updateDesignAreaList",
222
+ value: function updateDesignAreaList(designAreaList) {}
223
+ /**
224
+ * Calls the given drawing function for custom drawing implementations
225
+ * It provides the drawing context (among with other custom parameters if needed) in the callback function.
226
+ * @param {function(ctx: CanvasRenderingContext2D, image: HTMLImageElement)} drawingFn
227
+ * @param {boolean} updateAlpha Indicates that the alpha map needs to be updated
228
+ * @param {boolean} clearTexture Indicates that the texture has to be cleared before drawing
229
+ * @param {string|undefined} materialName Request for a specific material texture context
230
+ */
231
+
232
+ }, {
233
+ key: "getDrawingContext",
234
+ value: function getDrawingContext(drawingFn) {
235
+ var updateAlpha = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
236
+ var clearTexture = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
237
+ var materialName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
238
+ }
239
+ /**
240
+ * Redraw the visualization
241
+ */
242
+
243
+ }, {
244
+ key: "render",
245
+ value: function render() {}
246
+ }, {
247
+ key: "isAnimating",
248
+ value: function isAnimating() {
249
+ return false;
250
+ }
251
+ }, {
252
+ key: "getScreenshots",
253
+ value:
254
+ /**
255
+ * A function to create screenshots from the visualization
256
+ * It can include switching views and async loading of resources, so the results are better returned
257
+ * in a callback function. If there is no result, simply return null.
258
+ * @param {function} callback The callback function should get the generated screenshots in the first arg
259
+ * @param {object} options The options object to pass extra data
260
+ */
261
+ // eslint-disable-next-line no-unused-vars
262
+ function () {
263
+ var _getScreenshots = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(callback, options) {
264
+ return regeneratorRuntime.wrap(function _callee$(_context) {
265
+ while (1) {
266
+ switch (_context.prev = _context.next) {
267
+ case 0:
268
+ callback && callback(null);
269
+
270
+ case 1:
271
+ case "end":
272
+ return _context.stop();
273
+ }
274
+ }
275
+ }, _callee);
276
+ }));
277
+
278
+ function getScreenshots(_x, _x2) {
279
+ return _getScreenshots.apply(this, arguments);
280
+ }
281
+
282
+ return getScreenshots;
283
+ }()
284
+ /**
285
+ * This function has to be called when the visualization instance is not needed any longer
286
+ * The implementation has to free all the allocated resources including the removal of the element appended
287
+ * to the container, if there is any
288
+ */
289
+
290
+ }, {
291
+ key: "dispose",
292
+ value: function dispose() {}
293
+ }]);
294
+
295
+ return VisualizationInterface;
296
+ }();
297
+
298
+ exports.VisualizationInterface = VisualizationInterface;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.withVisualization = exports.VisualizationProvider = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+
12
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
13
+
14
+ var VisualizationContext = /*#__PURE__*/_react["default"].createContext({
15
+ visualization: null
16
+ });
17
+
18
+ var VisualizationProvider = function VisualizationProvider(_ref) {
19
+ var visualization = _ref.visualization,
20
+ children = _ref.children;
21
+ return /*#__PURE__*/_react["default"].createElement(VisualizationContext.Provider, {
22
+ value: {
23
+ visualization: visualization
24
+ }
25
+ }, children);
26
+ };
27
+
28
+ exports.VisualizationProvider = VisualizationProvider;
29
+
30
+ var withVisualization = function withVisualization(Component) {
31
+ return function (props) {
32
+ return /*#__PURE__*/_react["default"].createElement(VisualizationContext.Consumer, null, function (state) {
33
+ return /*#__PURE__*/_react["default"].createElement(Component, _extends({}, state, props));
34
+ });
35
+ };
36
+ };
37
+
38
+ exports.withVisualization = withVisualization;