| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.getBBoxSize = exports.getContainerSize = void 0;
- const parseInt10 = (d) => (d ? parseInt(d) : 0);
- /**
- * @description Get the element's bounding size.
- * @param container dom element.
- * @returns the element width and height
- */
- function getContainerSize(container) {
- // size = width/height - padding.
- const style = getComputedStyle(container);
- const wrapperWidth = container.clientWidth || parseInt10(style.width);
- const wrapperHeight = container.clientHeight || parseInt10(style.height);
- const widthPadding = parseInt10(style.paddingLeft) + parseInt10(style.paddingRight);
- const heightPadding = parseInt10(style.paddingTop) + parseInt10(style.paddingBottom);
- return {
- width: wrapperWidth - widthPadding,
- height: wrapperHeight - heightPadding,
- };
- }
- exports.getContainerSize = getContainerSize;
- /**
- * @description Calculate the real canvas size by view options.
- */
- function getBBoxSize(options) {
- const { height, width, padding = 0, paddingLeft = padding, paddingRight = padding, paddingTop = padding, paddingBottom = padding, margin = 0, marginLeft = margin, marginRight = margin, marginTop = margin, marginBottom = margin, inset = 0, insetLeft = inset, insetRight = inset, insetTop = inset, insetBottom = inset, } = options;
- // @todo Add this padding to theme.
- // 30 is default size for padding, which defined in runtime.
- const maybeAuto = (padding) => (padding === 'auto' ? 30 : padding);
- const finalWidth = width -
- maybeAuto(paddingLeft) -
- maybeAuto(paddingRight) -
- marginLeft -
- marginRight -
- insetLeft -
- insetRight;
- const finalHeight = height -
- maybeAuto(paddingTop) -
- maybeAuto(paddingBottom) -
- marginTop -
- marginBottom -
- insetTop -
- insetBottom;
- return { width: finalWidth, height: finalHeight };
- }
- exports.getBBoxSize = getBBoxSize;
- //# sourceMappingURL=size.js.map
|