@overmvp/kumi 0.3.0 → 0.5.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 (89) hide show
  1. package/animation/index.ts +4 -0
  2. package/animation/motion-policy.ts +20 -0
  3. package/animation/slide.ts +61 -0
  4. package/animation/spring.ts +75 -0
  5. package/animation/staggered-reveal.ts +34 -0
  6. package/builder/css-gradients.mjs +74 -0
  7. package/builder/css-mask-assets.mjs +52 -0
  8. package/builder/css-mask-assets.test.mjs +31 -0
  9. package/builder/css-v1.mjs +73 -22
  10. package/builder/css-v1.test.mjs +42 -2
  11. package/builder/module-declarations.mjs +2 -2
  12. package/builder/module-declarations.test.mjs +4 -2
  13. package/builder/src/compiler.rs +25 -0
  14. package/builder/src/lua_upvalues.rs +641 -0
  15. package/builder/src/main.rs +1 -0
  16. package/builder/style-modules.mjs +21 -3
  17. package/builder/style-modules.test.mjs +24 -0
  18. package/builder/style-states.mjs +6 -4
  19. package/package.json +1 -1
  20. package/router/index.ts +1 -0
  21. package/router/link.tsx +32 -0
  22. package/router/router-view.ts +5 -3
  23. package/scripts/addon-build.mjs +17 -2
  24. package/scripts/addon-project.mjs +22 -11
  25. package/scripts/kumi-cli.mjs +0 -0
  26. package/src/bindings.ts +10 -4
  27. package/src/context.ts +31 -7
  28. package/src/css-tokens.ts +11 -2
  29. package/src/css-v1.ts +3 -0
  30. package/src/elements.ts +20 -1
  31. package/src/flex-layout.ts +26 -5
  32. package/src/frame-scheduler.ts +3 -1
  33. package/src/index.ts +2 -2
  34. package/src/keyed-list.ts +9 -6
  35. package/src/module-ui.ts +22 -2
  36. package/src/module.ts +26 -7
  37. package/src/reactivity.ts +14 -1
  38. package/src/style-classes.ts +22 -1
  39. package/src/style-states.ts +13 -6
  40. package/state/setup-store.ts +3 -3
  41. package/templates/addon/.agents/skills/kumi-ui/SKILL.md +1 -1
  42. package/templates/addon/.claude/skills/kumi-ui/SKILL.md +1 -1
  43. package/templates/addon/AGENTS.md +1 -1
  44. package/templates/addon/kumi.config.ts +17 -17
  45. package/templates/addon/src/app/app.module.ts +3 -5
  46. package/templates/addon/src/app/layout/{AppWindow.module.scss → AppWindow.module.css} +10 -12
  47. package/templates/addon/src/modules/greeting/greeting.module.ts +2 -2
  48. package/templates/addon/src/modules/greeting/ui/{Greeting.module.scss → Greeting.module.css} +9 -11
  49. package/templates/addon/src/modules/playtime/playtime.module.ts +3 -5
  50. package/templates/addon/src/modules/playtime/ui/{Playtime.module.scss → Playtime.module.css} +3 -5
  51. package/templates/addon/src/shared/styles/tokens.css +13 -0
  52. package/templates/addon/src/shared/ui/{Controls.module.scss → Controls.module.css} +18 -20
  53. package/utils/format.ts +13 -0
  54. package/utils/index.ts +1 -1
  55. package/wow/action-button.ts +26 -1
  56. package/wow/addon-manifest.ts +2 -0
  57. package/wow/animation.ts +19 -18
  58. package/wow/app-ui.ts +150 -31
  59. package/wow/aura-container.ts +132 -38
  60. package/wow/aura-countdown.ts +19 -3
  61. package/wow/aura-follower.ts +32 -0
  62. package/wow/aura-view.ts +49 -0
  63. package/wow/css-background-image.ts +75 -0
  64. package/wow/css-box.ts +14 -9
  65. package/wow/css-image-mask.ts +32 -0
  66. package/wow/css-surfaces.ts +88 -35
  67. package/wow/element-events.ts +33 -13
  68. package/wow/frames.ts +2 -0
  69. package/wow/heal-prediction.ts +2 -4
  70. package/wow/hooks.ts +17 -0
  71. package/wow/hotkeys.ts +221 -0
  72. package/wow/index.ts +11 -6
  73. package/wow/initial-view.ts +99 -0
  74. package/wow/layout-view.ts +19 -10
  75. package/wow/module-replacements.ts +103 -0
  76. package/wow/native.ts +1 -0
  77. package/wow/pixel.ts +25 -0
  78. package/wow/pointer-click.ts +35 -0
  79. package/wow/protected-view.ts +49 -13
  80. package/wow/rounded-texture.ts +9 -4
  81. package/wow/scroll-view.ts +5 -4
  82. package/wow/state-paint.ts +5 -14
  83. package/wow/status-bar.ts +65 -0
  84. package/wow/texture-fill.ts +10 -0
  85. package/wow/unit-button.ts +25 -4
  86. package/wow/unit-cast.ts +6 -4
  87. package/wow/view-nodes.ts +11 -4
  88. package/wow/view.ts +387 -278
  89. package/templates/addon/src/shared/styles/_tokens.scss +0 -12
