molstar
Version:
A comprehensive macromolecular library.
57 lines (56 loc) • 3.13 kB
JavaScript
"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-2022 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 = tslib_1.__importStar(require("react"));
var base_1 = require("../base");
var ViewportCanvas = /** @class */ (function (_super) {
tslib_1.__extends(ViewportCanvas, _super);
function ViewportCanvas() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.container = 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.container.current || !this.plugin.mount(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);
this.plugin.unmount();
};
ViewportCanvas.prototype.renderMissing = function () {
if (this.props.noWebGl) {
var C = this.props.noWebGl;
return (0, jsx_runtime_1.jsx)(C, {});
}
return (0, jsx_runtime_1.jsx)("div", 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." }) }), (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. Also, make sure hardware acceleration is enabled in your browser." }), (0, jsx_runtime_1.jsxs)("p", { children: ["For a list of supported browsers, refer to ", (0, jsx_runtime_1.jsx)("a", tslib_1.__assign({ href: 'http://caniuse.com/#feat=webgl', target: '_blank' }, { children: "http://caniuse.com/#feat=webgl" })), "."] })] }) }));
};
ViewportCanvas.prototype.render = function () {
if (this.state.noWebGl)
return this.renderMissing();
var Logo = this.props.logo;
return (0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ className: this.props.parentClassName || 'msp-viewport', style: this.props.parentStyle, ref: this.container }, { children: (this.state.showLogo && Logo) && (0, jsx_runtime_1.jsx)(Logo, {}) }));
};
return ViewportCanvas;
}(base_1.PluginUIComponent));
exports.ViewportCanvas = ViewportCanvas;