@overmvp/kumi 0.1.0 → 0.4.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.
Files changed (201) hide show
  1. package/README.md +59 -6
  2. package/animation/index.ts +4 -0
  3. package/animation/motion-policy.ts +20 -0
  4. package/animation/slide.ts +61 -0
  5. package/animation/spring.ts +75 -0
  6. package/animation/staggered-reveal.ts +34 -0
  7. package/builder/css-gradients.mjs +74 -0
  8. package/builder/css-mask-assets.mjs +52 -0
  9. package/builder/css-mask-assets.test.mjs +31 -0
  10. package/builder/css-v1.mjs +127 -23
  11. package/builder/css-v1.test.mjs +82 -2
  12. package/builder/link-addon-package.mjs +47 -6
  13. package/builder/module-declarations.test.mjs +9 -18
  14. package/builder/native-kernels.mjs +1 -1
  15. package/builder/src/compiler.rs +205 -8
  16. package/builder/src/lua_upvalues.rs +641 -0
  17. package/builder/src/main.rs +20 -5
  18. package/builder/src/native_ir.rs +1 -1
  19. package/builder/src/native_signal.rs +46 -10
  20. package/builder/src/numbers.lua +14 -0
  21. package/builder/src/project-front.mjs +385 -34
  22. package/builder/src/routes.rs +11 -14
  23. package/builder/src/setup-store.lua +18 -0
  24. package/builder/src/signal-kernel.fingerprint +1 -1
  25. package/builder/src/ts-lower.mjs +2 -2
  26. package/builder/src/wow-reads.lua +22 -0
  27. package/builder/style-modules.mjs +111 -0
  28. package/builder/style-modules.test.mjs +24 -0
  29. package/builder/style-states.mjs +6 -4
  30. package/config.ts +56 -14
  31. package/eslint.mjs +74 -0
  32. package/form/index.ts +15 -11
  33. package/package.json +11 -7
  34. package/router/index.ts +10 -2
  35. package/router/link.tsx +32 -0
  36. package/router/navigation.ts +22 -0
  37. package/router/router-view.ts +134 -0
  38. package/scripts/addon-build.mjs +377 -0
  39. package/scripts/addon-project.mjs +89 -0
  40. package/scripts/kumi-cli.mjs +52 -17
  41. package/scripts/link-addons.mjs +12 -2
  42. package/src/bindings.ts +12 -6
  43. package/src/context.ts +31 -7
  44. package/src/css-tokens.ts +27 -13
  45. package/src/css-v1.ts +13 -0
  46. package/src/elements.ts +35 -0
  47. package/src/flex-layout.ts +26 -5
  48. package/src/frame-scheduler.ts +6 -2
  49. package/src/index.ts +2 -1
  50. package/src/jsx-runtime.ts +8 -1
  51. package/src/keyed-list.ts +17 -11
  52. package/src/module-ui.ts +163 -0
  53. package/src/module.ts +51 -8
  54. package/src/owned-collections.ts +8 -0
  55. package/src/providers.ts +7 -1
  56. package/src/reactive-scope.ts +3 -3
  57. package/src/reactivity.ts +42 -8
  58. package/src/result.ts +6 -0
  59. package/src/signal-kernel.ts +35 -2
  60. package/src/style-classes.ts +22 -1
  61. package/src/style-states.ts +13 -6
  62. package/state/index.ts +6 -0
  63. package/state/setup-store-persistence.ts +206 -0
  64. package/state/setup-store-view.ts +10 -0
  65. package/state/setup-store.ts +342 -0
  66. package/state/store.ts +2 -0
  67. package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
  68. package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
  69. package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
  70. package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
  71. package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
  72. package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
  73. package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
  74. package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
  75. package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
  76. package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
  77. package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
  78. package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
  79. package/templates/addon/AGENTS.md +34 -0
  80. package/templates/addon/Assets/Art/Corner10.tga +0 -0
  81. package/templates/addon/Assets/Art/Corner11.tga +0 -0
  82. package/templates/addon/Assets/Art/Corner12.tga +0 -0
  83. package/templates/addon/Assets/Art/Corner13.tga +0 -0
  84. package/templates/addon/Assets/Art/Corner14.tga +0 -0
  85. package/templates/addon/Assets/Art/Corner15.tga +0 -0
  86. package/templates/addon/Assets/Art/Corner16.tga +0 -0
  87. package/templates/addon/Assets/Art/Corner2.tga +0 -0
  88. package/templates/addon/Assets/Art/Corner3.tga +0 -0
  89. package/templates/addon/Assets/Art/Corner4.tga +0 -0
  90. package/templates/addon/Assets/Art/Corner5.tga +0 -0
  91. package/templates/addon/Assets/Art/Corner6.tga +0 -0
  92. package/templates/addon/Assets/Art/Corner7.tga +0 -0
  93. package/templates/addon/Assets/Art/Corner8.tga +0 -0
  94. package/templates/addon/Assets/Art/Corner9.tga +0 -0
  95. package/templates/addon/Assets/Art/Dot.tga +0 -0
  96. package/templates/addon/Assets/Art/Gear.tga +0 -0
  97. package/templates/addon/Assets/Art/Grip.tga +0 -0
  98. package/templates/addon/Assets/Art/Outline10.tga +0 -0
  99. package/templates/addon/Assets/Art/Outline12.tga +0 -0
  100. package/templates/addon/Assets/Art/Outline13.tga +0 -0
  101. package/templates/addon/Assets/Art/Outline14.tga +0 -0
  102. package/templates/addon/Assets/Art/Outline15.tga +0 -0
  103. package/templates/addon/Assets/Art/Outline2.tga +0 -0
  104. package/templates/addon/Assets/Art/Outline3.tga +0 -0
  105. package/templates/addon/Assets/Art/Outline5.tga +0 -0
  106. package/templates/addon/Assets/Art/Outline7.tga +0 -0
  107. package/templates/addon/Assets/Art/Outline9.tga +0 -0
  108. package/templates/addon/Assets/Art/Round11.tga +0 -0
  109. package/templates/addon/Assets/Art/Round11Border.tga +0 -0
  110. package/templates/addon/Assets/Art/Round4.tga +0 -0
  111. package/templates/addon/Assets/Art/Round4Border.tga +0 -0
  112. package/templates/addon/Assets/Art/Round6.tga +0 -0
  113. package/templates/addon/Assets/Art/Round6Border.tga +0 -0
  114. package/templates/addon/Assets/Art/Round8.tga +0 -0
  115. package/templates/addon/Assets/Art/Round8Border.tga +0 -0
  116. package/templates/addon/Assets/Art/Search.tga +0 -0
  117. package/templates/addon/CLAUDE.md +1 -0
  118. package/templates/addon/README.md +42 -7
  119. package/templates/addon/eslint.config.mjs +3 -9
  120. package/templates/addon/gitignore +1 -0
  121. package/templates/addon/kumi.config.ts +17 -0
  122. package/templates/addon/package.json +4 -5
  123. package/templates/addon/src/app/app.module.ts +18 -0
  124. package/templates/addon/src/app/commands.store.ts +11 -0
  125. package/templates/addon/src/app/layout/AppWindow.module.css +90 -0
  126. package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
  127. package/templates/addon/src/app/main.ts +5 -0
  128. package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
  129. package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
  130. package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
  131. package/templates/addon/src/app/theme.ts +6 -0
  132. package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
  133. package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
  134. package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
  135. package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
  136. package/templates/addon/src/modules/greeting/ui/Greeting.module.css +103 -0
  137. package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
  138. package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
  139. package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
  140. package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
  141. package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
  142. package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
  143. package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
  144. package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
  145. package/templates/addon/src/modules/playtime/ui/Playtime.module.css +23 -0
  146. package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
  147. package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
  148. package/templates/addon/src/shared/api/native-art.ts +28 -0
  149. package/templates/addon/src/shared/assets/close.png +0 -0
  150. package/templates/addon/src/shared/lib/format.ts +20 -0
  151. package/templates/addon/src/shared/styles/tokens.css +13 -0
  152. package/templates/addon/src/shared/ui/Button.tsx +29 -0
  153. package/templates/addon/src/shared/ui/Choice.tsx +34 -0
  154. package/templates/addon/src/shared/ui/Controls.module.css +91 -0
  155. package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
  156. package/templates/addon/src/shared/ui/Slider.tsx +25 -0
  157. package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
  158. package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
  159. package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
  160. package/templates/addon/tsconfig.json +49 -10
  161. package/wow/action-bar-layout.ts +108 -0
  162. package/wow/action-button.ts +244 -0
  163. package/wow/action-catalog.ts +98 -0
  164. package/wow/addon-manifest.ts +38 -0
  165. package/wow/animation.ts +3 -14
  166. package/wow/app-ui.ts +230 -0
  167. package/wow/cooldown-timing.ts +24 -0
  168. package/wow/css-background-image.ts +75 -0
  169. package/wow/css-box.ts +46 -10
  170. package/wow/css-image-mask.ts +32 -0
  171. package/wow/css-surfaces.ts +295 -43
  172. package/wow/cursor.ts +45 -0
  173. package/wow/element-events.ts +33 -13
  174. package/wow/frame-access.ts +23 -1
  175. package/wow/frame-timing.ts +13 -0
  176. package/wow/heal-prediction.ts +2 -4
  177. package/wow/hooks.ts +133 -0
  178. package/wow/index.ts +19 -4
  179. package/wow/layout-view.ts +44 -23
  180. package/wow/locale-font.ts +15 -0
  181. package/wow/module-replacements.ts +103 -0
  182. package/wow/native.ts +18 -0
  183. package/wow/panel-host.ts +97 -0
  184. package/wow/pixel.ts +35 -0
  185. package/wow/plugins.ts +246 -0
  186. package/wow/pointer-click.ts +35 -0
  187. package/wow/protect.ts +27 -3
  188. package/wow/protected-view.ts +139 -0
  189. package/wow/range-art.ts +7 -0
  190. package/wow/readable-api.ts +120 -0
  191. package/wow/rounded-texture.ts +38 -6
  192. package/wow/saved-variables.ts +67 -18
  193. package/wow/spell-cooldown.ts +36 -0
  194. package/wow/start-addon.ts +31 -8
  195. package/wow/state-paint.ts +5 -14
  196. package/wow/texture-fill.ts +10 -0
  197. package/wow/unit-cast.ts +6 -4
  198. package/wow/view.ts +458 -228
  199. package/templates/addon/__ADDON_NAME__.toc +0 -4
  200. package/templates/addon/scripts/build.mjs +0 -25
  201. package/templates/addon/src/app/main.tsx +0 -13