@@ -3,13 +3,14 @@ import { fail, ok, type Failure, type Result } from "../src/result";
3
3
  import type { AuraDispelTarget } from "./aura-button";
4
4
  import type { FontString, Frame, FrameMap, FrameParent, Texture } from "./frames";
5
5
  import { rawField, weakKeys } from "./lua-table";
6
- import { api, isSecret } from "./native";
6
+ import { api, isSecret, reveal } from "./native";
7
7
  import { protect } from "./protect";
8
8
 
9
9
  export type AuraButton = Frame & AuraDispelTarget & {
10
10
  SetIcon?(this: object, texture: Texture): void;
11
11
  SetDurationCooldown?(this: object, cooldown: FrameMap["Cooldown"]): void;
12
12
  SetApplicationCount?(this: object, text: FontString): void;
13
+ SetDurationText?: Parameters<typeof import("./aura-countdown").bindAuraDurationText>[0]["SetDurationText"];
13
14
  SetTooltipAnchorPoint?(this: object, anchor: "ANCHOR_BOTTOMRIGHT", x: number, y: number): void;
14
15
  };
15
16
 
@@ -28,6 +29,7 @@ export interface AuraCandidateFilters {
28
29
  readonly isFromPlayerOrPlayerPet?: boolean;
29
30
  readonly isStealable?: boolean;
30
31
  readonly isNameplateOnly?: boolean;
32
+ readonly nameplateShowPersonal?: boolean;
31
33
  }
32
34
 
33
35
  export interface AuraGroupFilter {
@@ -73,14 +75,26 @@ export interface AuraContainerOptions {
73
75
  onActivated?(this: void, frame: Frame, unit: string): void;
74
76
  }
75
77
 
78
+ export interface AuraFlowLayout {
79
+ readonly gap: number;
80
+ readonly rowGap: number;
81
+ readonly lineWidth: number;
82
+ readonly maxFrameCount: number;
83
+ readonly groupLimits?: Readonly<Partial<Record<string, number>>>;
84
+ }
85
+
76
86
  export interface AuraContainer {
77
87
  readonly frame: Frame;
78
88
  /** Register a fixed aura slot on this display. */
79
89
  addSlot(this: void, slot: AuraContainerSlot): Result<void>;
80
90
  /** Force a reread when a new occupant uses the same unit token. */
81
91
  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>;
92
+ /** Update filters and refresh the binding. Exact updates fail closed if the client rejects a filter. */
93
+ rebind(this: void, unit: string, filters: readonly AuraGroupFilter[], exact?: true): Result<void>;
94
+ setGroupEnabled(this: void, key: string, enabled: boolean): Result<void>;
95
+ /** Retune existing native groups out of combat without rebuilding their buttons. */
96
+ setFlowLayout(this: void, layout: AuraFlowLayout): Result<void>;
97
+ setPlacement(this: void, point: AuraContainerOptions["anchor"], grow?: AuraContainerOptions["grow"]): Result<void>;
84
98
  /** Hide the display and keep its native groups and slots for reuse. */
85
99
  disable(this: void): Result<void>;
86
100
  /** Release the native groups and slots and prevent further activation. */
@@ -104,19 +118,21 @@ interface NativeSlotOptions {
104
118
  initializeFrame(this: void, button: AuraButton): void;
105
119
  }
106
120
 
121
+ interface NativeGroupLayout {
122
+ elementWidth: number;
123
+ elementHeight: number;
124
+ elementSpacing: number;
125
+ lineSpacing: number;
126
+ groupSpacing: number;
127
+ groupLineSpacing: number;
128
+ layoutIndex: number;
129
+ }
130
+
107
131
  interface NativeGroupOptions extends NativeSlotOptions {
108
132
  maxFrameCount: number;
109
133
  sortMethod?: number;
110
134
  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
- };
135
+ layout: NativeGroupLayout;
120
136
  }
121
137
 
122
138
  type NativeContainer = Frame & {
@@ -132,6 +148,7 @@ type NativeContainer = Frame & {
132
148
  SetAuraGroupFilterString?(this: object, key: string, filter: string): void;
133
149
  SetAuraGroupCandidateFilters?(this: object, key: string, candidateFilters?: AuraCandidateFilters): void;
134
150
  SetAuraGroupMaxFrameCount?(this: object, key: string, count: number): void;
151
+ SetAuraGroupLayout?(this: object, key: string, layout: NativeGroupLayout): void;
135
152
  SetAuraGroupEnabled?(this: object, key: string, enabled: boolean): void;
136
153
  SetAuraSlotEnabled?(this: object, key: string, enabled: boolean): void;
137
154
  };
@@ -176,13 +193,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
176
193
  const anchorUtil = rawField<{ FlowDirection?: FlowDirection; FlowLayoutAxis?: FlowLayoutAxis }>(api, "AnchorUtil");
177
194
  const direction = anchorUtil?.FlowDirection ?? rawField<FlowDirection>(api, "FlowDirection");
178
195
  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
- }
196
+ if (create === undefined) return fail("Native aura layout is unavailable");
186
197
  const sortMethods = rawField<Partial<Record<NonNullable<AuraContainerGroup["sort"]>, number>>>(api, "AuraContainerSortMethod");
187
198
  const sortDirections = rawField<{ Normal?: number; Reverse?: number }>(api, "AuraContainerSortDirection");
188
199
 
@@ -192,6 +203,8 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
192
203
  const container = created.value;
193
204
 
194
205
  const registeredGroups = new Map<string, AuraGroupFilter>();
206
+ const disabledGroups = new Set<string>();
207
+ const groupLimits = new Map<string, number>();
195
208
  const registeredSlots = new Set<string>();
196
209
  const initialized = weakKeys({});
197
210
  let initializationFailure: Failure | undefined;
@@ -238,7 +251,11 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
238
251
  for (const key of registeredSlots) release(() => container.SetAuraSlotEnabled?.(key, false));
239
252
  release(() => container.SetUnit(noUnit));
240
253
  released = result.ok;
241
- if (released) registeredGroups.clear();
254
+ if (released) {
255
+ registeredGroups.clear();
256
+ disabledGroups.clear();
257
+ groupLimits.clear();
258
+ }
242
259
  return result;
243
260
  }
