mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-01 14:28:49 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
9dc2662e7d
4 changed files with 71 additions and 13 deletions
2
app/stage/protyle/js/lute/lute.min.js
vendored
2
app/stage/protyle/js/lute/lute.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -18,8 +18,10 @@ package api
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -33,26 +35,82 @@ type ColorScheme struct {
|
|||
}
|
||||
|
||||
var colorSchemes = map[string]ColorScheme{
|
||||
"red": {"#DD2F45", "#F4BEC3"},
|
||||
"blue": {"#2bb7ff", "#0097e6"},
|
||||
"yellow": {"#feca57", "#ff9f43"},
|
||||
"green": {"#55efc4", "#19b37a"},
|
||||
"purple": {"#a55eea", "#8854d0"},
|
||||
"pink": {"#fd79a8", "#e05b8a"},
|
||||
"orange": {"#ff7f50", "#ff6348"},
|
||||
"grey": {"#576574", "#222f3e"},
|
||||
"red": {"#d13d51", "#ba2c3f"},
|
||||
"blue": {"#3eb0ea", "#0097e6"},
|
||||
"yellow": {"#eec468", "#d89b18"},
|
||||
"green": {"#52E0B8", "#19b37a"},
|
||||
"purple": {"#a36cda", "#8952d5"},
|
||||
"pink": {"#f183aa", "#e05b8a"},
|
||||
"orange": {"#f3865e", "#ef5e2a"},
|
||||
"grey": {"#576574", "#374a60"},
|
||||
}
|
||||
|
||||
func getColorScheme(color string) ColorScheme {
|
||||
// 去除可能的空格
|
||||
color = strings.TrimSpace(color)
|
||||
|
||||
// 检查是否是预定义的颜色
|
||||
if scheme, ok := colorSchemes[strings.ToLower(color)]; ok {
|
||||
return scheme
|
||||
}
|
||||
// 支持自定义颜色
|
||||
// 如果颜色值不以#开头,自动添加#
|
||||
if !strings.HasPrefix(color, "#") && len(color) > 0 {
|
||||
color = "#" + color
|
||||
}
|
||||
|
||||
// 如果不是预定义颜色,返回默认颜色
|
||||
// 检查是否是十六进制颜色值
|
||||
hexColorPattern := `^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$`
|
||||
if matched, _ := regexp.MatchString(hexColorPattern, color); matched {
|
||||
// 确保颜色值有#前缀
|
||||
if !strings.HasPrefix(color, "#") {
|
||||
color = "#" + color
|
||||
}
|
||||
|
||||
// 如果是3位十六进制,转换为6位
|
||||
if len(color) == 4 {
|
||||
r := string(color[1])
|
||||
g := string(color[2])
|
||||
b := string(color[3])
|
||||
color = "#" + r + r + g + g + b + b
|
||||
}
|
||||
|
||||
// 生成次要颜色(将主色调变深)
|
||||
secondary := darkenColor(color, 0.1)
|
||||
|
||||
return ColorScheme{
|
||||
Primary: color,
|
||||
Secondary: secondary,
|
||||
}
|
||||
}
|
||||
|
||||
// 如果既不是预定义颜色也不是有效的十六进制值,返回默认颜色
|
||||
return colorSchemes["red"]
|
||||
}
|
||||
|
||||
func darkenColor(hexColor string, factor float64) string {
|
||||
// 去掉#号
|
||||
hex := hexColor[1:]
|
||||
|
||||
// 将十六进制转换为RGB
|
||||
r, _ := strconv.ParseInt(hex[0:2], 16, 64)
|
||||
g, _ := strconv.ParseInt(hex[2:4], 16, 64)
|
||||
b, _ := strconv.ParseInt(hex[4:6], 16, 64)
|
||||
|
||||
// 使颜色变深
|
||||
r = int64(float64(r) * (1 - factor))
|
||||
g = int64(float64(g) * (1 - factor))
|
||||
b = int64(float64(b) * (1 - factor))
|
||||
|
||||
// 确保值在0-255范围内
|
||||
r = int64(math.Max(0, float64(r)))
|
||||
g = int64(math.Max(0, float64(g)))
|
||||
b = int64(math.Max(0, float64(b)))
|
||||
|
||||
// 转回十六进制
|
||||
return fmt.Sprintf("#%02X%02X%02X", r, g, b)
|
||||
}
|
||||
|
||||
func getDynamicIcon(c *gin.Context) {
|
||||
// Add internal kernel API `/api/icon/getDynamicIcon` https://github.com/siyuan-note/siyuan/pull/12939
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ require (
|
|||
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
|
||||
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
|
||||
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02
|
||||
github.com/88250/lute v1.7.7-0.20241020155135-9028c989d61e
|
||||
github.com/88250/lute v1.7.7-0.20241028035735-91bbe8c1a561
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
||||
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceT
|
|||
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02 h1:3e5+yobj655pTeKOYMbJrnc1mE51ZkbXIxquTYZuYCY=
|
||||
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
|
||||
github.com/88250/lute v1.7.7-0.20241020155135-9028c989d61e h1:Qru5UqQig60u3au9Zo2OSHcIKVzR2QFtGFEkldHW1as=
|
||||
github.com/88250/lute v1.7.7-0.20241020155135-9028c989d61e/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
|
||||
github.com/88250/lute v1.7.7-0.20241028035735-91bbe8c1a561 h1:m0Akk/6lc7329W1QUWpy5Fph9W1poRYs1JSvCCxX/fQ=
|
||||
github.com/88250/lute v1.7.7-0.20241028035735-91bbe8c1a561/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue