UNPKG

2.03 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getBBoxSize = exports.getContainerSize = void 0;
4const parseInt10 = (d) => (d ? parseInt(d) : 0);
5/**
6 * @description Get the element's bounding size.
7 * @param container dom element.
8 * @returns the element width and height
9 */
10function getContainerSize(container) {
11 // size = width/height - padding.
12 const style = getComputedStyle(container);
13 const wrapperWidth = container.clientWidth || parseInt10(style.width);
14 const wrapperHeight = container.clientHeight || parseInt10(style.height);
15 const widthPadding = parseInt10(style.paddingLeft) + parseInt10(style.paddingRight);
16 const heightPadding = parseInt10(style.paddingTop) + parseInt10(style.paddingBottom);
17 return {
18 width: wrapperWidth - widthPadding,
19 height: wrapperHeight - heightPadding,
20 };
21}
22exports.getContainerSize = getContainerSize;
23/**
24 * @description Calculate the real canvas size by view options.
25 */
26function getBBoxSize(options) {
27 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;
28 // @todo Add this padding to theme.
29 // 30 is default size for padding, which defined in runtime.
30 const maybeAuto = (padding) => (padding === 'auto' ? 20 : padding);
31 const finalWidth = width -
32 maybeAuto(paddingLeft) -
33 maybeAuto(paddingRight) -
34 marginLeft -
35 marginRight -
36 insetLeft -
37 insetRight;
38 const finalHeight = height -
39 maybeAuto(paddingTop) -
40 maybeAuto(paddingBottom) -
41 marginTop -
42 marginBottom -
43 insetTop -
44 insetBottom;
45 return { width: finalWidth, height: finalHeight };
46}
47exports.getBBoxSize = getBBoxSize;
48//# sourceMappingURL=size.js.map
\No newline at end of file