244
261
 
@@ -333,10 +350,10 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
333
350
  const { key } = requested;
334
351
  const accepted = registeredGroups.get(key);
335
352
  const setFilter = container.SetAuraGroupFilterString;
336
- if (accepted === undefined || setFilter === undefined) return undefined;
353
+ if (accepted === undefined) return undefined;
337
354
 
338
355
  let { filter, candidateFilters } = accepted;
339
- if (filter !== requested.filter && protect(() => setFilter.call(container, key, requested.filter)).ok) {
356
+ if (filter !== requested.filter && setFilter !== undefined && protect(() => setFilter.call(container, key, requested.filter)).ok) {
340
357
  filter = requested.filter;
341
358
  }
342
359
  const setCandidates = container.SetAuraGroupCandidateFilters;
@@ -351,7 +368,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
351
368
  return changed;
352
369
  }
353
370
 
354
- function rebind(this: void, unit: string, supplied: readonly AuraGroupFilter[]): Result<void> {
371
+ function rebind(this: void, unit: string, supplied: readonly AuraGroupFilter[], exact?: true): Result<void> {
355
372
  if (retired) return fail("Aura container is retired");
356
373
  if (building) return fail("Aura container is still building");
357
374
  if (initializationFailure !== undefined) {
@@ -369,11 +386,19 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
369
386
  }
370
387
 
371
388
  const changed: AuraGroupFilter[] = [];
389
+ let rejected: string | undefined;
372
390
  const rebound = protect(() => {
373
391
  container.Hide();
374
392
  for (const group of filters) {
375
393
  const accepted = updateGroup(group);
376
394
  if (accepted !== undefined) changed.push(accepted);
395
+ if (exact) {
396
+ const current = registeredGroups.get(group.key);
397
+ if (current?.filter !== group.filter || current?.candidateFilters !== group.candidateFilters) {
398
+ rejected = group.key;
399
+ return;
400
+ }
401
+ }
377
402
  }
378
403
  resetUnit(unit);
379
404
  disabled = false;
@@ -381,7 +406,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
381
406
  container.Show();
382
407
  queueVisibilityRefresh("rebind");
383
408
  });
384
- const failure = rebound.ok ? initializationFailure : rebound;
409
+ const failure = !rebound.ok ? rebound : rejected !== undefined ? fail("The client rejected the aura filter for " + rejected) : initializationFailure;
385
410
  if (failure !== undefined) disable();
386
411
  else if (!retired) active = true;
387
412
 
@@ -397,6 +422,78 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
397
422
  return ok(undefined);
398
423
  }
399
424
 
425
+ function setGroupEnabled(this: void, key: string, enabled: boolean): Result<void> {
426
+ const setEnabled = container.SetAuraGroupEnabled;
427
+ const cap = container.SetAuraGroupMaxFrameCount;
428
+ const limit = groupLimits.get(key);
429
+ if (retired || limit === undefined || (setEnabled === undefined && cap === undefined)) return fail("Aura group is unavailable");
430
+ const changed = protect(() => {
431
+ if (setEnabled !== undefined) setEnabled.call(container, key, enabled);
432
+ else cap?.call(container, key, enabled ? limit : 0);
433
+ });
434
+ if (changed.ok) {
435
+ if (enabled) disabledGroups.delete(key);
436
+ else disabledGroups.add(key);
437
+ }
438
+ return changed;
439
+ }
440
+
441
+ function nativeGroupLayout(index: number, spacing: number, rows: number, lines: number): NativeGroupLayout {
442
+ return { elementWidth: cellWidth, elementHeight: cellHeight, elementSpacing: spacing,
443
+ lineSpacing: lines, groupSpacing: 0, groupLineSpacing: rows, layoutIndex: index };
444
+ }
445
+
446
+ function setFlowLayout(this: void, layout: AuraFlowLayout): Result<void> {
447
+ if (retired || building || !hasGroups) return fail("Aura groups are unavailable");
448
+ if (reveal(api.InCombatLockdown()) !== false) return fail("Aura flow layout requires an unlocked client");
449
+ const { gap, rowGap, lineWidth, maxFrameCount, groupLimits: limits } = layout;
450
+ if (!Number.isFinite(gap) || gap < 0 || !Number.isFinite(rowGap) || rowGap < 0
451
+ || !Number.isFinite(lineWidth) || lineWidth <= 0 || !Number.isInteger(maxFrameCount) || maxFrameCount <= 0) {
452
+ return fail("Invalid aura flow layout");
453
+ }
454
+ if (limits !== undefined) {
455
+ for (const key of Object.keys(limits)) {
456
+ const limit = limits[key];
457
+ if (limit !== undefined && (!registeredGroups.has(key) || !Number.isInteger(limit) || limit <= 0)) {
458
+ return fail("Invalid aura flow limit for " + key);
459
+ }
460
+ }
461
+ }
462
+ const width = container.SetFlowLayoutMaximumLineSize;
463
+ const arrange = container.SetAuraGroupLayout;
464
+ const cap = container.SetAuraGroupMaxFrameCount;
465
+ const nativeEnabled = container.SetAuraGroupEnabled !== undefined;
466
+ if (width === undefined || arrange === undefined || cap === undefined) return fail("Native aura flow updates are unavailable");
467
+ const result = protect(() => {
468
+ width.call(container, lineWidth);
469
+ let index = 0;
470
+ for (const { key } of groups) {
471
+ const limit = limits?.[key] ?? maxFrameCount;
472
+ arrange.call(container, key, nativeGroupLayout(++index, gap, rowGap, rowGap));
473
+ cap.call(container, key, nativeEnabled || !disabledGroups.has(key) ? limit : 0);
474
+ groupLimits.set(key, limit);
475
+ }
476
+ });
477
+ if (!result.ok) disable();
478
+ return result;
479
+ }
480
+
481
+ function setPlacement(this: void, point: AuraContainerOptions["anchor"], grow?: AuraContainerOptions["grow"]): Result<void> {
482
+ if (retired) return fail("Aura container is retired");
483
+ const [x, y] = grow ?? [point === "TOPRIGHT" || point === "RIGHT" || point === "BOTTOMRIGHT" ? "Left" : "Right", "Down"];
484
+ const primary = direction?.[x];
485
+ const secondary = direction?.[y];
486
+ if (hasGroups && (primary === undefined || secondary === undefined)) return fail("Native aura growth is unavailable");
487
+ return protect(() => {
488
+ if (hasGroups && primary !== undefined && secondary !== undefined) {
489
+ container.SetFlowLayoutAnchorPoint(point);
490
+ container.SetFlowLayoutGrowthDirection(primary, secondary);
491
+ }
492
+ container.ClearAllPoints();
493
+ container.SetPoint(point, parent, point);
494
+ });
495
+ }
496
+
400
497
  const idle = disable();
401
498
  if (!idle.ok) {
402
499
  retire();
@@ -407,20 +504,24 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
407
504
  if (hasGroups && add === undefined) return undefined;
408
505
  container.SetUnit(initialUnit);
409
506
  if (initialUnit !== noUnit) boundUnit = initialUnit;
410
- if (hasGroups && horizontal !== undefined && vertical !== undefined) {
507
+ if (hasGroups) {
508
+ // The native aura container needs a rectangle before its first layout pass.
509
+ container.SetSize(1, 1);
411
510
  container.SetFlattensRenderLayers?.(true);
412
511
  if (axis?.Horizontal !== undefined) container.SetFlowLayoutAxis?.(axis.Horizontal);
413
- container.SetFlowLayoutAnchorPoint(anchor);
414
- container.SetFlowLayoutGrowthDirection(horizontal, vertical);
415
512
  if (lineWidth !== undefined) container.SetFlowLayoutMaximumLineSize?.(lineWidth);
416
513
  }
417
- container.SetPoint(anchor, parent, anchor);
418
514
  return { add };
419
515
  });
420
516
  if (!configured.ok || configured.value === undefined) {
421
517
  retire();
422
518
  return configured.ok ? fail("Native aura groups are unavailable") : configured;
423
519
  }
520
+ const placed = setPlacement(anchor, options.grow);
521
+ if (!placed.ok) {
522
+ retire();
523
+ return placed;
524
+ }
424
525
  const add = configured.value.add;
425
526
 
426
527
  function registerGroup(group: AuraContainerGroup): Result<void> {
@@ -428,6 +529,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
428
529
  const { candidateFilters, filter, initializeFrame, key, maxFrameCount, sort, sortDirection, templates } = group;
429
530
  // Keep the attempted key for retirement even if the native registration fails.
430
531
  registeredGroups.set(key, { key, filter, candidateFilters });
532
+ groupLimits.set(key, maxFrameCount);
431
533
  const added = protect(() => add.call(container, key, filter, {
432
534
  maxFrameCount,
433
535
  candidateFilters,
@@ -445,15 +547,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
445
547
  const result = protect(() => initializeFrame(button));
446
548
  if (!result.ok) initializationFailure = result;
447
549
  },
448
- layout: {
449
- elementWidth: cellWidth,
450
- elementHeight: cellHeight,
451
- elementSpacing: gap,
452
- elementSpacingX: gap,
453
- elementSpacingY: rowGap,
454
- lineSpacing,
455
- layoutIndex: registeredGroups.size,
456
- },
550
+ layout: nativeGroupLayout(registeredGroups.size, gap, rowGap, lineSpacing),
457
551
  }));
458
552
  return added.ok ? initializationFailure ?? added : added;
459
553
  }
