UNPKG

molstar

Version:

A comprehensive macromolecular library.

112 lines 6.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GeometryExporterUI = void 0; var tslib_1 = require("tslib"); var jsx_runtime_1 = require("react/jsx-runtime"); /** * Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Sukolsak Sakshuwong <sukolsak@stanford.edu> */ var rxjs_1 = require("rxjs"); 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 GeometryExporterUI = /** @class */ (function (_super) { (0, tslib_1.__extends)(GeometryExporterUI, _super); function GeometryExporterUI() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.save = 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.exportGeometry()]; case 1: data = _b.sent(); this.setState({ busy: false }); (0, download_1.download)(data.blob, data.filename); return [3 /*break*/, 3]; case 2: _a = _b.sent(); this.setState({ busy: false }); return [3 /*break*/, 3]; case 3: return [2 /*return*/]; } }); }); }; _this.viewInAR = function () { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { var data, a_1, _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.exportGeometry()]; case 1: data = _b.sent(); this.setState({ busy: false }); a_1 = document.createElement('a'); a_1.rel = 'ar'; a_1.href = URL.createObjectURL(data.blob); // For in-place viewing of USDZ on iOS, the link must contain a single child that is either an img or picture. // https://webkit.org/blog/8421/viewing-augmented-reality-assets-in-safari-for-ios/ a_1.appendChild(document.createElement('img')); setTimeout(function () { return URL.revokeObjectURL(a_1.href); }, 4E4); // 40s setTimeout(function () { return a_1.dispatchEvent(new MouseEvent('click')); }); 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(GeometryExporterUI.prototype, "controls", { get: function () { return this._controls || (this._controls = new controls_1.GeometryControls(this.plugin)); }, enumerable: false, configurable: true }); GeometryExporterUI.prototype.defaultState = function () { return { header: 'Export Geometry', isCollapsed: true, brand: { accent: 'cyan', svg: icons_1.CubeSendSvg } }; }; GeometryExporterUI.prototype.renderControls = function () { var _a, _b, _c, _d; if (this.isARSupported === undefined) { this.isARSupported = !!((_b = (_a = document.createElement('a').relList) === null || _a === void 0 ? void 0 : _a.supports) === null || _b === void 0 ? void 0 : _b.call(_a, 'ar')); } var ctrl = this.controls; return (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(parameters_1.ParameterControls, { params: controls_1.GeometryParams, 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)({ icon: icons_1.GetAppSvg, onClick: this.save, style: { marginTop: 1 }, disabled: this.state.busy || !((_c = this.plugin.canvas3d) === null || _c === void 0 ? void 0 : _c.reprCount.value) }, { children: "Save" }), void 0), this.isARSupported && ctrl.behaviors.params.value.format === 'usdz' && (0, jsx_runtime_1.jsx)(common_1.Button, (0, tslib_1.__assign)({ icon: icons_1.CubeScanSvg, onClick: this.viewInAR, style: { marginTop: 1 }, disabled: this.state.busy || !((_d = this.plugin.canvas3d) === null || _d === void 0 ? void 0 : _d.reprCount.value) }, { children: "View in AR" }), void 0)] }, void 0); }; GeometryExporterUI.prototype.componentDidMount = function () { var _this = this; var merged = (0, rxjs_1.merge)(this.controls.behaviors.params, this.plugin.canvas3d.reprCount); this.subscribe(merged, function () { if (!_this.state.isCollapsed) _this.forceUpdate(); }); }; GeometryExporterUI.prototype.componentWillUnmount = function () { var _a; (_a = this._controls) === null || _a === void 0 ? void 0 : _a.dispose(); this._controls = void 0; }; return GeometryExporterUI; }(base_1.CollapsableControls)); exports.GeometryExporterUI = GeometryExporterUI; //# sourceMappingURL=ui.js.map