feat: Support dark theme for PlantUML

This commit is contained in:
Yrom 2025-02-18 13:59:21 +08:00 committed by 亢奋猫
parent d0ee764732
commit b31b1c7908

View File

@ -1,5 +1,6 @@
import { CopyOutlined, LoadingOutlined } from '@ant-design/icons' import { CopyOutlined, LoadingOutlined } from '@ant-design/icons'
import { TopView } from '@renderer/components/TopView' import { TopView } from '@renderer/components/TopView'
import { useTheme } from '@renderer/context/ThemeProvider'
import { Button, Modal, Space, Spin, Tabs } from 'antd' import { Button, Modal, Space, Spin, Tabs } from 'antd'
import pako from 'pako' import pako from 'pako'
import React, { useState } from 'react' import React, { useState } from 'react'
@ -87,9 +88,19 @@ type PlantUMLServerImageProps = {
onClick?: React.MouseEventHandler<HTMLDivElement> onClick?: React.MouseEventHandler<HTMLDivElement>
} }
function getPlantUMLImageUrl(format: 'png' | 'svg', diagram: string, isDark?: boolean) {
const encodedDiagram = encodeDiagram(diagram)
if (isDark) {
return `${PlantUMLServer}/d${format}/${encodedDiagram}`
}
return `${PlantUMLServer}/${format}/${encodedDiagram}`
}
const PlantUMLServerImage: React.FC<PlantUMLServerImageProps> = ({ format, diagram, onClick }) => { const PlantUMLServerImage: React.FC<PlantUMLServerImageProps> = ({ format, diagram, onClick }) => {
const url = `${PlantUMLServer}/${format}/${encodeDiagram(diagram)}`
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
const { theme } = useTheme()
const isDark = theme === 'dark'
const url = getPlantUMLImageUrl(format, diagram, isDark)
return ( return (
<StyledPlantUML onClick={onClick}> <StyledPlantUML onClick={onClick}>
<Spin <Spin