@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.
Files changed (205) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -2
  3. package/animation/color-transition.ts +196 -0
  4. package/animation/cycle.ts +151 -0
  5. package/animation/ease.ts +29 -0
  6. package/animation/index.ts +13 -0
  7. package/animation/package.json +12 -0
  8. package/animation/presets.ts +376 -0
  9. package/animation/spec.ts +197 -0
  10. package/builder/Cargo.lock +192 -0
  11. package/builder/Cargo.toml +7 -0
  12. package/builder/css-v1.mjs +334 -0
  13. package/builder/css-v1.test.mjs +321 -0
  14. package/builder/generated-output.mjs +61 -0
  15. package/builder/generated-output.test.mjs +132 -0
  16. package/builder/jsx-form.mjs +93 -0
  17. package/builder/jsx-form.test.mjs +48 -0
  18. package/builder/jsx-lists.mjs +209 -0
  19. package/builder/link-addon-package.mjs +86 -0
  20. package/builder/lua-assets.mjs +74 -0
  21. package/builder/lua-builtin-values.mjs +57 -0
  22. package/builder/lua-builtin-values.test.mjs +155 -0
  23. package/builder/lua-loop-closures.mjs +183 -0
  24. package/builder/lua-loop-closures.test.mjs +89 -0
  25. package/builder/lua-truthiness.mjs +61 -0
  26. package/builder/lua-truthiness.test.mjs +113 -0
  27. package/builder/module-declarations.mjs +594 -0
  28. package/builder/module-declarations.test.mjs +444 -0
  29. package/builder/native-kernels.mjs +60 -0
  30. package/builder/native-lua.d.ts +57 -0
  31. package/builder/native-routes.mjs +51 -0
  32. package/builder/no-static-ref-read.mjs +93 -0
  33. package/builder/no-static-ref-read.test.mjs +181 -0
  34. package/builder/secure-snippet.mjs +317 -0
  35. package/builder/secure-snippet.test.mjs +101 -0
  36. package/builder/shared-lua-runtime.mjs +150 -0
  37. package/builder/src/addon-link.lua +29 -0
  38. package/builder/src/arrays.lua +260 -0
  39. package/builder/src/assets.rs +177 -0
  40. package/builder/src/classes.lua +75 -0
  41. package/builder/src/collections.lua +190 -0
  42. package/builder/src/compiler.rs +2164 -0
  43. package/builder/src/config.rs +42 -0
  44. package/builder/src/entries.rs +166 -0
  45. package/builder/src/errors.lua +15 -0
  46. package/builder/src/lua_data.rs +231 -0
  47. package/builder/src/main.rs +367 -0
  48. package/builder/src/native_ir.rs +65 -0
  49. package/builder/src/native_signal.rs +47 -0
  50. package/builder/src/numbers.lua +62 -0
  51. package/builder/src/project-front.mjs +3331 -0
  52. package/builder/src/records.lua +75 -0
  53. package/builder/src/routes.rs +127 -0
  54. package/builder/src/signal-kernel.fingerprint +1 -0
  55. package/builder/src/strings.lua +103 -0
  56. package/builder/src/ts-lower.mjs +68 -0
  57. package/builder/src/wow_client.rs +253 -0
  58. package/builder/src/wow_types.rs +564 -0
  59. package/builder/style-states.mjs +100 -0
  60. package/builder/style-states.test.mjs +103 -0
  61. package/builder/vite-assets.mjs +53 -0
  62. package/builder/vite-project.mjs +10 -0
  63. package/config.ts +17 -0
  64. package/form/index.ts +522 -0
  65. package/form/package.json +13 -0
  66. package/motion/index.ts +2 -0
  67. package/motion/package.json +10 -0
  68. package/package.json +22 -4
  69. package/router/index.ts +43 -0
  70. package/router/package.json +12 -0
  71. package/router/routes.ts +64 -0
  72. package/scripts/kumi-cli.mjs +70 -0
  73. package/scripts/link-addons.mjs +51 -0
  74. package/src/bindings.ts +35 -0
  75. package/src/context.ts +15 -0
  76. package/src/css-tokens.ts +234 -0
  77. package/src/css-v1.ts +58 -0
  78. package/src/cvars.ts +91 -0
  79. package/src/element-node.ts +32 -0
  80. package/src/elements.ts +479 -0
  81. package/src/feature-scope.ts +82 -0
  82. package/src/flex-layout.ts +807 -0
  83. package/src/frame-scheduler.ts +334 -0
  84. package/src/grid-tracks.ts +165 -0
  85. package/src/image-imports.d.ts +24 -0
  86. package/src/images.ts +79 -0
  87. package/src/index.ts +28 -0
  88. package/src/jsx-dev-runtime.ts +2 -0
  89. package/src/jsx-runtime.ts +22 -0
  90. package/src/jsx.d.ts +12 -0
  91. package/src/keyed-list.ts +363 -0
  92. package/src/media-query.ts +144 -0
  93. package/src/module.ts +277 -0
  94. package/src/node-selectors.ts +114 -0
  95. package/src/owned-collections.ts +44 -0
  96. package/src/providers.ts +235 -0
  97. package/src/reactive-scope.ts +34 -0
  98. package/src/reactivity.ts +254 -0
  99. package/src/result.ts +58 -0
  100. package/src/runtime.ts +52 -0
  101. package/src/scheduler.ts +185 -0
  102. package/src/signal-kernel.ts +30 -0
  103. package/src/style-classes.ts +51 -0
  104. package/src/style-states.ts +134 -0
  105. package/src/style-variables.ts +53 -0
  106. package/src/text-children.ts +42 -0
  107. package/src/theme.ts +50 -0
  108. package/src/transition.ts +18 -0
  109. package/state/index.ts +3 -0
  110. package/state/package.json +12 -0
  111. package/state/store-bindings.ts +25 -0
  112. package/state/store.ts +82 -0
  113. package/styles/_layers.scss +14 -0
  114. package/templates/addon/README.md +14 -0
  115. package/templates/addon/__ADDON_NAME__.toc +4 -0
  116. package/templates/addon/eslint.config.mjs +12 -0
  117. package/templates/addon/gitignore +8 -0
  118. package/templates/addon/package.json +21 -0
  119. package/templates/addon/scripts/build.mjs +25 -0
  120. package/templates/addon/src/app/main.tsx +13 -0
  121. package/templates/addon/tsconfig.json +24 -0
  122. package/translate/index.ts +14 -0
  123. package/translate/package.json +9 -0
  124. package/utils/colors.ts +76 -0
  125. package/utils/format.ts +37 -0
  126. package/utils/index.ts +4 -0
  127. package/utils/number.ts +17 -0
  128. package/utils/package.json +7 -0
  129. package/utils/text.ts +6 -0
  130. package/validate/index.ts +119 -0
  131. package/validate/package.json +9 -0
  132. package/wow/absolute-position.ts +142 -0
  133. package/wow/animation.ts +428 -0
  134. package/wow/aura-button.ts +76 -0
  135. package/wow/aura-container.ts +591 -0
  136. package/wow/aura-countdown.ts +201 -0
  137. package/wow/aura-slot.ts +153 -0
  138. package/wow/bar-shade.ts +93 -0
  139. package/wow/borrowed-slot.ts +216 -0
  140. package/wow/button-drag.ts +48 -0
  141. package/wow/cast-clock.ts +153 -0
  142. package/wow/cast-text.ts +83 -0
  143. package/wow/class-colors.ts +126 -0
  144. package/wow/clock.ts +7 -0
  145. package/wow/color-picker.ts +128 -0
  146. package/wow/commands.ts +17 -0
  147. package/wow/contained-frame.ts +128 -0
  148. package/wow/contract.ts +42 -0
  149. package/wow/css-box.ts +110 -0
  150. package/wow/css-color.ts +12 -0
  151. package/wow/css-style.ts +109 -0
  152. package/wow/css-surfaces.ts +398 -0
  153. package/wow/css-text.ts +399 -0
  154. package/wow/cvar-schema.ts +32 -0
  155. package/wow/cvars.ts +98 -0
  156. package/wow/dropdown-art.ts +39 -0
  157. package/wow/element-click.ts +20 -0
  158. package/wow/element-event-coordinator.ts +219 -0
  159. package/wow/element-events.ts +317 -0
  160. package/wow/event-dispatcher.ts +151 -0
  161. package/wow/events.ts +50 -0
  162. package/wow/font-cache.ts +92 -0
  163. package/wow/frame-access.ts +31 -0
  164. package/wow/frame-layer.ts +5 -0
  165. package/wow/frames.ts +236 -0
  166. package/wow/heal-prediction.ts +305 -0
  167. package/wow/image-layers.ts +55 -0
  168. package/wow/index.ts +97 -0
  169. package/wow/layout-view.ts +651 -0
  170. package/wow/lua-string.ts +18 -0
  171. package/wow/lua-table.ts +18 -0
  172. package/wow/macro-book.ts +84 -0
  173. package/wow/map-position.ts +27 -0
  174. package/wow/media-query.ts +65 -0
  175. package/wow/module-events.ts +11 -0
  176. package/wow/native-hooks.ts +168 -0
  177. package/wow/native-placement.ts +88 -0
  178. package/wow/native.ts +135 -0
  179. package/wow/number-format.ts +8 -0
  180. package/wow/number-input.ts +10 -0
  181. package/wow/protect.ts +24 -0
  182. package/wow/protected-layout.ts +133 -0
  183. package/wow/range-art.ts +74 -0
  184. package/wow/reparent-frame.ts +99 -0
  185. package/wow/rounded-texture.ts +156 -0
  186. package/wow/saved-variables.ts +60 -0
  187. package/wow/scroll-view.ts +64 -0
  188. package/wow/secret-ref.ts +14 -0
  189. package/wow/secure-bindings.ts +89 -0
  190. package/wow/secure-clicks.ts +432 -0
  191. package/wow/secure-snippet.ts +235 -0
  192. package/wow/secure-state.ts +130 -0
  193. package/wow/secure-target-visibility.ts +89 -0
  194. package/wow/secure-transaction.ts +331 -0
  195. package/wow/special-window.ts +269 -0
  196. package/wow/start-addon.ts +99 -0
  197. package/wow/state-paint.ts +256 -0
  198. package/wow/transition.ts +86 -0
  199. package/wow/unit-button.ts +39 -0
  200. package/wow/unit-cast.ts +92 -0
  201. package/wow/unit-health-text.ts +47 -0
  202. package/wow/view-nodes.ts +304 -0
  203. package/wow/view.ts +1746 -0
  204. package/wow/visible-frame-job.ts +34 -0
  205. package/wow/width-reserve.ts +108 -0
