@bookbox/view-html
Version:
Bookbox view for html
34 lines (33 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLayoutParams = exports.getCssSizeStyle = exports.parseSize = void 0;
const core_1 = require("@bookbox/core");
const defaultSize = 100;
const getNormalSize = (value) => value <= 0 ? defaultSize : Math.floor(value);
function parseSize(value = 1) {
if (typeof value === 'string') {
if (value[value.length - 1] === '%') {
const size = parseFloat(value);
if (Number.isNaN(size)) {
return defaultSize;
}
return getNormalSize(size);
}
return defaultSize;
}
return getNormalSize(value * defaultSize);
}
exports.parseSize = parseSize;
function getCssSizeStyle(params) {
const { width, height } = params;
return `max-height: ${height}vh; max-width: ${width}%`;
}
exports.getCssSizeStyle = getCssSizeStyle;
function getLayoutParams(props) {
var _a;
return {
view: (0, core_1.getLayoutView)(props),
position: (_a = props.position) !== null && _a !== void 0 ? _a : 'center',
};
}
exports.getLayoutParams = getLayoutParams;