mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-01 09:49:03 +08:00
fix: svg rendering (#9291)
* fix: svg max-width * fix: disable sanitizer
This commit is contained in:
parent
86545f4fff
commit
585e49ac65
@ -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' })
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user