vanillajs-browser-helpers
Version:
Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser
40 lines (39 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var num = function (n) { return parseInt(n, 10); };
/**
* Parses the box model numbers of an given Element (margin, padding and border widths)
*
* @param elm - The element to parse numbers from
* @returns The mapping of the box model
*
* @example
*
* ```ts
* boxModel(someDiv);
* ```
*/
function boxModel(elm) {
var style = window.getComputedStyle(elm);
return {
margin: {
top: num(style.marginTop),
left: num(style.marginLeft),
bottom: num(style.marginBottom),
right: num(style.marginRight)
},
padding: {
top: num(style.paddingTop),
left: num(style.paddingLeft),
bottom: num(style.paddingBottom),
right: num(style.paddingRight)
},
border: {
top: num(style.borderTopWidth),
left: num(style.borderLeftWidth),
bottom: num(style.borderBottomWidth),
right: num(style.borderRightWidth)
}
};
}
exports.default = boxModel;