molstar
Version:
A comprehensive macromolecular library.
55 lines • 3.13 kB
JavaScript
import { __assign, __extends } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "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>
*/
import * as React from 'react';
import { PluginUIComponent } from '../base';
var ViewportCanvas = /** @class */ (function (_super) {
__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 _jsx(C, {}, void 0);
}
return _jsx("div", __assign({ className: 'msp-no-webgl' }, { children: _jsxs("div", { children: [_jsx("p", { children: _jsx("b", { children: "WebGL does not seem to be available." }, void 0) }, void 0), _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), _jsxs("p", { children: ["For a list of supported browsers, refer to ", _jsx("a", __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 _jsxs("div", __assign({ className: this.props.parentClassName || 'msp-viewport', style: this.props.parentStyle }, { children: [_jsx("div", __assign({ className: this.props.hostClassName || 'msp-viewport-host3d', style: this.props.hostStyle, ref: this.container }, { children: _jsx("canvas", { ref: this.canvas }, void 0) }), void 0), (this.state.showLogo && Logo) && _jsx(Logo, {}, void 0)] }), void 0);
};
return ViewportCanvas;
}(PluginUIComponent));
export { ViewportCanvas };
//# sourceMappingURL=canvas.js.map