diff --git a/base/nfs/cat.go b/base/nfs/cat.go index e4fe9887..3918f9ba 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -77,6 +77,7 @@ const ( BINARY = "binary" SCRIPT = "script" FORMAT = "format" + TRANS = "trans" CLONE = "clone" REPOS = "repos" diff --git a/base/web/html/html.go b/base/web/html/html.go index ce48a4fe..9b4e8d85 100644 --- a/base/web/html/html.go +++ b/base/web/html/html.go @@ -41,6 +41,10 @@ const ( TEXT_PLAIN = "text/plain" ) const ( + TABLE = "table" + TR = "tr" + TH = "th" + TD = "td" H1 = "h1" H2 = "h2" H3 = "h3" diff --git a/core/chat/theme/color.go b/core/chat/theme/color.go index bfeb8c0c..e73dee4f 100644 --- a/core/chat/theme/color.go +++ b/core/chat/theme/color.go @@ -5,54 +5,66 @@ import ( "strings" "shylinux.com/x/ice" + "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/base/web/html" kit "shylinux.com/x/toolkits" ) type color struct { ice.Hash - limit string `data:"300"` - short string `data:"type,name,text"` - field string `data:"type,name,text,group,order,hash"` - vendor string `data:"https://www.w3.org/TR/css-color-3/"` - group string `name:"group group*"` - load string `name:"load file*"` + checkbox string `data:"true"` + export string `data:"true"` + limit string `data:"300"` + short string `data:"type,name,text"` + field string `data:"type,name,text,help,group,order,hash"` + 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) { - nfs.ScanCSV(m.Message, m.Option(nfs.FILE), func(data []string) { - s.Hash.Create(m, mdb.TYPE, m.Option(nfs.FILE), mdb.NAME, data[0], mdb.TEXT, strings.ToUpper(data[1])) - }, mdb.NAME, mdb.TEXT) + defer m.ToastProcess()() + trans := map[string]string{} + 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) { - m.Cmd("").Table(func(value ice.Maps) { - key, info := Group(value[mdb.NAME], value[mdb.TEXT]) - m.Push(key, info) - }) - m.Display("") + m.Cmd("").Table(func(value ice.Maps) { key, info := Group(value[mdb.NAME], value[mdb.TEXT]); m.Push(key, info) }) + m.Action(s.Matrix).Display("") } 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) { 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.Sort("type,group,order,text", ice.STR, []string{"red", "yellow", "green", "cyan", "blue", "purple", "brown", "meet", "gray"}, "int", ice.STR).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)) + m.Cut("type,name,text,help,group,order,color,weight,hash,action") + m.Sort("type,group,order,color,text", ice.STR, group, ice.INT, group, ice.STR) + m.Display("") } +func (s color) Group(m *ice.Message, arg ...string) { s.Hash.Modify(m, mdb.GROUP, m.Option(mdb.GROUP)) } + 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) { if text == "#000000" { - return "gray", "" + return cli.GRAY, "" } r, _ := strconv.ParseInt(text[1:3], 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) green := float32(g) / float32(n) blue := float32(b) / float32(n) - name = kit.Format( - "%s %0.2f %0.2f %0.2f %s", - text, + name = kit.Format("%s %0.2f %0.2f %0.2f %s", text, float32(r)/float32(n), float32(g)/float32(n), float32(b)/float32(n), name, ) if red > 0.33 && green > 0.33 && blue > 0.33 { - return "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 + return cli.GRAY, name } if red > 0.57 { - return "red", name + return cli.RED, name } else if green > 0.57 { - return "green", name + return cli.GREEN, name } else if blue > 0.57 { - return "blue", name + return cli.BLUE, name } - if red < 0.1 && green > 0.3 && blue > 0.3 { - return "cyan", name - } else if red > 0.3 && green < 0.1 && blue > 0.3 { - return "purple", name - } else if red > 0.3 && green > 0.3 && blue < 0.1 { - return "yellow", name + if red < 0.15 && green > 0.3 && blue > 0.3 { + return cli.CYAN, name + } else if red > 0.3 && green < 0.15 && blue > 0.3 { + return cli.PURPLE, name + } else if red > 0.3 && green > 0.3 && blue < 0.15 { + return cli.YELLOW, name } 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 { - return "purple", name + return cli.PURPLE, name } 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 { - return "red", name + return cli.RED, name } 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 { - return "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 + return cli.BLUE, name } if red > green && red > blue { - return "red", name + return cli.RED, name } else if green > red && green > blue { - return "green", name + return cli.GREEN, name } else if blue > red && blue > green { - return "blue", name - } else { - return "", name + return cli.BLUE, 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 } diff --git a/core/chat/theme/color.js b/core/chat/theme/color.js index 70f530b5..617054bc 100644 --- a/core/chat/theme/color.js +++ b/core/chat/theme/color.js @@ -1,7 +1,7 @@ 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) { - 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) }) }): can.page.Select(can, can._output, html.TD, function(target, index) { diff --git a/core/chat/theme/color.shy b/core/chat/theme/color.shy new file mode 100644 index 00000000..e93727ce --- /dev/null +++ b/core/chat/theme/color.shy @@ -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 diff --git a/core/chat/theme/theme.go b/core/chat/theme/theme.go index 1032ca48..58ff31f5 100644 --- a/core/chat/theme/theme.go +++ b/core/chat/theme/theme.go @@ -15,8 +15,8 @@ func init() { const THEME = "theme" chat.Index.MergeCommands(ice.Commands{ 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.CREATE: {Name: "create name* plugin-bg-color@color plugin-fg-color@color output-bg-color@color hover-bg-color@color"}, + 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 output-bg-color@color hover-bg-color@color"}, mdb.SHOW: {Hand: func(m *ice.Message, arg ...string) { 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", - "plugin-bg-color", "plugin-fg-color", - "output-bg-color", "output-fg-color", - "hover-bg-color", "hover-fg-color", - "shadow-color", "border-color", - "notice-color", "danger-color", + "plugin-bg-color", "output-bg-color", "hover-bg-color", + "plugin-fg-color", "output-fg-color", "hover-fg-color", + "shadow-color", "border-color", "notice-color", "danger-color", ))), Hand: func(m *ice.Message, arg ...string) { 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) diff --git a/core/chat/theme/theme.js b/core/chat/theme/theme.js index c9780bad..f371a499 100644 --- a/core/chat/theme/theme.js +++ b/core/chat/theme/theme.js @@ -1,6 +1,5 @@ Volcanos(chat.ONIMPORT, { - _init: function(can, msg) { - msg.Dump(can) + _init: function(can, msg) { msg.Show(can) 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) }) diff --git a/core/wiki/field.go b/core/wiki/field.go index c4e63585..e746dcfc 100644 --- a/core/wiki/field.go +++ b/core/wiki/field.go @@ -7,19 +7,13 @@ import ( "shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/base/web/html" kit "shylinux.com/x/toolkits" ) func _field_show(m *ice.Message, name, text string, arg ...string) { 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) { if k == ctx.ARGS { 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) } }) + 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 _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() { Index.MergeCommands(ice.Commands{ 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) _field_show(m, arg[0], arg[1], arg[2:]...) }},