@@ -0,0 +1,139 @@
1
+ import type { UIElement } from "../src/elements";
2
+ import type { FrameDriver } from "../src/frame-scheduler";
3
+ import type { OwnedRecord } from "../src/owned-collections";
4
+ import { ref, type ReadonlyRef } from "../src/reactivity";
5
+ import { formatFailure, ok, type Failure, type Result } from "../src/result";
6
+ import { createRuntime, type Runtime, type RuntimeScope } from "../src/runtime";
7
+ import { unlockedActionSlot } from "./action-button";
8
+ import { clock } from "./clock";
9
+ import { canAccessRegion } from "./frame-access";
10
+ import type { Frame } from "./frames";
11
+ import { api, reveal } from "./native";
12
+ import { physicalPixel } from "./pixel";
13
+ import { protect } from "./protect";
14
+ import { createProtectedLayoutUpdate } from "./protected-layout";
15
+ import { frameTiming } from "./frame-timing";
16
+ import { mountNative, type NativeViewOptions } from "./view";
17
+
18
+ interface ProtectedView {
19
+ refresh(this: void): Result<void>;
20
+ refreshDisplay(this: void): Result<void>;
21
+ }
22
+
23
+ export interface ProtectedViewOptions extends Omit<NativeViewOptions, "unprotectedOnly"> {
24
+ /** Opt in to combat updates for an unprotected visual tree after it mounts. */
25
+ readonly combatUpdates?: true;
26
+ }
27
+
28
+ function report(error: Failure) {
29
+ api.geterrorhandler()(formatFailure(error));
30
+ }
31
+
32
+ function canUpdateInCombat(frame: Frame): boolean {
33
+ if (!canAccessRegion(frame)) return false;
34
+ const [state] = frame.IsProtected();
35
+ return reveal(state) === false;
36
+ }
37
+
38
+ /** Mount and dispose out of combat. An opted-in visual view can update while its root stays unprotected. */
39
+ export function mountProtectedView(this: void, host: Runtime, owner: RuntimeScope,
40
+ render: (this: void, scope: RuntimeScope, refresh: ProtectedView["refresh"], pixel: ReadonlyRef<number>) => UIElement,
41
+ options: ProtectedViewOptions = {}): Result<ProtectedView> {
42
+ type Mount = Extract<ReturnType<typeof mountNative>, { ok: true }>["value"];
43
+ let view: Mount | undefined;
44
+ const pixel = ref(physicalPixel(api.UIParent as Frame));
45
+ const key = {};
46
+ let measure = false;
47
+ let flush = false;
48
+ let refreshingInCombat = false;
49
+
50
+ function drive() {
51
+ if (!owner.isActive()) return;
52
+ const updated = requestUpdate();
53
+ if (!updated.ok) return updated;
54
+ }
55
+
56
+ const driver: FrameDriver = {
57
+ nowMs: frameTiming.nowMs,
58
+ remainingMs: owner.frameJobs.remainingMs,
59
+ start: (_step, delay) => {
60
+ const enqueue = () => { if (owner.isActive()) owner.frameJobs.queue(key, drive); };
61
+ const cancel = delay > 0 ? clock(delay, enqueue) : undefined;
62
+ if (cancel === undefined) enqueue();
63
+ return () => {
64
+ cancel?.();
65
+ owner.frameJobs.cancel(key);
66
+ };
67
+ },
68
+ };
69
+ const runtime = createRuntime(clock, report, protect, { driver });
70
+
71
+ function refreshMounted(mounted: Mount) {
72
+ if (measure) {
73
+ pixel.value = physicalPixel(mounted.frame as Frame);
74
+ measure = false;
75
+ }
76
+ const urgent = flush;
77
+ flush = false;
78
+ runtime.frameJobs.step(urgent);
79
+ }
80
+
81
+ const guarded = createProtectedLayoutUpdate(() => {
82
+ if (view !== undefined) {
83
+ refreshMounted(view);
84
+ return;
85
+ }
86
+ const mounted = mountNative(api.UIParent, runtime, scope => render(scope, refresh, pixel), {
87
+ ...options as OwnedRecord<NativeViewOptions>, bindings: undefined, initialLayout: "sync",
88
+ unprotectedOnly: options.combatUpdates,
89
+ });
90
+ if (!mounted.ok) return mounted;
91
+ view = mounted.value;
92
+ const frame = view.frame as Frame;
93
+ frame.SetClampedToScreen(true);
94
+ pixel.value = physicalPixel(frame);
95
+ }, { scope: owner, label: "Protected JSX view" });
96
+ if (!guarded.ok) return guarded;
97
+ const update = guarded.value;
98
+
99
+ function requestUpdate(): Result<void> {
100
+ const mounted = view;
101
+ if (!owner.isActive() || mounted === undefined || options.combatUpdates !== true
102
+ || reveal(api.InCombatLockdown()) !== true || !canUpdateInCombat(mounted.frame as Frame)) {
103
+ return update.request();
104
+ }
105
+ if (refreshingInCombat) {
106
+ owner.frameJobs.queue(key, drive);
107
+ return ok(undefined);
108
+ }
109
+ refreshingInCombat = true;
110
+ const refreshed = protect(() => refreshMounted(mounted));
111
+ refreshingInCombat = false;
112
+ return refreshed;
113
+ }
114
+
115
+ const refresh = () => { flush = true; return requestUpdate(); };
116
+
117
+ const subscription = owner.onDispose(() => {
118
+ owner.frameJobs.cancel(key);
119
+ const mounted = view;
120
+ view = undefined;
121
+ if (mounted === undefined) return;
122
+ if (unlockedActionSlot()) return mounted.dispose();
123
+ const cleanup = host.scope();
124
+ const waiting = createProtectedLayoutUpdate(() => {
125
+ const disposed = mounted.dispose();
126
+ cleanup.dispose();
127
+ if (!disposed.ok) return disposed;
128
+ }, { scope: cleanup, label: "Dispose protected JSX view" });
129
+ if (waiting.ok) return waiting.value.request();
130
+ cleanup.dispose();
131
+ return waiting;
132
+ });
133
+ if (!subscription.ok) return subscription;
134
+ const mounted = refresh();
135
+ return mounted.ok ? ok({
136
+ refresh,
137
+ refreshDisplay: () => { measure = true; return requestUpdate(); },
138
+ }) : mounted;
139
+ }
package/wow/range-art.ts CHANGED
@@ -45,6 +45,13 @@ export function mountRangeArt(this: void, slider: FrameMap["Slider"], size: numb
45
45
  const thumb = createFrame("Frame", undefined, slider);
46
46
  scope.onDispose(() => thumb.Hide());
47
47
 
48
+ const level = reveal(slider.GetFrameLevel());
49
+ if (level !== undefined) {
50
+ track.SetFrameLevel(level + 1);
51
+ fill.SetFrameLevel(level + 2);
52
+ thumb.SetFrameLevel(level + 3);
53
+ }
54
+
48
55
  track.SetHeight(size);
49
56
  track.SetPoint("LEFT", slider, "LEFT", size / 2, 0);
50
57
  track.SetPoint("RIGHT", slider, "RIGHT", -size / 2, 0);
@@ -0,0 +1,120 @@
1
+ import { api, reveal, type LuaMultiReturn } from "./native";
2
+ import { readSpellCooldown } from "./spell-cooldown";
3
+
4
+ declare const $multi: (<Values extends unknown[]>(this: void, ...values: Values) => LuaMultiReturn<Values>) & {
5
+ readonly __tstlExtension: "MultiFunction";
6
+ };
7
+ declare function error(this: void, message: string): never;
8
+ declare function setmetatable<View extends object>(
9
+ this: void, view: object,
10
+ meta: { __index: (this: void, view: object, key: keyof View) => unknown; __newindex: (this: void) => never; __metatable: false },
11
+ ): View;
12
+ declare function setmetatable<Overrides extends object, Host extends object>(
13
+ this: void, overrides: Overrides, meta: { __index: Host; __newindex?: (this: void) => never; __metatable?: false },
14
+ ): Readonly<Omit<Host, keyof Overrides> & Overrides>;
15
+
16
+ function rejectWrite(this: void): never {
17
+ return error("The readable WoW API is read-only");
18
+ }
19
+
20
+ type ReadableSpellApi = Readonly<Omit<typeof api.C_Spell, "GetSpellCooldown"> & {
21
+ GetSpellCooldown: typeof readSpellCooldown;
22
+ }>;
23
+
24
+ function readSpellMember(this: void, _view: object, key: keyof typeof api.C_Spell) {
25
+ if (key === "GetSpellCooldown") return readSpellCooldown;
26
+ return api.C_Spell[key];
27
+ }
28
+
29
+ const readableSpellApi = setmetatable<ReadableSpellApi>({}, {
30
+ __index: readSpellMember,
31
+ __newindex: rejectWrite,
32
+ __metatable: false,
33
+ });
34
+
35
+ type ReadableName = LuaMultiReturn<[name?: string, realm?: string]>;
36
+ type ReadableUnitKind = LuaMultiReturn<[name?: string, token?: string, id?: number]>;
37
+
38
+ const readableMethods = setmetatable({
39
+ C_Spell: readableSpellApi,
40
+ InCombatLockdown(this: void, ...args: Parameters<typeof api.InCombatLockdown>) {
41
+ return reveal(api.InCombatLockdown(...args));
42
+ },
43
+ PlayerHasToy(this: void, ...args: Parameters<typeof api.PlayerHasToy>) {
44
+ return reveal(api.PlayerHasToy(...args));
45
+ },
46
+ GetCursorPosition(this: void): LuaMultiReturn<[x?: number, y?: number]> {
47
+ const [x, y] = api.GetCursorPosition();
48
+ return $multi(reveal(x), reveal(y));
49
+ },
50
+ UnitName(this: void, unit: string): ReadableName {
51
+ const [name, realm] = api.UnitName(unit);
52
+ return $multi(reveal(name), reveal(realm));
53
+ },
54
+ UnitFullName(this: void, unit: string): ReadableName {
55
+ const [name, realm] = api.UnitFullName(unit);
56
+ return $multi(reveal(name), reveal(realm));
57
+ },
58
+ UnitNameFromGUID(this: void, guid: string): ReadableName {
59
+ const [name, realm] = api.UnitNameFromGUID(guid);
60
+ return $multi(reveal(name), reveal(realm));
61
+ },
62
+ UnitNameUnmodified(this: void, unit: string): ReadableName {
63
+ const [name, realm] = api.UnitNameUnmodified(unit);
64
+ return $multi(reveal(name), reveal(realm));
65
+ },
66
+ UnitClass(this: void, unit: string): ReadableUnitKind {
67
+ const [name, token, id] = api.UnitClass(unit);
68
+ return $multi(reveal(name), reveal(token), reveal(id));
69
+ },
70
+ UnitRace(this: void, unit: string): ReadableUnitKind {
71
+ const [name, token, id] = api.UnitRace(unit);
72
+ return $multi(reveal(name), reveal(token), reveal(id));
73
+ },
74
+ UnitGUID(this: void, ...args: Parameters<typeof api.UnitGUID>) {
75
+ return reveal(api.UnitGUID(...args));
76
+ },
77
+ UnitIsUnit(this: void, ...args: Parameters<typeof api.UnitIsUnit>) {
78
+ return reveal(api.UnitIsUnit(...args));
79
+ },
80
+ UnitThreatSituation(this: void, ...args: Parameters<typeof api.UnitThreatSituation>) {
81
+ return reveal(api.UnitThreatSituation(...args));
82
+ },
83
+ UnitGroupRolesAssigned(this: void, ...args: Parameters<typeof api.UnitGroupRolesAssigned>) {
84
+ return reveal(api.UnitGroupRolesAssigned?.(...args));
85
+ },
86
+ UnitInRaid(this: void, ...args: Parameters<typeof api.UnitInRaid>) {
87
+ return reveal(api.UnitInRaid?.(...args));
88
+ },
89
+ UnitIsAFK(this: void, ...args: Parameters<typeof api.UnitIsAFK>) {
90
+ return reveal(api.UnitIsAFK?.(...args));
91
+ },
92
+ UnitPhaseReason(this: void, ...args: Parameters<typeof api.UnitPhaseReason>) {
93
+ return reveal(api.UnitPhaseReason?.(...args));
94
+ },
95
+ UnitSex(this: void, ...args: Parameters<typeof api.UnitSex>) {
96
+ return reveal(api.UnitSex?.(...args));
97
+ },
98
+ UnitSpellTargetClass(this: void, ...args: Parameters<typeof api.UnitSpellTargetClass>) {
99
+ return reveal(api.UnitSpellTargetClass?.(...args));
100
+ },
101
+ UnitHealth(this: void, ...args: Parameters<typeof api.UnitHealth>) {
102
+ return reveal(api.UnitHealth(...args));
103
+ },
104
+ UnitHealthMax(this: void, ...args: Parameters<typeof api.UnitHealthMax>) {
105
+ return reveal(api.UnitHealthMax(...args));
106
+ },
107
+ UnitPower(this: void, ...args: Parameters<typeof api.UnitPower>) {
108
+ return reveal(api.UnitPower(...args));
109
+ },
110
+ UnitPowerMax(this: void, ...args: Parameters<typeof api.UnitPowerMax>) {
111
+ return reveal(api.UnitPowerMax(...args));
112
+ },
113
+ }, { __index: api });
114
+
115
+ /** A read-only view of the WoW API with guarded reads for migrated operations. */
116
+ export const readableApi = setmetatable({}, {
117
+ __index: readableMethods,
118
+ __newindex: rejectWrite,
119
+ __metatable: false,
120
+ });
@@ -7,12 +7,24 @@ type SliceTexture = Pick<FillMask, "SetTexture" | "SetTextureSliceMargins" | "Se
7
7
  type TextureAsset = NonNullable<Parameters<SliceTexture["SetTexture"]>[0]>;
8
8
  export type RoundedTextureSide = "left" | "right";
9
9
 
10
+ export interface RoundedBorderCorner {
11
+ readonly asset: string | number;
12
+ /** UV extent of the upper-left cutout. The renderer mirrors it for other corners. */
13
+ readonly extent: number;
14
+ }
15
+
10
16
  export interface RoundedTextureOptions {
11
17
  directory(this: void): string;
12
18
  readonly resolveArt?: never;
13
19
  fallback(this: void): string;
14
20
  readonly radii: readonly number[];
15
21
  readonly stretched?: number;
22
+ /** Resolve a sliced outline with a one-texel stroke at the requested physical radius. */
23
+ resolveBorderOutline?(this: void, radius: number): TextureAsset | undefined;
24
+ /** Matching solid fill on the physical pixel grid. Also provides exact CSS masks for integer radii. */
25
+ resolveBorderFill?(this: void, radius: number): TextureAsset | undefined;
26
+ /** Resolve the inner cutout for a one-texel stroke at an integer display radius. */
27
+ resolveBorderCorner?(this: void, radius: number): RoundedBorderCorner | undefined;
16
28
  }
17
29
 
18
30
  export interface RoundedTextureResolverOptions extends Omit<RoundedTextureOptions, "directory" | "resolveArt"> {
@@ -31,13 +43,21 @@ export interface RoundedTextures {
31
43
  apply(this: void, texture: Texture, radius: number, outline?: boolean, side?: RoundedTextureSide): void;
32
44
  /** Install an exact registered radius on a caller-owned mask. */
33
45
  applyMask(this: void, mask: FillMask, radius: number): boolean;
46
+ /** Paint an exact solid fill when the client supports native slicing. */
47
+ applyExactFill?(this: void, texture: Texture, radius: number): boolean;
48
+ readonly borderOutline?: {
49
+ readonly stretched: number;
50
+ resolve(this: void, radius: number): TextureAsset | undefined;
51
+ resolveFill?(this: void, radius: number): TextureAsset | undefined;
52
+ };
53
+ resolveBorderCorner?(this: void, radius: number): RoundedBorderCorner | undefined;
34
54
  bindStatusBarFill(this: void, bar: StatusBar, fill: Texture): MaskedStatusBarFill;
35
55
  }
36
56
 
37
57
  const maskWrap = "CLAMPTOBLACKADDITIVE";
38
58
 
39
59
  /** Apply host-supplied Round textures with native nine-slice margins. */
40
- export function createRoundedTextures(this: void, { directory, resolveArt, fallback, radii, stretched }:
60
+ export function createRoundedTextures(this: void, { directory, resolveArt, fallback, radii, stretched, resolveBorderCorner, resolveBorderOutline, resolveBorderFill }:
41
61
  RoundedTextureOptions | RoundedTextureResolverOptions): RoundedTextures {
42
62
  const rounded = (radii as OwnedReadonlyArray<number>).filter(radius => radius > 0).sort((left, right) => right - left);
43
63
  const square = [0];
@@ -102,11 +122,21 @@ export function createRoundedTextures(this: void, { directory, resolveArt, fallb
102
122
  return texture;
103
123
  }
104
124
 
105
- function applyMask(this: void, mask: FillMask, radius: number): boolean {
106
- if (stretched === undefined || !rounded.includes(radius) || typeof mask.SetTextureSliceMargins !== "function"
107
- || typeof mask.SetTextureSliceMode !== "function") return false;
125
+ function applyExact(texture: SliceTexture, radius: number, wrap?: string): boolean {
126
+ if (stretched === undefined || typeof texture.SetTextureSliceMargins !== "function"
127
+ || typeof texture.SetTextureSliceMode !== "function") return false;
108
128
  const prefix = directory === undefined ? "" : directory() + "Round";
109
- return setArt(mask, readArt(prefix, radius, false), radius, maskWrap);
129
+ if (rounded.includes(radius) && setArt(texture, readArt(prefix, radius, false), radius, wrap)) return true;
130
+ return Number.isFinite(radius) && radius > 0 && Math.floor(radius) === radius
131
+ && setArt(texture, resolveBorderFill?.(radius), radius, wrap);
132
+ }
133
+
134
+ function applyMask(this: void, mask: FillMask, radius: number): boolean {
135
+ return applyExact(mask, radius, maskWrap);
136
+ }
137
+
138
+ function applyExactFill(this: void, texture: Texture, radius: number): boolean {
139
+ return applyExact(texture, radius);
110
140
  }
111
141
 
112
142
  /** Keep the mask anchored to the bar while the native fill changes size. */
@@ -152,5 +182,7 @@ export function createRoundedTextures(this: void, { directory, resolveArt, fallb
152
182
  return { setRadius };
153
183
  }
154
184
 
155
- return { create, apply, applyMask, bindStatusBarFill };
185
+ const borderOutline = stretched === undefined || resolveBorderOutline === undefined
186
+ ? undefined : { stretched, resolve: resolveBorderOutline, resolveFill: resolveBorderFill };
187
+ return { create, apply, applyMask, applyExactFill, bindStatusBarFill, resolveBorderCorner, borderOutline };
156
188
  }
@@ -1,55 +1,104 @@
1
- import { fail, ok } from "../src/result";
1
+ import { fail, ok, type Result } from "../src/result";
2
+ import { ownedMap, type OwnedLuaArray } from "../src/owned-collections";
2
3
  import type { StoreStorage } from "@kumi/state";
3
4
  import { rawField, setRawField } from "./lua-table";
4
5
  import { api, reveal } from "./native";
5
6
 
6
- type SavedValue = string | number | boolean;
7
+ /** A value WoW can write to a SavedVariables file: text, finite numbers, booleans, lists and records of them. */
8
+ export type SavedValue = string | number | boolean | readonly SavedValue[] | { readonly [key: string]: SavedValue };
9
+ /** A record whose fields are all savable. Interfaces work as well as type literals. */
10
+ export type SavedRecord<State> = { readonly [Key in keyof State]: SavedValue };
7
11
 
8
- export interface SavedVariablesOptions<State extends Record<string, SavedValue>> {
12
+ export interface SavedVariablesOptions<State extends SavedRecord<State>> {
13
+ /** The global named in the TOC's `## SavedVariables` or `## SavedVariablesPerCharacter` line. */
9
14
  global: string;
15
+ /** The record inside that global. Use one key per store. */
10
16
  key: string;
17
+ /** Field names and their types. Saved fields with another type fall back to these values. */
11
18
  defaults: State;
12
- isReady(this: void): boolean;
19
+ /** Defaults to "the player is logged in", when WoW has loaded every SavedVariables file of enabled addons. */
20
+ isReady?(this: void): boolean;
13
21
  }
14
22
 
15
- /** Opens one record in a .toc-declared SavedVariables table once the host has loaded it. */
16
- export function savedVariablesStorage<State extends Record<string, SavedValue>>(
17
- { global, key, defaults, isReady }: SavedVariablesOptions<State>,
23
+ const claims = ownedMap<string, string>();
24
+ const MAX_DEPTH = 16;
25
+
26
+ function loggedIn() {
27
+ return reveal(api.IsLoggedIn?.()) === true;
28
+ }
29
+
30
+ // Copy only what WoW can serialize and drop protected values, so a reactive list never aliases the saved table.
31
+ function copySaved(value: unknown, depth: number): SavedValue | undefined {
32
+ const plain = reveal(value);
33
+ if (typeof plain === "string" || typeof plain === "boolean") return plain;
34
+ if (typeof plain === "number") return Number.isFinite(plain) ? plain : undefined;
35
+ if (typeof plain !== "object" || plain === null || depth > MAX_DEPTH) return undefined;
36
+ if (Array.isArray(plain)) {
37
+ const items = plain as OwnedLuaArray<unknown>;
38
+ const list: SavedValue[] = [];
39
+ for (let index = 0; index < items.length; index++) {
40
+ const copy = copySaved(items[index], depth + 1);
41
+ if (copy !== undefined) list.push(copy);
42
+ }
43
+ return list;
44
+ }
45
+ const source = plain as Record<string, unknown>;
46
+ const record: Record<string, SavedValue> = {};
47
+ for (const name of Object.keys(source)) {
48
+ const copy = copySaved(source[name], depth + 1);
49
+ if (copy !== undefined) record[name] = copy;
50
+ }
51
+ return record;
52
+ }
53
+
54
+ function sameShape(value: unknown, fallback: unknown) {
55
+ if (typeof value !== typeof fallback) return false;
56
+ if (typeof value === "number") return Number.isFinite(value);
57
+ if (typeof value === "object") return Array.isArray(value) === Array.isArray(fallback);
58
+ return true;
59
+ }
60
+
61
+ /** Open one record of a TOC-declared SavedVariables table for a store. */
62
+ export function savedVariablesStorage<State extends SavedRecord<State>>(
63
+ { global, key, defaults, isReady = loggedIn }: SavedVariablesOptions<State>,
18
64
  ): StoreStorage<State> {
19
65
  const keys = Object.keys(defaults) as (keyof State & string)[];
66
+ const claim = global + "." + key;
20
67
 
21
68
  function root() {
22
- if (!isReady()) return fail("SavedVariables are not ready: " + global);
69
+ if (!isReady()) return fail("SavedVariables " + global + " are not loaded yet. Open the store after the player logs in.");
23
70
  const stored = reveal(rawField(api, global));
24
71
  if (stored !== undefined && typeof stored !== "object") return fail("Invalid SavedVariables table: " + global);
25
72
  return ok(stored);
26
73
  }
27
74
 
28
- function valid<K extends keyof State & string>(field: K, value: unknown): value is State[K] {
29
- return typeof value === typeof defaults[field] && (typeof value !== "number" || Number.isFinite(value));
30
- }
31
-
32
75
  return {
76
+ claim: owner => {
77
+ const holder = claims.get(claim);
78
+ if (holder !== undefined) return fail("SavedVariables " + claim + " is already used by store " + holder);
79
+ claims.set(claim, owner);
80
+ return ok(() => { if (claims.get(claim) === owner) claims.delete(claim); });
81
+ },
33
82
  read: () => {
34
83
  const opened = root();
35
84
  if (!opened.ok) return opened;
36
85
  const stored = reveal(rawField(opened.value, key));
37
86
  if (stored === undefined) return ok(undefined);
38
- if (typeof stored !== "object") return fail("Invalid saved store: " + key);
87
+ if (typeof stored !== "object") return fail("Invalid saved record: " + claim);
39
88
  const result: Partial<State> = {};
40
89
  for (const field of keys) {
41
- const value = reveal(rawField(stored, field));
42
- if (valid(field, value)) result[field] = value;
90
+ const value = copySaved(rawField(stored, field), 0);
91
+ if (value !== undefined && sameShape(value, defaults[field])) result[field] = value as State[typeof field];
43
92
  }
44
93
  return ok(result);
45
94
  },
46
95
  write: snapshot => {
47
96
  const opened = root();
48
97
  if (!opened.ok) return opened;
49
- const record: Partial<State> = {};
98
+ const record: Record<string, unknown> = {};
50
99
  for (const field of keys) {
51
- const value = reveal(snapshot[field]);
52
- if (!valid(field, value)) return fail("Invalid saved value: " + key + "." + field);
100
+ const value = copySaved(snapshot[field], 0);
101
+ if (value === undefined || !sameShape(value, defaults[field])) return fail("Invalid saved value: " + claim + "." + field);
53
102
  record[field] = value;
54
103
  }
55
104
  if (opened.value) setRawField(opened.value as object, key, record);
@@ -0,0 +1,36 @@
1
+ import { api, reveal, type SecretValue } from "./native";
2
+
3
+ type SpellCooldownLookup = typeof api.C_Spell.GetSpellCooldown;
4
+ type SpellIdentifier = Parameters<SpellCooldownLookup>[0];
5
+ type NativeSpellCooldown = Exclude<ReturnType<SpellCooldownLookup>, SecretValue | undefined>;
6
+
7
+ /** A snapshot containing only readable fields. A restricted field is absent. */
8
+ export type ReadableSpellCooldown = Readonly<Partial<NativeSpellCooldown>>;
9
+
10
+ /** Read the cooldown snapshot for an existing spell, when the client exposes it. */
11
+ export function readSpellCooldown(this: void, spell: SpellIdentifier): ReadableSpellCooldown | undefined {
12
+ const spells = api.C_Spell;
13
+ if (spells === undefined) return undefined;
14
+ const read = spells.GetSpellCooldown;
15
+ if (read === undefined) return undefined;
16
+ const info = reveal(read(spell));
17
+ if (info === undefined) return undefined;
18
+ const canAccessTable = api.canaccesstable;
19
+ if (canAccessTable !== undefined) {
20
+ if (!canAccessTable(info)) return undefined;
21
+ } else {
22
+ const isSecretTable = api.issecrettable;
23
+ if (isSecretTable !== undefined && isSecretTable(info)) return undefined;
24
+ }
25
+
26
+ return {
27
+ startTime: reveal(info.startTime),
28
+ duration: reveal(info.duration),
29
+ isEnabled: reveal(info.isEnabled),
30
+ isActive: reveal(info.isActive),
31
+ modRate: reveal(info.modRate),
32
+ activeCategory: reveal(info.activeCategory),
33
+ timeUntilEndOfStartRecovery: reveal(info.timeUntilEndOfStartRecovery),
34
+ isOnGCD: reveal(info.isOnGCD),
35
+ };
36
+ }
@@ -1,7 +1,7 @@
1
1
  import { createFrameDriver, type FrameDriver } from "../src/frame-scheduler";
2
2
  import { createModuleContainer, moduleInput, type ModuleContainer, type ModuleInput, type ModuleReference } from "../src/module";
3
3
  import { ref, type ReadonlyRef } from "../src/reactivity";
4
- import { fail, ok, type Failure, type Result } from "../src/result";
4
+ import { fail, formatFailure, ok, type Failure, type Result } from "../src/result";
5
5
  import { createRuntime, type Runtime, type RuntimeScope } from "../src/runtime";
6
6
  import { clock } from "./clock";
7
7
  import type { EventApi } from "./contract";
@@ -10,13 +10,15 @@ import { rawField } from "./lua-table";
10
10
  import { moduleEvents } from "./module-events";
11
11
  import { api, reveal } from "./native";
12
12
  import { protect } from "./protect";
13
+ import { savedVariablesStorage, type SavedValue } from "./saved-variables";
14
+ import { activateStoreHost } from "../state/setup-store";
15
+ import { addonManifest } from "./addon-manifest";
16
+ import { startPlugins } from "./plugins";
17
+ import { installAppUi, type AppTheme } from "./app-ui";
13
18
 
14
- const profileClock = rawField<(this: void) => number>(api, "debugprofilestop");
15
- export const frameTiming = {
16
- nowMs: () => profileClock?.() ?? api.GetTime() * 1000,
17
- inCombat: () => api.InCombatLockdown() === true,
18
- };
19
- export const frameDriver = createFrameDriver(clock, frameTiming);
19
+ import { frameDriver, frameTiming } from "./frame-timing";
20
+
21
+ export { frameDriver, frameTiming };
20
22
 
21
23
  /** The runtime of the addon that resolved a provider. */
22
24
  export const addonRuntime = moduleInput<Runtime>("kumi/wow/addon-runtime");
@@ -35,6 +37,13 @@ export interface AddonStartOptions {
35
37
  readonly driver?: FrameDriver;
36
38
  readonly prepare?: (this: void, context: AddonContext) => void;
37
39
  readonly onError?: (this: void, failure: Failure) => void;
40
+ /**
41
+ * SavedVariables globals for persisted stores that pass no storage. Each store saves under its ID.
42
+ * Defaults to `addon.savedVariables` and `addon.savedVariablesPerCharacter` from kumi.config.ts.
43
+ */
44
+ readonly savedVariables?: { readonly account?: string; readonly character?: string };
45
+ /** Textures, fonts, control skins and breakpoints for every view and window Kumi mounts. */
46
+ readonly theme?: AppTheme;
38
47
  }
39
48
 
40
49
  export interface AddonStart<Exports extends object> extends AddonContext {
@@ -49,13 +58,26 @@ export function startAddon<Exports extends object>(this: void,
49
58
  ): Result<AddonStart<Exports>> {
50
59
  const existing = options.modules;
51
60
  if (existing !== undefined && existing.resolve(addonRuntime).ok === true) return fail("The module container already has an addon runtime");
52
- const report = options.onError ?? (failure => api.geterrorhandler()(failure.reason));
61
+ const report = options.onError ?? (failure => api.geterrorhandler()(formatFailure(failure)));
53
62
  const runtime = createRuntime(clock, report, protect, { driver: options.driver ?? frameDriver });
54
63
  const scope = runtime.scope();
55
64
  const modules = options.modules ?? createModuleContainer(protect, { forkScope: scope.fork });
65
+ activateStoreHost(modules.stores);
66
+ const manifest = addonManifest();
67
+ const account = options.savedVariables?.account ?? manifest?.savedVariables;
68
+ const character = options.savedVariables?.character ?? manifest?.savedVariablesPerCharacter;
69
+ if (account !== undefined || character !== undefined) {
70
+ modules.stores.storage = (id, defaults, perCharacter) => {
71
+ const global = perCharacter ? character : account;
72
+ return global === undefined ? undefined : savedVariablesStorage({
73
+ global, key: id, defaults: defaults as Record<string, SavedValue>,
74
+ }) as never;
75
+ };
76
+ }
56
77
  const registered = modules.resolve(moduleEvents);
57
78
  const events = registered.ok ? registered.value : createEventDispatcher();
58
79
  const context = { runtime, scope, modules, events };
80
+ installAppUi(runtime, scope, events, options.theme ?? {});
59
81
  const activation = ref<Result<Readonly<Exports>> | undefined>(undefined);
60
82
 
61
83
  function release(failure: Failure): Failure {
@@ -72,6 +94,7 @@ export function startAddon<Exports extends object>(this: void,
72
94
  const wake = events.on(scope, "PLAYER_REGEN_ENABLED", runtime.frameJobs.combatChanged);
73
95
  const result = wake.ok ? modules.resolve(root) : wake;
74
96
  const settled = result.ok ? result : release(result);
97
+ if (settled.ok) startPlugins(modules, scope, report);
75
98
  activation.value = settled;
76
99
  return settled;
77
100
  }
@@ -10,6 +10,7 @@ import { prepareStyleStates, type StatePaint, type StateStyleVariant, type Style
10
10
  import { resolveStyleValue, styleValue, type StyleEnvironment } from "../src/style-variables";
11
11
  import type { TransitionOptions } from "../src/transition";
12
12
  import type { RGBA } from "../utils/colors";
13
+ import { createBackgroundPainter } from "./css-background-image";
13
14
  import { readCssColor } from "./css-color";
14
15
  import type { ElementStyleInput } from "./element-events";
15
16
  import { borderSides, type CssSurface } from "./css-surfaces";
@@ -231,25 +232,15 @@ export function bindStatePaint(this: void, scope: RuntimeScope, state: NativePai
231
232
  }
232
233
  if (state?.usesBackgroundImage === true || surface.base?.backgroundImage !== undefined) {
233
234
  const background = surface.css === undefined ? layer(surface, -7) : undefined;
234
- let previous: StatePaint["backgroundImage"];
235
235
  background?.Hide();
236
+ if (background !== undefined) scope.onDispose(() => background.Hide());
237
+ const draw = surface.css?.setBackgroundImage ?? createBackgroundPainter(background!, visible => background!.SetShown(visible), options.environment);
236
238
  const observed = scope.watchEffect(() => {
237
239
  const appearance = state?.evaluate() ?? ok(empty);
238
240
  if (!appearance.ok) return appearance;
239
241
  const image = appearance.value.backgroundImage ?? (options.liveStyle?.() ?? base)?.backgroundImage;
240
- if (image === previous) return;
241
- previous = image;
242
- if (surface.css !== undefined) {
243
- surface.css.setBackgroundImage(image);
244
- return;
245
- }
246
- if (background === undefined) return;
247
- if (image === undefined) background.Hide();
248
- else if ("path" in image) background.SetShown(background.SetTexture(image.path.split("/").join("\\")));
249
- else {
250
- background.SetAtlas(image.atlas, false);
251
- background.Show();
252
- }
242
+ const drawn = draw(image);
243
+ if (!drawn.ok) return drawn;
253
244
  });
254
245
  if (!observed.ok) return observed;
255
246
  }
@@ -0,0 +1,10 @@
1
+ import type { Texture } from "./frames";
2
+
3
+ /** Paint an existing texture. Tiled axes need repeat sampling as well as the native tile flags. */
4
+ export function setTextureFill(this: void, texture: Texture, asset: string | number, tileX = false, tileY = false): boolean {
5
+ const loaded = texture.SetTexture(asset, tileX ? "REPEAT" : "CLAMP", tileY ? "REPEAT" : "CLAMP");
6
+ if (loaded === false) return false;
7
+ texture.SetHorizTile(tileX);
8
+ texture.SetVertTile(tileY);
9
+ return true;
10
+ }