@@ -518,7 +612,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
518
612
  return registerSlot(slot, false);
519
613
  }
520
614
 
521
- const auraContainer: AuraContainer = { frame: container, addSlot, activate, rebind, disable, retire };
615
+ const auraContainer: AuraContainer = { frame: container, addSlot, activate, rebind, setGroupEnabled, setFlowLayout, setPlacement, disable, retire };
522
616
  if (defer === undefined) {
523
617
  for (const group of groups) {
524
618
  const added = registerGroup(group);
@@ -9,7 +9,7 @@ import { rawField } from "./lua-table";
9
9
  import { api, reveal } from "./native";
10
10
  import { protect } from "./protect";
11
11
 
12
- type CountdownStyle = "compact" | "minutes" | "seconds";
12
+ type CountdownStyle = "abbreviated" | "compact" | "minutes" | "seconds";
13
13
  type Countdown = Partial<Pick<Cooldown, "SetCountdownFormatter">>;
14
14
  // The client inherits the breakpoint rounding when its component omits the override.
15
15
  type Rule = Omit<Data_NumericRuleFormatBreakpoint, "components"> & {
@@ -20,11 +20,21 @@ type Formatter = NumericFormatterAPI & { SetBreakpoints(this: object, rules: Rul
20
20
  declare function tonumber(this: void, value: unknown): number | undefined;
21
21
 
22
22
  const formatters: Record<CountdownStyle, Partial<Record<number, NumericFormatterAPI>>> = {
23
+ abbreviated: {},
23
24
  compact: {},
24
25
  minutes: {},
25
26
  seconds: {},
26
27
  };
27
28
 
29
+ function abbreviatedRules(rounding: Rule["rounding"]): Rule[] {
30
+ return [
31
+ { threshold: 0, format: "%d", rounding, step: 1 },
32
+ { threshold: 60, format: "%dM", rounding, step: 60, components: [{ div: 60 }] },
33
+ { threshold: 3600, format: "%dH", rounding, step: 3600, components: [{ div: 3600 }] },
34
+ { threshold: 86400, format: "%dD", rounding, step: 86400, components: [{ div: 86400 }] },
35
+ ];
36
+ }
37
+
28
38
  function createRuleFormatter(rules: Rule[]): NumericFormatterAPI | undefined {
29
39
  const create = rawField<(this: void) => Formatter | undefined>(api.C_StringUtil, "CreateNumericRuleFormatter");
30
40
  if (typeof create !== "function") return undefined;
@@ -40,14 +50,20 @@ function createRuleFormatter(rules: Rule[]): NumericFormatterAPI | undefined {
40
50
 
41
51
  function countdownFormatter(decimals?: number, style?: string): NumericFormatterAPI | undefined {
42
52
  const value = tonumber(reveal(decimals)) ?? 0;
43
- const precision = Number.isNaN(value) ? 0 : Math.max(0, Math.min(2, Math.floor(value)));
44
53
  const mode = reveal(style);
45
- const format: CountdownStyle = mode === "minutes" || mode === "seconds" ? mode : "compact";
54
+ const format: CountdownStyle = mode === "abbreviated" || mode === "minutes" || mode === "seconds" ? mode : "compact";
55
+ const precision = format === "abbreviated" || Number.isNaN(value) ? 0 : Math.max(0, Math.min(2, Math.floor(value)));
46
56
  const byPrecision = formatters[format];
47
57
  const cached = byPrecision[precision];
48
58
  if (cached !== undefined) return cached;
49
59
 
50
60
  const rounding = api.Enum?.NumericRuleFormatRounding;
61
+ if (format === "abbreviated") {
62
+ if (rounding?.Down === undefined) return undefined;
63
+ const formatter = createRuleFormatter(abbreviatedRules(rounding.Down));
64
+ if (formatter !== undefined) byPrecision[precision] = formatter;
65
+ return formatter;
66
+ }
51
67
  if (rounding?.Up === undefined || rounding.Nearest === undefined) return undefined;
52
68
 
53
69
  const rules: Rule[] = [{
@@ -0,0 +1,32 @@
1
+ import type { Anchor } from "../src/elements";
2
+ import { fail, ok, type Result } from "../src/result";
3
+ import type { AuraContainer } from "./aura-container";
4
+ import { createFrame, type Frame, type FrameParent } from "./frames";
5
+ import { api, reveal } from "./native";
6
+ import { protect } from "./protect";
7
+
8
+ /** The template opts into Blizzard's untrusted-layout aspect at construction. */
9
+ export function createAuraFollowerFrame(this: void, parent: FrameParent): Frame {
10
+ const created = protect(() => createFrame("Frame", undefined, parent, "DisableUntrustedLayoutScriptsTemplate"));
11
+ return created.ok ? created.value : createFrame("Frame", undefined, parent);
12
+ }
13
+
14
+ /** Follow the native bottom edge, or use the authored parent-relative anchor on older clients. */
15
+ export function anchorAuraFollower(this: void, frame: Frame, container: AuraContainer | undefined, gap: number, fallback: Anchor): Result<"native" | "fallback"> {
16
+ if (reveal(api.InCombatLockdown()) !== false) return fail("Aura follower placement requires an unlocked client");
17
+ if (!Number.isFinite(gap) || gap < 0) return fail("Invalid aura follower gap");
18
+ if (container !== undefined) {
19
+ const followed = protect(() => {
20
+ frame.ClearAllPoints();
21
+ frame.SetPoint("TOPLEFT", container.frame, "BOTTOMLEFT", 0, -gap);
22
+ });
23
+ if (followed.ok) return ok("native");
24
+ }
25
+ return protect(() => {
26
+ const parent = reveal(frame.GetParent()) as FrameParent | undefined;
27
+ if (parent === undefined || parent === null) throw new Error("Aura follower has no readable parent");
28
+ frame.ClearAllPoints();
29
+ frame.SetPoint(fallback.point, parent, fallback.point, fallback.x ?? 0, fallback.y ?? 0);
30
+ return "fallback" as const;
31
+ });
32
+ }
@@ -0,0 +1,49 @@
1
+ import type { ElementRef, UIElement } from "../src/elements";
2
+ import type { OwnedRecord } from "../src/owned-collections";
3
+ import { fail } from "../src/result";
4
+ import { appContext } from "./app-ui";
5
+ import { configureAuraMouse } from "./aura-button";
6
+ import type { AuraButton } from "./aura-container";
7
+ import { bindAuraDurationText, bindAuraStackText } from "./aura-countdown";
8
+ import type { FontString, Texture } from "./frames";
9
+ import { protect } from "./protect";
10
+ import { mountNative, type NativeViewOptions } from "./view";
11
+
12
+ export interface AuraButtonRegions {
13
+ readonly icon: ElementRef<"image">;
14
+ readonly count: ElementRef<"text">;
15
+ readonly duration: ElementRef<"text">;
16
+ }
17
+
18
+ /** Mount static JSX regions before Blizzard binds and restricts the button. */
19
+ export function mountAuraButton(this: void, button: AuraButton, size: number,
20
+ render: (this: void, regions: AuraButtonRegions) => UIElement) {
21
+ const context = appContext();
22
+ if (context === undefined) return fail("Aura buttons require a running addon");
23
+ if (!Number.isFinite(size) || size <= 0) return fail("Invalid aura button size");
24
+ const sized = protect(() => button.SetSize(size, size));
25
+ if (!sized.ok) return sized;
26
+ let icon: Texture | undefined;
27
+ let count: FontString | undefined;
28
+ let duration: FontString | undefined;
29
+ const mounted = mountNative(button, context.runtime, () => render({
30
+ icon: region => { icon = region; },
31
+ count: region => { count = region; },
32
+ duration: region => { duration = region; },
33
+ }), { ...context.theme as OwnedRecord<NativeViewOptions>, regionsOnly: "native-owned" });
34
+ if (!mounted.ok) return mounted;
35
+ const image = icon, stack = count, clock = duration;
36
+ // Stop JSX bindings while the regions are still readable. Native updates own them from here.
37
+ const stopped = mounted.value.dispose();
38
+ if (!stopped.ok) return stopped;
39
+ if (image === undefined || stack === undefined || clock === undefined || button.SetIcon === undefined) {
40
+ return fail("Aura button display regions are unavailable");
41
+ }
42
+ const setIcon = button.SetIcon;
43
+ const iconBound = protect(() => setIcon.call(button, image));
44
+ if (!iconBound.ok) return iconBound;
45
+ const stackBound = bindAuraStackText(button, stack);
46
+ if (!stackBound.ok) return stackBound;
47
+ const clockBound = bindAuraDurationText(button, clock);
48
+ return clockBound.ok ? configureAuraMouse(button, "shown") : clockBound;
49
+ }
@@ -0,0 +1,75 @@
1
+ import { fail, ok, type Result } from "../src/result";
2
+ import { sameBackgroundImage, type StatePaint } from "../src/style-states";
3
+ import { resolveStyleValue, type StyleEnvironment } from "../src/style-variables";
4
+ import type { RGBA } from "../utils/colors";
5
+ import { readCssColor } from "./css-color";
6
+ import type { Texture } from "./frames";
7
+ import { api, reveal } from "./native";
8
+
9
+ type BackgroundImage = StatePaint["backgroundImage"];
10
+
11
+ export function cssTexturePath(path: string): string {
12
+ const local = path.startsWith("./") ? path.slice(2) : path;
13
+ return local.split("/").join("\\");
14
+ }
15
+
16
+ function gradientStop(input: string, environment: StyleEnvironment | undefined): Result<RGBA> {
17
+ const resolved = resolveStyleValue(input, environment);
18
+ if (!resolved.ok) return resolved;
19
+ const literal = reveal(resolved.value);
20
+ const color = literal === "transparent" ? [0, 0, 0, 0] as RGBA
21
+ : literal === "black" ? [0, 0, 0, 1] as RGBA
22
+ : literal === "white" ? [1, 1, 1, 1] as RGBA
23
+ : literal === undefined ? undefined : readCssColor(literal);
24
+ return color === undefined ? fail(`Invalid CSS gradient color ${input}`) : ok(color);
25
+ }
26
+
27
+ function sameColor(previous: RGBA | undefined, next: RGBA) {
28
+ return previous !== undefined && previous[0] === next[0] && previous[1] === next[1]
29
+ && previous[2] === next[2] && previous[3] === next[3];
30
+ }
31
+
32
+ export function createBackgroundPainter(texture: Texture, show: (this: void, visible: boolean) => void, environment?: StyleEnvironment) {
33
+ let previous: BackgroundImage;
34
+ let minColor: RGBA | undefined;
35
+ let maxColor: RGBA | undefined;
36
+
37
+ return function paint(this: void, image?: BackgroundImage): Result<void> {
38
+ if (image !== undefined && "gradient" in image) {
39
+ const { axis, min, max } = image.gradient;
40
+ const low = gradientStop(min, environment);
41
+ if (!low.ok) return low;
42
+ const high = gradientStop(max, environment);
43
+ if (!high.ok) return high;
44
+ const a = low.value, b = high.value;
45
+ if (sameBackgroundImage(previous, image) && sameColor(minColor, a) && sameColor(maxColor, b)) return ok(undefined);
46
+
47
+ const createColor = api.CreateColor;
48
+ if (typeof createColor !== "function" || typeof texture.SetGradient !== "function") {
49
+ return fail("CSS linear gradients require native texture gradients");
50
+ }
51
+ if (previous !== undefined && "atlas" in previous) texture.SetTexCoord(0, 1, 0, 1);
52
+ texture.SetColorTexture(1, 1, 1, 1);
53
+ // A fully transparent CSS stop takes the hue of its neighbor.
54
+ const start = a[3] === 0 ? createColor(b[0], b[1], b[2], 0) : createColor(...a);
55
+ const end = b[3] === 0 ? createColor(a[0], a[1], a[2], 0) : createColor(...b);
56
+ texture.SetGradient(axis, start, end);
57
+ minColor = a;
58
+ maxColor = b;
59
+ show(true);
60
+ } else {
61
+ if (sameBackgroundImage(previous, image)) return ok(undefined);
62
+ if (previous !== undefined && "gradient" in previous) texture.SetVertexColor(1, 1, 1, 1);
63
+ if (image === undefined) show(false);
64
+ else if ("path" in image) {
65
+ if (previous !== undefined && "atlas" in previous) texture.SetTexCoord(0, 1, 0, 1);
66
+ show(texture.SetTexture(cssTexturePath(image.path)) !== false);
67
+ } else {
68
+ texture.SetAtlas(image.atlas, false);
69
+ show(true);
70
+ }
71
+ }
72
+ previous = image;
73
+ return ok(undefined);
74
+ };
75
+ }
package/wow/css-box.ts CHANGED
@@ -19,8 +19,8 @@ type Inset = readonly [top: number, right: number, bottom: number, left: number]
19
19
  type Content = { readonly frame: Frame; readonly layout?: NativeLayoutGroup };
20
20
 
21
21
  export function hasCssSurface(this: void, style: NativeStyle, paint?: NativePaintState): boolean {
22
- return style.border !== undefined || style.backgroundImage !== undefined || (style.borderRadius !== undefined
23
- && (style.backgroundColor !== undefined || paint?.usesBackgroundColor === true || paint?.usesBackgroundImage === true));
22
+ return style.border !== undefined || style.backgroundImage !== undefined || paint?.usesBackgroundImage === true
23
+ || (style.borderRadius !== undefined && (style.backgroundColor !== undefined || paint?.usesBackgroundColor === true));
24
24
  }
25
25
 
26
26
  export function mountCssSurface(this: void, scope: RuntimeScope, frame: Frame, style: NativeStyle, paint: NativePaintState | undefined,
@@ -32,7 +32,8 @@ export function mountCssSurface(this: void, scope: RuntimeScope, frame: Frame, s
32
32
  const fixedBorderRadius = rounded?.borderOutline !== undefined && style.border !== undefined ? fixedRadius : undefined;
33
33
  const created = createCssSurface(scope, frame, {
34
34
  rounded, environment, nativeRoundedArt, color: style.backgroundColor !== undefined || paint?.usesBackgroundColor === true,
35
- image, fixedFillRadius, fixedBorderRadius,
35
+ image, maskImage: style.maskImage, fixedFillRadius, fixedBorderRadius,
36
+ liveOutline: live !== undefined && style.border !== undefined && style.borderRadius !== undefined,
36
37
  borderState: style.border !== undefined && paint?.usesBorderColor === true,
37
38
  fixedBorder: live === undefined ? style.border : undefined,
38
39
  borderPaint: style.borderPaint,
@@ -81,11 +82,12 @@ function padding(style: NativeStyle | undefined, live?: ReadCssStyle, decorative
81
82
  return ok([top + bt, (right ?? top) + br, (bottom ?? top) + bb, (left ?? right ?? top) + bl]);
82
83
  }
83
84
 
84
- export function includeCssBorderPadding(this: void, scope: RuntimeScope, props: FrameProps, live?: ReadCssStyle, decorativeBorder = false): FrameProps {
85
+ export function includeCssBorderPadding<Props extends Pick<FrameProps, "style">>(this: void, scope: RuntimeScope, props: Props,
86
+ live?: ReadCssStyle, decorativeBorder = false): Props {
85
87
  const style = props.style;
86
88
  if (decorativeBorder || style?.border === undefined) return props;
87
89
  const adjusted = scope.computedResult(() => padding(style, live), "CSS border padding");
88
- return { ...props as OwnedRecord<FrameProps>, style: { ...style as OwnedRecord<NativeStyle>, padding: adjusted } };
90
+ return { ...props as OwnedRecord<Props>, style: { ...style as OwnedRecord<NativeStyle>, padding: adjusted } };
89
91
  }
90
92
 
91
93
  function insetContent(scope: RuntimeScope, frame: Frame, style: NativeStyle, live?: ReadCssStyle, decorativeBorder = false): Result<Frame> {
@@ -115,7 +117,7 @@ export function mountCssContent(this: void, scope: RuntimeScope, frame: Frame, s
115
117
  if (!content.ok) return content;
116
118
  if (overflow !== "scroll") return ok({ frame: content.value, layout });
117
119
 
118
- const scroll = mountScrollView(content.value, scope, { contentHeight: 1 }, createScroll);
120
+ const scroll = mountScrollView(content.value, scope, { contentHeight: 1 }, createScroll, true);
119
121
  if (scroll.failure !== undefined) return scroll.failure;
120
122
  scroll.frame.SetAllPoints(content.value);
121
123
  const display = style.display === "grid" ? "grid" : "flex";
@@ -135,9 +137,12 @@ export function mountCssContent(this: void, scope: RuntimeScope, frame: Frame, s
135
137
  scroll.frame.SetContentHeight(Math.max(1, next));
136
138
  }, scope);
137
139
  if (!resize.ok) return resize;
138
- // A host can wrap the viewport in a wider frame that owns padding and the scrollbar.
139
- const viewport = (reveal(scroll.content.GetParent()) as FrameParent | undefined) ?? scroll.frame;
140
- const root = mountLayoutRoot(scroll.content, viewport, { style: contentStyle, fullWidth: true }, scope, undefined, stageInitial);
140
+ // The default viewport fills the CSS box. Read that box directly, including when the
141
+ // native ScrollFrame has yet to resolve its anchors during staged mounting.
142
+ // A custom host may reserve part of the CSS box for its scrollbar.
143
+ const widthOwner = createScroll === undefined ? content.value
144
+ : (reveal(scroll.content.GetParent()) as FrameParent | undefined) ?? scroll.frame;
145
+ const root = mountLayoutRoot(scroll.content, widthOwner, { style: contentStyle, fullWidth: true }, scope, undefined, stageInitial);
141
146
  if (!root.ok) return root;
142
147
  scroll.notifyVisible();
143
148
  return ok({ frame: scroll.content, layout: root.value.group });
@@ -0,0 +1,32 @@
1
+ import type { CssV1Style } from "../src/css-v1";
2
+ import { fail, ok, type Result } from "../src/result";
3
+ import type { RuntimeScope } from "../src/runtime";
4
+ import { cssTexturePath } from "./css-background-image";
5
+ import type { Frame, MaskTexture, Texture } from "./frames";
6
+
7
+ export function mountImageMask(scope: RuntimeScope, parent: Frame, texture: Texture, source: NonNullable<CssV1Style["maskImage"]>): Result<void> {
8
+ if (typeof parent.CreateMaskTexture !== "function" || typeof texture.AddMaskTexture !== "function"
9
+ || typeof texture.RemoveMaskTexture !== "function") return fail("CSS mask-image requires native texture masks");
10
+
11
+ let mask: MaskTexture | undefined;
12
+ let attached = false;
13
+ const cleanup = scope.onDispose(() => {
14
+ if (mask === undefined) return;
15
+ if (attached) texture.RemoveMaskTexture(mask);
16
+ mask.Hide();
17
+ });
18
+ if (!cleanup.ok) return cleanup;
19
+ const applied = scope.protect(() => {
20
+ const target = parent.CreateMaskTexture();
21
+ mask = target;
22
+ const path = cssTexturePath(source.path);
23
+ if (target.SetTexture(path, "CLAMPTOBLACKADDITIVE", "CLAMPTOBLACKADDITIVE") === false) {
24
+ return fail(`Could not load CSS mask image ${source.path}`);
25
+ }
26
+ target.SetAllPoints(texture);
27
+ texture.AddMaskTexture(target);
28
+ attached = true;
29
+ return ok(undefined);
30
+ });
31
+ return applied.ok ? applied.value : applied;
32
+ }