@spearwolf/twopoint5d
Version:
a library to create 2.5d realtime graphics and pixelart with three.js
35 lines • 1.57 kB
JavaScript
export function getVerticalPadding(style) {
return parseFloat(style.getPropertyValue('padding-top') || '0') + parseFloat(style.getPropertyValue('padding-bottom') || '0');
}
export function getHorizontalPadding(style) {
return parseFloat(style.getPropertyValue('padding-left') || '0') + parseFloat(style.getPropertyValue('padding-right') || '0');
}
export function getVerticalBorder(style) {
return (parseFloat(style.getPropertyValue('border-top-width') || '0') +
parseFloat(style.getPropertyValue('border-bottom-width') || '0'));
}
export function getHorizontalBorder(style) {
return (parseFloat(style.getPropertyValue('border-right-width') || '0') +
parseFloat(style.getPropertyValue('border-left-width') || '0'));
}
export function getVerticalInnerMargin(style) {
return getVerticalBorder(style) + getVerticalPadding(style);
}
export function getHorizontalInnerMargin(style) {
return getVerticalBorder(style) + getHorizontalPadding(style);
}
export function getContentAreaSize(element, style) {
style ??= getComputedStyle(element, null);
const elementSize = element.getBoundingClientRect();
const horizontalInnerMargin = getHorizontalInnerMargin(style);
const verticalInnerMargin = getVerticalInnerMargin(style);
return {
style,
width: elementSize.width - horizontalInnerMargin,
height: elementSize.height - verticalInnerMargin,
};
}
export function getIsContentBox(style) {
return style.getPropertyValue('box-sizing') === 'content-box';
}
//# sourceMappingURL=styleUtils.js.map