@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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { CssTokenRecipe } from "./css-v1";
|
|
2
|
+
import { mergeCssTokens } from "./css-tokens";
|
|
3
|
+
import type { OwnedArray, OwnedReadonlyArray } from "./owned-collections";
|
|
4
|
+
|
|
5
|
+
export type StyleState = "hover" | "active" | "focus" | "disabled" | "checked";
|
|
6
|
+
|
|
7
|
+
export interface StatePaint {
|
|
8
|
+
color?: string;
|
|
9
|
+
backgroundColor?: string;
|
|
10
|
+
borderColor?: string;
|
|
11
|
+
opacity?: number;
|
|
12
|
+
backgroundImage?: Readonly<{ path: string } | { atlas: string }>;
|
|
13
|
+
styleTokens?: readonly CssTokenRecipe[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface StateStyleVariant {
|
|
17
|
+
readonly when: readonly StyleState[];
|
|
18
|
+
readonly paint: Readonly<StatePaint>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PreparedStyleStates {
|
|
22
|
+
/** Complete cached paint for the current flags. Treat the returned snapshot as immutable. */
|
|
23
|
+
current(this: void): Readonly<StatePaint>;
|
|
24
|
+
/** Whether a state appears in any variant and needs to be observed by the host. */
|
|
25
|
+
needs(this: void, state: StyleState): boolean;
|
|
26
|
+
isActive(this: void, state: StyleState): boolean;
|
|
27
|
+
/** Update a flag and return the new cached snapshot only if its paint changed. */
|
|
28
|
+
set(this: void, state: StyleState, on: boolean): Readonly<StatePaint> | undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface StyleRule {
|
|
32
|
+
readonly mask: number;
|
|
33
|
+
readonly paint: Readonly<StatePaint>;
|
|
34
|
+
readonly order: number;
|
|
35
|
+
readonly priority: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const bits: Readonly<Record<StyleState, number>> = { hover: 1, active: 2, focus: 4, disabled: 8, checked: 16 };
|
|
39
|
+
|
|
40
|
+
function has(mask: number, bit: number) {
|
|
41
|
+
// Use arithmetic masks on Lua 5.1.
|
|
42
|
+
return mask % (bit * 2) >= bit;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function matches(required: number, active: number) {
|
|
46
|
+
while (required !== 0) {
|
|
47
|
+
if (required % 2 === 1 && active % 2 === 0) return false;
|
|
48
|
+
required = Math.floor(required / 2);
|
|
49
|
+
active = Math.floor(active / 2);
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function sameImage(left: StatePaint["backgroundImage"], right: StatePaint["backgroundImage"]) {
|
|
55
|
+
if (left === right) return true;
|
|
56
|
+
if (left === undefined || right === undefined) return false;
|
|
57
|
+
return "path" in left
|
|
58
|
+
? "path" in right && left.path === right.path
|
|
59
|
+
: "atlas" in right && left.atlas === right.atlas;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function sameTokens(left: StatePaint["styleTokens"], right: StatePaint["styleTokens"]) {
|
|
63
|
+
if (left === right) return true;
|
|
64
|
+
if (left === undefined || right === undefined) return false;
|
|
65
|
+
const before = left as OwnedReadonlyArray<CssTokenRecipe>;
|
|
66
|
+
const after = right as OwnedReadonlyArray<CssTokenRecipe>;
|
|
67
|
+
return before.length === after.length && before.every((recipe, index) => recipe === after[index]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Compile state conditions once. More conditions win, then disabled, then author order. */
|
|
71
|
+
export function prepareStyleStates(this: void, base: Readonly<StatePaint>, variants: readonly StateStyleVariant[]): PreparedStyleStates {
|
|
72
|
+
let needed = 0;
|
|
73
|
+
const rules = (variants as OwnedReadonlyArray<StateStyleVariant>).map((variant, order) => {
|
|
74
|
+
const { when, paint } = variant;
|
|
75
|
+
let mask = 0;
|
|
76
|
+
let count = 0;
|
|
77
|
+
for (const state of when as OwnedReadonlyArray<StyleState>) {
|
|
78
|
+
const bit = bits[state];
|
|
79
|
+
if (!has(mask, bit)) { mask += bit; count++; }
|
|
80
|
+
if (!has(needed, bit)) needed += bit;
|
|
81
|
+
}
|
|
82
|
+
return { mask, paint, order, priority: count * 2 + (has(mask, bits.disabled) ? 1 : 0) };
|
|
83
|
+
}) as OwnedArray<StyleRule>;
|
|
84
|
+
rules.sort((left, right) => left.priority === right.priority ? left.order - right.order : left.priority - right.priority);
|
|
85
|
+
|
|
86
|
+
const paints: Partial<Record<number, Readonly<StatePaint>>> = {};
|
|
87
|
+
const snapshots: Readonly<StatePaint>[] = [base];
|
|
88
|
+
|
|
89
|
+
function resolve(mask: number) {
|
|
90
|
+
let { color, backgroundColor, borderColor, opacity, backgroundImage, styleTokens } = base;
|
|
91
|
+
for (const rule of rules) {
|
|
92
|
+
if (!matches(rule.mask, mask)) continue;
|
|
93
|
+
const { paint } = rule;
|
|
94
|
+
color = paint.color ?? color;
|
|
95
|
+
backgroundColor = paint.backgroundColor ?? backgroundColor;
|
|
96
|
+
borderColor = paint.borderColor ?? borderColor;
|
|
97
|
+
opacity = paint.opacity ?? opacity;
|
|
98
|
+
backgroundImage = paint.backgroundImage ?? backgroundImage;
|
|
99
|
+
if (styleTokens !== undefined || paint.styleTokens !== undefined) styleTokens = mergeCssTokens(styleTokens, paint);
|
|
100
|
+
}
|
|
101
|
+
for (const paint of snapshots) {
|
|
102
|
+
if (paint.color === color && paint.backgroundColor === backgroundColor && paint.borderColor === borderColor && paint.opacity === opacity
|
|
103
|
+
&& sameImage(paint.backgroundImage, backgroundImage) && sameTokens(paint.styleTokens, styleTokens)) return paint;
|
|
104
|
+
}
|
|
105
|
+
const paint: StatePaint = {};
|
|
106
|
+
if (color !== undefined) paint.color = color;
|
|
107
|
+
if (backgroundColor !== undefined) paint.backgroundColor = backgroundColor;
|
|
108
|
+
if (borderColor !== undefined) paint.borderColor = borderColor;
|
|
109
|
+
if (opacity !== undefined) paint.opacity = opacity;
|
|
110
|
+
if (backgroundImage !== undefined) paint.backgroundImage = backgroundImage;
|
|
111
|
+
if (styleTokens !== undefined) paint.styleTokens = styleTokens;
|
|
112
|
+
snapshots.push(paint);
|
|
113
|
+
return paint;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (let mask = 0; mask <= needed; mask++) {
|
|
117
|
+
if (matches(mask, needed)) paints[mask] = resolve(mask);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let active = 0;
|
|
121
|
+
return {
|
|
122
|
+
current: () => paints[active]!,
|
|
123
|
+
needs: state => has(needed, bits[state]),
|
|
124
|
+
isActive: state => has(active, bits[state]),
|
|
125
|
+
set: (state, on) => {
|
|
126
|
+
const bit = bits[state];
|
|
127
|
+
if (!has(needed, bit) || has(active, bit) === on) return;
|
|
128
|
+
const previous = paints[active];
|
|
129
|
+
active += on ? bit : -bit;
|
|
130
|
+
const next = paints[active];
|
|
131
|
+
return next === previous ? undefined : next;
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Binding } from "./elements";
|
|
2
|
+
import { ownedSet, type OwnedSet } from "./owned-collections";
|
|
3
|
+
import { ok, type Result } from "./result";
|
|
4
|
+
|
|
5
|
+
export type StyleVariable = `--${string}`;
|
|
6
|
+
export type StyleVariables = Readonly<Partial<Record<StyleVariable, Binding<string>>>>;
|
|
7
|
+
export type StyleEnvironment = (this: void, name: StyleVariable) => Result<string | undefined>;
|
|
8
|
+
|
|
9
|
+
type RestrictedValue = (this: void, value: unknown) => boolean;
|
|
10
|
+
|
|
11
|
+
export function styleValue(value: Binding<string>, restricted: RestrictedValue): Result<string | undefined> {
|
|
12
|
+
if (restricted(value)) return ok(undefined);
|
|
13
|
+
if (typeof value === "string") return ok(value);
|
|
14
|
+
const next = value.value;
|
|
15
|
+
if (restricted(next)) return ok(undefined);
|
|
16
|
+
if (typeof next === "string") return ok(next);
|
|
17
|
+
return next.ok && restricted(next.value) ? ok(undefined) : next;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Resolve a color literal or a CSS variable with an optional fallback. */
|
|
21
|
+
export function resolveStyleValue(value: string, lookup?: StyleEnvironment): Result<string | undefined> {
|
|
22
|
+
if (!value.startsWith("var(") || !value.endsWith(")")) return ok(value);
|
|
23
|
+
const argument = value.slice(4, -1);
|
|
24
|
+
const comma = argument.indexOf(",");
|
|
25
|
+
const name = (comma < 0 ? argument : argument.slice(0, comma)).trim();
|
|
26
|
+
if (!name.startsWith("--")) return ok(undefined);
|
|
27
|
+
const resolved = lookup?.(name as StyleVariable);
|
|
28
|
+
if (resolved && (!resolved.ok || resolved.value !== undefined)) return resolved;
|
|
29
|
+
return comma < 0 ? ok(undefined) : resolveStyleValue(argument.slice(comma + 1).trim(), lookup);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Extend the inherited variable lookup for a single element and its descendants. */
|
|
33
|
+
export function extendStyleEnvironment(parent: StyleEnvironment | undefined, variables: StyleVariables | undefined,
|
|
34
|
+
restricted: RestrictedValue): StyleEnvironment | undefined {
|
|
35
|
+
if (variables === undefined) return parent;
|
|
36
|
+
|
|
37
|
+
function read(name: StyleVariable, resolving?: OwnedSet<StyleVariable>): Result<string | undefined> {
|
|
38
|
+
const binding = variables?.[name];
|
|
39
|
+
if (restricted(binding)) return ok(undefined);
|
|
40
|
+
if (binding === undefined) return parent?.(name) ?? ok(undefined);
|
|
41
|
+
if (resolving !== undefined && resolving.has(name)) return ok(undefined);
|
|
42
|
+
const value = styleValue(binding, restricted);
|
|
43
|
+
if (!value.ok || value.value === undefined) return value;
|
|
44
|
+
if (!value.value.startsWith("var(") || !value.value.endsWith(")")) return value;
|
|
45
|
+
const chain = resolving ?? ownedSet<StyleVariable>();
|
|
46
|
+
chain.add(name);
|
|
47
|
+
const result = resolveStyleValue(value.value, next => read(next, chain));
|
|
48
|
+
chain.delete(name);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return name => read(name);
|
|
53
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Binding } from "./elements";
|
|
2
|
+
import type { ReadonlyRef } from "./reactivity";
|
|
3
|
+
import type { OwnedReadonlyArray } from "./owned-collections";
|
|
4
|
+
import { ok, type Result } from "./result";
|
|
5
|
+
|
|
6
|
+
type Text = string | number;
|
|
7
|
+
export type TextRef = ReadonlyRef<Text> | ReadonlyRef<Result<Text>>;
|
|
8
|
+
type TextPart = string | TextRef;
|
|
9
|
+
|
|
10
|
+
/** Defer reads to the mounted value binding so all fragments share its subscription. */
|
|
11
|
+
export class TextBinding implements ReadonlyRef<Result<string>> {
|
|
12
|
+
constructor(private readonly parts: readonly TextPart[]) {}
|
|
13
|
+
|
|
14
|
+
static join(values: readonly Binding<string>[]): Binding<string> {
|
|
15
|
+
const source = values as OwnedReadonlyArray<Binding<string>>;
|
|
16
|
+
if (source.length === 1) return source[0];
|
|
17
|
+
|
|
18
|
+
const parts: TextPart[] = [];
|
|
19
|
+
for (const value of source) {
|
|
20
|
+
if (value instanceof TextBinding) {
|
|
21
|
+
for (const part of value.parts as OwnedReadonlyArray<TextPart>) parts.push(part);
|
|
22
|
+
} else parts.push(value);
|
|
23
|
+
}
|
|
24
|
+
return new TextBinding(parts);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get value(): Result<string> {
|
|
28
|
+
let text = "";
|
|
29
|
+
for (const part of this.parts as OwnedReadonlyArray<TextPart>) {
|
|
30
|
+
if (typeof part === "string") {
|
|
31
|
+
text += part;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const current = part.value;
|
|
35
|
+
if (typeof current === "object") {
|
|
36
|
+
if (!current.ok) return current;
|
|
37
|
+
text += String(current.value);
|
|
38
|
+
} else text += String(current);
|
|
39
|
+
}
|
|
40
|
+
return ok(text);
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/theme.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { OwnedMap, OwnedRecord } from "./owned-collections";
|
|
2
|
+
import { ref, type ReadonlyRef } from "./reactivity";
|
|
3
|
+
import { fail, ok, type Failure, type Result } from "./result";
|
|
4
|
+
|
|
5
|
+
type Token = string | number | boolean;
|
|
6
|
+
type Tokens = Record<string, Token>;
|
|
7
|
+
type Resolved<T extends Tokens> = {
|
|
8
|
+
readonly [K in keyof T]: T[K] extends string ? string : T[K] extends number ? number : boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export interface Theme<T extends Tokens, Name extends string> {
|
|
12
|
+
name: ReadonlyRef<Name | "Default">;
|
|
13
|
+
tokens: ReadonlyRef<Resolved<T>>;
|
|
14
|
+
select: (this: void, name: Name | "Default") => Result<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class ThemeBuilder<T extends Tokens, Name extends string = never> {
|
|
18
|
+
private readonly variants = new Map<string, Resolved<T>>() as OwnedMap<string, Resolved<T>>;
|
|
19
|
+
private readonly defaults: OwnedRecord<T>;
|
|
20
|
+
private failure?: Failure;
|
|
21
|
+
|
|
22
|
+
constructor(defaults: T) {
|
|
23
|
+
this.defaults = { ...defaults as OwnedRecord<T> };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
add<Next extends string, Patch extends Partial<Resolved<T>>>(name: Next extends "Default" ? never : Next,
|
|
27
|
+
tokens: Patch & Record<Exclude<keyof Patch, keyof T>, never>): ThemeBuilder<T, Name | Next> {
|
|
28
|
+
if (name === "Default" || this.variants.has(name)) this.failure ??= fail(`Duplicate theme: ${name}`);
|
|
29
|
+
else this.variants.set(name, { ...this.defaults, ...tokens as unknown as OwnedRecord<Patch> } as Resolved<T>);
|
|
30
|
+
return this as ThemeBuilder<T, Name | Next>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
build(): Result<Theme<T, Name>> {
|
|
34
|
+
if (this.failure) return this.failure;
|
|
35
|
+
const variants = new Map(this.variants);
|
|
36
|
+
const defaults = { ...this.defaults } as Resolved<T>;
|
|
37
|
+
const active = ref<Name | "Default">("Default");
|
|
38
|
+
const tokens = ref(defaults);
|
|
39
|
+
return ok({
|
|
40
|
+
name: active,
|
|
41
|
+
tokens,
|
|
42
|
+
select: name => {
|
|
43
|
+
if (name !== "Default" && !variants.has(name)) return fail(`Unknown theme: ${name}`);
|
|
44
|
+
tokens.value = variants.get(name) ?? defaults;
|
|
45
|
+
active.value = name;
|
|
46
|
+
return ok(undefined);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Timing = "linear" | "ease-in" | "ease-out" | "ease-in-out" | ((this: void, progress: number) => number);
|
|
2
|
+
|
|
3
|
+
export interface TransitionOptions {
|
|
4
|
+
duration?: number;
|
|
5
|
+
enter?: "fade-in" | "none";
|
|
6
|
+
exit?: "fade-out" | "none";
|
|
7
|
+
enterOffset?: number;
|
|
8
|
+
exitOffset?: number;
|
|
9
|
+
timing?: Timing;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function transitionProgress(timing: Timing | undefined, progress: number) {
|
|
13
|
+
if (typeof timing === "function") return timing(progress);
|
|
14
|
+
if (timing === "ease-in") return progress * progress;
|
|
15
|
+
if (timing === "ease-in-out") return progress * progress * (3 - 2 * progress);
|
|
16
|
+
if (timing === "linear") return progress;
|
|
17
|
+
return 1 - (1 - progress) * (1 - progress);
|
|
18
|
+
}
|
package/state/index.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { computed, computedResult, watch, watchEffect, withReactiveScope } from "../src/reactive-scope";
|
|
2
|
+
export { ref, type Equality, type ReadonlyRef, type Ref, type RefOptions, type WatchOptions } from "../src/reactivity";
|
|
3
|
+
export { createStateStore, createStore, type StateStore, type StoreStorage } from "./store";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ref, type ReadonlyRef, type Ref } from "../src/reactivity";
|
|
2
|
+
|
|
3
|
+
export function createStore<State extends object>(read: <K extends keyof State>(this: void, key: K) => State[K]) {
|
|
4
|
+
const fields = new Map<keyof State, Ref<State[keyof State]>>();
|
|
5
|
+
|
|
6
|
+
function field<K extends keyof State>(key: K): ReadonlyRef<State[K]> {
|
|
7
|
+
let value = fields.get(key);
|
|
8
|
+
if (!value) {
|
|
9
|
+
value = ref(read(key));
|
|
10
|
+
fields.set(key, value);
|
|
11
|
+
}
|
|
12
|
+
return value as ReadonlyRef<State[K]>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function sync(key?: keyof State) {
|
|
16
|
+
if (key !== undefined) {
|
|
17
|
+
const value = fields.get(key);
|
|
18
|
+
if (value) value.value = read(key);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (const [field, value] of fields) value.value = read(field);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { field, sync };
|
|
25
|
+
}
|
package/state/store.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ownedArray, type OwnedRecord } from "../src/owned-collections";
|
|
2
|
+
import type { ReadonlyRef } from "../src/reactivity";
|
|
3
|
+
import { fail, ok, type Result } from "../src/result";
|
|
4
|
+
import { createStore } from "./store-bindings";
|
|
5
|
+
|
|
6
|
+
export { createStore };
|
|
7
|
+
|
|
8
|
+
// A store owns the snapshot. A host may supply synchronous storage for it.
|
|
9
|
+
export interface StoreStorage<State extends object> {
|
|
10
|
+
read(this: void): Result<Partial<State> | undefined>;
|
|
11
|
+
write(this: void, snapshot: Readonly<State>): Result<void>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type StateKey<State> = keyof State & string;
|
|
15
|
+
|
|
16
|
+
export interface StateStore<State extends object> {
|
|
17
|
+
field<K extends StateKey<State>>(this: void, key: K): ReadonlyRef<State[K]>;
|
|
18
|
+
set<K extends StateKey<State>>(this: void, key: K, value: NoInfer<State[K]>): Result<void>;
|
|
19
|
+
patch(this: void, values: Partial<State>): Result<void>;
|
|
20
|
+
reset(this: void): Result<void>;
|
|
21
|
+
snapshot(this: void): Readonly<State>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createStateStore<State extends object>(defaults: State, storage?: StoreStorage<NoInfer<State>>): Result<StateStore<State>> {
|
|
25
|
+
const restored = storage?.read();
|
|
26
|
+
if (restored && !restored.ok) return restored;
|
|
27
|
+
const initial = {} as State;
|
|
28
|
+
for (const key of Object.keys(defaults) as StateKey<State>[]) {
|
|
29
|
+
const value = defaults[key];
|
|
30
|
+
if (value != null) initial[key] = value;
|
|
31
|
+
}
|
|
32
|
+
const keys = Object.keys(initial) as StateKey<State>[];
|
|
33
|
+
const writable = new Set<StateKey<State>>();
|
|
34
|
+
for (const key of keys) writable.add(key);
|
|
35
|
+
let current = { ...initial };
|
|
36
|
+
const { field, sync } = createStore<State>(key => current[key as StateKey<State>] as State[typeof key]);
|
|
37
|
+
|
|
38
|
+
function snapshot(): State {
|
|
39
|
+
return { ...(current as OwnedRecord<State>) };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function apply(next: State): Result<void> {
|
|
43
|
+
const changed = ownedArray<StateKey<State>>();
|
|
44
|
+
for (const key of keys) if (next[key] !== current[key]) changed.push(key);
|
|
45
|
+
if (changed.length === 0) return ok(undefined);
|
|
46
|
+
const written = storage?.write(next);
|
|
47
|
+
if (written && !written.ok) return written;
|
|
48
|
+
current = next;
|
|
49
|
+
for (const key of changed) sync(key);
|
|
50
|
+
return ok(undefined);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const key of keys) {
|
|
54
|
+
const value = restored?.value?.[key];
|
|
55
|
+
if (value !== undefined) current[key] = value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function patch(values: Partial<State>): Result<void> {
|
|
59
|
+
const next = snapshot();
|
|
60
|
+
for (const key of Object.keys(values) as StateKey<State>[]) {
|
|
61
|
+
const value = values[key];
|
|
62
|
+
if (value == null) continue;
|
|
63
|
+
if (!writable.has(key)) return fail("Unknown state field " + String(key));
|
|
64
|
+
next[key] = value;
|
|
65
|
+
}
|
|
66
|
+
return apply(next);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function set<K extends StateKey<State>>(key: K, value: NoInfer<State[K]>): Result<void> {
|
|
70
|
+
if (value == null) return fail("Use a concrete value for " + String(key));
|
|
71
|
+
if (!writable.has(key)) return fail("Unknown state field " + String(key));
|
|
72
|
+
return apply({ ...(current as OwnedRecord<State>), [key]: value });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return ok({
|
|
76
|
+
field,
|
|
77
|
+
set,
|
|
78
|
+
patch,
|
|
79
|
+
reset: () => apply({ ...initial }),
|
|
80
|
+
snapshot,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# __ADDON_NAME__
|
|
2
|
+
|
|
3
|
+
A minimal World of Warcraft Retail addon written in TypeScript and TSX. Clicking the button increments its count.
|
|
4
|
+
|
|
5
|
+
Install Node.js 24, Rust with Cargo, and a complete Blizzard documentation export from the target Retail client. Point `KUMI_WOW_DOCS` to that export.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install
|
|
9
|
+
npm run check
|
|
10
|
+
npm run build
|
|
11
|
+
npm run link -- "<path-to-WoW-Retail>/Interface/AddOns"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The build produces a native Lua 5.1 addon in `build/addons/__ADDON_NAME__`. The link command expects the AddOns directory to exist.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import ts from "@typescript-eslint/eslint-plugin";
|
|
2
|
+
import parser from "@typescript-eslint/parser";
|
|
3
|
+
|
|
4
|
+
export default [{
|
|
5
|
+
files: ["src/**/*.{ts,tsx}"],
|
|
6
|
+
languageOptions: { parser },
|
|
7
|
+
plugins: { "@typescript-eslint": ts },
|
|
8
|
+
rules: {
|
|
9
|
+
"no-debugger": "error",
|
|
10
|
+
"@typescript-eslint/consistent-type-imports": "error",
|
|
11
|
+
},
|
|
12
|
+
}];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__PROJECT_NAME__",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"prepare:types": "node scripts/build.mjs types",
|
|
8
|
+
"typecheck": "npm run prepare:types && tsc -p tsconfig.json",
|
|
9
|
+
"lint": "eslint src",
|
|
10
|
+
"check": "npm run typecheck && npm run lint",
|
|
11
|
+
"build": "node scripts/build.mjs build",
|
|
12
|
+
"link": "kumi link build/addons"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"__KUMI_PACKAGE__": "__KUMI_VERSION__",
|
|
16
|
+
"@typescript-eslint/eslint-plugin": "8.72.2",
|
|
17
|
+
"@typescript-eslint/parser": "8.72.2",
|
|
18
|
+
"eslint": "10.14.0",
|
|
19
|
+
"typescript": "6.0.2"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync } from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const cli = fileURLToPath(import.meta.resolve("__KUMI_PACKAGE__/scripts/kumi-cli.mjs"));
|
|
6
|
+
const mode = process.argv[2];
|
|
7
|
+
if (mode !== "types" && mode !== "build") throw new Error("Expected types or build");
|
|
8
|
+
|
|
9
|
+
function pack(...args) {
|
|
10
|
+
const child = spawnSync(process.execPath, ["--v8-pool-size=1", cli, "pack", ...args], {
|
|
11
|
+
stdio: "inherit", windowsHide: true,
|
|
12
|
+
});
|
|
13
|
+
if (child.error) throw child.error;
|
|
14
|
+
if (child.status !== 0) process.exit(child.status ?? 1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!existsSync("build/types/wow-api.d.ts")) pack("wow-api");
|
|
18
|
+
if (mode === "build") {
|
|
19
|
+
const addon = "build/addons/__ADDON_NAME__";
|
|
20
|
+
mkdirSync(addon, { recursive: true });
|
|
21
|
+
pack("compile", "src/app/main.tsx", "--tsconfig", "tsconfig.json", "--addon-entry",
|
|
22
|
+
"--compile-output", addon + "/__ADDON_NAME__.lua");
|
|
23
|
+
copyFileSync("__ADDON_NAME__.toc", addon + "/__ADDON_NAME__.toc");
|
|
24
|
+
console.log("Addon available at " + addon);
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createElement, createRuntime } from "@kumi/core";
|
|
2
|
+
import { computed, ref } from "@kumi/state";
|
|
3
|
+
import { api, clock, mountNative, protect } from "@kumi/wow";
|
|
4
|
+
|
|
5
|
+
const runtime = createRuntime(clock, failure => api.geterrorhandler()(failure.reason), protect);
|
|
6
|
+
const mounted = mountNative(api.UIParent, runtime, () => {
|
|
7
|
+
const count = ref(0);
|
|
8
|
+
const caption = computed(() => String(count.value));
|
|
9
|
+
return <div width={160} height={52} anchor={{ point: "CENTER" }}>
|
|
10
|
+
<button width={140} height={32} anchor={{ point: "CENTER" }} value={caption} onClick={() => { count.value += 1; }} />
|
|
11
|
+
</div>;
|
|
12
|
+
});
|
|
13
|
+
if (!mounted.ok) api.geterrorhandler()(mounted.reason);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"lib": ["ES2020"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "Bundler",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"types": [],
|
|
10
|
+
"jsx": "react",
|
|
11
|
+
"jsxFactory": "createElement",
|
|
12
|
+
"paths": {
|
|
13
|
+
"@kumi/core": ["./node_modules/__KUMI_PACKAGE__/src/index.ts"],
|
|
14
|
+
"@kumi/state": ["./node_modules/__KUMI_PACKAGE__/state/index.ts"],
|
|
15
|
+
"@kumi/wow": ["./node_modules/__KUMI_PACKAGE__/wow/index.ts"],
|
|
16
|
+
"@kumi/wow-generated": ["./build/types/wow-api.d.ts"]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"node_modules/__KUMI_PACKAGE__/src/jsx.d.ts",
|
|
21
|
+
"node_modules/__KUMI_PACKAGE__/builder/native-lua.d.ts"
|
|
22
|
+
],
|
|
23
|
+
"include": ["src/**/*.ts", "src/**/*.tsx"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Translate = (this: void, key: string, ...values: (string | number)[]) => string;
|
|
2
|
+
|
|
3
|
+
const identity: Translate = key => key;
|
|
4
|
+
let translate = identity;
|
|
5
|
+
|
|
6
|
+
export function configureTranslation(resolve?: Translate): void {
|
|
7
|
+
translate = resolve ?? identity;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const t: Translate = (key, ...values) => translate(key, ...values);
|
|
11
|
+
|
|
12
|
+
export function useT(): Translate {
|
|
13
|
+
return t;
|
|
14
|
+
}
|