@overmvp/kumi 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +14 -2
- package/animation/color-transition.ts +196 -0
- package/animation/cycle.ts +151 -0
- package/animation/ease.ts +29 -0
- package/animation/index.ts +13 -0
- package/animation/package.json +12 -0
- package/animation/presets.ts +376 -0
- package/animation/spec.ts +197 -0
- package/builder/Cargo.lock +192 -0
- package/builder/Cargo.toml +7 -0
- package/builder/css-v1.mjs +334 -0
- package/builder/css-v1.test.mjs +321 -0
- package/builder/generated-output.mjs +61 -0
- package/builder/generated-output.test.mjs +132 -0
- package/builder/jsx-form.mjs +93 -0
- package/builder/jsx-form.test.mjs +48 -0
- package/builder/jsx-lists.mjs +209 -0
- package/builder/link-addon-package.mjs +86 -0
- package/builder/lua-assets.mjs +74 -0
- package/builder/lua-builtin-values.mjs +57 -0
- package/builder/lua-builtin-values.test.mjs +155 -0
- package/builder/lua-loop-closures.mjs +183 -0
- package/builder/lua-loop-closures.test.mjs +89 -0
- package/builder/lua-truthiness.mjs +61 -0
- package/builder/lua-truthiness.test.mjs +113 -0
- package/builder/module-declarations.mjs +594 -0
- package/builder/module-declarations.test.mjs +444 -0
- package/builder/native-kernels.mjs +60 -0
- package/builder/native-lua.d.ts +57 -0
- package/builder/native-routes.mjs +51 -0
- package/builder/no-static-ref-read.mjs +93 -0
- package/builder/no-static-ref-read.test.mjs +181 -0
- package/builder/secure-snippet.mjs +317 -0
- package/builder/secure-snippet.test.mjs +101 -0
- package/builder/shared-lua-runtime.mjs +150 -0
- package/builder/src/addon-link.lua +29 -0
- package/builder/src/arrays.lua +260 -0
- package/builder/src/assets.rs +177 -0
- package/builder/src/classes.lua +75 -0
- package/builder/src/collections.lua +190 -0
- package/builder/src/compiler.rs +2164 -0
- package/builder/src/config.rs +42 -0
- package/builder/src/entries.rs +166 -0
- package/builder/src/errors.lua +15 -0
- package/builder/src/lua_data.rs +231 -0
- package/builder/src/main.rs +367 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +47 -0
- package/builder/src/numbers.lua +62 -0
- package/builder/src/project-front.mjs +3331 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +127 -0
- package/builder/src/signal-kernel.fingerprint +1 -0
- package/builder/src/strings.lua +103 -0
- package/builder/src/ts-lower.mjs +68 -0
- package/builder/src/wow_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -0
- package/builder/style-states.mjs +100 -0
- package/builder/style-states.test.mjs +103 -0
- package/builder/vite-assets.mjs +53 -0
- package/builder/vite-project.mjs +10 -0
- package/config.ts +17 -0
- package/form/index.ts +522 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +22 -4
- package/router/index.ts +43 -0
- package/router/package.json +12 -0
- package/router/routes.ts +64 -0
- package/scripts/kumi-cli.mjs +70 -0
- package/scripts/link-addons.mjs +51 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +234 -0
- package/src/css-v1.ts +58 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +479 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +334 -0
- package/src/grid-tracks.ts +165 -0
- package/src/image-imports.d.ts +24 -0
- package/src/images.ts +79 -0
- package/src/index.ts +28 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +22 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +363 -0
- package/src/media-query.ts +144 -0
- package/src/module.ts +277 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +44 -0
- package/src/providers.ts +235 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +254 -0
- package/src/result.ts +58 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +30 -0
- package/src/style-classes.ts +51 -0
- package/src/style-states.ts +134 -0
- package/src/style-variables.ts +53 -0
- package/src/text-children.ts +42 -0
- package/src/theme.ts +50 -0
- package/src/transition.ts +18 -0
- package/state/index.ts +3 -0
- package/state/package.json +12 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +82 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/README.md +14 -0
- package/templates/addon/__ADDON_NAME__.toc +4 -0
- package/templates/addon/eslint.config.mjs +12 -0
- package/templates/addon/gitignore +8 -0
- package/templates/addon/package.json +21 -0
- package/templates/addon/scripts/build.mjs +25 -0
- package/templates/addon/src/app/main.tsx +13 -0
- package/templates/addon/tsconfig.json +24 -0
- package/translate/index.ts +14 -0
- package/translate/package.json +9 -0
- package/utils/colors.ts +76 -0
- package/utils/format.ts +37 -0
- package/utils/index.ts +4 -0
- package/utils/number.ts +17 -0
- package/utils/package.json +7 -0
- package/utils/text.ts +6 -0
- package/validate/index.ts +119 -0
- package/validate/package.json +9 -0
- package/wow/absolute-position.ts +142 -0
- package/wow/animation.ts +428 -0
- package/wow/aura-button.ts +76 -0
- package/wow/aura-container.ts +591 -0
- package/wow/aura-countdown.ts +201 -0
- package/wow/aura-slot.ts +153 -0
- package/wow/bar-shade.ts +93 -0
- package/wow/borrowed-slot.ts +216 -0
- package/wow/button-drag.ts +48 -0
- package/wow/cast-clock.ts +153 -0
- package/wow/cast-text.ts +83 -0
- package/wow/class-colors.ts +126 -0
- package/wow/clock.ts +7 -0
- package/wow/color-picker.ts +128 -0
- package/wow/commands.ts +17 -0
- package/wow/contained-frame.ts +128 -0
- package/wow/contract.ts +42 -0
- package/wow/css-box.ts +110 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +398 -0
- package/wow/css-text.ts +399 -0
- package/wow/cvar-schema.ts +32 -0
- package/wow/cvars.ts +98 -0
- package/wow/dropdown-art.ts +39 -0
- package/wow/element-click.ts +20 -0
- package/wow/element-event-coordinator.ts +219 -0
- package/wow/element-events.ts +317 -0
- package/wow/event-dispatcher.ts +151 -0
- package/wow/events.ts +50 -0
- package/wow/font-cache.ts +92 -0
- package/wow/frame-access.ts +31 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +97 -0
- package/wow/layout-view.ts +651 -0
- package/wow/lua-string.ts +18 -0
- package/wow/lua-table.ts +18 -0
- package/wow/macro-book.ts +84 -0
- package/wow/map-position.ts +27 -0
- package/wow/media-query.ts +65 -0
- package/wow/module-events.ts +11 -0
- package/wow/native-hooks.ts +168 -0
- package/wow/native-placement.ts +88 -0
- package/wow/native.ts +135 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/protect.ts +24 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/range-art.ts +74 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +156 -0
- package/wow/saved-variables.ts +60 -0
- package/wow/scroll-view.ts +64 -0
- package/wow/secret-ref.ts +14 -0
- package/wow/secure-bindings.ts +89 -0
- package/wow/secure-clicks.ts +432 -0
- package/wow/secure-snippet.ts +235 -0
- package/wow/secure-state.ts +130 -0
- package/wow/secure-target-visibility.ts +89 -0
- package/wow/secure-transaction.ts +331 -0
- package/wow/special-window.ts +269 -0
- package/wow/start-addon.ts +99 -0
- package/wow/state-paint.ts +256 -0
- package/wow/transition.ts +86 -0
- package/wow/unit-button.ts +39 -0
- package/wow/unit-cast.ts +92 -0
- package/wow/unit-health-text.ts +47 -0
- package/wow/view-nodes.ts +304 -0
- package/wow/view.ts +1746 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
package/wow/css-text.ts
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { createColorTransitions, type ColorTransitions } from "../animation/color-transition";
|
|
2
|
+
import type { CssFontWeight, CssTextAlign, CssTextShadow, CssTokenRecipe, CssV1Style } from "../src/css-v1";
|
|
3
|
+
import type { Binding, Element, NativeStyle } from "../src/elements";
|
|
4
|
+
import type { OwnedReadonlyArray } from "../src/owned-collections";
|
|
5
|
+
import { ok, type Failure, type Result } from "../src/result";
|
|
6
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
7
|
+
import { resolveStyleValue, styleValue, type StyleEnvironment } from "../src/style-variables";
|
|
8
|
+
import type { RGBA } from "../utils/colors";
|
|
9
|
+
import { readCssColor } from "./css-color";
|
|
10
|
+
import type { FontString, FrameMap } from "./frames";
|
|
11
|
+
import { luaString } from "./lua-string";
|
|
12
|
+
import { api, isSecret, reveal, type SecretValue } from "./native";
|
|
13
|
+
import { bindColorChannel, type ButtonPaintTiming, type NativePaintState, type TextColorStateChange } from "./state-paint";
|
|
14
|
+
|
|
15
|
+
type Transform = NonNullable<CssV1Style["textTransform"]>;
|
|
16
|
+
type ColorRead = (this: void) => Result<string | undefined>;
|
|
17
|
+
type Value<T> = T | ((this: void) => T | undefined);
|
|
18
|
+
|
|
19
|
+
interface Typography {
|
|
20
|
+
fontSize: number;
|
|
21
|
+
fontWeight: CssFontWeight;
|
|
22
|
+
textAlign: CssTextAlign;
|
|
23
|
+
textShadow: CssTextShadow;
|
|
24
|
+
textTransform: Transform;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type TypographySources = { readonly [Property in keyof Typography]?: Value<Typography[Property]> };
|
|
28
|
+
type TextColorDuration = (this: void, change: TextColorStateChange) => number;
|
|
29
|
+
|
|
30
|
+
interface TextColorMotion {
|
|
31
|
+
readonly change: NonNullable<NativePaintState["colorChange"]>;
|
|
32
|
+
readonly duration: TextColorDuration;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type NativeTextStyle = TypographySources & {
|
|
36
|
+
readonly color?: ColorRead;
|
|
37
|
+
readonly colorMotion?: TextColorMotion;
|
|
38
|
+
readonly buttonTiming?: ButtonPaintTiming;
|
|
39
|
+
readonly shadowEnvironment?: StyleEnvironment;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface NativeTextHost {
|
|
43
|
+
fontSize?(this: void, text: FontString, size: number): void;
|
|
44
|
+
fontFile?(this: void, weight: CssFontWeight): string | undefined;
|
|
45
|
+
transform?(this: void, mode: Exclude<Transform, "none">, text: string): string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type TextProps = Pick<Element<"text">["props"], "align" | "font" | "fontSize" | "heading">;
|
|
49
|
+
type TextRead = string | SecretValue<string>;
|
|
50
|
+
|
|
51
|
+
const headingSizes = [24, 20, 18, 16, 14, 12];
|
|
52
|
+
const alignment = { left: "LEFT", center: "CENTER", right: "RIGHT" } as const;
|
|
53
|
+
|
|
54
|
+
export function bindEditTextAlign(this: void, edit: FrameMap["EditBox"], scope: RuntimeScope,
|
|
55
|
+
style: NativeStyle | undefined, live?: (this: void) => NativeStyle): Failure | undefined {
|
|
56
|
+
const authored = reveal(style?.textAlign);
|
|
57
|
+
if (authored === undefined) return;
|
|
58
|
+
const tokens = live === undefined ? undefined : style?.styleTokens as OwnedReadonlyArray<CssTokenRecipe> | undefined;
|
|
59
|
+
if (live === undefined || tokens === undefined
|
|
60
|
+
|| !tokens.some(recipe => (recipe.path as OwnedReadonlyArray<string | number>)[0] === "textAlign")) {
|
|
61
|
+
edit.SetJustifyH(alignment[authored]);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let previous: CssTextAlign | undefined;
|
|
66
|
+
const observed = scope.watchEffect(() => {
|
|
67
|
+
const next = reveal(live().textAlign);
|
|
68
|
+
if (next === undefined || next === previous) return;
|
|
69
|
+
edit.SetJustifyH(alignment[next]);
|
|
70
|
+
previous = next;
|
|
71
|
+
});
|
|
72
|
+
return observed.ok ? undefined : observed;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function read<T>(value: Value<T> | undefined): T | undefined {
|
|
76
|
+
// All typography leaf types are ordinary values; functions are live readers.
|
|
77
|
+
return typeof value === "function" ? (value as (this: void) => T | undefined)() : value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Carry nearest property sources through the logical JSX mount, including portal branches. */
|
|
81
|
+
export function inheritTextStyle(this: void, parent: NativeTextStyle | undefined, style: NativeStyle | undefined,
|
|
82
|
+
environment?: StyleEnvironment, paint?: NativePaintState, color?: Binding<string>,
|
|
83
|
+
live?: (this: void) => NativeStyle, duration?: TextColorDuration, buttonTiming?: ButtonPaintTiming): NativeTextStyle | undefined {
|
|
84
|
+
if (style?.fontSize === undefined && style?.fontWeight === undefined && style?.textAlign === undefined
|
|
85
|
+
&& style?.textShadow === undefined && style?.textTransform === undefined && style?.color === undefined
|
|
86
|
+
&& color === undefined && paint?.usesColor !== true && buttonTiming === undefined) return parent;
|
|
87
|
+
|
|
88
|
+
function property<Key extends keyof Typography>(name: Key): Value<Typography[Key]> | undefined {
|
|
89
|
+
const initial: Partial<Typography> | undefined = style;
|
|
90
|
+
const inherited: TypographySources | undefined = parent;
|
|
91
|
+
const authored = initial?.[name];
|
|
92
|
+
if (authored === undefined) return inherited?.[name];
|
|
93
|
+
if (live === undefined) return authored;
|
|
94
|
+
return () => {
|
|
95
|
+
const current: Partial<Typography> = live();
|
|
96
|
+
return current[name];
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function colorSource(this: void): Result<string | undefined> {
|
|
101
|
+
const current = paint?.usesColor === true ? paint.evaluate() : undefined;
|
|
102
|
+
if (current?.ok === false) return current;
|
|
103
|
+
const authored = current?.value.color ?? color ?? (live === undefined ? style?.color : live().color);
|
|
104
|
+
if (authored === undefined) return parent?.color?.() ?? ok(undefined);
|
|
105
|
+
const plain = styleValue(authored, isSecret);
|
|
106
|
+
if (!plain.ok || plain.value === undefined) return plain;
|
|
107
|
+
return resolveStyleValue(plain.value, environment);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const ownColor = color !== undefined || style?.color !== undefined || paint?.usesColor === true;
|
|
111
|
+
const colorChange = paint?.colorChange;
|
|
112
|
+
return {
|
|
113
|
+
fontSize: property("fontSize"),
|
|
114
|
+
fontWeight: property("fontWeight"),
|
|
115
|
+
textAlign: property("textAlign"),
|
|
116
|
+
textShadow: property("textShadow"),
|
|
117
|
+
textTransform: property("textTransform"),
|
|
118
|
+
shadowEnvironment: style?.textShadow === undefined ? parent?.shadowEnvironment : environment,
|
|
119
|
+
color: ownColor ? colorSource : parent?.color,
|
|
120
|
+
colorMotion: !ownColor ? parent?.colorMotion
|
|
121
|
+
: duration === undefined || colorChange === undefined ? undefined : { change: colorChange, duration },
|
|
122
|
+
buttonTiming: buttonTiming ?? parent?.buttonTiming,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function nativeColor(text: FontString): RGBA {
|
|
127
|
+
const [rawRed, rawGreen, rawBlue, rawAlpha] = text.GetTextColor();
|
|
128
|
+
const red = reveal(rawRed), green = reveal(rawGreen), blue = reveal(rawBlue), alpha = reveal(rawAlpha);
|
|
129
|
+
return red === undefined || green === undefined || blue === undefined || alpha === undefined
|
|
130
|
+
? [1, 1, 1, 1] : [red, green, blue, alpha];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Subscribe only when a color source is present, and never schedule geometry from a paint write. */
|
|
134
|
+
export function bindTextColor(this: void, text: FontString, scope: RuntimeScope, source: ColorRead | undefined,
|
|
135
|
+
onTextPaint?: (this: void, paint: (this: void) => Failure | undefined) => void,
|
|
136
|
+
motion?: TextColorMotion, reduceMotion?: (this: void) => boolean, buttonTiming?: ButtonPaintTiming): Failure | undefined {
|
|
137
|
+
if (source === undefined) return;
|
|
138
|
+
const readColor = source;
|
|
139
|
+
if (buttonTiming !== undefined) {
|
|
140
|
+
let original: RGBA | undefined;
|
|
141
|
+
return bindColorChannel(scope, readColor, undefined, (r, g, b, a) => {
|
|
142
|
+
original ??= nativeColor(text);
|
|
143
|
+
text.SetTextColor(r, g, b, a);
|
|
144
|
+
}, { buttonTiming, reduceMotion, visible: () => reveal(text.IsVisible()) === true }, () => {
|
|
145
|
+
if (original !== undefined) text.SetTextColor(...original);
|
|
146
|
+
original = undefined;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
let fallback: RGBA | undefined;
|
|
150
|
+
let previous: string | undefined;
|
|
151
|
+
let drawn: Readonly<RGBA> | undefined;
|
|
152
|
+
let target: Readonly<RGBA> | undefined;
|
|
153
|
+
let previousChange: TextColorStateChange | undefined;
|
|
154
|
+
let transition: ColorTransitions<FontString> | undefined;
|
|
155
|
+
const duration = motion === undefined ? undefined : (change: TextColorStateChange) =>
|
|
156
|
+
reveal(text.IsVisible()) === true && reduceMotion?.() !== true ? motion.duration(change) : 0;
|
|
157
|
+
if (duration !== undefined) {
|
|
158
|
+
transition = createColorTransitions(scope, {
|
|
159
|
+
now: () => api.GetTime(),
|
|
160
|
+
maxStep: 0.05,
|
|
161
|
+
paint: (_, value) => {
|
|
162
|
+
const running = transition?.running(text) === true;
|
|
163
|
+
const finish = running && previousChange !== undefined && duration(previousChange) <= 0;
|
|
164
|
+
if (finish) transition?.cancel(text);
|
|
165
|
+
const next = finish ? target ?? value : value;
|
|
166
|
+
text.SetTextColor(next[0], next[1], next[2], next[3]);
|
|
167
|
+
// The transition owns intermediate samples. Only keep colors that outlive the track.
|
|
168
|
+
if (finish || !running) drawn = next;
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function apply(force: boolean) {
|
|
173
|
+
const resolved = readColor();
|
|
174
|
+
if (!resolved.ok) return resolved;
|
|
175
|
+
const value = reveal(resolved.value);
|
|
176
|
+
const change = motion?.change();
|
|
177
|
+
const stateChanged = change !== undefined && change !== previousChange;
|
|
178
|
+
previousChange = change;
|
|
179
|
+
if (!force && previous === value) return;
|
|
180
|
+
const next = value === undefined ? fallback : readCssColor(value) ?? fallback;
|
|
181
|
+
if (next !== undefined) {
|
|
182
|
+
fallback ??= nativeColor(text);
|
|
183
|
+
if (transition === undefined) text.SetTextColor(next[0], next[1], next[2], next[3]);
|
|
184
|
+
else {
|
|
185
|
+
target = next;
|
|
186
|
+
const seconds = change !== undefined && !force && drawn !== undefined ? duration?.(change) ?? 0 : 0;
|
|
187
|
+
const failure = !stateChanged && seconds > 0 && transition.running(text)
|
|
188
|
+
? transition.retarget(text, next)
|
|
189
|
+
: transition.start(text, drawn ?? next, next, stateChanged ? seconds : 0, "out");
|
|
190
|
+
if (failure !== undefined) return failure;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
previous = value;
|
|
194
|
+
}
|
|
195
|
+
const watched = scope.watchEffect(() => apply(false));
|
|
196
|
+
if (!watched.ok) return watched;
|
|
197
|
+
onTextPaint?.(() => scope.isActive() ? apply(true) : undefined);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function sizeValue(binding: Binding<number>): Result<number | undefined> {
|
|
201
|
+
if (isSecret(binding)) return ok(undefined);
|
|
202
|
+
if (typeof binding === "number") return ok(binding);
|
|
203
|
+
const value = binding.value;
|
|
204
|
+
if (isSecret(value)) return ok(undefined);
|
|
205
|
+
if (typeof value === "number") return ok(value);
|
|
206
|
+
return value.ok && isSecret(value.value) ? ok(undefined) : value;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Apply typography separately from text, paint transitions, and layout. */
|
|
210
|
+
export function bindTextTypography(this: void, text: FontString, scope: RuntimeScope, props: TextProps,
|
|
211
|
+
style: NativeTextStyle | undefined, host: NativeTextHost, onMetrics?: (this: void) => void): Failure | undefined {
|
|
212
|
+
let previousSize: number | undefined;
|
|
213
|
+
let previousFile: string | undefined;
|
|
214
|
+
let previousAlign: TextProps["align"];
|
|
215
|
+
let previousShadow: CssTextShadow | undefined;
|
|
216
|
+
let previousShadowColor: string | undefined;
|
|
217
|
+
|
|
218
|
+
function apply(this: void) {
|
|
219
|
+
const align = read(style?.textAlign);
|
|
220
|
+
const justify = props.align ?? (align === undefined ? undefined : alignment[align]);
|
|
221
|
+
if (justify !== undefined && previousAlign !== justify) text.SetJustifyH(justify);
|
|
222
|
+
previousAlign = justify;
|
|
223
|
+
|
|
224
|
+
const sizing = props.fontSize === undefined ? ok(read(style?.fontSize)
|
|
225
|
+
?? (props.heading === undefined ? undefined : headingSizes[props.heading - 1])) : sizeValue(props.fontSize);
|
|
226
|
+
if (!sizing.ok) return sizing;
|
|
227
|
+
const value = reveal(sizing.value);
|
|
228
|
+
const size = value !== undefined && Number.isFinite(value) && value > 0 ? value : undefined;
|
|
229
|
+
const weight = props.font === undefined ? read(style?.fontWeight) : undefined;
|
|
230
|
+
const file = weight === undefined ? undefined : host.fontFile?.(weight);
|
|
231
|
+
if (previousSize !== size || previousFile !== file) {
|
|
232
|
+
const changeSize = size !== undefined && previousSize !== size;
|
|
233
|
+
if (changeSize && host.fontSize !== undefined) host.fontSize(text, size);
|
|
234
|
+
let fontChanged = false;
|
|
235
|
+
if (file !== undefined) {
|
|
236
|
+
const [rawFile, rawHeight, rawFlags] = text.GetFont();
|
|
237
|
+
const height = changeSize && host.fontSize === undefined ? size : reveal(rawHeight);
|
|
238
|
+
if (height !== undefined && Number.isFinite(height) && height > 0
|
|
239
|
+
&& (file !== reveal(rawFile) || height !== reveal(rawHeight))) {
|
|
240
|
+
fontChanged = text.SetFont(file, height, reveal(rawFlags));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (changeSize && !fontChanged && host.fontSize === undefined) text.SetTextHeight(size);
|
|
244
|
+
if (changeSize || fontChanged) onMetrics?.();
|
|
245
|
+
previousSize = size;
|
|
246
|
+
previousFile = file;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const shadow = read(style?.textShadow);
|
|
250
|
+
if (shadow === undefined) return;
|
|
251
|
+
const resolved = resolveStyleValue(shadow.color, style?.shadowEnvironment);
|
|
252
|
+
if (!resolved.ok) return resolved;
|
|
253
|
+
if (previousShadow?.x !== shadow.x || previousShadow?.y !== shadow.y) text.SetShadowOffset(shadow.x, -shadow.y);
|
|
254
|
+
const color = reveal(resolved.value);
|
|
255
|
+
if (color !== previousShadowColor) {
|
|
256
|
+
const rgba = color === undefined ? undefined : readCssColor(color);
|
|
257
|
+
if (rgba !== undefined) text.SetShadowColor(rgba[0], rgba[1], rgba[2], rgba[3]);
|
|
258
|
+
else if (previousShadowColor !== undefined) text.SetShadowColor(0, 0, 0, 0);
|
|
259
|
+
}
|
|
260
|
+
previousShadow = shadow;
|
|
261
|
+
previousShadowColor = color;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const dynamic = typeof props.fontSize === "object" || typeof style?.fontSize === "function"
|
|
265
|
+
|| typeof style?.fontWeight === "function" || typeof style?.textAlign === "function"
|
|
266
|
+
|| typeof style?.textShadow === "function" || style?.shadowEnvironment !== undefined;
|
|
267
|
+
if (!dynamic) return apply();
|
|
268
|
+
const watched = scope.watchEffect(apply);
|
|
269
|
+
return watched.ok ? undefined : watched;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export interface NativeTextContent {
|
|
273
|
+
set(this: void, value: TextRead): void;
|
|
274
|
+
width(this: void, width: number | undefined): void;
|
|
275
|
+
refresh(this: void): void;
|
|
276
|
+
measureText(this: void): string | undefined;
|
|
277
|
+
watchTransform(this: void, scope: RuntimeScope, onMetrics?: (this: void) => void): Failure | undefined;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const ellipsis = "…";
|
|
281
|
+
const continuation = luaString.char(128) + "-" + luaString.char(191);
|
|
282
|
+
const codePoint = "[^" + continuation + "][" + continuation + "]*";
|
|
283
|
+
|
|
284
|
+
function fitText(text: FontString, value: string, width: number): string {
|
|
285
|
+
// A shortened native markup packet could leave an unterminated hyperlink or texture command.
|
|
286
|
+
const [markup] = luaString.find(value, "|", 1, true);
|
|
287
|
+
if (value === "" || markup !== undefined) return value;
|
|
288
|
+
const measure = text.GetUnboundedStringWidthForText;
|
|
289
|
+
if (typeof measure !== "function") return value;
|
|
290
|
+
const natural = reveal(text.GetUnboundedStringWidthForText(value));
|
|
291
|
+
if (natural === undefined || natural <= width) return value;
|
|
292
|
+
const dotWidth = reveal(text.GetUnboundedStringWidthForText(ellipsis));
|
|
293
|
+
if (dotWidth === undefined) return value;
|
|
294
|
+
if (dotWidth > width) return "";
|
|
295
|
+
|
|
296
|
+
const ends = [0];
|
|
297
|
+
let boundary = 0;
|
|
298
|
+
for (const character of luaString.gmatch(value, codePoint)) {
|
|
299
|
+
boundary += character.length;
|
|
300
|
+
ends.push(boundary);
|
|
301
|
+
}
|
|
302
|
+
let low = 0;
|
|
303
|
+
let high = ends.length - 1;
|
|
304
|
+
while (low < high) {
|
|
305
|
+
const middle = Math.floor((low + high + 1) / 2);
|
|
306
|
+
const candidate = luaString.sub(value, 1, ends[middle]) + ellipsis;
|
|
307
|
+
const measured = reveal(text.GetUnboundedStringWidthForText(candidate));
|
|
308
|
+
if (measured === undefined) return value;
|
|
309
|
+
if (measured <= width) low = middle;
|
|
310
|
+
else high = middle - 1;
|
|
311
|
+
}
|
|
312
|
+
return luaString.sub(value, 1, ends[low]) + ellipsis;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function defaultTransform(mode: Exclude<Transform, "none">, text: string): string {
|
|
316
|
+
// Host ports can use locale-aware casing. Restrict the fallback to ASCII letters so Lua locale rules cannot split UTF-8.
|
|
317
|
+
if (mode === "uppercase" || mode === "lowercase") {
|
|
318
|
+
const uppercase = mode === "uppercase";
|
|
319
|
+
const [converted] = luaString.gsub(text, uppercase ? "[a-z]" : "[A-Z]",
|
|
320
|
+
letter => uppercase ? letter.toUpperCase() : letter.toLowerCase());
|
|
321
|
+
return converted;
|
|
322
|
+
}
|
|
323
|
+
const [converted] = luaString.gsub(text, "%S+", word => {
|
|
324
|
+
const [capitalized] = luaString.gsub(word, "^[a-z]", letter => letter.toUpperCase());
|
|
325
|
+
return capitalized;
|
|
326
|
+
});
|
|
327
|
+
return converted;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** Keep readable source separate from the displayed text so resizing can restore the full label. */
|
|
331
|
+
export function createTextContent(this: void, text: FontString, local: NativeStyle | undefined,
|
|
332
|
+
style: NativeTextStyle | undefined, host: NativeTextHost): NativeTextContent | undefined {
|
|
333
|
+
const nowrap = local?.whiteSpace === "nowrap";
|
|
334
|
+
const clip = nowrap && local?.textOverflow === "ellipsis";
|
|
335
|
+
const transform = style?.textTransform;
|
|
336
|
+
if (!nowrap && (transform === undefined || transform === "none")) return;
|
|
337
|
+
if (nowrap) {
|
|
338
|
+
text.SetWordWrap(false);
|
|
339
|
+
text.SetNonSpaceWrap(false);
|
|
340
|
+
text.SetMaxLines(1);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
let source: string | undefined;
|
|
344
|
+
let formatted: string | undefined;
|
|
345
|
+
let shown: string | undefined;
|
|
346
|
+
let width: number | undefined;
|
|
347
|
+
let fitted = false;
|
|
348
|
+
|
|
349
|
+
function paint() {
|
|
350
|
+
if (formatted === undefined) return;
|
|
351
|
+
const next = clip && width !== undefined ? fitText(text, formatted, width) : formatted;
|
|
352
|
+
if (!fitted || shown !== next) text.SetText(next);
|
|
353
|
+
shown = next;
|
|
354
|
+
fitted = true;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function applyTransform(mode: Transform | undefined) {
|
|
358
|
+
if (source === undefined) return;
|
|
359
|
+
const transformed = mode === undefined || mode === "none" ? source : (host.transform ?? defaultTransform)(mode, source);
|
|
360
|
+
formatted = reveal(transformed) ?? source;
|
|
361
|
+
paint();
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return {
|
|
365
|
+
set(value) {
|
|
366
|
+
if (isSecret(value)) {
|
|
367
|
+
source = formatted = shown = undefined;
|
|
368
|
+
fitted = false;
|
|
369
|
+
text.SetText(value);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
source = value as string;
|
|
373
|
+
applyTransform(reveal(read(transform)));
|
|
374
|
+
},
|
|
375
|
+
width(next) {
|
|
376
|
+
if (!clip) return;
|
|
377
|
+
const value = reveal(next);
|
|
378
|
+
const known = value !== undefined && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
379
|
+
if (width === known) return;
|
|
380
|
+
width = known;
|
|
381
|
+
paint();
|
|
382
|
+
},
|
|
383
|
+
refresh: () => paint(),
|
|
384
|
+
measureText: () => formatted,
|
|
385
|
+
watchTransform(scope, onMetrics) {
|
|
386
|
+
if (typeof transform !== "function") return;
|
|
387
|
+
let previous: Transform | undefined;
|
|
388
|
+
const watched = scope.watchEffect(() => {
|
|
389
|
+
const mode = reveal(transform());
|
|
390
|
+
if (mode === previous) return;
|
|
391
|
+
const before = formatted;
|
|
392
|
+
applyTransform(mode);
|
|
393
|
+
if (before !== formatted) onMetrics?.();
|
|
394
|
+
previous = mode;
|
|
395
|
+
});
|
|
396
|
+
return watched.ok ? undefined : watched;
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { cvar, defineCVars, type CVarName, type CVarValueFor } from "../src";
|
|
2
|
+
|
|
3
|
+
// ConsoleGetAllCommands lists names and help. The client transports every CVar value as text.
|
|
4
|
+
export const wowCVarSchema = defineCVars({
|
|
5
|
+
SpellQueueWindow: cvar.integer(0, 400),
|
|
6
|
+
graphicsTextureResolution: cvar.oneOf(0, 1, 2),
|
|
7
|
+
graphicsSpellDensity: cvar.oneOf(0, 1, 2),
|
|
8
|
+
graphicsProjectedTextures: cvar.boolean,
|
|
9
|
+
graphicsViewDistance: cvar.integer(0, 9),
|
|
10
|
+
graphicsEnvironmentDetail: cvar.integer(0, 9),
|
|
11
|
+
graphicsGroundClutter: cvar.integer(0, 9),
|
|
12
|
+
graphicsShadowQuality: cvar.integer(0, 5),
|
|
13
|
+
graphicsLiquidDetail: cvar.oneOf(0, 1, 2, 3),
|
|
14
|
+
sunShafts: cvar.oneOf(0, 1, 2),
|
|
15
|
+
graphicsParticleDensity: cvar.integer(0, 5),
|
|
16
|
+
graphicsSSAO: cvar.integer(0, 4),
|
|
17
|
+
graphicsDepthEffects: cvar.oneOf(0, 1, 2, 3),
|
|
18
|
+
graphicsComputeEffects: cvar.integer(0, 4),
|
|
19
|
+
graphicsOutlineMode: cvar.oneOf(0, 1, 2),
|
|
20
|
+
weatherDensity: cvar.oneOf(0, 1, 2, 3),
|
|
21
|
+
ffxGlow: cvar.boolean,
|
|
22
|
+
ffxDeath: cvar.boolean,
|
|
23
|
+
colorblindMode: cvar.boolean,
|
|
24
|
+
colorblindSimulator: cvar.oneOf(0, 1, 2, 3),
|
|
25
|
+
colorblindWeaknessFactor: cvar.number,
|
|
26
|
+
showToastWindow: cvar.boolean,
|
|
27
|
+
toastDuration: cvar.number,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export type WoWCVarSchema = typeof wowCVarSchema;
|
|
31
|
+
export type WoWCVarName = CVarName<WoWCVarSchema>;
|
|
32
|
+
export type WoWCVarValue<Name extends WoWCVarName> = CVarValueFor<WoWCVarSchema, Name>;
|
package/wow/cvars.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createCVars, fail, ok, type CVarSchema, type CVars, type RawCVars } from "../src";
|
|
2
|
+
import type { OwnedArray } from "../src/owned-collections";
|
|
3
|
+
import { wowCVarSchema } from "./cvar-schema";
|
|
4
|
+
import { rawField } from "./lua-table";
|
|
5
|
+
import { api, isSecret, reveal } from "./native";
|
|
6
|
+
import { protect } from "./protect";
|
|
7
|
+
|
|
8
|
+
export interface WoWCVarInfo {
|
|
9
|
+
value: string;
|
|
10
|
+
default?: string;
|
|
11
|
+
account?: boolean;
|
|
12
|
+
character?: boolean;
|
|
13
|
+
locked?: boolean;
|
|
14
|
+
secure?: boolean;
|
|
15
|
+
readOnly?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface WoWCVarEntry { name: string; help: string }
|
|
19
|
+
|
|
20
|
+
export interface WoWRawCVars extends RawCVars {
|
|
21
|
+
readInfo(this: void, name: string): WoWCVarInfo | undefined;
|
|
22
|
+
list(this: void): WoWCVarEntry[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type Reader = (this: void, name: string) => string | undefined;
|
|
26
|
+
type Writer = (this: void, name: string, value: string) => boolean | undefined;
|
|
27
|
+
type Register = (this: void, name: string, value: string) => void;
|
|
28
|
+
|
|
29
|
+
function readValue(name: string, reader?: Reader) {
|
|
30
|
+
if (isSecret(name) || reader === undefined) return undefined;
|
|
31
|
+
const result = protect(() => reveal(reader(name)));
|
|
32
|
+
return result.ok ? result.value : undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const rawCVars: WoWRawCVars = {
|
|
36
|
+
read: name => readValue(name, api.C_CVar?.GetCVar ?? rawField<Reader>(api, "GetCVar")),
|
|
37
|
+
readDefault: name => readValue(name, api.C_CVar?.GetCVarDefault ?? rawField<Reader>(api, "GetCVarDefault")),
|
|
38
|
+
write(name, value) {
|
|
39
|
+
if (isSecret(name) || isSecret(value)) return fail("CVar names and values must be readable");
|
|
40
|
+
const modern = api.C_CVar?.SetCVar;
|
|
41
|
+
const write = modern ?? rawField<Writer>(api, "SetCVar");
|
|
42
|
+
if (write === undefined) return fail("CVar writes are unavailable");
|
|
43
|
+
const result = protect(() => reveal(write(name, value)));
|
|
44
|
+
if (!result.ok) return result;
|
|
45
|
+
if (result.value === true || modern === undefined && result.value === undefined) return ok(undefined);
|
|
46
|
+
return fail("The client rejected CVar " + name);
|
|
47
|
+
},
|
|
48
|
+
register(name, defaultValue) {
|
|
49
|
+
if (isSecret(name) || isSecret(defaultValue)) return fail("CVar names and values must be readable");
|
|
50
|
+
const register = api.C_CVar?.RegisterCVar ?? rawField<Register>(api, "RegisterCVar");
|
|
51
|
+
if (register === undefined) return fail("CVar registration is unavailable");
|
|
52
|
+
return protect(() => register(name, defaultValue));
|
|
53
|
+
},
|
|
54
|
+
readInfo(name) {
|
|
55
|
+
if (isSecret(name)) return undefined;
|
|
56
|
+
const read = api.C_CVar?.GetCVarInfo;
|
|
57
|
+
if (read === undefined) {
|
|
58
|
+
const value = rawCVars.read(name);
|
|
59
|
+
return value === undefined ? undefined : { value, default: rawCVars.readDefault(name) };
|
|
60
|
+
}
|
|
61
|
+
const result = protect(() => {
|
|
62
|
+
const [value, initial, account, character, locked, secure, readOnly] = read(name);
|
|
63
|
+
const plain = reveal(value);
|
|
64
|
+
if (plain === undefined) return undefined;
|
|
65
|
+
return { value: plain, default: reveal(initial), account: reveal(account), character: reveal(character),
|
|
66
|
+
locked: reveal(locked), secure: reveal(secure), readOnly: reveal(readOnly) };
|
|
67
|
+
});
|
|
68
|
+
return result.ok ? result.value : undefined;
|
|
69
|
+
},
|
|
70
|
+
list() {
|
|
71
|
+
type ConsoleCommands = typeof api.ConsoleGetAllCommands;
|
|
72
|
+
const read = rawField<{ GetAllCommands?: ConsoleCommands }>(api, "C_Console")?.GetAllCommands ?? api.ConsoleGetAllCommands;
|
|
73
|
+
if (read === undefined) return [];
|
|
74
|
+
const result = protect(read);
|
|
75
|
+
if (!result.ok || typeof result.value !== "object") return [];
|
|
76
|
+
const type = api.Enum?.ConsoleCommandType?.Cvar ?? 0;
|
|
77
|
+
const entries: WoWCVarEntry[] = [];
|
|
78
|
+
for (const entry of result.value as OwnedArray<NonNullable<ReturnType<ConsoleCommands>>[number]>) {
|
|
79
|
+
const name = reveal(entry.command);
|
|
80
|
+
if (name === undefined || reveal(entry.commandType) !== type) continue;
|
|
81
|
+
entries.push({ name, help: reveal(entry.help) ?? "" });
|
|
82
|
+
}
|
|
83
|
+
return entries;
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export function createWoWCVars<Schema extends CVarSchema>(schema: Schema): CVars<Schema> {
|
|
88
|
+
const typed = createCVars(schema, rawCVars);
|
|
89
|
+
return {
|
|
90
|
+
raw: rawCVars,
|
|
91
|
+
read: name => isSecret(name) ? undefined : typed.read(name),
|
|
92
|
+
readDefault: name => isSecret(name) ? undefined : typed.readDefault(name),
|
|
93
|
+
write: (name, value) => isSecret(name) || isSecret(value) ? fail("CVar names and values must be readable") : typed.write(name, value),
|
|
94
|
+
register: (name, value) => isSecret(name) || isSecret(value) ? fail("CVar names and values must be readable") : typed.register(name, value),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const cvars = createWoWCVars(wowCVarSchema);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Failure } from "../src/result";
|
|
2
|
+
import { ok } from "../src/result";
|
|
3
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
4
|
+
import type { FontString, FrameMap, Texture } from "./frames";
|
|
5
|
+
import { rawField } from "./lua-table";
|
|
6
|
+
import { api, reveal } from "./native";
|
|
7
|
+
import { hookSecureMethod } from "./native-hooks";
|
|
8
|
+
|
|
9
|
+
type PaintText = (this: void) => Failure | undefined;
|
|
10
|
+
|
|
11
|
+
/** Leave Blizzard's label and menu in place while suppressing the stock decoration. */
|
|
12
|
+
export function prepareDropdownArt(this: void, dropdown: FrameMap["DropdownButton"], scope: RuntimeScope) {
|
|
13
|
+
let caption = reveal(rawField<FontString>(dropdown, "Text"));
|
|
14
|
+
const stock: Texture[] = [];
|
|
15
|
+
for (const raw of [...dropdown.GetRegions()]) {
|
|
16
|
+
const region = reveal(raw) as FontString | Texture | undefined;
|
|
17
|
+
if (region === undefined) continue;
|
|
18
|
+
const kind = reveal(region.GetObjectType());
|
|
19
|
+
if (kind === "FontString") caption ??= region as FontString;
|
|
20
|
+
else if (kind === "Texture") stock.push(region as Texture);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function suppressStock() {
|
|
24
|
+
for (const region of stock) if (reveal(region.GetAlpha()) !== 0) region.SetAlpha(0);
|
|
25
|
+
}
|
|
26
|
+
let repaint: PaintText | undefined;
|
|
27
|
+
suppressStock();
|
|
28
|
+
const native = dropdown as FrameMap["DropdownButton"] & { OnButtonStateChanged?(this: object): void };
|
|
29
|
+
if (typeof reveal(native.OnButtonStateChanged) === "function") {
|
|
30
|
+
// The template reassigns the arrow atlas and label tint on native input and enable state changes.
|
|
31
|
+
const hooked = hookSecureMethod(native, "OnButtonStateChanged", () => {
|
|
32
|
+
suppressStock();
|
|
33
|
+
const failure = repaint?.();
|
|
34
|
+
if (failure !== undefined) api.geterrorhandler()(failure.reason);
|
|
35
|
+
}, scope);
|
|
36
|
+
if (!hooked.ok) return hooked;
|
|
37
|
+
}
|
|
38
|
+
return ok({ caption, onTextPaint: (update: PaintText) => { repaint = update; } });
|
|
39
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ClickEvent, MouseButton } from "../src/elements";
|
|
2
|
+
import { api, reveal } from "./native";
|
|
3
|
+
|
|
4
|
+
export function readMouseButton(this: void, raw: unknown): MouseButton | undefined {
|
|
5
|
+
const button = reveal(raw);
|
|
6
|
+
if (button !== "LeftButton" && button !== "RightButton" && button !== "MiddleButton"
|
|
7
|
+
&& button !== "Button4" && button !== "Button5") return;
|
|
8
|
+
return button;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function readClickEvent(this: void, raw: unknown): ClickEvent | undefined {
|
|
12
|
+
const button = readMouseButton(raw);
|
|
13
|
+
if (button === undefined) return;
|
|
14
|
+
return {
|
|
15
|
+
button,
|
|
16
|
+
shift: reveal(api.IsShiftKeyDown?.()) === true,
|
|
17
|
+
ctrl: reveal(api.IsControlKeyDown?.()) === true,
|
|
18
|
+
alt: reveal(api.IsAltKeyDown?.()) === true,
|
|
19
|
+
};
|
|
20
|
+
}
|