@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
package/wow/view.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { Anchor, Binding, Element, Job, NativeStyle, ReadonlyRef, Runtime, RuntimeScope, StatusBarValue, StyleClass, TransitionOptions, UIElement } from "../src";
1
+ import type { Anchor, Binding, CooldownValue, Element, Job, NativeStyle, ReadonlyRef, Runtime, RuntimeScope, StatusBarValue, StyleClass, TransitionOptions, UIElement } from "../src";
2
2
  import { bindValue } from "../src/bindings";
3
3
  import type { CssTokenRecipe } from "../src/css-v1";
4
4
  import { bindImageSize, imageSize, positiveImageDimension } from "../src/images";
5
5
  import { attachMediaReads, markMediaReads, type MediaRead } from "../src/media-query";
6
- import { ownedMap, ownedSet, type OwnedArray, type OwnedReadonlyArray, type OwnedRecord, type OwnedSet } from "../src/owned-collections";
6
+ import { ownedArray, ownedMap, ownedSet, type OwnedArray, type OwnedReadonlyArray, type OwnedRecord, type OwnedSet } from "../src/owned-collections";
7
7
  import { ref } from "../src/reactivity";
8
8
  import { withReactiveScope } from "../src/reactive-scope";
9
9
  import { fail, ok, type Failure, type Result } from "../src/result";
