UNPKG

molstar

Version:

A comprehensive macromolecular library.

58 lines 3.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ViewportCanvas = void 0; var tslib_1 = require("tslib"); var jsx_runtime_1 = require("react/jsx-runtime"); /** * Copyright (c) 2020-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ var React = (0, tslib_1.__importStar)(require("react")); var base_1 = require("../base"); var ViewportCanvas = /** @class */ (function (_super) { (0, tslib_1.__extends)(ViewportCanvas, _super); function ViewportCanvas() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.container = React.createRef(); _this.canvas = React.createRef(); _this.state = { noWebGl: false, showLogo: true }; _this.handleLogo = function () { var _a; _this.setState({ showLogo: !((_a = _this.plugin.canvas3d) === null || _a === void 0 ? void 0 : _a.reprCount.value) }); }; return _this; } ViewportCanvas.prototype.componentDidMount = function () { if (!this.canvas.current || !this.container.current || !this.plugin.initViewer(this.canvas.current, this.container.current)) { this.setState({ noWebGl: true }); return; } this.handleLogo(); this.subscribe(this.plugin.canvas3d.reprCount, this.handleLogo); }; ViewportCanvas.prototype.componentWillUnmount = function () { _super.prototype.componentWillUnmount.call(this); // TODO viewer cleanup }; ViewportCanvas.prototype.renderMissing = function () { if (this.props.noWebGl) { var C = this.props.noWebGl; return (0, jsx_runtime_1.jsx)(C, {}, void 0); } return (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-no-webgl' }, { children: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("p", { children: (0, jsx_runtime_1.jsx)("b", { children: "WebGL does not seem to be available." }, void 0) }, void 0), (0, jsx_runtime_1.jsx)("p", { children: "This can be caused by an outdated browser, graphics card driver issue, or bad weather. Sometimes, just restarting the browser helps." }, void 0), (0, jsx_runtime_1.jsxs)("p", { children: ["For a list of supported browsers, refer to ", (0, jsx_runtime_1.jsx)("a", (0, tslib_1.__assign)({ href: 'http://caniuse.com/#feat=webgl', target: '_blank' }, { children: "http://caniuse.com/#feat=webgl" }), void 0), "."] }, void 0)] }, void 0) }), void 0); }; ViewportCanvas.prototype.render = function () { if (this.state.noWebGl) return this.renderMissing(); var Logo = this.props.logo; return (0, jsx_runtime_1.jsxs)("div", (0, tslib_1.__assign)({ className: this.props.parentClassName || 'msp-viewport', style: this.props.parentStyle }, { children: [(0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: this.props.hostClassName || 'msp-viewport-host3d', style: this.props.hostStyle, ref: this.container }, { children: (0, jsx_runtime_1.jsx)("canvas", { ref: this.canvas }, void 0) }), void 0), (this.state.showLogo && Logo) && (0, jsx_runtime_1.jsx)(Logo, {}, void 0)] }), void 0); }; return ViewportCanvas; }(base_1.PluginUIComponent)); exports.ViewportCanvas = ViewportCanvas; //# sourceMappingURL=canvas.js.map