UNPKG

@react-financial-charts/utils

Version:
35 lines 1.64 kB
import * as React from "react"; export const withDeviceRatio = () => { return (OriginalComponent) => { return class WithRatio extends React.Component { constructor() { super(...arguments); this.ref = React.createRef(); } componentDidMount() { var _a, _b, _c, _d, _e; const { current } = this.ref; if (current === null) { this.setState({ ratio: 1, }); return; } const context = current.getContext("2d"); const { devicePixelRatio } = window; const backingStoreRatio = (_e = (_d = (_c = (_b = (_a = context.webkitBackingStorePixelRatio) !== null && _a !== void 0 ? _a : context.mozBackingStorePixelRatio) !== null && _b !== void 0 ? _b : context.msBackingStorePixelRatio) !== null && _c !== void 0 ? _c : context.oBackingStorePixelRatio) !== null && _d !== void 0 ? _d : context.backingStorePixelRatio) !== null && _e !== void 0 ? _e : 1; this.setState({ ratio: devicePixelRatio / backingStoreRatio, }); } render() { const state = this.state; if (state !== null) { return React.createElement(OriginalComponent, Object.assign({}, this.props, { ratio: state.ratio })); } return React.createElement("canvas", { ref: this.ref }); } }; }; }; //# sourceMappingURL=withDeviceRatio.js.map