UNPKG

@bookbox/view-html

Version:

Bookbox view for html

33 lines (32 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseSize = parseSize; exports.getCssSizeStyle = getCssSizeStyle; exports.getLayoutParams = getLayoutParams; 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); } function getCssSizeStyle(params) { const { width, height } = params; return `max-height: ${height}vh; max-width: ${width}%`; } function getLayoutParams(props) { var _a; return { view: (0, core_1.getLayoutView)(props), position: (_a = props.position) !== null && _a !== void 0 ? _a : 'center', }; }