UNPKG

@drozdik.m/dimensions-ratio

Version:

Simple helper for setting dimensions using ratio parameters.

64 lines (63 loc) 2.78 kB
exports.__esModule = true; var dimensions_helper_1 = require("@drozdik.m/dimensions-helper"); var DimensionsRatio = /** @class */ (function () { //-------------------------------------------------- //----------CONSTRUCTOR----------------------------- //-------------------------------------------------- /** * Creates active container for providing * @param element */ function DimensionsRatio(element) { this.element = element; this.dimensionsHelper = new dimensions_helper_1.DimensionsHelper(this.element); } //-------------------------------------------------- //----------RATIOS---------------------------------- //-------------------------------------------------- /** * Sets height of the element by given ratio and its width * @param widthRatio Width ratio * @param heightRatio Height ratio */ DimensionsRatio.prototype.ByWidth = function (widthRatio, heightRatio) { var targetHeight = this.dimensionsHelper.Width() / widthRatio * heightRatio; this.dimensionsHelper.SetHeight(targetHeight); }; /** * Sets width of the element by given ratio and its height * @param widthRatio Width ratio * @param heightRatio Height ratio */ DimensionsRatio.prototype.ByHeight = function (widthRatio, heightRatio) { var targetWidth = this.dimensionsHelper.Height() / heightRatio * widthRatio; this.dimensionsHelper.SetWidth(targetWidth); }; //-------------------------------------------------- //----------RATIOS STATICS-------------------------- //-------------------------------------------------- /** * Sets height of the element by given ratio and its width * @param element Target element * @param widthRatio Width ratio * @param heightRatio Height ratio */ DimensionsRatio.ByWidth = function (element, widthRatio, heightRatio) { var dimensionsHelper = new dimensions_helper_1.DimensionsHelper(element); var targetHeight = dimensionsHelper.Width() / widthRatio * heightRatio; dimensionsHelper.SetHeight(targetHeight); }; /** * Sets width of the element by given ratio and its height * @param element Target element * @param widthRatio Width ratio * @param heightRatio Height ratio */ DimensionsRatio.ByHeight = function (element, widthRatio, heightRatio) { var dimensionsHelper = new dimensions_helper_1.DimensionsHelper(element); var targetWidth = dimensionsHelper.Height() / heightRatio * widthRatio; dimensionsHelper.SetWidth(targetWidth); }; return DimensionsRatio; }()); exports.DimensionsRatio = DimensionsRatio;