UNPKG

printmaker

Version:

Generate PDF documents and from JavaScript objects

28 lines 1.58 kB
import { ZERO_EDGES } from './box.js'; import { createAnchorObject, layoutBlock } from './layout.js'; export function layoutRows(block, box, doc) { const fixedWidth = block.width; const fixedHeight = block.height; const maxWidth = fixedWidth !== null && fixedWidth !== void 0 ? fixedWidth : box.width; const maxHeight = fixedHeight !== null && fixedHeight !== void 0 ? fixedHeight : box.height; const children = []; let rowY = 0; let lastMargin = 0; let aggregatedHeight = 0; let remainingHeight = maxHeight; block.rows.forEach((row) => { var _a; const margin = (_a = row.margin) !== null && _a !== void 0 ? _a : ZERO_EDGES; const topMargin = Math.max(lastMargin, margin.top); lastMargin = margin.bottom; const nextPos = { x: margin.left, y: rowY + topMargin }; const maxSize = { width: maxWidth - margin.left - margin.right, height: remainingHeight }; const frame = layoutBlock(row, Object.assign(Object.assign({}, nextPos), maxSize), doc); children.push(frame); rowY += topMargin + frame.height; remainingHeight -= topMargin + frame.height; aggregatedHeight += topMargin + frame.height; }); return Object.assign({ type: 'rows', x: box.x, y: box.y, width: fixedWidth !== null && fixedWidth !== void 0 ? fixedWidth : box.width, height: fixedHeight !== null && fixedHeight !== void 0 ? fixedHeight : aggregatedHeight + lastMargin, children }, (block.id && { objects: [createAnchorObject(block.id)] })); } //# sourceMappingURL=layout-rows.js.map