@nanggo/social-preview
Version:
Generate beautiful social media preview images from any URL
36 lines (35 loc) • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.measureTextBlockHeight = measureTextBlockHeight;
exports.layoutCenteredTitleDescription = layoutCenteredTitleDescription;
exports.createSvgStyleCdata = createSvgStyleCdata;
function measureTextBlockHeight(lineCount, fontSize, lineHeight) {
return lineCount * fontSize * lineHeight;
}
function layoutCenteredTitleDescription(params) {
const titleHeight = measureTextBlockHeight(params.titleLineCount, params.titleFontSize, params.titleLineHeight);
const descHeight = params.descLineCount > 0
? measureTextBlockHeight(params.descLineCount, params.descFontSize, params.descLineHeight)
: 0;
const appliedGap = params.descLineCount > 0 ? params.gap : 0;
const totalContentHeight = titleHeight + appliedGap + descHeight;
const contentStartY = (params.height - totalContentHeight) / 2;
return {
contentStartY,
titleStartY: contentStartY + params.titleFontSize,
descStartY: contentStartY + titleHeight + appliedGap + params.descFontSize,
titleHeight,
descHeight,
totalContentHeight,
gap: appliedGap,
};
}
function createSvgStyleCdata(css) {
return `
<style type="text/css">
<![CDATA[
${css.trim()}
]]>
</style>
`;
}