diff --git a/src/renderer/src/components/Preview/utils.ts b/src/renderer/src/components/Preview/utils.ts index 476a3b913a..9a011048c3 100644 --- a/src/renderer/src/components/Preview/utils.ts +++ b/src/renderer/src/components/Preview/utils.ts @@ -1,5 +1,4 @@ import { makeSvgSizeAdaptive } from '@renderer/utils' -import DOMPurify from 'dompurify' /** * Renders an SVG string inside a host element's Shadow DOM to ensure style encapsulation. @@ -15,12 +14,14 @@ export function renderSvgInShadowHost(svgContent: string, hostElement: HTMLEleme throw new Error('Host element for SVG rendering is not available.') } - // Sanitize the SVG content - const sanitizedContent = DOMPurify.sanitize(svgContent, { - USE_PROFILES: { svg: true, svgFilters: true }, - RETURN_DOM_FRAGMENT: false, - RETURN_DOM: false - }) + // FIXME: Sanitize the SVG content + // const sanitizedContent = DOMPurify.sanitize(svgContent, { + // USE_PROFILES: { svg: true, svgFilters: true }, + // RETURN_DOM_FRAGMENT: false, + // RETURN_DOM: false + // }) + + const sanitizedContent = svgContent const shadowRoot = hostElement.shadowRoot || hostElement.attachShadow({ mode: 'open' }) diff --git a/src/renderer/src/utils/image.ts b/src/renderer/src/utils/image.ts index 533f3defe1..235050a07b 100644 --- a/src/renderer/src/utils/image.ts +++ b/src/renderer/src/utils/image.ts @@ -331,12 +331,14 @@ export const makeSvgSizeAdaptive = (element: Element): Element => { } } - // 设置 max-width + // 如果没有则设置 max-width // 优先使用测量得到的宽度值,否则回退到 width 属性值 - if (measuredWidth !== undefined) { - element.style.setProperty('max-width', `${measuredWidth}px`) - } else if (widthStr) { - element.style.setProperty('max-width', widthStr) + if (!element.style.getPropertyValue('max-width')) { + if (measuredWidth !== undefined) { + element.style.setProperty('max-width', `${measuredWidth}px`) + } else if (widthStr) { + element.style.setProperty('max-width', widthStr) + } } // 调整 width 和 height