This commit is contained in:
2026-01-31 23:51:25 +01:00
parent 77c5792fb0
commit 7f01e4f9f1
2 changed files with 78 additions and 26 deletions

View File

@@ -1 +1 @@
1.1.77 1.1.78

View File

@@ -485,33 +485,85 @@
if (component && component.view && component.view.el) { if (component && component.view && component.view.el) {
const viewEl = component.view.el; const viewEl = component.view.el;
const hasInline = /<span\b|style\s*=/i.test(htmlSource); const hasInline = /<span\b|style\s*=/i.test(htmlSource);
if (!hasInline) { const inlineComputedStyles = (sourceEl) => {
try { try {
const cs = (viewEl.ownerDocument || document).defaultView.getComputedStyle(viewEl); const docRef = sourceEl.ownerDocument || document;
const styles = []; const winRef = docRef.defaultView || window;
const pushStyle = (prop, val) => { const clone = sourceEl.cloneNode(true);
if (val) styles.push(`${prop}:${val}`); const props = [
'font-family',
'font-size',
'font-weight',
'font-style',
'text-decoration-line',
'text-align',
'line-height',
'color',
];
const walk = (orig, copy) => {
if (!orig || !copy) return;
if (orig.nodeType === 1 && copy.nodeType === 1) {
const cs = winRef.getComputedStyle(orig);
let style = copy.getAttribute('style') || '';
const hasStyle = (name) => new RegExp(`${name}\\s*:`, 'i').test(style);
const pushStyle = (name, value) => {
if (!value || hasStyle(name)) return;
style += `${style && !style.trim().endsWith(';') ? ';' : ''}${name}:${value};`;
};
props.forEach((prop) => {
let value = cs.getPropertyValue(prop);
if (!value) return;
if (prop === 'text-decoration-line' && value === 'none') return;
if (prop === 'text-align' && value === 'start') return;
if (prop === 'line-height' && value === 'normal') return;
pushStyle(prop === 'text-decoration-line' ? 'text-decoration' : prop, value.trim());
});
if (style) copy.setAttribute('style', style.trim());
}
const origChildren = orig.childNodes || [];
const copyChildren = copy.childNodes || [];
for (let i = 0; i < origChildren.length; i += 1) {
walk(origChildren[i], copyChildren[i]);
}
}; };
pushStyle('font-family', cs.fontFamily); walk(sourceEl, clone);
pushStyle('font-size', cs.fontSize); return clone.innerHTML || '';
pushStyle('font-weight', cs.fontWeight); } catch {
pushStyle('font-style', cs.fontStyle); return '';
if (cs.textDecorationLine && cs.textDecorationLine !== 'none') { }
pushStyle('text-decoration', cs.textDecorationLine); };
} if (!hasInline) {
if (cs.textAlign && cs.textAlign !== 'start') { const inlined = inlineComputedStyles(viewEl);
pushStyle('text-align', cs.textAlign); if (inlined) {
} htmlSource = inlined;
if (cs.lineHeight && cs.lineHeight !== 'normal') { } else {
pushStyle('line-height', cs.lineHeight); try {
} const cs = (viewEl.ownerDocument || document).defaultView.getComputedStyle(viewEl);
if (cs.color) { const styles = [];
pushStyle('color', cs.color); const pushStyle = (prop, val) => {
} if (val) styles.push(`${prop}:${val}`);
if (styles.length) { };
htmlSource = `<span style="${styles.join(';')}">${htmlSource}</span>`; pushStyle('font-family', cs.fontFamily);
} pushStyle('font-size', cs.fontSize);
} catch {} pushStyle('font-weight', cs.fontWeight);
pushStyle('font-style', cs.fontStyle);
if (cs.textDecorationLine && cs.textDecorationLine !== 'none') {
pushStyle('text-decoration', cs.textDecorationLine);
}
if (cs.textAlign && cs.textAlign !== 'start') {
pushStyle('text-align', cs.textAlign);
}
if (cs.lineHeight && cs.lineHeight !== 'normal') {
pushStyle('line-height', cs.lineHeight);
}
if (cs.color) {
pushStyle('color', cs.color);
}
if (styles.length) {
htmlSource = `<span style="${styles.join(';')}">${htmlSource}</span>`;
}
} catch {}
}
} }
} }
const initialHtml = this.sanitizeInlineHtml(htmlSource, modelContent || ''); const initialHtml = this.sanitizeInlineHtml(htmlSource, modelContent || '');