chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
+56
@@ -0,0 +1,56 @@
|
||||
import { createTheme } from '../theme'
|
||||
|
||||
describe('createTheme', () => {
|
||||
it('uses the default palette when no custom color is configured', () => {
|
||||
const theme = createTheme()
|
||||
|
||||
expect(theme).toMatchObject({
|
||||
chatColorTheme: null,
|
||||
chatColorThemeInverted: false,
|
||||
primaryColor: '#1C64F2',
|
||||
backgroundHeaderColorStyle: 'backgroundImage: linear-gradient(to right, #2563eb, #0ea5e9)',
|
||||
headerBorderBottomStyle: '',
|
||||
colorFontOnHeaderStyle: 'color: white',
|
||||
colorPathOnHeader: 'text-text-primary-on-surface',
|
||||
backgroundButtonDefaultColorStyle: 'backgroundColor: #1C64F2',
|
||||
roundedBackgroundColorStyle: 'backgroundColor: rgb(245 248 255)',
|
||||
chatBubbleColorStyle: '',
|
||||
})
|
||||
})
|
||||
|
||||
it('treats an empty custom color as the default palette', () => {
|
||||
expect(createTheme('')).toMatchObject({
|
||||
chatColorTheme: '',
|
||||
primaryColor: '#1C64F2',
|
||||
backgroundHeaderColorStyle: 'backgroundImage: linear-gradient(to right, #2563eb, #0ea5e9)',
|
||||
chatBubbleColorStyle: '',
|
||||
})
|
||||
})
|
||||
|
||||
it('derives the custom palette without mutating another theme', () => {
|
||||
const firstTheme = createTheme('#FF5733')
|
||||
const secondTheme = createTheme('#123456')
|
||||
|
||||
expect(firstTheme).toMatchObject({
|
||||
chatColorTheme: '#FF5733',
|
||||
primaryColor: '#FF5733',
|
||||
backgroundHeaderColorStyle: 'backgroundColor: #FF5733',
|
||||
backgroundButtonDefaultColorStyle: 'backgroundColor: #FF5733; color: color: white;',
|
||||
roundedBackgroundColorStyle: 'backgroundColor: rgba(255,87,51,0.05)',
|
||||
chatBubbleColorStyle: 'backgroundColor: rgba(255,87,51,0.15)',
|
||||
})
|
||||
expect(secondTheme.primaryColor).toBe('#123456')
|
||||
expect(firstTheme.primaryColor).toBe('#FF5733')
|
||||
})
|
||||
|
||||
it('derives the inverted palette from the configured primary color', () => {
|
||||
expect(createTheme('#FF5733', true)).toMatchObject({
|
||||
chatColorThemeInverted: true,
|
||||
primaryColor: '#FF5733',
|
||||
backgroundHeaderColorStyle: 'backgroundColor: #ffffff',
|
||||
headerBorderBottomStyle: 'borderBottom: 1px solid #ccc',
|
||||
colorFontOnHeaderStyle: 'color: #FF5733',
|
||||
colorPathOnHeader: '#FF5733',
|
||||
})
|
||||
})
|
||||
})
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { CssTransform, hexToRGBA } from '../utils'
|
||||
|
||||
describe('theme value conversions', () => {
|
||||
it.each([
|
||||
['#000000', 0, 'rgba(0,0,0,0)'],
|
||||
['FFFFFF', 0.5, 'rgba(255,255,255,0.5)'],
|
||||
['#12AB34', 1, 'rgba(18,171,52,1)'],
|
||||
])('converts %s with opacity %s', (hex, opacity, expected) => {
|
||||
expect(hexToRGBA(hex, opacity)).toBe(expected)
|
||||
})
|
||||
|
||||
it('parses style declarations while trimming whitespace and skipping empty pairs', () => {
|
||||
expect(CssTransform(' color : red ;; margin: 10px; ')).toEqual({
|
||||
color: 'red',
|
||||
margin: '10px',
|
||||
})
|
||||
})
|
||||
|
||||
it('has no declarations for an empty style', () => {
|
||||
expect(CssTransform('')).toEqual({})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
import { hexToRGBA } from './utils'
|
||||
|
||||
export type Theme = Readonly<{
|
||||
chatColorTheme: string | null
|
||||
chatColorThemeInverted: boolean
|
||||
primaryColor: string
|
||||
backgroundHeaderColorStyle: string
|
||||
headerBorderBottomStyle: string
|
||||
colorFontOnHeaderStyle: string
|
||||
colorPathOnHeader: string
|
||||
backgroundButtonDefaultColorStyle: string
|
||||
roundedBackgroundColorStyle: string
|
||||
chatBubbleColorStyle: string
|
||||
}>
|
||||
|
||||
export const createTheme = (
|
||||
chatColorTheme: string | null = null,
|
||||
chatColorThemeInverted = false,
|
||||
): Theme => {
|
||||
const hasCustomColor = chatColorTheme !== null && chatColorTheme !== ''
|
||||
const primaryColor = hasCustomColor ? chatColorTheme : '#1C64F2'
|
||||
const colorFontOnHeaderStyle = chatColorThemeInverted ? `color: ${primaryColor}` : 'color: white'
|
||||
|
||||
return Object.freeze({
|
||||
chatColorTheme,
|
||||
chatColorThemeInverted,
|
||||
primaryColor,
|
||||
backgroundHeaderColorStyle: chatColorThemeInverted
|
||||
? 'backgroundColor: #ffffff'
|
||||
: hasCustomColor
|
||||
? `backgroundColor: ${primaryColor}`
|
||||
: 'backgroundImage: linear-gradient(to right, #2563eb, #0ea5e9)',
|
||||
headerBorderBottomStyle: chatColorThemeInverted ? 'borderBottom: 1px solid #ccc' : '',
|
||||
colorFontOnHeaderStyle,
|
||||
colorPathOnHeader: chatColorThemeInverted ? primaryColor : 'text-text-primary-on-surface',
|
||||
backgroundButtonDefaultColorStyle: hasCustomColor
|
||||
? `backgroundColor: ${primaryColor}; color: color: white;`
|
||||
: 'backgroundColor: #1C64F2',
|
||||
roundedBackgroundColorStyle: hasCustomColor
|
||||
? `backgroundColor: ${hexToRGBA(primaryColor, 0.05)}`
|
||||
: 'backgroundColor: rgb(245 248 255)',
|
||||
chatBubbleColorStyle: hasCustomColor ? `backgroundColor: ${hexToRGBA(primaryColor, 0.15)}` : '',
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { CSSProperties } from 'react'
|
||||
|
||||
export function hexToRGBA(hex: string, opacity: number): string {
|
||||
hex = hex.replace('#', '')
|
||||
|
||||
const r = Number.parseInt(hex.slice(0, 2), 16)
|
||||
const g = Number.parseInt(hex.slice(2, 4), 16)
|
||||
const b = Number.parseInt(hex.slice(4, 6), 16)
|
||||
|
||||
// Returning an RGB color object
|
||||
return `rgba(${r},${g},${b},${opacity.toString()})`
|
||||
}
|
||||
|
||||
/**
|
||||
* Since strings cannot be directly assigned to the 'style' attribute in JSX,
|
||||
* this method transforms the string into an object representation of the styles.
|
||||
*/
|
||||
export function CssTransform(cssString: string): CSSProperties {
|
||||
if (cssString.length === 0) return {}
|
||||
|
||||
const style: CSSProperties = {}
|
||||
const propertyValuePairs = cssString.split(';')
|
||||
for (const pair of propertyValuePairs) {
|
||||
if (pair.trim().length > 0) {
|
||||
const [property, value] = pair.split(':')
|
||||
Object.assign(style, { [property!.trim()]: value!.trim() })
|
||||
}
|
||||
}
|
||||
return style
|
||||
}
|
||||
Reference in new issue
Block a user