UNPKG

@danilandreev/material-docs

Version:

material-docs - react framework for easy creating documentation site in material design style.

61 lines (50 loc) 2.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } /* * Author: Andrieiev Danil | danssg08@gmail.com | https://github.com/DanilAndreev * Copyright (C) 2020. */ var AspectRatio = /*#__PURE__*/function () { /** * Creates AspectRatio class * @method * @constructor * @param {number} height Relative height. * @param {number} width Relative width. * @throws TypeError * @example * const ratio = new AspectRatio(3, 5); * const height = ratio.getHeight(100); */ function AspectRatio(height, width) { _classCallCheck(this, AspectRatio); if (typeof height !== "number") throw new TypeError("MaterialDocs: Incorrect type of \"height\", expected \"number\" got \"".concat(_typeof(height), "\"")); if (typeof width !== "number") throw new TypeError("MaterialDocs: Incorrect type of \"height\", expected \"number\" got \"".concat(_typeof(width), "\"")); this.height = height; this.width = width; } /** * getHeight - method, designed to calculate absolute height from absolute width by ratio. * @method * @param {number} width Absolute width to calculate height. * @return {number} */ _createClass(AspectRatio, [{ key: "getHeight", value: function getHeight(width) { if (this.height === 0) return 0; var multiplier = this.width / this.height; if (isNaN(multiplier)) multiplier = 0; return Math.trunc(width * multiplier); } }]); return AspectRatio; }(); exports.default = AspectRatio;