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) {
const viewEl = component.view.el;
const hasInline = /<span\b|style\s*=/i.test(htmlSource);
if (!hasInline) {
const inlineComputedStyles = (sourceEl) => {
try {
const cs = (viewEl.ownerDocument || document).defaultView.getComputedStyle(viewEl);
const styles = [];
const pushStyle = (prop, val) => {
if (val) styles.push(`${prop}:${val}`);
const docRef = sourceEl.ownerDocument || document;
const winRef = docRef.defaultView || window;
const clone = sourceEl.cloneNode(true);
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);
pushStyle('font-size', cs.fontSize);
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 {}
walk(sourceEl, clone);
return clone.innerHTML || '';
} catch {
return '';
}
};
if (!hasInline) {
const inlined = inlineComputedStyles(viewEl);
if (inlined) {
htmlSource = inlined;
} else {
try {
const cs = (viewEl.ownerDocument || document).defaultView.getComputedStyle(viewEl);
const styles = [];
const pushStyle = (prop, val) => {
if (val) styles.push(`${prop}:${val}`);
};
pushStyle('font-family', cs.fontFamily);
pushStyle('font-size', cs.fontSize);
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 || '');