@@ -0,0 +1,591 @@
1
+ import type { OwnedReadonlyArray } from "../src/owned-collections";
2
+ import { fail, ok, type Failure, type Result } from "../src/result";
3
+ import type { AuraDispelTarget } from "./aura-button";
4
+ import type { FontString, Frame, FrameMap, FrameParent, Texture } from "./frames";
5
+ import { rawField, weakKeys } from "./lua-table";
6
+ import { api, isSecret } from "./native";
7
+ import { protect } from "./protect";
8
+
9
+ export type AuraButton = Frame & AuraDispelTarget & {
10
+ SetIcon?(this: object, texture: Texture): void;
11
+ SetDurationCooldown?(this: object, cooldown: FrameMap["Cooldown"]): void;
12
+ SetApplicationCount?(this: object, text: FontString): void;
13
+ SetTooltipAnchorPoint?(this: object, anchor: "ANCHOR_BOTTOMRIGHT", x: number, y: number): void;
14
+ };
15
+
16
+ type AuraSpellIDs = Readonly<Partial<Record<number, true>>>;
17
+ type AuraDispelTypes = Readonly<Partial<Record<"Magic" | "Curse" | "Poison" | "Disease" | "Bleed" | "Enrage" | "", true>>>;
18
+
19
+ export interface AuraCandidateFilters {
20
+ readonly includeSpellIDs?: AuraSpellIDs;
21
+ readonly excludeSpellIDs?: AuraSpellIDs;
22
+ readonly includeDispelTypes?: AuraDispelTypes;
23
+ readonly excludeDispelTypes?: AuraDispelTypes;
24
+ readonly maxDuration?: number;
25
+ readonly isBossAura?: boolean;
26
+ readonly isRoleAura?: boolean;
27
+ readonly isPriorityAura?: boolean;
28
+ readonly isFromPlayerOrPlayerPet?: boolean;
29
+ readonly isStealable?: boolean;
30
+ readonly isNameplateOnly?: boolean;
31
+ }
32
+
33
+ export interface AuraGroupFilter {
34
+ readonly key: string;
35
+ readonly filter: string;
36
+ readonly candidateFilters?: AuraCandidateFilters;
37
+ }
38
+
39
+ export interface AuraContainerSlot extends AuraGroupFilter {
40
+ readonly templates?: readonly string[];
41
+ readonly initializeFrame: (this: void, button: AuraButton) => void;
42
+ }
43
+
44
+ export interface AuraContainerGroup extends AuraContainerSlot {
45
+ readonly maxFrameCount: number;
46
+ readonly sort?: "Default" | "BigDefensive" | "ExpirationOnly" | "UnitFrameDebuff";
47
+ readonly sortDirection?: "Normal" | "Reverse";
48
+ }
49
+
50
+ export interface AuraContainerOptions {
51
+ readonly anchor: Parameters<Frame["SetPoint"]>[0];
52
+ readonly grow?: readonly ["Left" | "Right", "Up" | "Down"];
53
+ readonly lineWidth?: number;
54
+ /** Set the unit before registering groups and slots while the display is hidden. */
55
+ readonly initialUnit?: string;
56
+ readonly size: number;
57
+ readonly cellWidth?: number;
58
+ readonly cellHeight?: number;
59
+ readonly gap: number;
60
+ readonly lineSpacing?: number;
61
+ readonly rowGap?: number;
62
+ readonly groups: readonly AuraContainerGroup[];
63
+ readonly slots?: readonly AuraContainerSlot[];
64
+ /** Schedule each build step separately. A step returns true when it needs another turn. */
65
+ defer?(this: void, frame: Frame, step: (this: void) => true | undefined): (this: void) => void;
66
+ onBuildFailure?(this: void, failure: Failure): void;
67
+ onReusedFrame?(this: void): void;
68
+ /** Observe the accepted filter and candidate filters when either changes during rebind. */
69
+ onGroupChanged?(this: void, frame: Frame, group: AuraGroupFilter): void;
70
+ /** Request the aura reread through the host. A false result uses the unit rebind fallback. */
71
+ reread?(this: void, frame: Frame): boolean;
72
+ /** Observe a successful native activation. */
73
+ onActivated?(this: void, frame: Frame, unit: string): void;
74
+ }
75
+
76
+ export interface AuraContainer {
77
+ readonly frame: Frame;
78
+ /** Register a fixed aura slot on this display. */
79
+ addSlot(this: void, slot: AuraContainerSlot): Result<void>;
80
+ /** Force a reread when a new occupant uses the same unit token. */
81
+ activate(this: void, unit: string, force?: boolean): Result<void>;
82
+ /** Update registered group filters and refresh the native unit binding. */
83
+ rebind(this: void, unit: string, filters: readonly AuraGroupFilter[]): Result<void>;
84
+ /** Hide the display and keep its native groups and slots for reuse. */
85
+ disable(this: void): Result<void>;
86
+ /** Release the native groups and slots and prevent further activation. */
87
+ retire(this: void): Result<void>;
88
+ }
89
+
90
+ interface FlowDirection {
91
+ Left?: number;
92
+ Right?: number;
93
+ Up?: number;
94
+ Down?: number;
95
+ }
96
+
97
+ interface FlowLayoutAxis {
98
+ Horizontal?: number;
99
+ }
100
+
101
+ interface NativeSlotOptions {
102
+ candidateFilters?: AuraCandidateFilters;
103
+ templateNames?: readonly string[];
104
+ initializeFrame(this: void, button: AuraButton): void;
105
+ }
106
+
107
+ interface NativeGroupOptions extends NativeSlotOptions {
108
+ maxFrameCount: number;
109
+ sortMethod?: number;
110
+ sortDirection?: number;
111
+ layout: {
112
+ elementWidth: number;
113
+ elementHeight: number;
114
+ elementSpacing: number;
115
+ elementSpacingX: number;
116
+ elementSpacingY: number;
117
+ lineSpacing: number;
118
+ layoutIndex: number;
119
+ };
120
+ }
121
+
122
+ type NativeContainer = Frame & {
123
+ AddAuraGroup?(this: object, key: string, filter: string, options: NativeGroupOptions): void;
124
+ AddAuraSlot?(this: object, key: string, filter: string, options: NativeSlotOptions): void;
125
+ SetFlowLayoutAxis?(this: object, axis: number): void;
126
+ SetFlowLayoutAnchorPoint(this: object, point: AuraContainerOptions["anchor"]): void;
127
+ SetFlowLayoutGrowthDirection(this: object, primary: number, secondary: number): void;
128
+ SetFlowLayoutMaximumLineSize?(this: object, width: number): void;
129
+ SetUnit(this: object, unit: string): void;
130
+ SetEnabled(this: object, enabled: boolean): void;
131
+ UpdateAllAuras?(this: object): void;
132
+ SetAuraGroupFilterString?(this: object, key: string, filter: string): void;
133
+ SetAuraGroupCandidateFilters?(this: object, key: string, candidateFilters?: AuraCandidateFilters): void;
134
+ SetAuraGroupMaxFrameCount?(this: object, key: string, count: number): void;
135
+ SetAuraGroupEnabled?(this: object, key: string, enabled: boolean): void;
136
+ SetAuraSlotEnabled?(this: object, key: string, enabled: boolean): void;
137
+ };
138
+
139
+ type Create = (this: void, kind: "AuraContainer", name: undefined, parent: FrameParent,
140
+ template: "CustomAuraContainerTemplate") => NativeContainer | undefined;
141
+
142
+ declare function rawget(this: void, table: object, key: AuraButton): true | undefined;
143
+ declare function rawset(this: void, table: object, key: AuraButton, value: true): void;
144
+
145
+ const noUnit = "none";
146
+
147
+ export function createAuraContainer(parent: FrameParent, options: AuraContainerOptions): Result<AuraContainer> {
148
+ const { anchor, defer, gap, groups: suppliedGroups, lineWidth, onActivated, onBuildFailure, onGroupChanged, onReusedFrame, reread, size,
149
+ initialUnit = noUnit, cellWidth = size, cellHeight = size, lineSpacing = gap, rowGap = gap, slots: suppliedSlots = [] } = options;
150
+ const groups = suppliedGroups as OwnedReadonlyArray<AuraContainerGroup>;
151
+ const slots = suppliedSlots as OwnedReadonlyArray<AuraContainerSlot>;
152
+ const hasGroups = groups.length > 0;
153
+ if (!Number.isFinite(size) || size <= 0 || !Number.isFinite(cellWidth) || cellWidth <= 0
154
+ || !Number.isFinite(cellHeight) || cellHeight <= 0 || !Number.isFinite(gap) || gap < 0
155
+ || !Number.isFinite(lineSpacing) || lineSpacing < 0 || !Number.isFinite(rowGap) || rowGap < 0) {
156
+ return fail("Invalid aura layout dimensions");
157
+ }
158
+ if (isSecret(initialUnit) || initialUnit === "") return fail("Invalid initial aura unit token");
159
+ if (lineWidth !== undefined && (!Number.isFinite(lineWidth) || lineWidth <= 0)) return fail("Invalid aura line width");
160
+ if (!hasGroups && slots.length === 0) return fail("An aura container needs at least one group or slot");
161
+ const uniqueKeys = new Set<string>();
162
+ for (const { key, filter, maxFrameCount } of groups) {
163
+ if (key === "" || filter === "" || !Number.isInteger(maxFrameCount) || maxFrameCount <= 0) {
164
+ return fail("Invalid aura group");
165
+ }
166
+ if (uniqueKeys.has(key)) return fail("Duplicate aura group " + key);
167
+ uniqueKeys.add(key);
168
+ }
169
+ for (const { key, filter } of slots) {
170
+ if (key === "" || filter === "") return fail("Invalid aura slot");
171
+ if (uniqueKeys.has(key)) return fail("Duplicate aura slot " + key);
172
+ uniqueKeys.add(key);
173
+ }
174
+
175
+ const create = rawField<Create>(api, "CreateFrame");
176
+ const anchorUtil = rawField<{ FlowDirection?: FlowDirection; FlowLayoutAxis?: FlowLayoutAxis }>(api, "AnchorUtil");
177
+ const direction = anchorUtil?.FlowDirection ?? rawField<FlowDirection>(api, "FlowDirection");
178
+ const axis = anchorUtil?.FlowLayoutAxis ?? rawField<FlowLayoutAxis>(api, "FlowLayoutAxis");
179
+ const defaultHorizontal = anchor === "TOPRIGHT" || anchor === "RIGHT" || anchor === "BOTTOMRIGHT" ? "Left" : "Right";
180
+ const [growX, growY] = options.grow ?? [defaultHorizontal, "Down"];
181
+ const horizontal = direction?.[growX];
182
+ const vertical = direction?.[growY];
183
+ if (create === undefined || (hasGroups && (horizontal === undefined || vertical === undefined))) {
184
+ return fail("Native aura layout is unavailable");
185
+ }
186
+ const sortMethods = rawField<Partial<Record<NonNullable<AuraContainerGroup["sort"]>, number>>>(api, "AuraContainerSortMethod");
187
+ const sortDirections = rawField<{ Normal?: number; Reverse?: number }>(api, "AuraContainerSortDirection");
188
+
189
+ const created = protect(() => create("AuraContainer", undefined, parent, "CustomAuraContainerTemplate"));
190
+ if (!created.ok) return created;
191
+ if (created.value === undefined) return fail("The client did not create the aura container");
192
+ const container = created.value;
193
+
194
+ const registeredGroups = new Map<string, AuraGroupFilter>();
195
+ const registeredSlots = new Set<string>();
196
+ const initialized = weakKeys({});
197
+ let initializationFailure: Failure | undefined;
198
+ let boundUnit: string | undefined;
199
+ let active = false;
200
+ let disabled = false;
201
+ let retired = false;
202
+ let released = false;
203
+ let building = defer !== undefined;
204
+ let cancelBuild: ((this: void) => void) | undefined;
205
+ let pendingActivation: { unit: string; force: boolean } | undefined;
206
+ let refreshQueued = false;
207
+ let refreshPending: "activate" | "rebind" | undefined;
208
+
209
+ function disable(this: void): Result<void> {
210
+ pendingActivation = undefined;
211
+ refreshPending = undefined;
212
+ active = false;
213
+ if (disabled) return ok(undefined);
214
+ const stopped = protect(() => container.SetEnabled(false));
215
+ const hidden = protect(() => container.Hide());
216
+ disabled = stopped.ok && hidden.ok;
217
+ return stopped.ok ? hidden : stopped;
218
+ }
219
+
220
+ function retire(this: void): Result<void> {
221
+ if (released) return ok(undefined);
222
+ retired = true;
223
+ building = false;
224
+ let result = disable();
225
+ function release(run: (this: void) => void) {
226
+ const attempt = protect(run);
227
+ if (result.ok) result = attempt;
228
+ }
229
+ const cancel = cancelBuild;
230
+ if (cancel !== undefined) release(() => {
231
+ cancel();
232
+ cancelBuild = undefined;
233
+ });
234
+ for (const [key] of registeredGroups) {
235
+ release(() => container.SetAuraGroupMaxFrameCount?.(key, 0));
236
+ release(() => container.SetAuraGroupEnabled?.(key, false));
237
+ }
238
+ for (const key of registeredSlots) release(() => container.SetAuraSlotEnabled?.(key, false));
239
+ release(() => container.SetUnit(noUnit));
240
+ released = result.ok;
241
+ if (released) registeredGroups.clear();
242
+ return result;
243
+ }
244
+
245
+ function refreshVisibility(this: void) {
246
+ refreshQueued = false;
247
+ const pending = refreshPending;
248
+ refreshPending = undefined;
249
+ if (pending === undefined || !active || retired) return;
250
+ const refreshed = protect(() => {
251
+ if (pending === "rebind" && !container.IsShown()) return;
252
+ container.Hide();
253
+ if (active && !retired) container.Show();
254
+ });
255
+ if (!refreshed.ok) disable();
256
+ }
257
+
258
+ function queueVisibilityRefresh(this: void, source: "activate" | "rebind"): void {
259
+ if (!refreshQueued) {
260
+ api.C_Timer.After(0, refreshVisibility);
261
+ refreshQueued = true;
262
+ }
263
+ refreshPending = source;
264
+ }
265
+
266
+ function resetUnit(this: void, unit: string): void {
267
+ boundUnit = undefined;
268
+ container.SetUnit(noUnit);
269
+ container.SetUnit(unit);
270
+ boundUnit = unit;
271
+ }
272
+
273
+ function activate(this: void, unit: string, force = false): Result<void> {
274
+ if (retired) return fail("Aura container is retired");
275
+ if (initializationFailure !== undefined) {
276
+ disable();
277
+ return initializationFailure;
278
+ }
279
+ if (isSecret(unit) || unit === "" || unit === noUnit) return fail("Invalid aura unit token");
280
+ if (building) {
281
+ const preserveForce = pendingActivation?.unit === unit && pendingActivation.force;
282
+ pendingActivation = { unit, force: force || preserveForce };
283
+ return ok(undefined);
284
+ }
285
+ if (active && boundUnit === unit && !force) return ok(undefined);
286
+
287
+ const armed = protect(() => {
288
+ if (unit !== boundUnit) {
289
+ boundUnit = undefined;
290
+ container.SetUnit(unit);
291
+ boundUnit = unit;
292
+ }
293
+ if (!active) {
294
+ disabled = false;
295
+ container.SetEnabled(true);
296
+ container.Show();
297
+ }
298
+ });
299
+ if (!armed.ok) {
300
+ disable();
301
+ return armed;
302
+ }
303
+
304
+ const updated = protect(() => {
305
+ if (reread !== undefined) return reread(container);
306
+ if (container.UpdateAllAuras === undefined) return false;
307
+ container.UpdateAllAuras();
308
+ return true;
309
+ });
310
+ if (!updated.ok || !updated.value) {
311
+ const rebound = protect(() => {
312
+ resetUnit(unit);
313
+ queueVisibilityRefresh("activate");
314
+ });
315
+ if (!rebound.ok) {
316
+ disable();
317
+ return rebound;
318
+ }
319
+ } else {
320
+ refreshPending = undefined;
321
+ }
322
+
323
+ if (initializationFailure !== undefined) {
324
+ disable();
325
+ return initializationFailure;
326
+ }
327
+ active = true;
328
+ if (onActivated !== undefined) protect(() => onActivated(container, unit));
329
+ return ok(undefined);
330
+ }
331
+
332
+ function updateGroup(this: void, requested: AuraGroupFilter): AuraGroupFilter | undefined {
333
+ const { key } = requested;
334
+ const accepted = registeredGroups.get(key);
335
+ const setFilter = container.SetAuraGroupFilterString;
336
+ if (accepted === undefined || setFilter === undefined) return undefined;
337
+
338
+ let { filter, candidateFilters } = accepted;
339
+ if (filter !== requested.filter && protect(() => setFilter.call(container, key, requested.filter)).ok) {
340
+ filter = requested.filter;
341
+ }
342
+ const setCandidates = container.SetAuraGroupCandidateFilters;
343
+ if (setCandidates !== undefined && candidateFilters !== requested.candidateFilters
344
+ && protect(() => setCandidates.call(container, key, requested.candidateFilters)).ok) {
345
+ candidateFilters = requested.candidateFilters;
346
+ }
347
+ if (filter === accepted.filter && candidateFilters === accepted.candidateFilters) return undefined;
348
+
349
+ const changed = { key, filter, candidateFilters };
350
+ registeredGroups.set(key, changed);
351
+ return changed;
352
+ }
353
+
354
+ function rebind(this: void, unit: string, supplied: readonly AuraGroupFilter[]): Result<void> {
355
+ if (retired) return fail("Aura container is retired");
356
+ if (building) return fail("Aura container is still building");
357
+ if (initializationFailure !== undefined) {
358
+ disable();
359
+ return initializationFailure;
360
+ }
361
+ if (isSecret(unit) || unit === "" || unit === noUnit) return fail("Invalid aura unit token");
362
+
363
+ const filters = supplied as OwnedReadonlyArray<AuraGroupFilter>;
364
+ const keys = new Set<string>();
365
+ for (const { key, filter } of filters) {
366
+ if (isSecret(key) || isSecret(filter) || filter === "" || !registeredGroups.has(key)) return fail("Invalid aura group filter");
367
+ if (keys.has(key)) return fail("Duplicate aura group filter " + key);
368
+ keys.add(key);
369
+ }
370
+
371
+ const changed: AuraGroupFilter[] = [];
372
+ const rebound = protect(() => {
373
+ container.Hide();
374
+ for (const group of filters) {
375
+ const accepted = updateGroup(group);
376
+ if (accepted !== undefined) changed.push(accepted);
377
+ }
378
+ resetUnit(unit);
379
+ disabled = false;
380
+ container.SetEnabled(true);
381
+ container.Show();
382
+ queueVisibilityRefresh("rebind");
383
+ });
384
+ const failure = rebound.ok ? initializationFailure : rebound;
385
+ if (failure !== undefined) disable();
386
+ else if (!retired) active = true;
387
+
388
+ if (onGroupChanged !== undefined) {
389
+ for (const group of changed) {
390
+ if (retired) break;
391
+ if (registeredGroups.get(group.key) === group) protect(() => onGroupChanged(container, group));
392
+ }
393
+ }
394
+ if (failure !== undefined) return failure;
395
+ if (retired) return fail("Aura container is retired");
396
+ if (active && boundUnit === unit && onActivated !== undefined) protect(() => onActivated(container, unit));
397
+ return ok(undefined);
398
+ }
399
+
400
+ const idle = disable();
401
+ if (!idle.ok) {
402
+ retire();
403
+ return idle;
404
+ }
405
+ const configured = protect(() => {
406
+ const add = hasGroups ? container.AddAuraGroup : undefined;
407
+ if (hasGroups && add === undefined) return undefined;
408
+ container.SetUnit(initialUnit);
409
+ if (initialUnit !== noUnit) boundUnit = initialUnit;
410
+ if (hasGroups && horizontal !== undefined && vertical !== undefined) {
411
+ container.SetFlattensRenderLayers?.(true);
412
+ if (axis?.Horizontal !== undefined) container.SetFlowLayoutAxis?.(axis.Horizontal);
413
+ container.SetFlowLayoutAnchorPoint(anchor);
414
+ container.SetFlowLayoutGrowthDirection(horizontal, vertical);
415
+ if (lineWidth !== undefined) container.SetFlowLayoutMaximumLineSize?.(lineWidth);
416
+ }
417
+ container.SetPoint(anchor, parent, anchor);
418
+ return { add };
419
+ });
420
+ if (!configured.ok || configured.value === undefined) {
421
+ retire();
422
+ return configured.ok ? fail("Native aura groups are unavailable") : configured;
423
+ }
424
+ const add = configured.value.add;
425
+
426
+ function registerGroup(group: AuraContainerGroup): Result<void> {
427
+ if (add === undefined) return fail("Native aura groups are unavailable");
428
+ const { candidateFilters, filter, initializeFrame, key, maxFrameCount, sort, sortDirection, templates } = group;
429
+ // Keep the attempted key for retirement even if the native registration fails.
430
+ registeredGroups.set(key, { key, filter, candidateFilters });
431
+ const added = protect(() => add.call(container, key, filter, {
432
+ maxFrameCount,
433
+ candidateFilters,
434
+ templateNames: templates,
435
+ sortMethod: sort === "Default" ? sortMethods?.Default ?? sortMethods?.UnitFrameDebuff
436
+ : sort !== undefined ? sortMethods?.[sort] : undefined,
437
+ sortDirection: sortDirection !== undefined ? sortDirections?.[sortDirection] : undefined,
438
+ initializeFrame: button => {
439
+ if (retired || initializationFailure !== undefined) return;
440
+ if (rawget(initialized, button) === true) {
441
+ if (onReusedFrame !== undefined) protect(onReusedFrame);
442
+ return;
443
+ }
444
+ rawset(initialized, button, true);
445
+ const result = protect(() => initializeFrame(button));
446
+ if (!result.ok) initializationFailure = result;
447
+ },
448
+ layout: {
449
+ elementWidth: cellWidth,
450
+ elementHeight: cellHeight,
451
+ elementSpacing: gap,
452
+ elementSpacingX: gap,
453
+ elementSpacingY: rowGap,
454
+ lineSpacing,
455
+ layoutIndex: registeredGroups.size,
456
+ },
457
+ }));
458
+ return added.ok ? initializationFailure ?? added : added;
459
+ }
460
+
461
+ function rollbackSlot(this: void, key: string): void {
462
+ const stopped = protect(() => {
463
+ if (container.SetAuraSlotEnabled === undefined) return false;
464
+ container.SetAuraSlotEnabled(key, false);
465
+ return true;
466
+ });
467
+ if (stopped.ok && stopped.value) registeredSlots.delete(key);
468
+ }
469
+
470
+ function registerSlot(this: void, slot: AuraContainerSlot, required: boolean): Result<void> {
471
+ const { candidateFilters, filter, initializeFrame, key, templates } = slot;
472
+ let slotFailure: Failure | undefined;
473
+ let registering = true;
474
+ const added = protect(() => {
475
+ if (container.AddAuraSlot === undefined) return fail("Native aura slots are unavailable");
476
+ // The client can disable a slot, but exposes no way to remove its key.
477
+ uniqueKeys.add(key);
478
+ registeredSlots.add(key);
479
+ container.AddAuraSlot(key, filter, {
480
+ candidateFilters,
481
+ templateNames: templates,
482
+ initializeFrame: button => {
483
+ if (retired || slotFailure !== undefined) return;
484
+ if (rawget(initialized, button) === true) {
485
+ if (onReusedFrame !== undefined) protect(onReusedFrame);
486
+ return;
487
+ }
488
+ rawset(initialized, button, true);
489
+ const styled = protect(() => initializeFrame(button));
490
+ if (styled.ok) return;
491
+ slotFailure = styled;
492
+ if (registering) return;
493
+ if (required) {
494
+ initializationFailure ??= styled;
495
+ } else {
496
+ // Leave the native initializer before changing the slot's enabled state.
497
+ protect(() => api.C_Timer.After(0, () => {
498
+ if (!retired) rollbackSlot(key);
499
+ }));
500
+ }
501
+ },
502
+ });
503
+ return slotFailure ?? ok(undefined);
504
+ });
505
+ registering = false;
506
+ const result = added.ok ? added.value : added;
507
+ if (!result.ok && registeredSlots.has(key)) {
508
+ slotFailure = result;
509
+ rollbackSlot(key);
510
+ }
511
+ return result;
512
+ }
513
+
514
+ function addSlot(this: void, slot: AuraContainerSlot): Result<void> {
515
+ if (retired) return fail("Aura container is retired");
516
+ if (slot.key === "" || slot.filter === "") return fail("Invalid aura slot");
517
+ if (uniqueKeys.has(slot.key)) return fail("Duplicate aura slot " + slot.key);
518
+ return registerSlot(slot, false);
519
+ }
520
+
521
+ const auraContainer: AuraContainer = { frame: container, addSlot, activate, rebind, disable, retire };
522
+ if (defer === undefined) {
523
+ for (const group of groups) {
524
+ const added = registerGroup(group);
525
+ if (!added.ok) {
526
+ retire();
527
+ return added;
528
+ }
529
+ }
530
+ for (const slot of slots) {
531
+ const added = registerSlot(slot, true);
532
+ if (!added.ok) {
533
+ retire();
534
+ return added;
535
+ }
536
+ }
537
+ return ok(auraContainer);
538
+ }
539
+
540
+ let scheduling = true;
541
+ let registeredSlotCount = 0;
542
+ let buildFailure: Failure | undefined;
543
+ function failBuild(this: void, failure: Failure): undefined {
544
+ retire();
545
+ if (scheduling) buildFailure = failure;
546
+ else if (onBuildFailure !== undefined) protect(() => onBuildFailure(failure));
547
+ return undefined;
548
+ }
549
+
550
+ function buildStep(this: void): true | undefined {
551
+ if (!building) return undefined;
552
+ if (initializationFailure !== undefined) return failBuild(initializationFailure);
553
+ const group = groups[registeredGroups.size];
554
+ if (group !== undefined) {
555
+ const added = registerGroup(group);
556
+ if (!added.ok) return failBuild(added);
557
+ return building ? true : undefined;
558
+ }
559
+ const slot = slots[registeredSlotCount];
560
+ if (slot !== undefined) {
561
+ registeredSlotCount++;
562
+ const added = registerSlot(slot, true);
563
+ if (!added.ok) return failBuild(added);
564
+ return building ? true : undefined;
565
+ }
566
+
567
+ building = false;
568
+ const pending = pendingActivation;
569
+ pendingActivation = undefined;
570
+ if (pending !== undefined) {
571
+ const activated = activate(pending.unit, pending.force);
572
+ if (!activated.ok) return failBuild(activated);
573
+ }
574
+ cancelBuild = undefined;
575
+ return undefined;
576
+ }
577
+
578
+ const scheduled = protect(() => defer(container, buildStep));
579
+ scheduling = false;
580
+ if (!scheduled.ok) {
581
+ retire();
582
+ return buildFailure ?? scheduled;
583
+ }
584
+ if (building) cancelBuild = scheduled.value;
585
+ if (buildFailure !== undefined) {
586
+ // A host may run the step before returning its cancellation handle.
587
+ protect(scheduled.value);
588
+ return buildFailure;
589
+ }
590
+ return ok(auraContainer);
591
+ }