Enhance template manager with additional style attributes

- Added support for color, background, and scale attributes in getNodeStyles function.
- Updated transformCustomElements function to apply dynamic styles to Text, Bold, and Barcode elements.
- Changed Barcode element to use a div container for better structure and styling.
This commit is contained in:
Tom Butcher 2025-09-05 23:29:28 +01:00
parent 7ccc4bb993
commit ca78fd6e62

View File

@ -87,6 +87,15 @@ function getNodeStyles(attributes) {
if (attributes?.shrink) { if (attributes?.shrink) {
styles += `flex-shrink: ${attributes.shrink};`; styles += `flex-shrink: ${attributes.shrink};`;
} }
if (attributes?.color) {
styles += `color: ${attributes.color};`;
}
if (attributes?.background) {
styles += `background: ${attributes.background};`;
}
if (attributes?.scale) {
styles += `transform: scale(${attributes.scale});`;
}
return styles; return styles;
} }
@ -120,24 +129,36 @@ async function transformCustomElements(content) {
tree.match({ tag: 'Text' }, node => ({ tree.match({ tag: 'Text' }, node => ({
...node, ...node,
tag: 'p', tag: 'p',
attrs: { class: 'documentText' } attrs: { class: 'documentText', style: getNodeStyles(node.attrs) }
})), })),
tree => tree =>
tree.match({ tag: 'Bold' }, node => ({ tree.match({ tag: 'Bold' }, node => ({
...node, ...node,
tag: 'strong', tag: 'strong',
attrs: { style: 'font-weight: bold;', class: 'documentBoldText' } attrs: {
style: 'font-weight: bold;',
class: 'documentBoldText',
style: getNodeStyles(node.attrs)
}
})), })),
tree => tree =>
tree.match({ tag: 'Barcode' }, node => { tree.match({ tag: 'Barcode' }, node => {
return { return {
tag: 'svg', tag: 'div',
content: [
{
tag: 'svg',
attrs: {
class: 'documentBarcode',
'jsbarcode-displayValue': 'false',
'jsbarcode-value': node.content[0],
'jsbarcode-format': node.attrs.format
}
}
],
attrs: { attrs: {
class: 'documentBarcode', class: 'documentBarcodeContainer',
'jsbarcode-width': node.attrs?.width, style: getNodeStyles(node.attrs)
'jsbarcode-height': node.attrs?.height,
'jsbarcode-value': node.content[0],
'jsbarcode-format': node.attrs.format
} }
}; };
}), }),