@@ -16,30 +16,34 @@ import { bindAbsolutePosition, type NativeEndTarget, type NativeStartTarget, typ
16
16
  import { bindBorrowedSlot, type BorrowedSlot } from "./borrowed-slot";
17
17
  import { prepareCssStyle, type ReadCssStyle } from "./css-style";
18
18
  import { readCssColor } from "./css-color";
19
+ import { mountImageMask } from "./css-image-mask";
19
20
  import { bindEditTextAlign, bindTextColor, bindTextTypography, createTextContent, inheritTextStyle, type NativeTextHost, type NativeTextStyle } from "./css-text";
20
21
  import { hasCssSurface, includeCssBorderPadding, mountCssContent, mountCssSurface } from "./css-box";
21
22
  import type { CssSurfaceOptions } from "./css-surfaces";
22
23
  import { prepareDropdownArt } from "./dropdown-art";
23
24
  import { frameStrata, maximumFrameLevel, type FrameStrata } from "./frame-layer";
25
+ import { addonManifest } from "./addon-manifest";
24
26
  import { mountImageLayers } from "./image-layers";
25
27
  import { mountScrollView, type CreateScrollArea, type ScrollArea } from "./scroll-view";
26
28
  import { bindButtonDrag } from "./button-drag";
29
+ import { bindActionVisibility, bindButtonMove, bindSecureAction, bindSecureMacro, listenForDrop, unlockedActionSlot } from "./action-button";
27
30
  import { bindElementEvents, hasElementInput, type NativeElementEventHost } from "./element-events";
28
31
  import { api, isSecret, reveal } from "./native";
29
- import { hookSecureMethod } from "./native-hooks";
32
+ import { hookScript, hookSecureMethod } from "./native-hooks";
30
33
  import { rawField } from "./lua-table";
31
34
  import { observeContainer, type NativeMediaOptions } from "./media-query";
32
35
  import { mountRangeArt } from "./range-art";
33
36
  import { protect } from "./protect";
34
37
  import { animateVisibility } from "./transition";
35
- import { attachLayoutItem, mountLayoutRoot, NativeLayoutItem, readLayoutValue, type NativeLayoutDiagnostics, type NativeLayoutGroup, type StageInitialLayout } from "./layout-view";
38
+ import { attachLayoutItem, isAbsoluteFill, mountLayoutRoot, NativeLayoutItem, readLayoutValue, type NativeLayoutDiagnostics, type NativeLayoutGroup, type StageInitialLayout } from "./layout-view";
36
39
  import { finishViewNode, mountLogicalGroup, mountViewNode, orderLogicalRows, type LogicalGroup, type LogicalNode } from "./view-nodes";
37
40
  import { bindStatePaint, createNativePaintState, type ButtonPaintTiming, type NativeButtonPaintMotion, type NativePaintState,
38
41
  type NativeStateColor, type TextColorStateChange } from "./state-paint";
39
- import type { FlexNode } from "../src/flex-layout";
42
+ import { isIntrinsicWidth, type FlexNode } from "../src/flex-layout";
40
43
 
41
44
  type Frame = FrameMap["Frame"];
42
45
  declare const GameFontNormal: Parameters<FrameMap["EditBox"]["SetFontObject"]>[0];
46
+ declare function rawequal(this: void, left: unknown, right: unknown): boolean;
43
47
  type Region = Pick<FontString, "ClearAllPoints" | "SetWidth" | "SetHeight" | "SetSize" | "SetPoint" | "SetShown" | "IsShown"
44
48
  | "SetAlpha" | "GetSize" | "IsForbidden" | "GetObjectType">;
45
49
  type LayoutParent = NativeLayoutGroup | NativeLayoutItem;
@@ -114,6 +118,8 @@ export interface NativeListboxSkin extends NativeControlSkinStyle {
114
118
 
115
119
  export interface NativeViewOptions extends NativeTextHost {
116
120
  bindings?: "manual";
121
+ /** @internal Keep combat-updating views within their owned, unprotected subtree. */
122
+ unprotectedOnly?: true;
117
123
  /** Capture the manual bindings of matching text regions for a targeted flush. Full view flushes still include them. */
118
124
  manualTextBindings?: {
119
125
  readonly part: string;
@@ -232,7 +238,7 @@ function bindViewMedia(node: UIElement, scope: RuntimeScope, options: MountOptio
232
238
  return result;
233
239
  }
234
240
 
235
- function bind<T extends string | boolean | number | Anchor>(scope: RuntimeScope, value: Binding<T>,
241
+ function bind<T extends string | boolean | number | Anchor | undefined>(scope: RuntimeScope, value: Binding<T>,
236
242
  apply: (this: void, value: T) => void, validate?: (this: void, value: T) => Failure | undefined) {
237
243
  return bindValue(scope, value, apply, (previous, current) => !isSecret(previous) && !isSecret(current) && previous === current, validate);
238
244
  }
@@ -295,6 +301,49 @@ function placeFrame(frame: Region & Pick<Frame, "SetFrameLevel">, parent: FrameP
295
301
  return place(frame, parent, props, scope, motion, flex, undefined, undefined, paint, undefined, startAfter, endBefore);
296
302
  }
297
303
 
304
+ function boundSize(scope: RuntimeScope, size: NativeStyle["width"], min: NativeStyle["minWidth"], max: NativeStyle["maxWidth"]): NativeStyle["width"] {
305
+ if (size === undefined || min === undefined && max === undefined) return size;
306
+ return scope.computedResult(() => {
307
+ const requested = readLayoutValue(size);
308
+ if (!requested.ok || typeof requested.value !== "number") return requested.ok ? ok(requested.value ?? "auto") : requested;
309
+ const minimum = readLayoutValue(min);
310
+ if (!minimum.ok) return minimum;
311
+ const maximum = readLayoutValue(max);
312
+ if (!maximum.ok) return maximum;
313
+ return ok(Math.max(minimum.value ?? 0, Math.min(maximum.value ?? Infinity, requested.value)));
314
+ }, "CSS size limits");
315
+ }
316
+
317
+ function bindNativeSize(region: Region, scope: RuntimeScope, width: NativeStyle["width"], height: NativeStyle["width"],
318
+ combine: boolean, afterWidth?: (this: void, width: number) => void): Failure | undefined {
319
+ if (combine && afterWidth === undefined && typeof region.SetSize === "function") {
320
+ if (typeof width === "number" && typeof height === "number" && !isSecret(width) && !isSecret(height)
321
+ && Number.isFinite(width) && Number.isFinite(height) && width >= 0 && height >= 0) {
322
+ region.SetSize(width, height);
323
+ return;
324
+ }
325
+ if (typeof width === "object" && !isSecret(width) && !isSecret(height) && rawequal(width, height)) {
326
+ return bind(scope, width, value => {
327
+ if (typeof value !== "number") return;
328
+ if (!isSecret(value) && Number.isFinite(value) && value >= 0) region.SetSize(value, value);
329
+ else {
330
+ region.SetWidth(value);
331
+ region.SetHeight(value);
332
+ }
333
+ });
334
+ }
335
+ }
336
+ // A percent size needs a flow to resolve against; out of flow it is an auto size.
337
+ return (width === undefined ? undefined : bind(scope, width, value => {
338
+ if (typeof value !== "number") return;
339
+ region.SetWidth(value);
340
+ const plain = reveal(value);
341
+ if (plain !== undefined) afterWidth?.(plain);
342
+ })) ?? (height === undefined ? undefined : bind(scope, height, value => {
343
+ if (typeof value === "number") region.SetHeight(value);
344
+ }));
345
+ }
346
+
298
347
  function place(region: Region, parent: FrameParent, props: Layout, scope: RuntimeScope, motion?: TransitionOptions,
299
348
  flex?: LayoutParent, measure?: FlexNode["measure"], minContentWidth?: FlexNode["minContentWidth"], paint?: NativePaintState,
300
349
  afterWidth?: (this: void, width: number) => void, startAfter?: NativeStartTarget, endBefore?: NativeEndTarget) {
@@ -310,8 +359,8 @@ function place(region: Region, parent: FrameParent, props: Layout, scope: Runtim
310
359
  let x = 0, y = 0, motionOffset = 0;
311
360
  let opacity = 1, motionAlpha = 1;
312
361
  let stateOpacity: number | undefined, lastAlpha: number | undefined;
313
- const width = props.width ?? props.style?.width;
314
- const height = props.height ?? props.style?.height;
362
+ const width = boundSize(scope, props.width ?? props.style?.width, props.style?.minWidth, props.style?.maxWidth);
363
+ const height = boundSize(scope, props.height ?? props.style?.height, props.style?.minHeight, props.style?.maxHeight);
315
364
  const absoluteOffset = absolute && motion !== undefined ? ref(0) : undefined;
316
365
  const baseOpacity = props.opacity ?? props.style?.opacity;
317
366
  const drawAlpha = paint?.usesOpacity === true ? (force = false) => {
@@ -342,17 +391,7 @@ function place(region: Region, parent: FrameParent, props: Layout, scope: Runtim
342
391
  anchor(point, x, y + motionOffset);
343
392
  });
344
393
  const layoutFailure = anchored
345
- // A percent size needs a flow to resolve against; out of flow it is ignored, as an auto size is.
346
- ?? (item === undefined && !props.fullWidth && width !== undefined ? bind(scope, width, value => {
347
- if (typeof value === "number") {
348
- region.SetWidth(value);
349
- const plain = reveal(value);
350
- if (plain !== undefined) afterWidth?.(plain);
351
- }
352
- }) : undefined)
353
- ?? (item === undefined && height !== undefined ? bind(scope, height, value => {
354
- if (typeof value === "number") region.SetHeight(value);
355
- }) : undefined)
394
+ ?? (item === undefined ? bindNativeSize(region, scope, props.fullWidth ? undefined : width, height, !absolute, afterWidth) : undefined)
356
395
  ?? (baseOpacity !== undefined ? bind(scope, baseOpacity, value => {
357
396
  const next = reveal(value);
358
397
  if (next === undefined) return;
@@ -510,7 +549,7 @@ function mountPortal(parent: Frame, node: Element<"portal">, scope: RuntimeScope
510
549
  }
511
550
  }
512
551
 
513
- function bindRegionEvents(parent: Frame, region: Region, props: Element<"text">["props"] | Element<"image">["props"],
552
+ function bindRegionEvents(parent: Frame, region: Region, props: Element<"text" | "image" | "texture">["props"],
514
553
  scope: RuntimeScope, options: MountOptions, logical: LogicalNode, paint?: NativePaintState) {
515
554
  if (!hasElementInput(props) && paint?.needs("hover") !== true && paint?.needs("active") !== true) return;
516
555
  if (options.regionsOnly === true) return fail("Native region mounts do not create input frames");
@@ -651,7 +690,8 @@ function fixedSize<T>(size: T): Exclude<T, `${number}%`> | undefined {
651
690
  }
652
691
 
653
692
  const inlineBlocks: Partial<Record<UIElement["kind"], true>> = {
654
- button: true, checkbox: true, range: true, listbox: true, editbox: true, image: true, statusbar: true,
693
+ button: true, checkbox: true, range: true, listbox: true, editbox: true, image: true, texture: true,
694
+ statusbar: true, cooldown: true,
655
695
  };
656
696
 
657
697
  /**
@@ -718,10 +758,13 @@ function bindSkinCaption(caption: FontString, label: string, style: StyleClass,
718
758
  ?? bindTextColor(caption, scope, appearance?.color, position?.onTextPaint);
719
759
  }
720
760
 
761
+ const protectedCombatView = fail("Combat-updating views require owned, unprotected JSX");
762
+
721
763
  function mountFrame(frame: Frame, parent: FrameParent, node: Element<"frame">, scope: RuntimeScope,
722
764
  options: MountOptions, group: LogicalGroup, motion?: TransitionOptions, environment?: StyleEnvironment, skipStyleLevel = false,
723
765
  flow?: NativeLayoutGroup, typography?: NativeTextStyle, liveStyle?: ReadCssStyle, unanchored = false): Failure | undefined {
724
766
  const { style } = node.props;
767
+ if (options.unprotectedOnly === true && options.scrollArea !== undefined && style?.overflow === "scroll") return protectedCombatView;
725
768
  const display = style?.display;
726
769
  const container = flowContainer(display) && style?.overflow !== "scroll";
727
770
  const decorativeBorder = node.props.nativeRoundedArt === true;
@@ -832,10 +875,13 @@ function mountText(parent: Frame, node: Element<"text">, scope: RuntimeScope, op
832
875
  ?? finishViewNode(scope, logical, node.props.nodeRef);
833
876
  }
834
877
 
835
- function mountImage(parent: Frame, node: Element<"image">, scope: RuntimeScope, options: MountOptions, group: LogicalGroup,
836
- motion?: TransitionOptions, environment?: StyleEnvironment, flow?: NativeLayoutGroup, typography?: NativeTextStyle,
837
- liveStyle?: ReadCssStyle): Failure | undefined {
838
- const { src, width, height, style, verticalGradient, nativePixelSnap, nativeDesaturated } = node.props;
878
+ const noIntrinsicImage: Element<"image">["props"]["src"] = { path: "" };
879
+
880
+ function mountImage(parent: Frame, node: Element<"image"> | Element<"texture">, scope: RuntimeScope, options: MountOptions,
881
+ group: LogicalGroup, motion?: TransitionOptions, environment?: StyleEnvironment, flow?: NativeLayoutGroup,
882
+ typography?: NativeTextStyle, liveStyle?: ReadCssStyle): Failure | undefined {
883
+ const { width, height, style, verticalGradient, nativePixelSnap, nativeDesaturated } = node.props;
884
+ const src = node.kind === "image" ? node.props.src : noIntrinsicImage;
839
885
  const automatic = flow !== undefined && node.props.anchor === undefined;
840
886
  const absolute = node.props.anchor === undefined && style?.position === "absolute"
841
887
  && style.margin === undefined && style.autoMargin === undefined;
@@ -857,8 +903,21 @@ function mountImage(parent: Frame, node: Element<"image">, scope: RuntimeScope,
857
903
  texture.SetSnapToPixelGrid?.(false);
858
904
  texture.SetTexelSnappingBias?.(0);
859
905
  }
860
- texture.SetTexture(src.path);
861
- texture.SetTexCoord(0, src.uMax ?? 1, 0, src.vMax ?? 1);
906
+ if (node.kind === "image") {
907
+ texture.SetTexture(src.path);
908
+ texture.SetTexCoord(0, src.uMax ?? 1, 0, src.vMax ?? 1);
909
+ } else {
910
+ const { src: source, texCoords, onSourceChange } = node.props;
911
+ if (texCoords !== undefined) texture.SetTexCoord(...texCoords);
912
+ let mounted = false;
913
+ const bound = bind(scope, source, value => {
914
+ if (isSecret(value)) return;
915
+ texture.SetTexture(value);
916
+ if (mounted) onSourceChange?.(value);
917
+ });
918
+ if (bound !== undefined) return bound;
919
+ mounted = true;
920
+ }
862
921
  const paint = createNativePaintState(style, environment);
863
922
  // Both native points carry the parent size, including resizes after this image is mounted.
864
923
  const geometry = fillsWidth || fillsHeight
@@ -873,6 +932,10 @@ function mountImage(parent: Frame, node: Element<"image">, scope: RuntimeScope,
873
932
  } : undefined, undefined, paint);
874
933
  if (placed) return placed;
875
934
  const logical = mountViewNode(scope, group, "image", texture, node.props);
935
+ if (style?.maskImage !== undefined) {
936
+ const applied = mountImageMask(scope, parent, texture, style.maskImage);
937
+ if (!applied.ok) return applied;
938
+ }
876
939
  if (nativeDesaturated !== undefined) {
877
940
  const desaturated = bind(scope, nativeDesaturated, value => texture.SetDesaturated(value));
878
941
  if (desaturated !== undefined) return desaturated;
@@ -887,7 +950,7 @@ function mountImage(parent: Frame, node: Element<"image">, scope: RuntimeScope,
887
950
  });
888
951
  if (gradientFailure !== undefined) return gradientFailure;
889
952
  }
890
- options?.image?.(texture, parent, node.props);
953
+ if (node.kind === "image") options?.image?.(texture, parent, node.props);
891
954
  const inherited = node.props.inheritColor === true ? typography : undefined;
892
955
  return bindNativeTint(scope, style, paint, options, (r, g, b, a) => texture.SetVertexColor(r, g, b, a),
893
956
  () => captureImageTint(texture), motion, environment, liveStyle, inherited?.color,
@@ -909,9 +972,307 @@ function hasInteractivePaint(style: NativeStyle | undefined, kind: UIElement["ki
909
972
  return false;
910
973
  }
911
974
 
975
+ function mountButtonContent(button: FrameMap["Button"], node: Element<"button">, scope: RuntimeScope, options: MountOptions,
976
+ group: LogicalGroup, paint: NativePaintState | undefined, motion: TransitionOptions | undefined,
977
+ environment: StyleEnvironment | undefined, typography: NativeTextStyle | undefined, liveStyle: ReadCssStyle | undefined,
978
+ buttonTiming: ButtonPaintTiming | undefined, flow?: NativeLayoutGroup): Failure | undefined {
979
+ const appearance = inheritTextStyle(typography, node.props.style, environment, paint, undefined, liveStyle,
980
+ options.inheritedTextColorDuration, buttonTiming);
981
+ for (const child of node.children as NativeChildren) {
982
+ const failure = mountChild(button, child, scope, options, group, undefined, environment, flow, appearance);
983
+ if (failure) return failure;
984
+ }
985
+ const label = paint?.usesColor === true ? button.GetFontString() : undefined;
986
+ return bindFramePaint(button, node.props.style, paint, scope, options, motion, environment, liveStyle,
987
+ label === undefined ? undefined : { read: () => label.GetTextColor(), write: (r, g, b, a) => label.SetTextColor(r, g, b, a) },
988
+ node.props.nativeRoundedArt, buttonTiming);
989
+ }
990
+
991
+ function mountButton(parent: Frame, node: Element<"button">, scope: RuntimeScope, options: MountOptions, group: LogicalGroup,
992
+ motion: TransitionOptions | undefined, environment: StyleEnvironment | undefined, flow: NativeLayoutGroup | undefined,
993
+ typography: NativeTextStyle | undefined, rootControl: { unanchored?: boolean; attach(this: void, frame: Frame): void } | undefined,
994
+ liveStyle: ReadCssStyle | undefined, manualControl: ManualControlBindings | undefined): Failure | undefined {
995
+ const { value, unstyled, disabled, checked } = node.props;
996
+ const { secureAction, secureMacro, onReceiveDrag } = node.props;
997
+ if (secureAction !== undefined && secureMacro !== undefined) return fail("A button can have only one secure action");
998
+ const secure = secureAction !== undefined || secureMacro !== undefined;
999
+ if (secure && !unlockedActionSlot()) return fail("Secure action buttons must mount outside combat");
1000
+ const plain = unstyled === true || secure;
1001
+ const factory = plain ? undefined : options?.createButton;
1002
+ const created = factory === undefined ? undefined : protect(() => factory(parent, node.props, scope));
1003
+ if (created?.ok === false) return created;
1004
+ const custom = created?.value;
1005
+ const button = custom ?? createFrame("Button", undefined, parent,
1006
+ secure ? "SecureActionButtonTemplate" : plain ? undefined : "UIPanelButtonTemplate");
1007
+ rootControl?.attach(button);
1008
+ const duration = options.inheritedTextColorDuration;
1009
+ const colorMotion = options.buttonPaintMotion?.(button, node.props);
1010
+ const paint = createNativePaintState(node.props.style, environment, duration !== undefined, colorMotion?.repaint);
1011
+ const buttonTiming: ButtonPaintTiming | undefined = colorMotion === undefined ? undefined
1012
+ : { ...colorMotion as OwnedRecord<typeof colorMotion>, change: paint?.colorChange, visible: () => reveal(button.IsVisible()) === true };
1013
+ const startAfter = options.buttonStartAfter?.(parent, node.props);
1014
+ const deferred = secure && node.props.deferContentUntilShown === true && node.props.anchor !== undefined
1015
+ && options.bindings !== "manual" && motion === undefined && node.props.style?.display !== "none" ? node.props.shown : undefined;
1016
+ const unanchored = rootControl?.unanchored === true;
1017
+ const width = !secure && node.props.width === undefined ? readLayoutValue(node.props.style?.width) : undefined;
1018
+ if (width?.ok === false) return width;
1019
+ const intrinsic = isIntrinsicWidth(width?.value);
1020
+ const display = node.props.style?.display;
1021
+ const contentFlow = !secure && (node.children as NativeChildren).length > 0 && (intrinsic || flowContainer(display));
1022
+ let geometry: Layout = node.props;
1023
+ if (unanchored || deferred !== undefined) geometry = { ...geometry as OwnedRecord<Layout>, unanchored, shown: deferred === undefined ? node.props.shown : undefined };
1024
+ if (contentFlow && !flowContainer(display)) {
1025
+ geometry = { ...geometry as OwnedRecord<Layout>, style: { ...geometry.style as OwnedRecord<NativeStyle>, display: "flex" } };
1026
+ }
1027
+ if (intrinsic || contentFlow) geometry = includeCssBorderPadding(scope, geometry, liveStyle, node.props.nativeRoundedArt);
1028
+ const measure = intrinsic && !contentFlow ? () => {
1029
+ const label = button.GetFontString();
1030
+ return { width: reveal(label?.GetUnboundedStringWidth()) ?? 0, height: reveal(label?.GetStringHeight()) ?? 0 };
1031
+ } : undefined;
1032
+ const layout = !intrinsic && !contentFlow ? undefined
1033
+ : flow !== undefined && geometry.anchor === undefined && geometry.style?.position !== "absolute"
1034
+ ? attachLayoutItem(flow, button, parent, geometry, scope, contentFlow, measure)
1035
+ : mountLayoutRoot(button, parent, geometry, scope, options.layoutDiagnostics, options.stageInitialLayout, measure);
1036
+ if (layout?.ok === false) return layout;
1037
+ const item = layout?.value;
1038
+ const bindFlags = () => (disabled === undefined ? undefined : bind(scope, disabled, next => {
1039
+ if (isSecret(next)) return;
1040
+ button.SetEnabled(!next);
1041
+ paint?.set("disabled", next);
1042
+ })) ?? (paint?.needs("checked") !== true || checked === undefined ? undefined : bind(scope, checked, next => {
1043
+ const selected = reveal(next);
1044
+ if (selected !== undefined) paint.set("checked", selected);
1045
+ }));
1046
+ // In a manual paint batch the authored flags must refresh before opacity and color consume them.
1047
+ const flagsFirst = options.bindings === "manual" || buttonTiming !== undefined;
1048
+ const failure = (flagsFirst ? bindFlags() : undefined)
1049
+ ?? placeFrame(button, parent, geometry, scope, motion, false, item ?? flow, paint,
1050
+ startAfter === undefined ? undefined : { kind: "button", target: startAfter })
1051
+ ?? (plain ? undefined : bind(scope, value, next => {
1052
+ button.SetText(next);
1053
+ if (measure !== undefined) item?.group.enqueue();
1054
+ }))
1055
+ ?? (flagsFirst ? undefined : bindFlags());
1056
+ if (failure) return failure;
1057
+ if (disabled === undefined && paint?.needs("disabled") === true) paint.set("disabled", reveal(button.IsEnabled()) === false);
1058
+ const logical = mountViewNode(scope, group, "button", button, node.props);
1059
+ const action = secureAction !== undefined ? bindSecureAction(button, scope, secureAction, onReceiveDrag)
1060
+ : secureMacro !== undefined ? bindSecureMacro(button, scope, secureMacro) ?? listenForDrop(button, scope, onReceiveDrag)
1061
+ : listenForDrop(button, scope, onReceiveDrag);
1062
+ if (action !== undefined) return action;
1063
+ const move = bindButtonMove(button, scope, node.props);
1064
+ if (move !== undefined) return move;
1065
+ bindButtonDrag(button, scope, node.props);
1066
+ const content = deferred === undefined
1067
+ ? mountButtonContent(button, node, scope, options, logical, paint, motion, environment, typography, liveStyle, buttonTiming,
1068
+ contentFlow ? item?.group : undefined)
1069
+ : bindActionVisibility(button, scope, deferred, owner => mountButtonContent(button, node, owner, options,
1070
+ mountLogicalGroup(owner, logical), paint, motion, environment, typography, liveStyle, buttonTiming));
1071
+ if (content !== undefined) return content;
1072
+ const observedState = options.buttonPaintStateChanged;
1073
+ const stateChanged = observedState === undefined && buttonTiming === undefined ? undefined
1074
+ : (state: Parameters<NativePaintState["set"]>[0], active: boolean) => {
1075
+ const refresh = observedState?.(button, state, active);
1076
+ return buttonTiming !== undefined || refresh === true;
1077
+ };
1078
+ return attachRef(scope, node.props.ref, button)
1079
+ ?? bindElementEvents(button, node.props, scope, options.newEventScope, options.elementEvents, button, custom !== undefined,
1080
+ logical, interactiveControlPaint(paint, manualControl?.flush, stateChanged))
1081
+ ?? finishViewNode(scope, logical, node.props.nodeRef);
1082
+ }
1083
+
1084
+ function usableCooldown(value: CooldownValue | undefined): value is CooldownValue {
1085
+ if (isSecret(value) || typeof value !== "object" || value === null) return false;
1086
+ const start = reveal(value.start);
1087
+ const duration = reveal(value.duration);
1088
+ const rate = reveal(value.rate);
1089
+ return typeof start === "number" && Number.isFinite(start) && start >= 0
1090
+ && typeof duration === "number" && Number.isFinite(duration) && duration > 0
1091
+ && typeof rate === "number" && Number.isFinite(rate) && rate > 0;
1092
+ }
1093
+
1094
+ function sameCooldown(previous: CooldownValue | undefined, next: CooldownValue | undefined): boolean {
1095
+ if (!usableCooldown(previous)) return !usableCooldown(next);
1096
+ return usableCooldown(next) && previous.start === next.start && previous.duration === next.duration && previous.rate === next.rate;
1097
+ }
1098
+
1099
+ function mountCooldown(parent: Frame, node: Element<"cooldown">, scope: RuntimeScope, motion?: TransitionOptions,
1100
+ environment?: StyleEnvironment, flow?: NativeLayoutGroup): Failure | undefined {
1101
+ const cooldown = createFrame("Cooldown", undefined, parent, "CooldownFrameTemplate");
1102
+ scope.onDispose(() => cooldown.Hide());
1103
+ cooldown.EnableMouse(false);
1104
+ if (node.props.reverse !== undefined) cooldown.SetReverse(node.props.reverse);
1105
+ if (node.props.swipeTexture !== undefined) {
1106
+ cooldown.SetSwipeTexture(node.props.swipeTexture, 1, 1, 1, 1);
1107
+ cooldown.SetDrawEdge(false);
1108
+ cooldown.SetDrawBling(false);
1109
+ cooldown.SetHideCountdownNumbers(true);
1110
+ const color = node.props.style?.color;
1111
+ const tinted = color === undefined ? undefined : bindColor(scope, color, environment, literal => {
1112
+ const rgba = readCssColor(literal);
1113
+ if (rgba !== undefined) cooldown.SetSwipeColor(...rgba);
1114
+ });
1115
+ if (tinted !== undefined) return tinted;
1116
+ }
1117
+ const placed = placeFrame(cooldown, parent, node.props, scope, motion, false, flow);
1118
+ if (placed !== undefined) return placed;
1119
+ return bindValue(scope, node.props.value, timing => {
1120
+ if (usableCooldown(timing)) cooldown.SetCooldown(timing.start, timing.duration, timing.rate);
1121
+ else cooldown.Clear();
1122
+ }, sameCooldown);
1123
+ }
1124
+
1125
+ function mountEditBox(parent: Frame, node: Element<"editbox">, scope: RuntimeScope, options: MountOptions, group: LogicalGroup,
1126
+ inputSkin: NativeViewOptions["inputSkin"], styledInput: NativeViewOptions["inputSkin"], skinnedHint: boolean,
1127
+ motion?: TransitionOptions, environment?: StyleEnvironment, flow?: NativeLayoutGroup, liveStyle?: ReadCssStyle,
1128
+ rootControl?: { unanchored?: boolean; attach(this: void, frame: Frame): void }, manualControl?: ManualControlBindings): Failure | undefined {
1129
+ const { style } = node.props;
1130
+ const { value, type, placeholder, unstyled, maxLetters, disabled, onChange, onFocus, onBlur, onEnter, onEscape, ref } = node.props;
1131
+ const edit = createFrame("EditBox", undefined, parent, unstyled ? undefined : "InputBoxTemplate");
1132
+ rootControl?.attach(edit);
1133
+ if (styledInput !== undefined) {
1134
+ for (const raw of [...edit.GetRegions()]) {
1135
+ const region = reveal(raw) as Texture | undefined;
1136
+ if (region !== undefined && reveal(region.GetObjectType()) === "Texture") region.Hide();
1137
+ }
1138
+ }
1139
+ if (unstyled) edit.SetFontObject(GameFontNormal);
1140
+ const paint = createNativePaintState(node.props.style, environment);
1141
+ const eventPaint = interactiveControlPaint(paint, manualControl?.flush);
1142
+ const geometry = rootControl?.unanchored === true ? { ...node.props as OwnedRecord<typeof node.props>, unanchored: true } : node.props;
1143
+ const placed = placeFrame(edit, parent, geometry, scope, motion, false, flow, paint);
1144
+ if (placed) return placed;
1145
+ edit.SetAutoFocus(false);
1146
+ if (type === "password") edit.SetPassword(true);
1147
+ if (maxLetters !== undefined) edit.SetMaxLetters(maxLetters);
1148
+ const hint = placeholder !== undefined || skinnedHint ? edit.CreateFontString(undefined, "OVERLAY", "GameFontDisableSmall") : undefined;
1149
+ if (hint !== undefined) {
1150
+ if (styledInput?.unstyled !== true || styledInput.caption.position !== "absolute") {
1151
+ hint.SetPoint("LEFT", edit, "LEFT", 5, 0);
1152
+ hint.SetPoint("RIGHT", edit, "RIGHT", -5, 0);
1153
+ hint.SetJustifyH("LEFT");
1154
+ }
1155
+ hint.SetText(placeholder ?? "");
1156
+ }
1157
+ let enabled = true;
1158
+ const bound = bind(scope, value, next => {
1159
+ if (isSecret(next)) return;
1160
+ if (reveal(edit.GetText()) !== next) edit.SetText(next);
1161
+ hint?.SetShown(next === "");
1162
+ }) ?? (disabled === undefined ? undefined : bind(scope, disabled, next => {
1163
+ if (isSecret(next)) return;
1164
+ enabled = !next;
1165
+ edit.SetEnabled(enabled);
1166
+ paint?.set("disabled", next);
1167
+ }));
1168
+ if (bound) return bound;
1169
+ if (onChange !== undefined || hint !== undefined) {
1170
+ edit.SetScript("OnTextChanged", (_, userInput) => {
1171
+ if (!scope.isActive()) return;
1172
+ if (userInput ? !enabled : !skinnedHint) return;
1173
+ const text = reveal(edit.GetText());
1174
+ if (text === undefined) return;
1175
+ hint?.SetShown(text === "");
1176
+ if (userInput) onChange?.(text);
1177
+ });
1178
+ }
1179
+ const focusPaint = paint?.needs("focus") === true;
1180
+ const nativeFocus = styledInput === undefined ? undefined : edit.GetScript("OnEditFocusGained");
1181
+ const nativeBlur = styledInput === undefined ? undefined : edit.GetScript("OnEditFocusLost");
1182
+ if (onFocus || focusPaint) edit.SetScript("OnEditFocusGained", frame => {
1183
+ nativeFocus?.(frame);
1184
+ if (!enabled || !scope.isActive()) return;
1185
+ if (focusPaint) eventPaint?.set("focus", true);
1186
+ onFocus?.();
1187
+ });
1188
+ if (onBlur || focusPaint) edit.SetScript("OnEditFocusLost", frame => {
1189
+ nativeBlur?.(frame);
1190
+ if (!scope.isActive()) return;
1191
+ if (focusPaint) eventPaint?.set("focus", false);
1192
+ onBlur?.();
1193
+ });
1194
+ if (onEnter) edit.SetScript("OnEnterPressed", () => {
1195
+ if (!enabled || !scope.isActive()) return;
1196
+ const text = reveal(edit.GetText());
1197
+ if (text !== undefined) onEnter(text);
1198
+ });
1199
+ if (onEscape) edit.SetScript("OnEscapePressed", () => { if (enabled && scope.isActive()) onEscape(); });
1200
+ scope.onDispose(() => {
1201
+ edit.SetScript("OnTextChanged", undefined);
1202
+ if (onFocus || focusPaint) edit.SetScript("OnEditFocusGained", nativeFocus);
1203
+ edit.SetScript("OnEditFocusLost", nativeBlur);
1204
+ if (onEnter) edit.SetScript("OnEnterPressed", undefined);
1205
+ if (onEscape) edit.SetScript("OnEscapePressed", undefined);
1206
+ edit.ClearFocus();
1207
+ });
1208
+ if (ref) {
1209
+ ref({
1210
+ focus: () => {
1211
+ if (!scope.isActive() || !enabled || reveal(edit.IsVisible()) !== true) return false;
1212
+ edit.SetFocus();
1213
+ return true;
1214
+ },
1215
+ blur: () => {
1216
+ if (scope.isActive()) edit.ClearFocus();
1217
+ },
1218
+ });
1219
+ scope.onDispose(() => ref(undefined));
1220
+ }
1221
+ if (node.props.nativeImageLayers !== undefined) {
1222
+ const layers = mountImageLayers(edit, scope, node.props.nativeImageLayers);
1223
+ if (layers !== undefined) return layers;
1224
+ }
1225
+ options?.input?.(edit, node.props, scope, hint);
1226
+ if (styledInput !== undefined) {
1227
+ function syncEnabled() {
1228
+ const actual = reveal(edit.IsEnabled());
1229
+ if (actual === undefined) return;
1230
+ enabled = actual;
1231
+ eventPaint?.set("disabled", !actual);
1232
+ }
1233
+ syncEnabled();
1234
+ const hooked = hookSecureMethod(edit, "SetEnabled", syncEnabled, scope);
1235
+ if (!hooked.ok) return hooked;
1236
+ }
1237
+ if (hint !== undefined && placeholder !== undefined && inputSkin !== undefined) {
1238
+ const styled = bindSkinCaption(hint, placeholder, inputSkin.caption, scope, options, environment,
1239
+ styledInput === undefined ? undefined : { parent: edit });
1240
+ if (styled !== undefined) return styled;
1241
+ }
1242
+ const insets = unstyled || styledInput !== undefined ? bindEditInsets(edit, style?.padding, scope) : undefined;
1243
+ if (insets !== undefined) return insets;
1244
+ const alignment = bindEditTextAlign(edit, scope, style, liveStyle);
1245
+ if (alignment !== undefined) return alignment;
1246
+ const authoredColor = (unstyled || styledInput !== undefined) && (style?.color !== undefined || mediaPaint(style, "color"));
1247
+ const text = paint?.usesColor === true || authoredColor
1248
+ ? bindStatePaint(scope, paint, { environment, motion, reduceMotion: options.reduceMotion, liveStyle }, undefined, {
1249
+ fallback: () => ok((liveStyle?.() ?? style)?.color),
1250
+ read: () => edit.GetTextColor(),
1251
+ write: (r, g, b, a) => edit.SetTextColor(r, g, b, a),
1252
+ }) : undefined;
1253
+ return text ?? bindFramePaint(edit, node.props.style, paint, scope, options, motion, environment, liveStyle, undefined,
1254
+ node.props.nativeRoundedArt)
1255
+ ?? (eventPaint === undefined ? undefined
1256
+ : bindElementEvents(edit, {}, scope, options.newEventScope, options.elementEvents, undefined, true, undefined,
1257
+ eventPaint, styledInput !== undefined))
1258
+ ?? finishViewNode(scope, mountViewNode(scope, group, "editbox", edit, node.props), node.props.nodeRef);
1259
+ }
1260
+
1261
+ function rejectProtectedElement(node: UIElement, options: NativeViewOptions | undefined): Failure | undefined {
1262
+ if (options?.unprotectedOnly !== true) return;
1263
+ if (node.kind === "slot" || node.kind === "portal" || node.kind === "frame" && node.props.secureStateHandler === true
1264
+ || node.kind === "button" && (node.props.secureAction !== undefined || node.props.secureMacro !== undefined
1265
+ || options.createButton !== undefined && node.props.unstyled !== true)
1266
+ || node.kind === "scrollview" && options.scrollArea !== undefined) {
1267
+ return protectedCombatView;
1268
+ }
1269
+ }
1270
+
912
1271
  function mountChild(parent: Frame, node: UIElement, scope: RuntimeScope, options: MountOptions, group: LogicalGroup,
913
1272
  motion?: TransitionOptions, inherited?: StyleEnvironment, flow?: NativeLayoutGroup, typography?: NativeTextStyle,
914
1273
  rootControl?: { unanchored?: boolean; attach(this: void, frame: Frame): void }): Failure | undefined {
1274
+ const denied = rejectProtectedElement(node, options);
1275
+ if (denied !== undefined) return denied;
915
1276
  const checkboxSkin = node.kind === "checkbox" ? options.checkboxSkin : undefined;
916
1277
  const rangeSkin = node.kind === "range" ? options.rangeSkin : undefined;
917
1278
  const listboxSkin = node.kind === "listbox" ? options.listboxSkin : undefined;
@@ -960,8 +1321,8 @@ function mountChild(parent: Frame, node: UIElement, scope: RuntimeScope, options
960
1321
  node = { ...node as OwnedRecord<typeof node>, props: { ...node.props as OwnedRecord<typeof node.props>, anchor: { point: "TOPLEFT" } } };
961
1322
  }
962
1323
  }
963
- if (node.kind !== "frame" && (style?.display === "flex" || style?.display === "grid" || style?.display === "block")) {
964
- return fail("Layout containers require a native frame");
1324
+ if (node.kind !== "frame" && node.kind !== "button" && (style?.display === "flex" || style?.display === "grid" || style?.display === "block")) {
1325
+ return fail("Layout containers require a native frame or button");
965
1326
  }
966
1327
  if (node.kind !== "frame" && style?.overflow === "scroll") {
967
1328
  return fail("CSS overflow scroll requires a native frame");
@@ -1001,7 +1362,8 @@ function mountChild(parent: Frame, node: UIElement, scope: RuntimeScope, options
1001
1362
  case "portal":
1002
1363
  return mountPortal(parent, node, scope, options, group, environment, typography);
1003
1364
  case "frame": {
1004
- const frame = createFrame("Frame", undefined, parent);
1365
+ const frame = createFrame("Frame", undefined, parent, node.props.secureStateHandler === true ? "SecureHandlerStateTemplate" : undefined);
1366
+ rootControl?.attach(frame);
1005
1367
  return bindFrameScale(frame, scope, node.props.nativeScale)
1006
1368
  ?? mountFrame(frame, parent, node, scope, options, group, motion, environment, false, flow, typography, liveStyle);
1007
1369
  }
@@ -1038,7 +1400,10 @@ function mountChild(parent: Frame, node: UIElement, scope: RuntimeScope, options
1038
1400
  return failure;
1039
1401
  }
1040
1402
  case "image":
1403
+ case "texture":
1041
1404
  return mountImage(parent, node, scope, options, group, motion, environment, flow, typography, liveStyle);
1405
+ case "cooldown":
1406
+ return mountCooldown(parent, node, scope, motion, environment, flow);
1042
1407
  case "statusbar": {
1043
1408
  const bar = createFrame("StatusBar", undefined, parent);
1044
1409
  scope.onDispose(() => bar.Hide());
@@ -1056,188 +1421,11 @@ function mountChild(parent: Frame, node: UIElement, scope: RuntimeScope, options
1056
1421
  ?? bindElementEvents(bar, node.props, scope, options.newEventScope, options.elementEvents, undefined, false, logical, paint)
1057
1422
  ?? finishViewNode(scope, logical, node.props.nodeRef);
1058
1423
  }
1059
- case "button": {
1060
- const { value, unstyled, disabled, checked } = node.props;
1061
- const plain = unstyled === true;
1062
- const factory = plain ? undefined : options?.createButton;
1063
- const created = factory === undefined ? undefined : protect(() => factory(parent, node.props, scope));
1064
- if (created?.ok === false) return created;
1065
- const custom = created?.value;
1066
- const button = custom ?? createFrame("Button", undefined, parent, plain ? undefined : "UIPanelButtonTemplate");
1067
- rootControl?.attach(button);
1068
- const duration = options.inheritedTextColorDuration;
1069
- const colorMotion = options.buttonPaintMotion?.(button, node.props);
1070
- const paint = createNativePaintState(node.props.style, environment, duration !== undefined, colorMotion?.repaint);
1071
- const buttonTiming: ButtonPaintTiming | undefined = colorMotion === undefined ? undefined
1072
- : { ...colorMotion as OwnedRecord<typeof colorMotion>, change: paint?.colorChange, visible: () => reveal(button.IsVisible()) === true };
1073
- const startAfter = options.buttonStartAfter?.(parent, node.props);
1074
- const geometry = rootControl?.unanchored === true ? { ...node.props as OwnedRecord<typeof node.props>, unanchored: true } : node.props;
1075
- const bindFlags = () => (disabled === undefined ? undefined : bind(scope, disabled, next => {
1076
- if (isSecret(next)) return;
1077
- button.SetEnabled(!next);
1078
- paint?.set("disabled", next);
1079
- })) ?? (paint?.needs("checked") !== true || checked === undefined ? undefined : bind(scope, checked, next => {
1080
- const selected = reveal(next);
1081
- if (selected !== undefined) paint.set("checked", selected);
1082
- }));
1083
- // In a manual paint batch the authored flags must refresh before opacity and color consume them.
1084
- const flagsFirst = options.bindings === "manual" || buttonTiming !== undefined;
1085
- const failure = (flagsFirst ? bindFlags() : undefined)
1086
- ?? placeFrame(button, parent, geometry, scope, motion, false, flow, paint,
1087
- startAfter === undefined ? undefined : { kind: "button", target: startAfter })
1088
- ?? (plain ? undefined : bind(scope, value, next => button.SetText(next)))
1089
- ?? (flagsFirst ? undefined : bindFlags());
1090
- if (failure) return failure;
1091
- if (disabled === undefined && paint?.needs("disabled") === true) paint.set("disabled", reveal(button.IsEnabled()) === false);
1092
- const logical = mountViewNode(scope, group, "button", button, node.props);
1093
- bindButtonDrag(button, scope, node.props);
1094
- const appearance = inheritTextStyle(typography, node.props.style, environment, paint, undefined, liveStyle, duration, buttonTiming);
1095
- for (const child of node.children as NativeChildren) {
1096
- const childFailure = mountChild(button, child, scope, options, logical, undefined, environment, undefined, appearance);
1097
- if (childFailure) return childFailure;
1098
- }
1099
- const label = paint?.usesColor === true ? button.GetFontString() : undefined;
1100
- const observedState = options.buttonPaintStateChanged;
1101
- const stateChanged = observedState === undefined && buttonTiming === undefined ? undefined
1102
- : (state: Parameters<NativePaintState["set"]>[0], active: boolean) => {
1103
- const refresh = observedState?.(button, state, active);
1104
- return buttonTiming !== undefined || refresh === true;
1105
- };
1106
- return bindFramePaint(button, node.props.style, paint, scope, options, motion, environment, liveStyle,
1107
- label === undefined ? undefined : { read: () => label.GetTextColor(), write: (r, g, b, a) => label.SetTextColor(r, g, b, a) },
1108
- node.props.nativeRoundedArt, buttonTiming)
1109
- ?? attachRef(scope, node.props.ref, button)
1110
- ?? bindElementEvents(button, node.props, scope, options.newEventScope, options.elementEvents, button, custom !== undefined,
1111
- logical, interactiveControlPaint(paint, manualControl?.flush, stateChanged))
1112
- ?? finishViewNode(scope, logical, node.props.nodeRef);
1113
- }
1114
- case "editbox": {
1115
- const { value, type, placeholder, unstyled, maxLetters, disabled, onChange, onFocus, onBlur, onEnter, onEscape, ref } = node.props;
1116
- const edit = createFrame("EditBox", undefined, parent, unstyled ? undefined : "InputBoxTemplate");
1117
- rootControl?.attach(edit);
1118
- if (styledInput !== undefined) {
1119
- for (const raw of [...edit.GetRegions()]) {
1120
- const region = reveal(raw) as Texture | undefined;
1121
- if (region !== undefined && reveal(region.GetObjectType()) === "Texture") region.Hide();
1122
- }
1123
- }
1124
- if (unstyled) edit.SetFontObject(GameFontNormal);
1125
- const paint = createNativePaintState(node.props.style, environment);
1126
- const eventPaint = interactiveControlPaint(paint, manualControl?.flush);
1127
- const geometry = rootControl?.unanchored === true ? { ...node.props as OwnedRecord<typeof node.props>, unanchored: true } : node.props;
1128
- const placed = placeFrame(edit, parent, geometry, scope, motion, false, flow, paint);
1129
- if (placed) return placed;
1130
- edit.SetAutoFocus(false);
1131
- if (type === "password") edit.SetPassword(true);
1132
- if (maxLetters !== undefined) edit.SetMaxLetters(maxLetters);
1133
- const hint = placeholder !== undefined || skinnedHint ? edit.CreateFontString(undefined, "OVERLAY", "GameFontDisableSmall") : undefined;
1134
- if (hint !== undefined) {
1135
- if (styledInput?.unstyled !== true || styledInput.caption.position !== "absolute") {
1136
- hint.SetPoint("LEFT", edit, "LEFT", 5, 0);
1137
- hint.SetPoint("RIGHT", edit, "RIGHT", -5, 0);
1138
- hint.SetJustifyH("LEFT");
1139
- }
1140
- hint.SetText(placeholder ?? "");
1141
- }
1142
- let enabled = true;
1143
- const bound = bind(scope, value, next => {
1144
- if (isSecret(next)) return;
1145
- if (reveal(edit.GetText()) !== next) edit.SetText(next);
1146
- hint?.SetShown(next === "");
1147
- }) ?? (disabled === undefined ? undefined : bind(scope, disabled, next => {
1148
- if (isSecret(next)) return;
1149
- enabled = !next;
1150
- edit.SetEnabled(enabled);
1151
- paint?.set("disabled", next);
1152
- }));
1153
- if (bound) return bound;
1154
- if (onChange !== undefined || hint !== undefined) {
1155
- edit.SetScript("OnTextChanged", (_, userInput) => {
1156
- if (!scope.isActive()) return;
1157
- if (userInput ? !enabled : !skinnedHint) return;
1158
- const text = reveal(edit.GetText());
1159
- if (text === undefined) return;
1160
- hint?.SetShown(text === "");
1161
- if (userInput) onChange?.(text);
1162
- });
1163
- }
1164
- const focusPaint = paint?.needs("focus") === true;
1165
- const nativeFocus = styledInput === undefined ? undefined : edit.GetScript("OnEditFocusGained");
1166
- const nativeBlur = styledInput === undefined ? undefined : edit.GetScript("OnEditFocusLost");
1167
- if (onFocus || focusPaint) edit.SetScript("OnEditFocusGained", frame => {
1168
- nativeFocus?.(frame);
1169
- if (!enabled || !scope.isActive()) return;
1170
- if (focusPaint) eventPaint?.set("focus", true);
1171
- onFocus?.();
1172
- });
1173
- if (onBlur || focusPaint) edit.SetScript("OnEditFocusLost", frame => {
1174
- nativeBlur?.(frame);
1175
- if (!scope.isActive()) return;
1176
- if (focusPaint) eventPaint?.set("focus", false);
1177
- onBlur?.();
1178
- });
1179
- if (onEnter) edit.SetScript("OnEnterPressed", () => {
1180
- if (!enabled || !scope.isActive()) return;
1181
- const text = reveal(edit.GetText());
1182
- if (text !== undefined) onEnter(text);
1183
- });
1184
- if (onEscape) edit.SetScript("OnEscapePressed", () => { if (enabled && scope.isActive()) onEscape(); });
1185
- scope.onDispose(() => {
1186
- edit.SetScript("OnTextChanged", undefined);
1187
- if (onFocus || focusPaint) edit.SetScript("OnEditFocusGained", nativeFocus);
1188
- edit.SetScript("OnEditFocusLost", nativeBlur);
1189
- if (onEnter) edit.SetScript("OnEnterPressed", undefined);
1190
- if (onEscape) edit.SetScript("OnEscapePressed", undefined);
1191
- edit.ClearFocus();
1192
- });
1193
- if (ref) {
1194
- ref({
1195
- focus: () => {
1196
- if (!scope.isActive() || !enabled || reveal(edit.IsVisible()) !== true) return false;
1197
- edit.SetFocus();
1198
- return true;
1199
- },
1200
- blur: () => {
1201
- if (scope.isActive()) edit.ClearFocus();
1202
- },
1203
- });
1204
- scope.onDispose(() => ref(undefined));
1205
- }
1206
- options?.input?.(edit, node.props, scope, hint);
1207
- if (styledInput !== undefined) {
1208
- function syncEnabled() {
1209
- const actual = reveal(edit.IsEnabled());
1210
- if (actual === undefined) return;
1211
- enabled = actual;
1212
- eventPaint?.set("disabled", !actual);
1213
- }
1214
- syncEnabled();
1215
- const hooked = hookSecureMethod(edit, "SetEnabled", syncEnabled, scope);
1216
- if (!hooked.ok) return hooked;
1217
- }
1218
- if (hint !== undefined && placeholder !== undefined && inputSkin !== undefined) {
1219
- const styled = bindSkinCaption(hint, placeholder, inputSkin.caption, scope, options, environment,
1220
- styledInput === undefined ? undefined : { parent: edit });
1221
- if (styled !== undefined) return styled;
1222
- }
1223
- const insets = unstyled || styledInput !== undefined ? bindEditInsets(edit, style?.padding, scope) : undefined;
1224
- if (insets !== undefined) return insets;
1225
- const alignment = bindEditTextAlign(edit, scope, style, liveStyle);
1226
- if (alignment !== undefined) return alignment;
1227
- const authoredColor = (unstyled || styledInput !== undefined) && (style?.color !== undefined || mediaPaint(style, "color"));
1228
- const text = paint?.usesColor === true || authoredColor
1229
- ? bindStatePaint(scope, paint, { environment, motion, reduceMotion: options.reduceMotion, liveStyle }, undefined, {
1230
- fallback: () => ok((liveStyle?.() ?? style)?.color),
1231
- read: () => edit.GetTextColor(),
1232
- write: (r, g, b, a) => edit.SetTextColor(r, g, b, a),
1233
- }) : undefined;
1234
- return text ?? bindFramePaint(edit, node.props.style, paint, scope, options, motion, environment, liveStyle, undefined,
1235
- node.props.nativeRoundedArt)
1236
- ?? (eventPaint === undefined ? undefined
1237
- : bindElementEvents(edit, {}, scope, options.newEventScope, options.elementEvents, undefined, true, undefined,
1238
- eventPaint, styledInput !== undefined))
1239
- ?? finishViewNode(scope, mountViewNode(scope, group, "editbox", edit, node.props), node.props.nodeRef);
1240
- }
1424
+ case "button":
1425
+ return mountButton(parent, node, scope, options, group, motion, environment, flow, typography, rootControl, liveStyle, manualControl);
1426
+ case "editbox":
1427
+ return mountEditBox(parent, node, scope, options, group, inputSkin, styledInput, skinnedHint, motion, environment, flow,
1428
+ liveStyle, rootControl, manualControl);
1241
1429
  case "checkbox": {
1242
1430
  const { checked, disabled, label, onChange } = node.props;
1243
1431
  const check = createFrame("CheckButton", undefined, parent, "UICheckButtonTemplate");
@@ -1309,7 +1497,7 @@ function mountChild(parent: Frame, node: UIElement, scope: RuntimeScope, options
1309
1497
  ?? finishViewNode(scope, logical, node.props.nodeRef);
1310
1498
  }
1311
1499
  case "range": {
1312
- const { value, disabled, label, hideLabel, min, max, step = 1, onChange } = node.props;
1500
+ const { value, disabled, label, hideLabel, min, max, step = 1, onChange, onCommit } = node.props;
1313
1501
  if (!Number.isFinite(min) || !Number.isFinite(max) || !Number.isFinite(step) || max <= min || step <= 0) {
1314
1502
  return fail("Invalid slider range");
1315
1503
  }
@@ -1338,12 +1526,22 @@ function mountChild(parent: Frame, node: UIElement, scope: RuntimeScope, options
1338
1526
  if (failure) return failure;
1339
1527
  if (rangeSkin !== undefined) hideStockControlArt(slider, caption);
1340
1528
  if (caption !== undefined) options.range?.(slider, caption, node.props, scope);
1529
+ let changedByPointer = false;
1530
+ if (onCommit !== undefined) {
1531
+ const complete = hookScript(slider, "OnMouseUp", () => {
1532
+ if (!changedByPointer) return;
1533
+ changedByPointer = false;
1534
+ onCommit();
1535
+ }, scope);
1536
+ if (!complete.ok) return complete;
1537
+ }
1341
1538
  if (onChange !== undefined) {
1342
1539
  slider.SetScript("OnValueChanged", (_, raw, userInput) => {
1343
1540
  if (!userInput || !scope.isActive()) return;
1344
1541
  const next = reveal(raw);
1345
1542
  if (next === undefined || next === current) return;
1346
1543
  slider.SetValue(current, false);
1544
+ changedByPointer = onCommit !== undefined;
1347
1545
  onChange(next);
1348
1546
  });
1349
1547
  scope.onDispose(() => slider.SetScript("OnValueChanged", undefined));
@@ -1437,9 +1635,28 @@ function mountLayoutRows(parent: Frame, node: Element<"keyedList">, scope: Runti
1437
1635
  });
1438
1636
  return node.props.mount(scope, {
1439
1637
  mount: (tree, rowScope): Result<{ item?: NativeLayoutItem; logical: LogicalGroup }> => {
1638
+ const row = mountLogicalGroup(rowScope, logical, false);
1639
+ if (tree.kind === "frame" && motion === undefined && isAbsoluteFill(tree.props) && flowContainer(tree.props.style?.display)
1640
+ && tree.props.style?.mediaStyles === undefined && tree.props.style?.styleTokens === undefined) {
1641
+ const failure = mountChild(parent, tree, rowScope, options, row, motion, environment, undefined, typography, {
1642
+ attach: frame => { rowScope.onDispose(() => frame.Hide()); },
1643
+ });
1644
+ return failure ?? ok({ logical: row });
1645
+ }
1646
+ if ((tree.kind === "frame" || tree.kind === "button" && tree.props.secureAction === undefined && tree.props.secureMacro === undefined)
1647
+ && tree.props.directKeyedLayout === true && tree.props.anchor === undefined && tree.props.style?.position !== "absolute"
1648
+ && tree.props.style?.mediaStyles === undefined && tree.props.style?.styleTokens === undefined) {
1649
+ // Keep the item detached until the keyed reconciler publishes its order.
1650
+ const detached: NativeLayoutGroup = {
1651
+ children: ownedArray(), enqueue: flow.enqueue, visibility: flow.visibility, textMeasure: flow.textMeasure,
1652
+ };
1653
+ const failure = mountChild(parent, tree, rowScope, options, row, motion, environment, detached, typography);
1654
+ if (failure !== undefined) return failure;
1655
+ const item = detached.children[0];
1656
+ return item instanceof NativeLayoutItem ? ok({ item, logical: row }) : fail("Direct keyed row did not attach to its layout");
1657
+ }
1440
1658
  const frame = createFrame("Frame", undefined, parent);
1441
1659
  const style = "style" in tree.props ? tree.props.style : undefined;
1442
- const row = mountLogicalGroup(rowScope, logical, false);
1443
1660
  if (style && "position" in style && style.position === "absolute") {
1444
1661
  frame.SetAllPoints(parent);
1445
1662
  rowScope.onDispose(() => frame.Hide());
@@ -1536,7 +1753,7 @@ export function mountNativeRangeArt(this: void, slider: FrameMap["Slider"], owne
1536
1753
  const bindings = manual?.scope ?? scope;
1537
1754
  const result = scope.protect(() => {
1538
1755
  const mountedOptions: MountOptions = { ...options as OwnedRecord<NativeRangeArtOptions> | undefined, newEventScope: () => scope.fork() };
1539
- const theme = extendStyleEnvironment(undefined, options?.theme, isSecret);
1756
+ const theme = rootStyleEnvironment(options?.theme);
1540
1757
  const art = mountRangeArtView(slider, thumbSize, render, bindings, mountedOptions, { scope: bindings }, theme);
1541
1758
  if (!art.ok) return art;
1542
1759
  const failure = art.value.installThumb();
@@ -1547,6 +1764,13 @@ export function mountNativeRangeArt(this: void, slider: FrameMap["Slider"], owne
1547
1764
  return mounted;
1548
1765
  }
1549
1766
 
1767
+ function rootStyleEnvironment(theme?: StyleVariables): StyleEnvironment | undefined {
1768
+ const defaults = addonManifest()?.styleVariables;
1769
+ const variables = defaults === undefined ? theme : theme === undefined ? defaults
1770
+ : { ...defaults as OwnedRecord<StyleVariables>, ...theme as OwnedRecord<StyleVariables> };
1771
+ return extendStyleEnvironment(undefined, variables, isSecret);
1772
+ }
1773
+
1550
1774
  function readRootLayer(layer: NativeRootLayer): Result<NativeRootLayer> {
1551
1775
  const checked = protect(() => {
1552
1776
  if (isSecret(layer) || typeof layer !== "object" || layer === null) return fail("Native root layer is unreadable");
@@ -1574,22 +1798,24 @@ function unprotected(region: LayerRegion): boolean {
1574
1798
  return reveal(state) === false;
1575
1799
  }
1576
1800
 
1577
- function createRootFrame(parent: FrameParent, scope: RuntimeScope, backdrop?: NativeViewOptions["rootBackdrop"]): Frame {
1578
- const frame = backdrop === undefined ? createFrame("Frame", undefined, parent)
1579
- : createFrame("Frame", backdrop.name, parent, "BackdropTemplate");
1801
+ function createRootFrame(parent: FrameParent, scope: RuntimeScope, backdrop?: NativeViewOptions["rootBackdrop"],
1802
+ secureStateHandler = false): Frame {
1803
+ const template = secureStateHandler ? backdrop === undefined ? "SecureHandlerStateTemplate" : "BackdropTemplate,SecureHandlerStateTemplate"
1804
+ : backdrop === undefined ? undefined : "BackdropTemplate";
1805
+ const frame = createFrame("Frame", backdrop?.name, parent, template);
1580
1806
  scope.onDispose(() => frame.Hide());
1581
1807
  return frame;
1582
1808
  }
1583
1809
 
1584
1810
  function createLayeredRoot(parent: FrameParent, scope: RuntimeScope, { strata, level }: NativeRootLayer,
1585
- backdrop?: NativeViewOptions["rootBackdrop"]): Result<Frame> {
1811
+ backdrop?: NativeViewOptions["rootBackdrop"], secureStateHandler = false): Result<Frame> {
1586
1812
  const created = protect(() => {
1587
1813
  if (!accessibleLayerRegion(parent)) return fail("Native root parent is inaccessible");
1588
1814
  const inCombat = reveal(api.InCombatLockdown());
1589
1815
  if (typeof inCombat !== "boolean") return fail("Combat lockdown is unreadable");
1590
1816
  if (inCombat && !unprotected(parent)) return fail("Cannot layer a native root under a protected parent in combat");
1591
1817
 
1592
- const frame = createRootFrame(parent, scope, backdrop);
1818
+ const frame = createRootFrame(parent, scope, backdrop, secureStateHandler);
1593
1819
  if (!accessibleLayerRegion(frame)) return fail("Native root frame is inaccessible");
1594
1820
  if (inCombat && !unprotected(frame)) return fail("Cannot layer a protected native root in combat");
1595
1821
 
@@ -1607,7 +1833,7 @@ function createLayeredRoot(parent: FrameParent, scope: RuntimeScope, { strata, l
1607
1833
  function isNativeRegionTree(tree: UIElement): boolean {
1608
1834
  const children = tree.children as NativeChildren;
1609
1835
  if (tree.kind === "fragment") return children.every(child => isNativeRegionTree(child));
1610
- return (tree.kind === "text" || tree.kind === "image") && children.length === 0;
1836
+ return (tree.kind === "text" || tree.kind === "image" || tree.kind === "texture") && children.length === 0;
1611
1837
  }
1612
1838
 
1613
1839
  function initialLayoutQueue() {
@@ -1622,8 +1848,9 @@ function initialLayoutQueue() {
1622
1848
  for (let pass = 0; jobs.size > 0; pass++) {
1623
1849
  if (pass === 16) return fail("Initial native layout did not settle");
1624
1850
  const pending = [...jobs];
1625
- jobs.clear();
1626
1851
  for (const job of pending) {
1852
+ // A parent can invalidate a child that has yet to run in this pass.
1853
+ jobs.delete(job);
1627
1854
  const failure = job();
1628
1855
  if (failure !== undefined) return failure;
1629
1856
  }
@@ -1639,6 +1866,7 @@ function initialLayoutQueue() {
1639
1866
  /** Mount a WoW frame tree, an unstyled control, or scoped regions on a borrowed frame. */
1640
1867
  export function mountNative(parent: FrameParent, runtime: Runtime, render: (this: void, scope: RuntimeScope) => UIElement,
1641
1868
  options?: NativeViewOptions) {
1869
+ if (options?.unprotectedOnly === true && options.regionsOnly === true) return fail("Combat-updating views require an owned root");
1642
1870
  const requestedLayer = options?.rootLayer;
1643
1871
  const checkedLayer = requestedLayer === undefined ? undefined : readRootLayer(requestedLayer);
1644
1872
  if (checkedLayer?.ok === false) return checkedLayer;
@@ -1671,7 +1899,7 @@ export function mountNative(parent: FrameParent, runtime: Runtime, render: (this
1671
1899
  if (typeof frame.CreateTexture !== "function" || typeof frame.CreateFontString !== "function") {
1672
1900
  return fail("Native region mounts require a frame parent");
1673
1901
  }
1674
- const theme = extendStyleEnvironment(undefined, options.theme, isSecret);
1902
+ const theme = rootStyleEnvironment(options.theme);
1675
1903
  const failure = mountChild(frame, tree, owner, mountedOptions, { scope: owner }, undefined, theme);
1676
1904
  if (failure !== undefined) return failure;
1677
1905
  mountedTree = true;
@@ -1689,6 +1917,8 @@ export function mountNative(parent: FrameParent, runtime: Runtime, render: (this
1689
1917
  if (!child) return fail("A native view must return one root frame");
1690
1918
  tree = child;
1691
1919
  }
1920
+ const denied = rejectProtectedElement(tree, options);
1921
+ if (denied !== undefined) return denied;
1692
1922
  if ((tree.kind === "button" || tree.kind === "editbox") && tree.props.unstyled === true) {
1693
1923
  const kind = tree.kind === "button" ? "button" : "edit box";
1694
1924
  if (layer !== undefined || options?.rootScale !== undefined) {
@@ -1697,7 +1927,7 @@ export function mountNative(parent: FrameParent, runtime: Runtime, render: (this
1697
1927
  if (options?.rootBackdrop !== undefined) return fail("Native root backdrop requires a frame root");
1698
1928
  if (!accessibleLayerRegion(parent)) return fail(`Native root ${kind} requires an accessible frame parent`);
1699
1929
  let frame: Frame | undefined;
1700
- const theme = extendStyleEnvironment(undefined, options?.theme, isSecret);
1930
+ const theme = rootStyleEnvironment(options?.theme);
1701
1931
  const failure = mountChild(parent as Frame, tree, owner, mountedOptions, { scope: owner }, motion, theme, undefined, undefined, {
1702
1932
  unanchored: options?.unanchoredRoot,
1703
1933
  attach(this: void, control: Frame) {
@@ -1713,16 +1943,16 @@ export function mountNative(parent: FrameParent, runtime: Runtime, render: (this
1713
1943
  if (tree.kind !== "frame") return fail("A native view must return a frame");
1714
1944
  let frame: Frame;
1715
1945
  if (layer === undefined) {
1716
- frame = createRootFrame(parent, scope, options?.rootBackdrop);
1946
+ frame = createRootFrame(parent, scope, options?.rootBackdrop, tree.props.secureStateHandler);
1717
1947
  } else {
1718
- const created = createLayeredRoot(parent, scope, layer, options?.rootBackdrop);
1948
+ const created = createLayeredRoot(parent, scope, layer, options?.rootBackdrop, tree.props.secureStateHandler);
1719
1949
  if (!created.ok) return created;
1720
1950
  frame = created.value;
1721
1951
  }
1722
1952
  const rootScale = options?.rootScale;
1723
1953
  const scaleFailure = bindFrameScale(frame, rootScale === undefined ? owner : scope, rootScale ?? tree.props.nativeScale);
1724
1954
  if (scaleFailure !== undefined) return scaleFailure;
1725
- const theme = extendStyleEnvironment(extendStyleEnvironment(undefined, options?.theme, isSecret), tree.props.cssVars, isSecret);
1955
+ const theme = extendStyleEnvironment(rootStyleEnvironment(options?.theme), tree.props.cssVars, isSecret);
1726
1956
  const media = tree.mediaReads !== undefined || tree.props.style?.mediaStyles !== undefined
1727
1957
  ? bindViewMedia(tree, owner, mountedOptions) : undefined;
1728
1958
  if (media?.ok === false) return media;