1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2024-04-27 18:35:13 +08:00
parent 183faff9ce
commit 4dfe6269c5
8 changed files with 97 additions and 82 deletions

View File

@ -77,6 +77,7 @@ const (
BINARY = "binary" BINARY = "binary"
SCRIPT = "script" SCRIPT = "script"
FORMAT = "format" FORMAT = "format"
TRANS = "trans"
CLONE = "clone" CLONE = "clone"
REPOS = "repos" REPOS = "repos"

View File

@ -41,6 +41,10 @@ const (
TEXT_PLAIN = "text/plain" TEXT_PLAIN = "text/plain"
) )
const ( const (
TABLE = "table"
TR = "tr"
TH = "th"
TD = "td"
H1 = "h1" H1 = "h1"
H2 = "h2" H2 = "h2"
H3 = "h3" H3 = "h3"

View File

@ -5,54 +5,66 @@ import (
"strings" "strings"
"shylinux.com/x/ice" "shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/web"
"shylinux.com/x/icebergs/base/web/html" "shylinux.com/x/icebergs/base/web/html"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
type color struct { type color struct {
ice.Hash ice.Hash
limit string `data:"300"` checkbox string `data:"true"`
short string `data:"type,name,text"` export string `data:"true"`
field string `data:"type,name,text,group,order,hash"` limit string `data:"300"`
vendor string `data:"https://www.w3.org/TR/css-color-3/"` short string `data:"type,name,text"`
group string `name:"group group*"` field string `data:"type,name,text,help,group,order,hash"`
load string `name:"load file*"` trans string `data:"https://likexia.gitee.io/tools/colors/yansezhongwenming.html"`
vendor string `data:"https://www.w3.org/TR/css-color-3/"`
group string `name:"group group"`
} }
func (s color) Load(m *ice.Message, arg ...string) { func (s color) Load(m *ice.Message, arg ...string) {
nfs.ScanCSV(m.Message, m.Option(nfs.FILE), func(data []string) { defer m.ToastProcess()()
s.Hash.Create(m, mdb.TYPE, m.Option(nfs.FILE), mdb.NAME, data[0], mdb.TEXT, strings.ToUpper(data[1])) trans := map[string]string{}
}, mdb.NAME, mdb.TEXT) s.goquerys(m, m.Config(nfs.TRANS), "table#color").Table(func(value ice.Maps) {
trans[strings.ToLower(value["英文代码"])] = value["形像颜色"]
})
s.goquerys(m, m.Config(mdb.VENDOR), "table.colortable").Table(func(value ice.Maps) {
s.Hash.Create(m, mdb.TYPE, "css-color-3", mdb.NAME, value["Color name"], mdb.TEXT, strings.ToUpper(value["Hex rgb"]), mdb.HELP, trans[value["Color name"]])
})
} }
func (s color) Matrix(m *ice.Message, arg ...string) { func (s color) Matrix(m *ice.Message, arg ...string) {
m.Cmd("").Table(func(value ice.Maps) { m.Cmd("").Table(func(value ice.Maps) { key, info := Group(value[mdb.NAME], value[mdb.TEXT]); m.Push(key, info) })
key, info := Group(value[mdb.NAME], value[mdb.TEXT]) m.Action(s.Matrix).Display("")
m.Push(key, info)
})
m.Display("")
} }
func (s color) List(m *ice.Message, arg ...string) { func (s color) List(m *ice.Message, arg ...string) {
s.Hash.List(m, arg...).PushAction(s.Group, s.UnGroup, s.Remove).Action(s.Create, s.Load, s.Matrix, s.Vendor, html.FILTER) s.Hash.List(m, arg...).PushAction(s.Group, s.Remove).Action(s.Create, s.Load, s.Vendor, s.Matrix, html.FILTER)
m.Table(func(value ice.Maps) { m.Table(func(value ice.Maps) {
key, info := Group(value[mdb.NAME], value[mdb.TEXT]) key, info := Group(value[mdb.NAME], value[mdb.TEXT])
m.Push("color", key).Push("weight", info) m.Push(cli.COLOR, key).Push(mdb.WEIGHT, info)
}) })
m.Cut("type,name,text,group,order,color,weight,hash,action") m.Cut("type,name,text,help,group,order,color,weight,hash,action")
m.Sort("type,group,order,text", ice.STR, []string{"red", "yellow", "green", "cyan", "blue", "purple", "brown", "meet", "gray"}, "int", ice.STR).Display("") m.Sort("type,group,order,color,text", ice.STR, group, ice.INT, group, ice.STR)
} m.Display("")
func (s color) UnGroup(m *ice.Message, arg ...string) {
s.Hash.Modify(m, mdb.GROUP, "")
}
func (s color) Group(m *ice.Message, arg ...string) {
s.Hash.Modify(m, mdb.GROUP, m.Option(mdb.GROUP))
} }
func (s color) Group(m *ice.Message, arg ...string) { s.Hash.Modify(m, mdb.GROUP, m.Option(mdb.GROUP)) }
func init() { ice.ChatCmd(color{}) } func init() { ice.ChatCmd(color{}) }
var group = []string{cli.RED, cli.YELLOW, cli.GREEN, cli.CYAN, cli.BLUE, cli.PURPLE, "brown", "pink", "meet", cli.GRAY}
func (s color) goquerys(m *ice.Message, path, tags string, arg ...string) *ice.Message {
return s.goquery(m, s.goquery(m, mdb.CREATE, nfs.PATH, path, nfs.TAGS, tags).Result())
}
func (s color) goquery(m *ice.Message, arg ...string) *ice.Message {
return m.Cmd(web.SPACE, "20230511-golang-story", "web.code.goquery.goquery", arg)
}
func Group(name, text string) (string, string) { func Group(name, text string) (string, string) {
if text == "#000000" { if text == "#000000" {
return "gray", "" return cli.GRAY, ""
} }
r, _ := strconv.ParseInt(text[1:3], 16, 32) r, _ := strconv.ParseInt(text[1:3], 16, 32)
g, _ := strconv.ParseInt(text[3:5], 16, 32) g, _ := strconv.ParseInt(text[3:5], 16, 32)
@ -61,66 +73,56 @@ func Group(name, text string) (string, string) {
red := float32(r) / float32(n) red := float32(r) / float32(n)
green := float32(g) / float32(n) green := float32(g) / float32(n)
blue := float32(b) / float32(n) blue := float32(b) / float32(n)
name = kit.Format( name = kit.Format("%s %0.2f %0.2f %0.2f %s", text,
"%s %0.2f %0.2f %0.2f %s",
text,
float32(r)/float32(n), float32(r)/float32(n),
float32(g)/float32(n), float32(g)/float32(n),
float32(b)/float32(n), float32(b)/float32(n),
name, name,
) )
if red > 0.33 && green > 0.33 && blue > 0.33 { if red > 0.33 && green > 0.33 && blue > 0.33 {
return "gray", name return cli.GRAY, name
}
if red < 0.01 && green > 0.3 && blue > 0.3 {
return "cyan", name
} else if red > 0.3 && green < 0.01 && blue > 0.3 {
return "purple", name
} else if red > 0.3 && green > 0.3 && blue < 0.01 {
return "yellow", name
} }
if red > 0.57 { if red > 0.57 {
return "red", name return cli.RED, name
} else if green > 0.57 { } else if green > 0.57 {
return "green", name return cli.GREEN, name
} else if blue > 0.57 { } else if blue > 0.57 {
return "blue", name return cli.BLUE, name
} }
if red < 0.1 && green > 0.3 && blue > 0.3 { if red < 0.15 && green > 0.3 && blue > 0.3 {
return "cyan", name return cli.CYAN, name
} else if red > 0.3 && green < 0.1 && blue > 0.3 { } else if red > 0.3 && green < 0.15 && blue > 0.3 {
return "purple", name return cli.PURPLE, name
} else if red > 0.3 && green > 0.3 && blue < 0.1 { } else if red > 0.3 && green > 0.3 && blue < 0.15 {
return "yellow", name return cli.YELLOW, name
} }
if red-blue > 0.3 && green-blue > 0.3 { if red-blue > 0.3 && green-blue > 0.3 {
return "yellow", name return cli.YELLOW, name
} else if red-green > 0.3 && blue-green > 0.3 { } else if red-green > 0.3 && blue-green > 0.3 {
return "purple", name return cli.PURPLE, name
} else if green-red > 0.3 && blue-red > 0.3 { } else if green-red > 0.3 && blue-red > 0.3 {
return "cyan", name return cli.CYAN, name
} }
if red-green > 0.3 && red-blue > 0.3 { if red-green > 0.3 && red-blue > 0.3 {
return "red", name return cli.RED, name
} else if green-red > 0.3 && green-blue > 0.3 { } else if green-red > 0.3 && green-blue > 0.3 {
return "green", name return cli.GREEN, name
} else if blue-red > 0.3 && blue-green > 0.3 { } else if blue-red > 0.3 && blue-green > 0.3 {
return "blue", name return cli.BLUE, name
}
if red-blue > 0.2 && green-blue > 0.2 {
return "yellow", name
} else if red-green > 0.2 && blue-green > 0.2 {
return "purple", name
} else if green-red > 0.2 && blue-red > 0.2 {
return "cyan", name
} }
if red > green && red > blue { if red > green && red > blue {
return "red", name return cli.RED, name
} else if green > red && green > blue { } else if green > red && green > blue {
return "green", name return cli.GREEN, name
} else if blue > red && blue > green { } else if blue > red && blue > green {
return "blue", name return cli.BLUE, name
} else {
return "", name
} }
if red < green && red < blue {
return cli.CYAN, name
} else if green < red && green < blue {
return cli.PURPLE, name
} else if blue < red && blue < green {
return cli.YELLOW, name
}
return "", name
} }

View File

@ -1,7 +1,7 @@
Volcanos(chat.ONIMPORT, { Volcanos(chat.ONIMPORT, {
_init: function(can, msg) { msg.Dump(can) _init: function(can, msg) { msg.Show(can)
msg.append[0] == mdb.TYPE? can.page.Select(can, can._output, html.TR, function(target, index) { msg.append[0] == mdb.TYPE? can.page.Select(can, can._output, html.TR, function(target, index) {
can.page.Select(can, target, html.TD, function(target, index) { can.page.Select(can, target, html.TD, function(target, index) { msg.Option("table.checkbox") && (index -= 1)
msg.append[index] == mdb.NAME && can.page.style(can, target.parentNode, html.BACKGROUND_COLOR, target.innerText) msg.append[index] == mdb.NAME && can.page.style(can, target.parentNode, html.BACKGROUND_COLOR, target.innerText)
}) })
}): can.page.Select(can, can._output, html.TD, function(target, index) { }): can.page.Select(can, can._output, html.TD, function(target, index) {

View File

@ -0,0 +1,8 @@
chapter "color"
refer `
标准 https://www.w3.org/TR/css-color-3/
教程 https://www.w3ccoo.com/colors/colors_groups.html
翻译 https://likexia.gitee.io/tools/colors/yansezhongwenming.html
`
field web.code.goquery.goquery space "20230511-golang-story"
field web.chat.color

View File

@ -15,8 +15,8 @@ func init() {
const THEME = "theme" const THEME = "theme"
chat.Index.MergeCommands(ice.Commands{ chat.Index.MergeCommands(ice.Commands{
THEME: {Actions: ice.MergeActions(ice.Actions{ THEME: {Actions: ice.MergeActions(ice.Actions{
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("web.chat.color").Cut(mdb.NAME, mdb.TEXT, mdb.TYPE) }}, mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("web.chat.color").Cut(mdb.NAME, mdb.TEXT, mdb.HELP) }},
mdb.CREATE: {Name: "create name* plugin-bg-color@color plugin-fg-color@color output-bg-color@color hover-bg-color@color"}, mdb.CREATE: {Name: "create name* plugin-bg-color@color output-bg-color@color hover-bg-color@color"},
mdb.SHOW: {Hand: func(m *ice.Message, arg ...string) { mdb.SHOW: {Hand: func(m *ice.Message, arg ...string) {
ctx.ProcessFloat(m, "web.chat.iframe", []string{"/?theme=" + m.Option(mdb.NAME)}, arg...) ctx.ProcessFloat(m, "web.chat.iframe", []string{"/?theme=" + m.Option(mdb.NAME)}, arg...)
}}, }},
@ -29,11 +29,9 @@ func init() {
} }
}}, }},
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, kit.Fields("time,name", }, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, kit.Fields("time,name",
"plugin-bg-color", "plugin-fg-color", "plugin-bg-color", "output-bg-color", "hover-bg-color",
"output-bg-color", "output-fg-color", "plugin-fg-color", "output-fg-color", "hover-fg-color",
"hover-bg-color", "hover-fg-color", "shadow-color", "border-color", "notice-color", "danger-color",
"shadow-color", "border-color",
"notice-color", "danger-color",
))), Hand: func(m *ice.Message, arg ...string) { ))), Hand: func(m *ice.Message, arg ...string) {
if mdb.HashSelect(m, arg...).PushAction(mdb.SHOW, mdb.REMOVE).Display(""); len(arg) > 0 { if mdb.HashSelect(m, arg...).PushAction(mdb.SHOW, mdb.REMOVE).Display(""); len(arg) > 0 {
defer m.Echo("body.%s {"+lex.NL, kit.TrimExt(arg[0], nfs.CSS)).Echo("}" + lex.NL) defer m.Echo("body.%s {"+lex.NL, kit.TrimExt(arg[0], nfs.CSS)).Echo("}" + lex.NL)

View File

@ -1,6 +1,5 @@
Volcanos(chat.ONIMPORT, { Volcanos(chat.ONIMPORT, {
_init: function(can, msg) { _init: function(can, msg) { msg.Show(can)
msg.Dump(can)
can.page.Select(can, can._output, "tr>td:not(:first-child):not(:last-child)", function(target) { can.page.Select(can, can._output, "tr>td:not(:first-child):not(:last-child)", function(target) {
can.page.style(can, target, html.BACKGROUND_COLOR, target.innerText) can.page.style(can, target, html.BACKGROUND_COLOR, target.innerText)
}) })

View File

@ -7,19 +7,13 @@ import (
"shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web"
"shylinux.com/x/icebergs/base/web/html" "shylinux.com/x/icebergs/base/web/html"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
func _field_show(m *ice.Message, name, text string, arg ...string) { func _field_show(m *ice.Message, name, text string, arg ...string) {
meta := kit.Dict() meta := kit.Dict()
m.Search(text, func(key string, cmd *ice.Command) {
meta[mdb.LIST], name = cmd.List, kit.Select(cmd.Help, name)
kit.For(cmd.Meta, func(k string, v ice.Any) { meta[kit.Keys(mdb.META, k)] = v })
})
if m.WarnNotFound(len(meta) == 0, text) || !aaa.Right(m.Spawn(), text) {
return
}
kit.For(arg, func(k, v string) { kit.For(arg, func(k, v string) {
if k == ctx.ARGS { if k == ctx.ARGS {
kit.Value(meta, k, kit.Split(strings.TrimSuffix(strings.TrimPrefix(v, "["), "]"))) kit.Value(meta, k, kit.Split(strings.TrimSuffix(strings.TrimPrefix(v, "["), "]")))
@ -31,6 +25,15 @@ func _field_show(m *ice.Message, name, text string, arg ...string) {
kit.Value(meta, k, v) kit.Value(meta, k, v)
} }
}) })
if p := kit.Format(meta[web.SPACE]); p == "" {
m.Search(text, func(key string, cmd *ice.Command) {
meta[mdb.LIST], name = cmd.List, kit.Select(cmd.Help, name)
kit.For(cmd.Meta, func(k string, v ice.Any) { meta[kit.Keys(mdb.META, k)] = v })
})
if m.WarnNotFound(len(meta) == 0, text) || !aaa.Right(m.Spawn(), text) {
return
}
}
meta[mdb.NAME], meta[mdb.INDEX] = name, text meta[mdb.NAME], meta[mdb.INDEX] = name, text
_wiki_template(m.Options(mdb.META, kit.Format(meta)), "", kit.Select(name, text, m.IsEnglish()), text) _wiki_template(m.Options(mdb.META, kit.Format(meta)), "", kit.Select(name, text, m.IsEnglish()), text)
} }
@ -40,7 +43,7 @@ const FIELD = "field"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
FIELD: {Name: "field name cmd", Help: "插件", Hand: func(m *ice.Message, arg ...string) { FIELD: {Name: "field name cmd", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
kit.If(kit.IsIn(kit.Select("", arg, 1), ctx.ARGS), func() { arg = kit.Simple("", arg) }) kit.If(kit.IsIn(kit.Select("", arg, 1), ctx.ARGS, web.SPACE), func() { arg = kit.Simple("", arg) })
arg = _name(m, arg) arg = _name(m, arg)
_field_show(m, arg[0], arg[1], arg[2:]...) _field_show(m, arg[0], arg[1], arg[2:]...)
}}, }},