UNPKG

@kitware/vtk.js

Version:

Visualization Toolkit for the Web

156 lines (127 loc) 5.65 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import macro from '../../macros.js'; import vtkGenericRenderWindow from './GenericRenderWindow.js'; import { s as style } from './RenderWindowWithControlBar/RenderWindowWithControlBar.module.css.js'; import '../../Common/Core/Points.js'; import '../../Common/Core/DataArray.js'; import '../../Common/DataModel/PolyData.js'; import '../Core/Actor.js'; import '../Core/Mapper.js'; 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; } 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; } // Utility functions to control style // ---------------------------------------------------------------------------- var CONTROL_STYLE = { left: function left(size) { return { top: '0', left: '0', bottom: '0', right: 'unset', height: 'unset', width: "".concat(size, "px") }; }, right: function right(size) { return { top: '0', right: '0', bottom: '0', left: 'unset', height: 'unset', width: "".concat(size, "px") }; }, top: function top(size) { return { top: '0', left: '0', right: '0', bottom: 'unset', width: 'unset', height: "".concat(size, "px") }; }, bottom: function bottom(size) { return { bottom: '0', left: '0', right: '0', top: 'unset', width: 'unset', height: "".concat(size, "px") }; } }; function applyControlStyle(el, position, size) { var styleToApply = CONTROL_STYLE[position](size); Object.keys(styleToApply).forEach(function (key) { el.style[key] = styleToApply[key]; }); } // ---------------------------------------------------------------------------- function vtkRenderWindowWithControlBar(publicAPI, model) { var superClass = _objectSpread({}, publicAPI); function resetStyleToZero(key) { model.renderWindowContainer.style[key] = '0px'; } function updateControlerStyle() { ['left', 'right', 'top', 'bottom'].forEach(resetStyleToZero); model.renderWindowContainer.style[model.controlPosition] = "".concat(model.controlSize, "px"); applyControlStyle(model.controlContainer, model.controlPosition, model.controlSize); } // Create container for the vtkGenericRenderWindow model.renderWindowContainer = document.createElement('div'); model.renderWindowContainer.classList.add(style.renderWindow); superClass.setContainer(model.renderWindowContainer); // Create container for controls model.controlContainer = document.createElement('div'); model.controlContainer.classList.add(style.control); // Handle DOM container relocation publicAPI.setContainer = function (el) { if (model.rootContainer) { model.rootContainer.removeChild(model.container); model.rootContainer.removeChild(model.controlContainer); model.rootContainer.classList.remove(style.rootContainer); } // Switch container model.rootContainer = el; // Bind to new container if (model.rootContainer) { model.rootContainer.appendChild(model.container); model.rootContainer.appendChild(model.controlContainer); model.rootContainer.classList.add(style.rootContainer); updateControlerStyle(); publicAPI.resize(); } }; publicAPI.setControlSize = function (size) { model.controlSize = size; updateControlerStyle(); publicAPI.modified(); }; publicAPI.setControlPosition = function (pos) { model.controlPosition = pos; updateControlerStyle(); publicAPI.modified(); }; // Handle size if (model.listenWindowResize) { window.addEventListener('resize', publicAPI.resize); } updateControlerStyle(); publicAPI.resize(); } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- var DEFAULT_VALUES = { rootContainer: null, controlPosition: 'left', controlSize: 10 }; // ---------------------------------------------------------------------------- function extend(publicAPI, model) { var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; Object.assign(model, DEFAULT_VALUES, initialValues); // Object methods vtkGenericRenderWindow.extend(publicAPI, model); macro.get(publicAPI, model, ['rootContainer', 'controlContainer', 'renderWindowContainer']); // Object specific methods vtkRenderWindowWithControlBar(publicAPI, model); } // ---------------------------------------------------------------------------- var newInstance = macro.newInstance(extend, 'vtkRenderWindowWithControlBar'); // ---------------------------------------------------------------------------- var vtkRenderWindowWithControlBar$1 = { newInstance: newInstance, extend: extend }; export { vtkRenderWindowWithControlBar$1 as default, extend, newInstance };