@rbxts/centurion-ui 2.0.0-rc.4 → 2.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/analyse/leventine.luau +1 -1
- package/src/analyse/suggest.luau +39 -3
- package/src/app/header.luau +19 -9
- package/src/app/init.luau +10 -3
- package/src/init.luau +4 -2
- package/src/px.luau +2 -3
- package/src/state.luau +5 -4
- package/src/ts/index.d.ts +3 -1
- package/src/types.luau +6 -2
package/package.json
CHANGED
|
@@ -51,7 +51,7 @@ local function myers_32(a: string, b: string, a_len: number, b_len: number): num
|
|
|
51
51
|
|
|
52
52
|
-- Set the bits for characters in string a
|
|
53
53
|
for j, a_byte in a_bytes do
|
|
54
|
-
PEQ[a_byte] = OR(PEQ[a_byte], LSHIFT(1, j))
|
|
54
|
+
PEQ[a_byte] = OR(PEQ[a_byte], LSHIFT(1, j - 1))
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
for _, byte in b_bytes do
|
package/src/analyse/suggest.luau
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
local leventine = require("./leventine")
|
|
2
2
|
|
|
3
3
|
local MIN_SCORE = -math.huge
|
|
4
|
+
local SUBSEQUENCE_BONUS = 100
|
|
5
|
+
|
|
6
|
+
local function word_start(candidate: string, pos: number): boolean
|
|
7
|
+
return pos == 1 or string.find(string.sub(candidate, pos - 1, pos - 1), "[%s_%-]") ~= nil
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
-- rewards the query's characters appearing in order in the candidate, by how
|
|
11
|
+
-- tightly they're packed and whether they start a word. a flat bonus would
|
|
12
|
+
-- rank loose matches like "rsp" in "forcespawn" above close typos like "esp"
|
|
13
|
+
local function subsequence_bonus(query: string, candidate: string): number
|
|
14
|
+
local first = string.sub(query, 1, 1)
|
|
15
|
+
local best = 0
|
|
16
|
+
|
|
17
|
+
local start = string.find(candidate, first, 1, true)
|
|
18
|
+
while start do
|
|
19
|
+
local pos = start
|
|
20
|
+
for i = 2, #query do
|
|
21
|
+
local found = string.find(candidate, string.sub(query, i, i), pos + 1, true)
|
|
22
|
+
if not found then
|
|
23
|
+
-- later starts can't match either
|
|
24
|
+
return best
|
|
25
|
+
end
|
|
26
|
+
pos = found
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
local tightness = #query / (pos - start + 1)
|
|
30
|
+
-- abbreviations skip a lot, e.g. "tp" for "teleport", so don't punish gaps too hard
|
|
31
|
+
local bonus = SUBSEQUENCE_BONUS * tightness ^ 1.5
|
|
32
|
+
if not word_start(candidate, start) then
|
|
33
|
+
bonus /= 2
|
|
34
|
+
end
|
|
35
|
+
best = math.max(best, bonus)
|
|
36
|
+
|
|
37
|
+
start = string.find(candidate, first, start + 1, true)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
return best
|
|
41
|
+
end
|
|
4
42
|
|
|
5
43
|
-- returns the best matches, and how many there were before being limited
|
|
6
44
|
local function suggest(input: string, candidates: { string }, max_suggestions: number?): ({ string }, number)
|
|
@@ -21,9 +59,7 @@ local function suggest(input: string, candidates: { string }, max_suggestions: n
|
|
|
21
59
|
else
|
|
22
60
|
score = leventine.score(normalized, candidate, false)
|
|
23
61
|
score = (1 - score / math.max(#normalized, #candidate)) * 100
|
|
24
|
-
|
|
25
|
-
score += 100
|
|
26
|
-
end
|
|
62
|
+
score += subsequence_bonus(normalized, candidate:lower())
|
|
27
63
|
end
|
|
28
64
|
|
|
29
65
|
if score > MIN_SCORE then
|
package/src/app/header.luau
CHANGED
|
@@ -19,6 +19,7 @@ local source = vide.source
|
|
|
19
19
|
type Header = {
|
|
20
20
|
read order: number?,
|
|
21
21
|
read on_clear: () -> (),
|
|
22
|
+
read on_close: () -> (),
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
-- KeyCode names that aren't what's printed on the key
|
|
@@ -41,7 +42,7 @@ local function key_label(key: Enum.KeyCode): string
|
|
|
41
42
|
return key_labels[key.Name] or key.Name
|
|
42
43
|
end
|
|
43
44
|
|
|
44
|
-
local function
|
|
45
|
+
local function text_button(props: { order: number, label: string, on_activated: () -> () })
|
|
45
46
|
local hovered = source(false)
|
|
46
47
|
|
|
47
48
|
return create "TextButton" {
|
|
@@ -51,7 +52,7 @@ local function clear_button(props: { order: number, on_clear: () -> () })
|
|
|
51
52
|
LayoutOrder = props.order,
|
|
52
53
|
Text = "",
|
|
53
54
|
|
|
54
|
-
Activated = props.
|
|
55
|
+
Activated = props.on_activated,
|
|
55
56
|
MouseEnter = function()
|
|
56
57
|
hovered(true)
|
|
57
58
|
end,
|
|
@@ -61,7 +62,7 @@ local function clear_button(props: { order: number, on_clear: () -> () })
|
|
|
61
62
|
|
|
62
63
|
text {
|
|
63
64
|
auto = "XY",
|
|
64
|
-
text =
|
|
65
|
+
text = props.label,
|
|
65
66
|
text_size = px(state.subtext_size),
|
|
66
67
|
text_style = function()
|
|
67
68
|
return if hovered() then "highlight" else "subtext"
|
|
@@ -85,6 +86,11 @@ local function header(props: Header)
|
|
|
85
86
|
return input() == Enum.PreferredInput.KeyboardAndMouse and #state.activation_keys() > 0
|
|
86
87
|
end
|
|
87
88
|
|
|
89
|
+
-- touch devices have no key to close with, so give them a button instead
|
|
90
|
+
local function show_close()
|
|
91
|
+
return input() == Enum.PreferredInput.Touch
|
|
92
|
+
end
|
|
93
|
+
|
|
88
94
|
return container {
|
|
89
95
|
size = px(UDim2.new(1, 0, 0, 23)),
|
|
90
96
|
order = props.order,
|
|
@@ -99,7 +105,7 @@ local function header(props: Header)
|
|
|
99
105
|
flex():column():vertical("center"):gap(5),
|
|
100
106
|
|
|
101
107
|
image {
|
|
102
|
-
image = state.
|
|
108
|
+
image = state.header_icon,
|
|
103
109
|
size = px(function()
|
|
104
110
|
return UDim2.fromOffset(state.subtext_size(), state.subtext_size())
|
|
105
111
|
end),
|
|
@@ -107,7 +113,7 @@ local function header(props: Header)
|
|
|
107
113
|
return state.theme().highlight
|
|
108
114
|
end,
|
|
109
115
|
visible = function()
|
|
110
|
-
return state.
|
|
116
|
+
return state.header_icon() ~= ""
|
|
111
117
|
end,
|
|
112
118
|
order = 1,
|
|
113
119
|
},
|
|
@@ -115,7 +121,7 @@ local function header(props: Header)
|
|
|
115
121
|
text {
|
|
116
122
|
auto = "XY",
|
|
117
123
|
order = 2,
|
|
118
|
-
text = state.
|
|
124
|
+
text = state.header_title,
|
|
119
125
|
text_size = px(state.subtext_size),
|
|
120
126
|
text_style = "subtext",
|
|
121
127
|
weight = Enum.FontWeight.Bold,
|
|
@@ -130,12 +136,12 @@ local function header(props: Header)
|
|
|
130
136
|
|
|
131
137
|
-- only shown while there's something to clear
|
|
132
138
|
show(show_clear, function()
|
|
133
|
-
return
|
|
139
|
+
return text_button { order = 1, label = "Clear", on_activated = props.on_clear }
|
|
134
140
|
end),
|
|
135
141
|
|
|
136
|
-
-- vertical rule between the clear button and the close hint
|
|
142
|
+
-- vertical rule between the clear button and the close hint or button
|
|
137
143
|
show(function()
|
|
138
|
-
return show_clear() and show_hint()
|
|
144
|
+
return show_clear() and (show_hint() or show_close())
|
|
139
145
|
end, function()
|
|
140
146
|
return background {
|
|
141
147
|
order = 2,
|
|
@@ -188,6 +194,10 @@ local function header(props: Header)
|
|
|
188
194
|
},
|
|
189
195
|
}
|
|
190
196
|
end),
|
|
197
|
+
|
|
198
|
+
show(show_close, function()
|
|
199
|
+
return text_button { order = 4, label = "Close", on_activated = props.on_close }
|
|
200
|
+
end),
|
|
191
201
|
},
|
|
192
202
|
}
|
|
193
203
|
end
|
package/src/app/init.luau
CHANGED
|
@@ -621,10 +621,13 @@ local function app()
|
|
|
621
621
|
local offset = px.convert((reveal() - 1) * 8)
|
|
622
622
|
return px.get(state.position) + UDim2.fromOffset(0, offset)
|
|
623
623
|
end,
|
|
624
|
-
size =
|
|
624
|
+
size = function()
|
|
625
625
|
local w = state.width()
|
|
626
|
-
|
|
627
|
-
|
|
626
|
+
local viewport = px.viewport().X
|
|
627
|
+
-- never wider than the screen, leaving a margin on either side
|
|
628
|
+
local max_offset = viewport * (1 - w.Scale) - px.convert(16) * 2
|
|
629
|
+
return UDim2.new(w.Scale, math.min(px.convert(w.Offset), max_offset), 0, 0)
|
|
630
|
+
end,
|
|
628
631
|
|
|
629
632
|
padding(px(8)),
|
|
630
633
|
flex():row():gap(1),
|
|
@@ -660,6 +663,10 @@ local function app()
|
|
|
660
663
|
state.logs({})
|
|
661
664
|
refocus()
|
|
662
665
|
end,
|
|
666
|
+
on_close = function()
|
|
667
|
+
state.opened(false)
|
|
668
|
+
state.focused(false)
|
|
669
|
+
end,
|
|
663
670
|
},
|
|
664
671
|
divider { order = 2 },
|
|
665
672
|
|
package/src/init.luau
CHANGED
|
@@ -42,7 +42,6 @@ local function configure(options: types.OptionsPartial)
|
|
|
42
42
|
set_opt(state.hide_on_lost_focus, options.hide_on_lost_focus)
|
|
43
43
|
set_opt(state.activation_keys, options.activation_keys)
|
|
44
44
|
set_opt(state.theme, options.theme)
|
|
45
|
-
set_opt(state.icon, options.icon)
|
|
46
45
|
set_opt(state.font, options.font)
|
|
47
46
|
set_opt(state.transparency, options.transparency)
|
|
48
47
|
|
|
@@ -56,8 +55,11 @@ local function configure(options: types.OptionsPartial)
|
|
|
56
55
|
|
|
57
56
|
set_opt(state.visible_suggestions, options.visible_suggestions)
|
|
58
57
|
set_opt(state.max_suggestions, options.max_suggestions)
|
|
59
|
-
set_opt(state.clear_button, options.clear_button)
|
|
60
58
|
set_opt(state.format_date, options.format_date)
|
|
59
|
+
|
|
60
|
+
set_opt(state.header_title, options.header_title)
|
|
61
|
+
set_opt(state.header_icon, options.header_icon)
|
|
62
|
+
set_opt(state.clear_button, options.clear_button)
|
|
61
63
|
end
|
|
62
64
|
|
|
63
65
|
local function clear()
|
package/src/px.luau
CHANGED
|
@@ -12,6 +12,7 @@ const MIN_SCALE = 0.5
|
|
|
12
12
|
local DOMINANT_AXIS = 0.5
|
|
13
13
|
|
|
14
14
|
local scale = source(1)
|
|
15
|
+
local viewport_size = source(Vector2.new(0, 0))
|
|
15
16
|
|
|
16
17
|
local function modify_scale(scale_value: number): number
|
|
17
18
|
return math.max(scale_value, MIN_SCALE)
|
|
@@ -52,8 +53,6 @@ local function px<T>(value: T | () -> T, mode: Mode? | () -> Mode?): () -> T
|
|
|
52
53
|
end
|
|
53
54
|
|
|
54
55
|
local function mount()
|
|
55
|
-
local viewport_size = source(Vector2.new(0, 0))
|
|
56
|
-
|
|
57
56
|
effect(function()
|
|
58
57
|
local viewport = viewport_size()
|
|
59
58
|
local scaleX = math.log(viewport.X / BASE_RESOLUTION.X, 2)
|
|
@@ -69,7 +68,7 @@ local function mount()
|
|
|
69
68
|
viewport_size(workspace.CurrentCamera.ViewportSize)
|
|
70
69
|
end
|
|
71
70
|
|
|
72
|
-
return setmetatable({ mount = mount, convert = convert, get = px_raw }, {
|
|
71
|
+
return setmetatable({ mount = mount, convert = convert, get = px_raw, viewport = viewport_size }, {
|
|
73
72
|
__call = function<T>(_, value: T | () -> T, mode: Mode? | () -> Mode?): () -> T
|
|
74
73
|
return px(value, mode)
|
|
75
74
|
end,
|
package/src/state.luau
CHANGED
|
@@ -14,9 +14,7 @@ return {
|
|
|
14
14
|
hide_on_lost_focus = source(true),
|
|
15
15
|
theme = source(theme.themes.mocha),
|
|
16
16
|
font = source(Font.fromId(16658246179)),
|
|
17
|
-
|
|
18
|
-
icon = source("rbxassetid://115292290730914"),
|
|
19
|
-
transparency = source(0.2),
|
|
17
|
+
transparency = source(0.1),
|
|
20
18
|
format_date = source(function(log: types.Log): string
|
|
21
19
|
local dateTime = DateTime.fromUnixTimestamp(log.response.timestamp):FormatLocalTime("LT", "en-us")
|
|
22
20
|
local dateParts = dateTime:split(" ")
|
|
@@ -24,6 +22,9 @@ return {
|
|
|
24
22
|
end),
|
|
25
23
|
visible_suggestions = source(5),
|
|
26
24
|
max_suggestions = source(50),
|
|
25
|
+
|
|
26
|
+
header_title = source("Centurion"),
|
|
27
|
+
header_icon = source("rbxassetid://115292290730914"),
|
|
27
28
|
clear_button = source(false),
|
|
28
29
|
|
|
29
30
|
text_size = source(19),
|
|
@@ -31,6 +32,6 @@ return {
|
|
|
31
32
|
|
|
32
33
|
anchor = source(Vector2.new(0.5, 0)),
|
|
33
34
|
position = source(UDim2.new(0.5, 0, 0, 0)),
|
|
34
|
-
width = source(UDim.new(0,
|
|
35
|
+
width = source(UDim.new(0, 1000)),
|
|
35
36
|
display_order = source(1000),
|
|
36
37
|
}
|
package/src/ts/index.d.ts
CHANGED
|
@@ -5,11 +5,13 @@ export interface Options {
|
|
|
5
5
|
activation_keys: Enum.KeyCode[];
|
|
6
6
|
theme: Theme;
|
|
7
7
|
font: Font;
|
|
8
|
-
icon: string;
|
|
9
8
|
transparency: number;
|
|
10
9
|
format_date: (log: Log) => string;
|
|
11
10
|
visible_suggestions: number;
|
|
12
11
|
max_suggestions: number;
|
|
12
|
+
|
|
13
|
+
header_title: string;
|
|
14
|
+
header_icon: string;
|
|
13
15
|
clear_button: boolean;
|
|
14
16
|
|
|
15
17
|
text_size: number;
|
package/src/types.luau
CHANGED
|
@@ -10,11 +10,13 @@ export type Options = {
|
|
|
10
10
|
activation_keys: { Enum.KeyCode },
|
|
11
11
|
theme: Theme,
|
|
12
12
|
font: Font,
|
|
13
|
-
icon: string,
|
|
14
13
|
transparency: number,
|
|
15
14
|
format_date: (log: Log) -> string,
|
|
16
15
|
visible_suggestions: number,
|
|
17
16
|
max_suggestions: number,
|
|
17
|
+
|
|
18
|
+
header_title: string,
|
|
19
|
+
header_icon: string,
|
|
18
20
|
clear_button: boolean,
|
|
19
21
|
|
|
20
22
|
text_size: number,
|
|
@@ -31,11 +33,13 @@ export type OptionsPartial = {
|
|
|
31
33
|
activation_keys: { Enum.KeyCode }?,
|
|
32
34
|
theme: Theme?,
|
|
33
35
|
font: Font?,
|
|
34
|
-
icon: string?,
|
|
35
36
|
transparency: number?,
|
|
36
37
|
format_date: ((log: Log) -> string)?,
|
|
37
38
|
visible_suggestions: number?,
|
|
38
39
|
max_suggestions: number?,
|
|
40
|
+
|
|
41
|
+
header_title: string?,
|
|
42
|
+
header_icon: string?,
|
|
39
43
|
clear_button: boolean?,
|
|
40
44
|
|
|
41
45
|
text_size: number?,
|