UNPKG

molstar

Version:

A comprehensive macromolecular library.

93 lines 6.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Mp4EncoderUI = void 0; var tslib_1 = require("tslib"); var jsx_runtime_1 = require("react/jsx-runtime"); /** * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ var rxjs_1 = require("rxjs"); var operators_1 = require("rxjs/operators"); var base_1 = require("../../mol-plugin-ui/base"); var common_1 = require("../../mol-plugin-ui/controls/common"); var icons_1 = require("../../mol-plugin-ui/controls/icons"); var parameters_1 = require("../../mol-plugin-ui/controls/parameters"); var download_1 = require("../../mol-util/download"); var controls_1 = require("./controls"); var Mp4EncoderUI = /** @class */ (function (_super) { (0, tslib_1.__extends)(Mp4EncoderUI, _super); function Mp4EncoderUI() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.save = function () { (0, download_1.download)(new Blob([_this.state.data.movie]), _this.state.data.filename); }; _this.generate = function () { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { var data, _a; return (0, tslib_1.__generator)(this, function (_b) { switch (_b.label) { case 0: _b.trys.push([0, 2, , 3]); this.setState({ busy: true }); return [4 /*yield*/, this.controls.render()]; case 1: data = _b.sent(); this.setState({ busy: false, data: data }); return [3 /*break*/, 3]; case 2: _a = _b.sent(); this.setState({ busy: false }); return [3 /*break*/, 3]; case 3: return [2 /*return*/]; } }); }); }; return _this; } Object.defineProperty(Mp4EncoderUI.prototype, "controls", { get: function () { return this._controls || (this._controls = new controls_1.Mp4Controls(this.plugin)); }, enumerable: false, configurable: true }); Mp4EncoderUI.prototype.defaultState = function () { return { header: 'Export Animation', isCollapsed: true, brand: { accent: 'cyan', svg: icons_1.SubscriptionsOutlinedSvg } }; }; Mp4EncoderUI.prototype.downloadControls = function () { var _this = this; return (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-control-offset msp-help-text' }, { children: (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-help-description', style: { textAlign: 'center' } }, { children: "Rendering successful!" }), void 0) }), void 0), (0, jsx_runtime_1.jsx)(common_1.Button, (0, tslib_1.__assign)({ icon: icons_1.GetAppSvg, onClick: this.save, style: { marginTop: 1 } }, { children: "Save Animation" }), void 0), (0, jsx_runtime_1.jsx)(common_1.Button, (0, tslib_1.__assign)({ onClick: function () { return _this.setState({ data: void 0 }); }, style: { marginTop: 6 } }, { children: "Clear" }), void 0)] }, void 0); }; Mp4EncoderUI.prototype.renderControls = function () { var _a; if (this.state.data) { return this.downloadControls(); } var ctrl = this.controls; var current = ctrl.behaviors.current.value; var info = ctrl.behaviors.info.value; var canApply = ctrl.behaviors.canApply.value; return (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(parameters_1.ParameterControls, { params: ctrl.behaviors.animations.value, values: { current: current === null || current === void 0 ? void 0 : current.anim.name }, onChangeValues: function (xs) { return ctrl.setCurrent(xs.current); }, isDisabled: this.state.busy }, void 0), current && (0, jsx_runtime_1.jsx)(parameters_1.ParameterControls, { params: current.params, values: current.values, onChangeValues: function (xs) { return ctrl.setCurrentParams(xs); }, isDisabled: this.state.busy }, void 0), (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-control-offset msp-help-text' }, { children: (0, jsx_runtime_1.jsxs)("div", (0, tslib_1.__assign)({ className: 'msp-help-description', style: { textAlign: 'center' } }, { children: ["Resolution: ", info.width, "x", info.height, (0, jsx_runtime_1.jsx)("br", {}, void 0), "Adjust in viewport using ", (0, jsx_runtime_1.jsx)(icons_1.Icon, { svg: icons_1.CameraOutlinedSvg, inline: true }, void 0)] }), void 0) }), void 0), (0, jsx_runtime_1.jsx)(parameters_1.ParameterControls, { params: controls_1.Mp4AnimationParams, values: ctrl.behaviors.params.value, onChangeValues: function (xs) { return ctrl.behaviors.params.next(xs); }, isDisabled: this.state.busy }, void 0), (0, jsx_runtime_1.jsx)(common_1.Button, (0, tslib_1.__assign)({ onClick: this.generate, style: { marginTop: 1 }, disabled: this.state.busy || !canApply.canApply, commit: canApply.canApply ? 'on' : 'off' }, { children: canApply.canApply ? 'Render' : (_a = canApply.reason) !== null && _a !== void 0 ? _a : 'Invalid params/state' }), void 0)] }, void 0); }; Mp4EncoderUI.prototype.componentDidMount = function () { var _this = this; var merged = (0, rxjs_1.merge)(this.controls.behaviors.animations, this.controls.behaviors.current, this.controls.behaviors.canApply, this.controls.behaviors.info, this.controls.behaviors.params); this.subscribe(merged.pipe((0, operators_1.debounceTime)(10)), function () { if (!_this.state.isCollapsed) _this.forceUpdate(); }); }; Mp4EncoderUI.prototype.componentWillUnmount = function () { var _a; (_a = this._controls) === null || _a === void 0 ? void 0 : _a.dispose(); this._controls = void 0; }; return Mp4EncoderUI; }(base_1.CollapsableControls)); exports.Mp4EncoderUI = Mp4EncoderUI; //# sourceMappingURL=ui.js.map