@overmvp/kumi 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +14 -2
- package/animation/color-transition.ts +196 -0
- package/animation/cycle.ts +151 -0
- package/animation/ease.ts +29 -0
- package/animation/index.ts +13 -0
- package/animation/package.json +12 -0
- package/animation/presets.ts +376 -0
- package/animation/spec.ts +197 -0
- package/builder/Cargo.lock +192 -0
- package/builder/Cargo.toml +7 -0
- package/builder/css-v1.mjs +334 -0
- package/builder/css-v1.test.mjs +321 -0
- package/builder/generated-output.mjs +61 -0
- package/builder/generated-output.test.mjs +132 -0
- package/builder/jsx-form.mjs +93 -0
- package/builder/jsx-form.test.mjs +48 -0
- package/builder/jsx-lists.mjs +209 -0
- package/builder/link-addon-package.mjs +86 -0
- package/builder/lua-assets.mjs +74 -0
- package/builder/lua-builtin-values.mjs +57 -0
- package/builder/lua-builtin-values.test.mjs +155 -0
- package/builder/lua-loop-closures.mjs +183 -0
- package/builder/lua-loop-closures.test.mjs +89 -0
- package/builder/lua-truthiness.mjs +61 -0
- package/builder/lua-truthiness.test.mjs +113 -0
- package/builder/module-declarations.mjs +594 -0
- package/builder/module-declarations.test.mjs +444 -0
- package/builder/native-kernels.mjs +60 -0
- package/builder/native-lua.d.ts +57 -0
- package/builder/native-routes.mjs +51 -0
- package/builder/no-static-ref-read.mjs +93 -0
- package/builder/no-static-ref-read.test.mjs +181 -0
- package/builder/secure-snippet.mjs +317 -0
- package/builder/secure-snippet.test.mjs +101 -0
- package/builder/shared-lua-runtime.mjs +150 -0
- package/builder/src/addon-link.lua +29 -0
- package/builder/src/arrays.lua +260 -0
- package/builder/src/assets.rs +177 -0
- package/builder/src/classes.lua +75 -0
- package/builder/src/collections.lua +190 -0
- package/builder/src/compiler.rs +2164 -0
- package/builder/src/config.rs +42 -0
- package/builder/src/entries.rs +166 -0
- package/builder/src/errors.lua +15 -0
- package/builder/src/lua_data.rs +231 -0
- package/builder/src/main.rs +367 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +47 -0
- package/builder/src/numbers.lua +62 -0
- package/builder/src/project-front.mjs +3331 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +127 -0
- package/builder/src/signal-kernel.fingerprint +1 -0
- package/builder/src/strings.lua +103 -0
- package/builder/src/ts-lower.mjs +68 -0
- package/builder/src/wow_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -0
- package/builder/style-states.mjs +100 -0
- package/builder/style-states.test.mjs +103 -0
- package/builder/vite-assets.mjs +53 -0
- package/builder/vite-project.mjs +10 -0
- package/config.ts +17 -0
- package/form/index.ts +522 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +22 -4
- package/router/index.ts +43 -0
- package/router/package.json +12 -0
- package/router/routes.ts +64 -0
- package/scripts/kumi-cli.mjs +70 -0
- package/scripts/link-addons.mjs +51 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +234 -0
- package/src/css-v1.ts +58 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +479 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +334 -0
- package/src/grid-tracks.ts +165 -0
- package/src/image-imports.d.ts +24 -0
- package/src/images.ts +79 -0
- package/src/index.ts +28 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +22 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +363 -0
- package/src/media-query.ts +144 -0
- package/src/module.ts +277 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +44 -0
- package/src/providers.ts +235 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +254 -0
- package/src/result.ts +58 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +30 -0
- package/src/style-classes.ts +51 -0
- package/src/style-states.ts +134 -0
- package/src/style-variables.ts +53 -0
- package/src/text-children.ts +42 -0
- package/src/theme.ts +50 -0
- package/src/transition.ts +18 -0
- package/state/index.ts +3 -0
- package/state/package.json +12 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +82 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/README.md +14 -0
- package/templates/addon/__ADDON_NAME__.toc +4 -0
- package/templates/addon/eslint.config.mjs +12 -0
- package/templates/addon/gitignore +8 -0
- package/templates/addon/package.json +21 -0
- package/templates/addon/scripts/build.mjs +25 -0
- package/templates/addon/src/app/main.tsx +13 -0
- package/templates/addon/tsconfig.json +24 -0
- package/translate/index.ts +14 -0
- package/translate/package.json +9 -0
- package/utils/colors.ts +76 -0
- package/utils/format.ts +37 -0
- package/utils/index.ts +4 -0
- package/utils/number.ts +17 -0
- package/utils/package.json +7 -0
- package/utils/text.ts +6 -0
- package/validate/index.ts +119 -0
- package/validate/package.json +9 -0
- package/wow/absolute-position.ts +142 -0
- package/wow/animation.ts +428 -0
- package/wow/aura-button.ts +76 -0
- package/wow/aura-container.ts +591 -0
- package/wow/aura-countdown.ts +201 -0
- package/wow/aura-slot.ts +153 -0
- package/wow/bar-shade.ts +93 -0
- package/wow/borrowed-slot.ts +216 -0
- package/wow/button-drag.ts +48 -0
- package/wow/cast-clock.ts +153 -0
- package/wow/cast-text.ts +83 -0
- package/wow/class-colors.ts +126 -0
- package/wow/clock.ts +7 -0
- package/wow/color-picker.ts +128 -0
- package/wow/commands.ts +17 -0
- package/wow/contained-frame.ts +128 -0
- package/wow/contract.ts +42 -0
- package/wow/css-box.ts +110 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +398 -0
- package/wow/css-text.ts +399 -0
- package/wow/cvar-schema.ts +32 -0
- package/wow/cvars.ts +98 -0
- package/wow/dropdown-art.ts +39 -0
- package/wow/element-click.ts +20 -0
- package/wow/element-event-coordinator.ts +219 -0
- package/wow/element-events.ts +317 -0
- package/wow/event-dispatcher.ts +151 -0
- package/wow/events.ts +50 -0
- package/wow/font-cache.ts +92 -0
- package/wow/frame-access.ts +31 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +97 -0
- package/wow/layout-view.ts +651 -0
- package/wow/lua-string.ts +18 -0
- package/wow/lua-table.ts +18 -0
- package/wow/macro-book.ts +84 -0
- package/wow/map-position.ts +27 -0
- package/wow/media-query.ts +65 -0
- package/wow/module-events.ts +11 -0
- package/wow/native-hooks.ts +168 -0
- package/wow/native-placement.ts +88 -0
- package/wow/native.ts +135 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/protect.ts +24 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/range-art.ts +74 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +156 -0
- package/wow/saved-variables.ts +60 -0
- package/wow/scroll-view.ts +64 -0
- package/wow/secret-ref.ts +14 -0
- package/wow/secure-bindings.ts +89 -0
- package/wow/secure-clicks.ts +432 -0
- package/wow/secure-snippet.ts +235 -0
- package/wow/secure-state.ts +130 -0
- package/wow/secure-target-visibility.ts +89 -0
- package/wow/secure-transaction.ts +331 -0
- package/wow/special-window.ts +269 -0
- package/wow/start-addon.ts +99 -0
- package/wow/state-paint.ts +256 -0
- package/wow/transition.ts +86 -0
- package/wow/unit-button.ts +39 -0
- package/wow/unit-cast.ts +92 -0
- package/wow/unit-health-text.ts +47 -0
- package/wow/view-nodes.ts +304 -0
- package/wow/view.ts +1746 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
package/wow/view.ts
ADDED
|
@@ -0,0 +1,1746 @@
|
|
|
1
|
+
import type { Anchor, Binding, Element, Job, NativeStyle, ReadonlyRef, Runtime, RuntimeScope, StatusBarValue, StyleClass, TransitionOptions, UIElement } from "../src";
|
|
2
|
+
import { bindValue } from "../src/bindings";
|
|
3
|
+
import type { CssTokenRecipe } from "../src/css-v1";
|
|
4
|
+
import { bindImageSize, imageSize, positiveImageDimension } from "../src/images";
|
|
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";
|
|
7
|
+
import { ref } from "../src/reactivity";
|
|
8
|
+
import { withReactiveScope } from "../src/reactive-scope";
|
|
9
|
+
import { fail, ok, type Failure, type Result } from "../src/result";
|
|
10
|
+
import { resolveStyleClasses } from "../src/style-classes";
|
|
11
|
+
import type { StateStyleVariant, StyleState } from "../src/style-states";
|
|
12
|
+
import { extendStyleEnvironment, resolveStyleValue, styleValue, type StyleEnvironment, type StyleVariables } from "../src/style-variables";
|
|
13
|
+
import { createFrame, type FontString, type FrameMap, type FrameParent, type StatusBar, type Texture } from "./frames";
|
|
14
|
+
import { canAccessRegion } from "./frame-access";
|
|
15
|
+
import { bindAbsolutePosition, type NativeEndTarget, type NativeStartTarget, type NativeTextEndTarget } from "./absolute-position";
|
|
16
|
+
import { bindBorrowedSlot, type BorrowedSlot } from "./borrowed-slot";
|
|
17
|
+
import { prepareCssStyle, type ReadCssStyle } from "./css-style";
|
|
18
|
+
import { readCssColor } from "./css-color";
|
|
19
|
+
import { bindEditTextAlign, bindTextColor, bindTextTypography, createTextContent, inheritTextStyle, type NativeTextHost, type NativeTextStyle } from "./css-text";
|
|
20
|
+
import { hasCssSurface, includeCssBorderPadding, mountCssContent, mountCssSurface } from "./css-box";
|
|
21
|
+
import type { CssSurfaceOptions } from "./css-surfaces";
|
|
22
|
+
import { prepareDropdownArt } from "./dropdown-art";
|
|
23
|
+
import { frameStrata, maximumFrameLevel, type FrameStrata } from "./frame-layer";
|
|
24
|
+
import { mountImageLayers } from "./image-layers";
|
|
25
|
+
import { mountScrollView, type CreateScrollArea, type ScrollArea } from "./scroll-view";
|
|
26
|
+
import { bindButtonDrag } from "./button-drag";
|
|
27
|
+
import { bindElementEvents, hasElementInput, type NativeElementEventHost } from "./element-events";
|
|
28
|
+
import { api, isSecret, reveal } from "./native";
|
|
29
|
+
import { hookSecureMethod } from "./native-hooks";
|
|
30
|
+
import { rawField } from "./lua-table";
|
|
31
|
+
import { observeContainer, type NativeMediaOptions } from "./media-query";
|
|
32
|
+
import { mountRangeArt } from "./range-art";
|
|
33
|
+
import { protect } from "./protect";
|
|
34
|
+
import { animateVisibility } from "./transition";
|
|
35
|
+
import { attachLayoutItem, mountLayoutRoot, NativeLayoutItem, readLayoutValue, type NativeLayoutDiagnostics, type NativeLayoutGroup, type StageInitialLayout } from "./layout-view";
|
|
36
|
+
import { finishViewNode, mountLogicalGroup, mountViewNode, orderLogicalRows, type LogicalGroup, type LogicalNode } from "./view-nodes";
|
|
37
|
+
import { bindStatePaint, createNativePaintState, type ButtonPaintTiming, type NativeButtonPaintMotion, type NativePaintState,
|
|
38
|
+
type NativeStateColor, type TextColorStateChange } from "./state-paint";
|
|
39
|
+
import type { FlexNode } from "../src/flex-layout";
|
|
40
|
+
|
|
41
|
+
type Frame = FrameMap["Frame"];
|
|
42
|
+
declare const GameFontNormal: Parameters<FrameMap["EditBox"]["SetFontObject"]>[0];
|
|
43
|
+
type Region = Pick<FontString, "ClearAllPoints" | "SetWidth" | "SetHeight" | "SetSize" | "SetPoint" | "SetShown" | "IsShown"
|
|
44
|
+
| "SetAlpha" | "GetSize" | "IsForbidden" | "GetObjectType">;
|
|
45
|
+
type LayoutParent = NativeLayoutGroup | NativeLayoutItem;
|
|
46
|
+
/** Layout props shared by every native element. Each kind keeps its own typed `ref`. */
|
|
47
|
+
type Layout = Pick<Element<"frame">["props"], "width" | "height" | "fullWidth" | "anchor" | "shown" | "opacity" | "style"> & {
|
|
48
|
+
unanchored?: boolean;
|
|
49
|
+
};
|
|
50
|
+
type StatusBarProps = Element<"statusbar">["props"];
|
|
51
|
+
type NativeStatusBarValue = Parameters<StatusBar["SetValue"]>[0];
|
|
52
|
+
type NativeChildren = OwnedArray<UIElement>;
|
|
53
|
+
const headingSizes = [24, 20, 18, 16, 14, 12] as const;
|
|
54
|
+
|
|
55
|
+
declare module "../src/elements" {
|
|
56
|
+
/** Native handles passed to JSX `ref` callbacks in WoW. */
|
|
57
|
+
interface NativeHandles {
|
|
58
|
+
frame: Frame;
|
|
59
|
+
scrollview: ScrollArea;
|
|
60
|
+
image: Texture;
|
|
61
|
+
text: FontString;
|
|
62
|
+
statusbar: StatusBar;
|
|
63
|
+
button: FrameMap["Button"];
|
|
64
|
+
editbox: FrameMap["EditBox"];
|
|
65
|
+
checkbox: FrameMap["CheckButton"];
|
|
66
|
+
range: FrameMap["Slider"];
|
|
67
|
+
listbox: FrameMap["DropdownButton"];
|
|
68
|
+
slot: Frame | FontString;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Pass the mounted handle to the element's ref and clear it when the mount is released. */
|
|
73
|
+
function attachRef<Handle>(scope: RuntimeScope, ref: ((this: void, handle?: Handle) => void) | undefined, handle: Handle): Failure | undefined {
|
|
74
|
+
if (!ref) return;
|
|
75
|
+
const attached = scope.protect(() => ref(handle));
|
|
76
|
+
if (!attached.ok) return attached;
|
|
77
|
+
scope.onDispose(() => ref(undefined));
|
|
78
|
+
}
|
|
79
|
+
export interface NativeRootLayer {
|
|
80
|
+
readonly strata: FrameStrata;
|
|
81
|
+
readonly level?: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface NativeControlSkinStyle {
|
|
85
|
+
readonly control: StyleClass;
|
|
86
|
+
readonly caption: StyleClass;
|
|
87
|
+
/** Used where the view and the control do not supply a variable. */
|
|
88
|
+
readonly defaultTheme?: StyleVariables
|
|
89
|
+
| ((this: void, parent: Frame, scope: RuntimeScope, flush?: (this: void) => void) => StyleVariables);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface NativeInputSkin extends NativeControlSkinStyle {
|
|
93
|
+
/** Extend this skin to unstyled edit boxes without selecting a native template. */
|
|
94
|
+
readonly unstyled?: true;
|
|
95
|
+
/** Keep a native caption when the authored placeholder is an empty string. */
|
|
96
|
+
readonly emptyCaption?: true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface NativeCheckboxSkin extends NativeControlSkinStyle {
|
|
100
|
+
render(this: void, check: FrameMap["CheckButton"], checked: ReadonlyRef<boolean>, flush?: (this: void) => void): UIElement;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface NativeRangeSkin extends NativeControlSkinStyle {
|
|
104
|
+
/** The native thumb width and height in slider coordinates. */
|
|
105
|
+
readonly thumbSize: number;
|
|
106
|
+
render(this: void): { track: UIElement; fill: UIElement; thumb: UIElement };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type NativeRangeArtOptions = Pick<NativeViewOptions, "bindings" | "image" | "theme">;
|
|
110
|
+
|
|
111
|
+
export interface NativeListboxSkin extends NativeControlSkinStyle {
|
|
112
|
+
render(this: void): UIElement;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface NativeViewOptions extends NativeTextHost {
|
|
116
|
+
bindings?: "manual";
|
|
117
|
+
/** Capture the manual bindings of matching text regions for a targeted flush. Full view flushes still include them. */
|
|
118
|
+
manualTextBindings?: {
|
|
119
|
+
readonly part: string;
|
|
120
|
+
capture(this: void, flush: (this: void) => void): void;
|
|
121
|
+
};
|
|
122
|
+
/** Observe successful layout passes and the native geometry and visibility writes they commit. */
|
|
123
|
+
layoutDiagnostics?: NativeLayoutDiagnostics;
|
|
124
|
+
/** Complete the newly mounted tree's first CSS layout before returning. Later updates use the frame budget. */
|
|
125
|
+
initialLayout?: "sync";
|
|
126
|
+
/** Mount textures and text directly on a borrowed frame. Disposal hides only the new regions. */
|
|
127
|
+
regionsOnly?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Apply a strata and optional absolute frame level to the native root at mount time.
|
|
130
|
+
* An explicit level takes precedence over the root's `style.zIndex`.
|
|
131
|
+
* @example
|
|
132
|
+
* mountNative(parent, runtime, render, { rootLayer: { strata: "DIALOG", level: 40 } });
|
|
133
|
+
*/
|
|
134
|
+
rootLayer?: NativeRootLayer;
|
|
135
|
+
/** Create the native frame root with BackdropTemplate and an optional global name. */
|
|
136
|
+
rootBackdrop?: { name?: string };
|
|
137
|
+
/** Scale the native root independently of its logical layout and manual content bindings. */
|
|
138
|
+
rootScale?: Binding<number>;
|
|
139
|
+
/** Leave root placement to the host when the view declares neither an anchor nor absolute position. */
|
|
140
|
+
unanchoredRoot?: boolean;
|
|
141
|
+
theme?: StyleVariables;
|
|
142
|
+
elementEvents?: NativeElementEventHost;
|
|
143
|
+
portalRoot?: Frame;
|
|
144
|
+
rounded?: CssSurfaceOptions["rounded"];
|
|
145
|
+
reduceMotion?(this: void): boolean;
|
|
146
|
+
media?: NativeMediaOptions;
|
|
147
|
+
scrollArea?: CreateScrollArea;
|
|
148
|
+
/**
|
|
149
|
+
* Create a native button with host-owned art and a native FontString for its label.
|
|
150
|
+
* Return undefined to use the stock template. The renderer skips this factory for unstyled buttons.
|
|
151
|
+
*/
|
|
152
|
+
createButton?(this: void, parent: Frame, props: Element<"button">["props"], scope: RuntimeScope): FrameMap["Button"] | undefined;
|
|
153
|
+
frame?(this: void, frame: Frame, props: Element<"frame">["props"], scope: RuntimeScope): void;
|
|
154
|
+
text?(this: void, text: FontString, props: Element<"text">["props"], scope: RuntimeScope): void;
|
|
155
|
+
/** Let stretched, centered CSS text start at the right edge of a live native target. */
|
|
156
|
+
textStartAfter?(this: void, parent: Frame, props: Element<"text">["props"]): ReadonlyRef<Frame | undefined> | undefined;
|
|
157
|
+
/** While a target is present, let centered absolute text end at the left edge of that FontString. */
|
|
158
|
+
textEndBefore?(this: void, parent: Frame, props: Element<"text">["props"]): NativeTextEndTarget | undefined;
|
|
159
|
+
/** Let a centered absolute frame's single right anchor follow a FontString's left edge. */
|
|
160
|
+
frameEndBefore?(this: void, parent: FrameParent, props: Element<"frame">["props"]): NativeTextEndTarget | undefined;
|
|
161
|
+
buttonStartAfter?(this: void, parent: Frame, props: Element<"button">["props"]): ReadonlyRef<Frame | undefined> | undefined;
|
|
162
|
+
/** Duration in seconds for native text inheriting an interactive button's CSS color. Zero paints immediately. */
|
|
163
|
+
inheritedTextColorDuration?(this: void, change: TextColorStateChange): number;
|
|
164
|
+
/** Set scoped color timing for a button's CSS surface and foreground. Increment repaint to finish its current colors. */
|
|
165
|
+
buttonPaintMotion?(this: void, button: FrameMap["Button"], props: Element<"button">["props"]): NativeButtonPaintMotion | undefined;
|
|
166
|
+
/** Observe a native Button's changed CSS input flag. Return true to flush changed manual bindings. */
|
|
167
|
+
buttonPaintStateChanged?(this: void, button: FrameMap["Button"], state: Parameters<NativePaintState["set"]>[0],
|
|
168
|
+
active: boolean): boolean | void;
|
|
169
|
+
statusbar?(this: void, bar: StatusBar, props: StatusBarProps, scope: RuntimeScope): void;
|
|
170
|
+
image?(this: void, texture: Texture, parent: Frame, props: Element<"image">["props"]): void;
|
|
171
|
+
/** Style a native edit box; `hint` is its placeholder FontString when the element has one. */
|
|
172
|
+
input?(this: void, edit: FrameMap["EditBox"], props: Element<"editbox">["props"], scope: RuntimeScope, hint?: FontString): void;
|
|
173
|
+
/** Supply default CSS for an edit box and its placeholder. Unstyled boxes keep their own surface and insets. */
|
|
174
|
+
inputSkin?: NativeInputSkin;
|
|
175
|
+
/** Style a native check button and its caption with host-owned art. State textures follow `SetChecked`/`SetEnabled`. */
|
|
176
|
+
checkbox?(this: void, check: FrameMap["CheckButton"], caption: FontString, props: Element<"checkbox">["props"], scope: RuntimeScope): void;
|
|
177
|
+
/** Supply decorative children and CSS for a native check button with the usual native input. */
|
|
178
|
+
checkboxSkin?: NativeCheckboxSkin;
|
|
179
|
+
/** Style a native slider and its caption with host-owned art. The stock template remains when this is omitted. */
|
|
180
|
+
range?(this: void, slider: FrameMap["Slider"], caption: FontString, props: Element<"range">["props"], scope: RuntimeScope): void;
|
|
181
|
+
/** Supply a native slider's track, variable fill and thumb decoration. Input and thumb movement stay native. */
|
|
182
|
+
rangeSkin?: NativeRangeSkin;
|
|
183
|
+
/** Style a native dropdown button with host-owned art. Its label stays the template's `Text`; the menu stays Blizzard's. */
|
|
184
|
+
listbox?(this: void, dropdown: FrameMap["DropdownButton"], props: Element<"listbox">["props"], scope: RuntimeScope): void;
|
|
185
|
+
/** Supply CSS and decoration for a native dropdown without changing menu behavior. */
|
|
186
|
+
listboxSkin?: NativeListboxSkin;
|
|
187
|
+
slot?(this: void, parent: Frame, name: string, scope: RuntimeScope): Frame | FontString | undefined;
|
|
188
|
+
/** Supply caller-owned frames for absolute positioning. Placement-only requests keep visibility with the caller and can bind a single right inset. */
|
|
189
|
+
borrowedSlot?(this: void, parent: Frame, name: string): BorrowedSlot | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Lay the view out as CSS does. A frame without `display` is a block: its children stack, fill its width and size
|
|
192
|
+
* it. Text is inline and controls are inline-block: runs of them share wrapping lines. Every element without
|
|
193
|
+
* `anchor` or `position: absolute` takes part in its parent's flow, with padding, margins and percent sizes.
|
|
194
|
+
* `anchor` stays the explicit native escape hatch and leaves the flow. Without this option only display flex and
|
|
195
|
+
* grid lay children out, and a child without an anchor is centered on its parent.
|
|
196
|
+
*/
|
|
197
|
+
cssFlow?: boolean;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
type MountOptions = NativeViewOptions & {
|
|
201
|
+
newEventScope(this: void): RuntimeScope;
|
|
202
|
+
manualControl?(this: void, owner: RuntimeScope, nested: boolean): ManualControlBindings | undefined;
|
|
203
|
+
mediaContainer?: Frame;
|
|
204
|
+
stageInitialLayout?: StageInitialLayout;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
interface ManualControlBindings {
|
|
208
|
+
scope: RuntimeScope;
|
|
209
|
+
flush(this: void): void;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function interactiveControlPaint(paint: NativePaintState | undefined, flush?: ManualControlBindings["flush"],
|
|
213
|
+
onChange?: (this: void, state: Parameters<NativePaintState["set"]>[0], active: boolean) => boolean | void) {
|
|
214
|
+
if (paint === undefined || (flush === undefined && onChange === undefined)) return paint;
|
|
215
|
+
return {
|
|
216
|
+
needs: paint.needs,
|
|
217
|
+
set(this: void, state: Parameters<NativePaintState["set"]>[0], active: boolean) {
|
|
218
|
+
const previous = paint.current();
|
|
219
|
+
const changed = onChange !== undefined && paint.needs(state) && paint.isActive(state) !== active;
|
|
220
|
+
paint.set(state, active);
|
|
221
|
+
const bindingsChanged = changed && onChange?.(state, active) === true;
|
|
222
|
+
if (paint.current() !== previous || bindingsChanged) flush?.();
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function bindViewMedia(node: UIElement, scope: RuntimeScope, options: MountOptions) {
|
|
228
|
+
if (options.media === undefined) return fail("Media queries require a breakpoint table in the native view options");
|
|
229
|
+
const result = observeContainer(options.media, options.mediaContainer, scope, options.newEventScope);
|
|
230
|
+
const reads = node.mediaReads;
|
|
231
|
+
if (result.ok && reads !== undefined) for (const read of reads as OwnedReadonlyArray<MediaRead>) read(result.value, scope);
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function bind<T extends string | boolean | number | Anchor>(scope: RuntimeScope, value: Binding<T>,
|
|
236
|
+
apply: (this: void, value: T) => void, validate?: (this: void, value: T) => Failure | undefined) {
|
|
237
|
+
return bindValue(scope, value, apply, (previous, current) => !isSecret(previous) && !isSecret(current) && previous === current, validate);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Apply a readable, positive scale to an existing native frame. */
|
|
241
|
+
export function applyFrameScale(this: void, frame: Frame, value: number): void {
|
|
242
|
+
const scale = reveal(value);
|
|
243
|
+
if (scale !== undefined && Number.isFinite(scale) && scale > 0) frame.SetScale(scale);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function bindFrameScale(frame: Frame, scope: RuntimeScope, value: Binding<number> | undefined): Failure | undefined {
|
|
247
|
+
if (value === undefined) return;
|
|
248
|
+
return bind(scope, value, next => applyFrameScale(frame, next));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function bindEditInsets(edit: FrameMap["EditBox"], padding: NativeStyle["padding"], scope: RuntimeScope): Failure | undefined {
|
|
252
|
+
if (padding === undefined) return;
|
|
253
|
+
type Insets = readonly [number, number, number, number];
|
|
254
|
+
let original: Insets | undefined;
|
|
255
|
+
let previous: Insets | undefined;
|
|
256
|
+
const observed = scope.watchEffect(() => {
|
|
257
|
+
const read = readLayoutValue(padding);
|
|
258
|
+
if (!read.ok) return read;
|
|
259
|
+
const value = read.value;
|
|
260
|
+
if (value === undefined) {
|
|
261
|
+
if (original === undefined) return;
|
|
262
|
+
edit.SetTextInsets(...original);
|
|
263
|
+
original = undefined;
|
|
264
|
+
previous = undefined;
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const [top, right = top, bottom = top, left = right] = typeof value === "number" ? [value] : value;
|
|
268
|
+
const insets = [left, right, top, bottom] as const;
|
|
269
|
+
if (insets.some(amount => isSecret(amount) || !Number.isFinite(amount) || amount < 0)) return fail("Invalid edit box padding");
|
|
270
|
+
const applied = previous;
|
|
271
|
+
if (applied !== undefined && insets.every((amount, index) => amount === applied[index])) return;
|
|
272
|
+
if (original === undefined) {
|
|
273
|
+
const [nativeLeft, nativeRight, nativeTop, nativeBottom] = edit.GetTextInsets();
|
|
274
|
+
original = [nativeLeft, nativeRight, nativeTop, nativeBottom];
|
|
275
|
+
}
|
|
276
|
+
edit.SetTextInsets(left, right, top, bottom);
|
|
277
|
+
previous = insets;
|
|
278
|
+
});
|
|
279
|
+
return observed.ok ? undefined : observed;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function drawOrder(order: number): number {
|
|
283
|
+
return Math.max(-8, Math.min(7, order));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function placeFrame(frame: Region & Pick<Frame, "SetFrameLevel">, parent: FrameParent, props: Layout,
|
|
287
|
+
scope: RuntimeScope, motion?: TransitionOptions, skipStyleLevel = false, flex?: LayoutParent, paint?: NativePaintState,
|
|
288
|
+
startAfter?: NativeStartTarget, endBefore?: NativeEndTarget) {
|
|
289
|
+
const order = skipStyleLevel ? undefined : props.style?.zIndex;
|
|
290
|
+
if (order !== undefined && Number.isInteger(order)) {
|
|
291
|
+
const owner = parent as FrameParent & Partial<Pick<Frame, "GetFrameLevel">>;
|
|
292
|
+
const level = reveal(owner.GetFrameLevel?.());
|
|
293
|
+
if (level !== undefined) frame.SetFrameLevel(Math.max(0, Math.min(maximumFrameLevel, level + 1 + order)));
|
|
294
|
+
}
|
|
295
|
+
return place(frame, parent, props, scope, motion, flex, undefined, undefined, paint, undefined, startAfter, endBefore);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function place(region: Region, parent: FrameParent, props: Layout, scope: RuntimeScope, motion?: TransitionOptions,
|
|
299
|
+
flex?: LayoutParent, measure?: FlexNode["measure"], minContentWidth?: FlexNode["minContentWidth"], paint?: NativePaintState,
|
|
300
|
+
afterWidth?: (this: void, width: number) => void, startAfter?: NativeStartTarget, endBefore?: NativeEndTarget) {
|
|
301
|
+
const absolute = props.anchor === undefined && props.style?.position === "absolute";
|
|
302
|
+
if (startAfter !== undefined && !absolute) return fail("A native start target requires absolute CSS positioning");
|
|
303
|
+
if (endBefore !== undefined && !absolute) return fail("A native end target requires absolute CSS positioning");
|
|
304
|
+
const attached = flex !== undefined && !(flex instanceof NativeLayoutItem) && props.anchor === undefined && !absolute
|
|
305
|
+
? attachLayoutItem(flex, region, parent, props, scope, false, measure, false, minContentWidth, afterWidth)
|
|
306
|
+
: undefined;
|
|
307
|
+
if (attached?.ok === false) return attached;
|
|
308
|
+
const item = flex instanceof NativeLayoutItem ? flex : attached?.value;
|
|
309
|
+
let point: Anchor["point"] | undefined;
|
|
310
|
+
let x = 0, y = 0, motionOffset = 0;
|
|
311
|
+
let opacity = 1, motionAlpha = 1;
|
|
312
|
+
let stateOpacity: number | undefined, lastAlpha: number | undefined;
|
|
313
|
+
const width = props.width ?? props.style?.width;
|
|
314
|
+
const height = props.height ?? props.style?.height;
|
|
315
|
+
const absoluteOffset = absolute && motion !== undefined ? ref(0) : undefined;
|
|
316
|
+
const baseOpacity = props.opacity ?? props.style?.opacity;
|
|
317
|
+
const drawAlpha = paint?.usesOpacity === true ? (force = false) => {
|
|
318
|
+
const next = (stateOpacity ?? opacity) * motionAlpha;
|
|
319
|
+
if (!force && lastAlpha === next) return;
|
|
320
|
+
region.SetAlpha(next);
|
|
321
|
+
lastAlpha = next;
|
|
322
|
+
} : undefined;
|
|
323
|
+
const anchor = (at: Anchor["point"], x: number, y: number) => {
|
|
324
|
+
if (!props.fullWidth) {
|
|
325
|
+
region.SetPoint(at, parent, at, x, y);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const left = at.startsWith("TOP") ? "TOPLEFT" : at.startsWith("BOTTOM") ? "BOTTOMLEFT" : "LEFT";
|
|
329
|
+
const right = at.startsWith("TOP") ? "TOPRIGHT" : at.startsWith("BOTTOM") ? "BOTTOMRIGHT" : "RIGHT";
|
|
330
|
+
region.SetPoint(left, parent, left, x, y);
|
|
331
|
+
region.SetPoint(right, parent, right, x, y);
|
|
332
|
+
};
|
|
333
|
+
const skipAnchor = item?.inFlow || props.unanchored === true && props.anchor === undefined;
|
|
334
|
+
const anchored = absolute && props.style !== undefined ? bindAbsolutePosition(region, parent, scope, props.style, width, height, props.fullWidth,
|
|
335
|
+
absoluteOffset, startAfter, endBefore) : skipAnchor ? undefined : bind(scope, props.anchor ?? { point: "CENTER" }, next => {
|
|
336
|
+
const nextX = next.x ?? 0, nextY = next.y ?? 0;
|
|
337
|
+
if (point === next.point && x === nextX && y === nextY) return;
|
|
338
|
+
if (point !== undefined && point !== next.point) region.ClearAllPoints();
|
|
339
|
+
point = next.point;
|
|
340
|
+
x = nextX;
|
|
341
|
+
y = nextY;
|
|
342
|
+
anchor(point, x, y + motionOffset);
|
|
343
|
+
});
|
|
344
|
+
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)
|
|
356
|
+
?? (baseOpacity !== undefined ? bind(scope, baseOpacity, value => {
|
|
357
|
+
const next = reveal(value);
|
|
358
|
+
if (next === undefined) return;
|
|
359
|
+
opacity = next;
|
|
360
|
+
if (drawAlpha === undefined) region.SetAlpha(opacity * motionAlpha);
|
|
361
|
+
else drawAlpha();
|
|
362
|
+
}) : undefined);
|
|
363
|
+
if (layoutFailure) return layoutFailure;
|
|
364
|
+
if (drawAlpha !== undefined && paint !== undefined) {
|
|
365
|
+
let previousRepaint: number | undefined;
|
|
366
|
+
const opacityPaint = scope.watchEffect(() => {
|
|
367
|
+
const appearance = paint.evaluate();
|
|
368
|
+
if (!appearance.ok) return appearance;
|
|
369
|
+
const repaint = paint.repaint?.value;
|
|
370
|
+
const force = previousRepaint !== undefined && previousRepaint !== repaint;
|
|
371
|
+
previousRepaint = repaint;
|
|
372
|
+
const next = reveal(appearance.value.opacity);
|
|
373
|
+
stateOpacity = next;
|
|
374
|
+
drawAlpha(force);
|
|
375
|
+
});
|
|
376
|
+
if (!opacityPaint.ok) return opacityPaint;
|
|
377
|
+
}
|
|
378
|
+
const applyShown = (shown: boolean) => {
|
|
379
|
+
if (item === undefined) region.SetShown(shown);
|
|
380
|
+
else if (!isSecret(shown)) item.visibility(shown);
|
|
381
|
+
};
|
|
382
|
+
if (props.style?.display === "none") {
|
|
383
|
+
region.SetShown(false);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const visibilityTarget = motion && (baseOpacity !== undefined || drawAlpha !== undefined || item !== undefined) ? {
|
|
387
|
+
SetShown(this: object, shown: boolean) { applyShown(shown); },
|
|
388
|
+
SetAlpha(this: object, alpha: number) {
|
|
389
|
+
motionAlpha = alpha;
|
|
390
|
+
if (drawAlpha === undefined) region.SetAlpha(opacity * motionAlpha);
|
|
391
|
+
else drawAlpha();
|
|
392
|
+
},
|
|
393
|
+
} : region;
|
|
394
|
+
const show = motion ? animateVisibility(visibilityTarget, parent, scope, motion, offset => {
|
|
395
|
+
if (absoluteOffset !== undefined) {
|
|
396
|
+
absoluteOffset.value = offset;
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
motionOffset = offset;
|
|
400
|
+
if (!skipAnchor) anchor(point ?? "CENTER", x, y + offset);
|
|
401
|
+
}) : applyShown;
|
|
402
|
+
if (motion || (item === undefined && props.shown !== undefined)) return bind(scope, props.shown ?? true, show);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function bindColor(scope: RuntimeScope, color: Binding<string>, environment: StyleEnvironment | undefined,
|
|
406
|
+
apply: (this: void, color: string) => void): Failure | undefined {
|
|
407
|
+
if (isSecret(color)) return;
|
|
408
|
+
if (typeof color === "string" && !color.startsWith("var(")) {
|
|
409
|
+
apply(color);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
let previous: string | undefined;
|
|
413
|
+
const subscription = scope.watchEffect(() => {
|
|
414
|
+
const value = styleValue(color, isSecret);
|
|
415
|
+
if (!value.ok) return value;
|
|
416
|
+
if (value.value === undefined) return;
|
|
417
|
+
const resolved = resolveStyleValue(value.value, environment);
|
|
418
|
+
if (!resolved.ok) return resolved;
|
|
419
|
+
const next = resolved.value ?? "";
|
|
420
|
+
if (isSecret(next) || previous === next) return;
|
|
421
|
+
apply(next);
|
|
422
|
+
previous = next;
|
|
423
|
+
});
|
|
424
|
+
return subscription.ok ? undefined : subscription;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function mountBackground(frame: Frame, color: string | undefined, scope: RuntimeScope, environment?: StyleEnvironment) {
|
|
428
|
+
if (color === undefined) return;
|
|
429
|
+
const texture = frame.CreateTexture(undefined, "BACKGROUND", undefined, -8);
|
|
430
|
+
texture.SetAllPoints(frame);
|
|
431
|
+
return bindColor(scope, color, environment, value => {
|
|
432
|
+
const channels = readCssColor(value);
|
|
433
|
+
if (channels === undefined) {
|
|
434
|
+
texture.Hide();
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
texture.SetColorTexture(channels[0], channels[1], channels[2], channels[3]);
|
|
438
|
+
texture.Show();
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/** Box a WoW number so application refs can publish it without comparing the number. */
|
|
443
|
+
export function statusBarValue(this: void, value: NativeStatusBarValue): StatusBarValue {
|
|
444
|
+
return { nativeValue: value } as StatusBarValue;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function readStatusBarBinding(binding: Binding<StatusBarValue>): Result<StatusBarValue> {
|
|
448
|
+
if (typeof binding === "number" || "nativeValue" in binding) return ok(binding);
|
|
449
|
+
const value = binding.value;
|
|
450
|
+
return typeof value === "object" && "ok" in value ? value : ok(value);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function unwrapStatusBarValue(value: StatusBarValue): NativeStatusBarValue {
|
|
454
|
+
return typeof value === "number" ? value : value.nativeValue as NativeStatusBarValue;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function bindStatusBar(scope: RuntimeScope, bar: StatusBar, { min, max, value, smooth }: StatusBarProps): Failure | undefined {
|
|
458
|
+
const interpolation = smooth ? api.Enum?.StatusBarInterpolation?.ExponentialEaseOut : undefined;
|
|
459
|
+
let previousMin: StatusBarValue | undefined;
|
|
460
|
+
let previousMax: StatusBarValue | undefined;
|
|
461
|
+
let previousValue: StatusBarValue | undefined;
|
|
462
|
+
const subscription = scope.watchEffect(() => {
|
|
463
|
+
const nextMin = readStatusBarBinding(min);
|
|
464
|
+
const nextMax = readStatusBarBinding(max);
|
|
465
|
+
const nextValue = readStatusBarBinding(value);
|
|
466
|
+
if (!nextMin.ok) return nextMin;
|
|
467
|
+
if (!nextMax.ok) return nextMax;
|
|
468
|
+
if (!nextValue.ok) return nextValue;
|
|
469
|
+
|
|
470
|
+
// Compare plain numbers and wrapper identities only. The payload reaches native setters directly.
|
|
471
|
+
const boundsChanged = previousMin !== nextMin.value || previousMax !== nextMax.value;
|
|
472
|
+
if (boundsChanged) bar.SetMinMaxValues(unwrapStatusBarValue(nextMin.value), unwrapStatusBarValue(nextMax.value));
|
|
473
|
+
if (boundsChanged || previousValue !== nextValue.value) {
|
|
474
|
+
bar.SetValue(unwrapStatusBarValue(nextValue.value), interpolation);
|
|
475
|
+
}
|
|
476
|
+
previousMin = nextMin.value;
|
|
477
|
+
previousMax = nextMax.value;
|
|
478
|
+
previousValue = nextValue.value;
|
|
479
|
+
});
|
|
480
|
+
return subscription.ok ? undefined : subscription;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function onlyChild(node: Element<"transition">) {
|
|
484
|
+
const children = node.children as NativeChildren;
|
|
485
|
+
return children.length === 1 ? children[0] : undefined;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function mountPortal(parent: Frame, node: Element<"portal">, scope: RuntimeScope, options: MountOptions,
|
|
489
|
+
group: LogicalGroup, environment?: StyleEnvironment, typography?: NativeTextStyle): Failure | undefined {
|
|
490
|
+
const target = node.props.target === undefined ? options.portalRoot ?? rawField<Frame>(api, "UIParent") : node.props.target.native;
|
|
491
|
+
if (target === undefined || !accessibleLayerRegion(target) || !unprotected(target)) {
|
|
492
|
+
return fail("A native portal needs an accessible unprotected root");
|
|
493
|
+
}
|
|
494
|
+
const portal = createFrame("Frame", undefined, target);
|
|
495
|
+
const owner = scope.fork();
|
|
496
|
+
owner.onDispose(() => portal.Hide());
|
|
497
|
+
portal.SetAllPoints(target);
|
|
498
|
+
function updateVisibility(this: void) {
|
|
499
|
+
const shown = typeof parent.IsVisible === "function" ? reveal(parent.IsVisible()) : reveal(parent.IsShown());
|
|
500
|
+
portal.SetShown(shown === true);
|
|
501
|
+
}
|
|
502
|
+
updateVisibility();
|
|
503
|
+
const observation = bindElementEvents(parent, { onShow: updateVisibility, onHide: updateVisibility }, owner,
|
|
504
|
+
options.newEventScope, options.elementEvents, undefined, true);
|
|
505
|
+
if (observation !== undefined) return observation;
|
|
506
|
+
const branch = mountLogicalGroup(owner, group);
|
|
507
|
+
for (const child of node.children as NativeChildren) {
|
|
508
|
+
const failure = mountChild(portal, child, owner, options, branch, undefined, environment, undefined, typography);
|
|
509
|
+
if (failure !== undefined) return failure;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function bindRegionEvents(parent: Frame, region: Region, props: Element<"text">["props"] | Element<"image">["props"],
|
|
514
|
+
scope: RuntimeScope, options: MountOptions, logical: LogicalNode, paint?: NativePaintState) {
|
|
515
|
+
if (!hasElementInput(props) && paint?.needs("hover") !== true && paint?.needs("active") !== true) return;
|
|
516
|
+
if (options.regionsOnly === true) return fail("Native region mounts do not create input frames");
|
|
517
|
+
const input = createFrame("Frame", undefined, parent);
|
|
518
|
+
input.SetAllPoints(region);
|
|
519
|
+
logical.hitTarget = input;
|
|
520
|
+
scope.onDispose(() => input.Hide());
|
|
521
|
+
const { shown } = props;
|
|
522
|
+
if (shown !== undefined) {
|
|
523
|
+
const failure = bind(scope, shown, value => input.SetShown(value));
|
|
524
|
+
if (failure) return failure;
|
|
525
|
+
}
|
|
526
|
+
return bindElementEvents(input, props, scope, options.newEventScope, options.elementEvents, undefined, false, logical, paint);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function mediaPaint(style: NativeStyle | undefined, field: "color" | "backgroundColor"): style is NativeStyle {
|
|
530
|
+
type Variant = NonNullable<NativeStyle["mediaStyles"]>[number];
|
|
531
|
+
const variants = style?.mediaStyles as OwnedReadonlyArray<Variant> | undefined;
|
|
532
|
+
if (variants === undefined) return false;
|
|
533
|
+
for (const variant of variants) {
|
|
534
|
+
if (variant.style[field] !== undefined) return true;
|
|
535
|
+
if (field !== "backgroundColor") continue;
|
|
536
|
+
const recipes = variant.style.styleTokens as OwnedReadonlyArray<CssTokenRecipe> | undefined;
|
|
537
|
+
if (recipes === undefined) continue;
|
|
538
|
+
for (const recipe of recipes) {
|
|
539
|
+
if ((recipe.path as OwnedReadonlyArray<string | number>)[0] === field) return true;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
function bindFramePaint(frame: Frame, style: Layout["style"], paint: NativePaintState | undefined, scope: RuntimeScope,
|
|
546
|
+
options: MountOptions, motion?: TransitionOptions, environment?: StyleEnvironment, liveStyle?: ReadCssStyle, color?: NativeStateColor,
|
|
547
|
+
nativeRoundedArt?: true, buttonTiming?: ButtonPaintTiming) {
|
|
548
|
+
if (nativeRoundedArt === true && style === undefined) return fail("Native rounded art requires CSS surface styles");
|
|
549
|
+
if (style?.overflow === "hidden") {
|
|
550
|
+
if (typeof frame.SetClipsChildren !== "function") return fail("CSS overflow hidden requires native clipping");
|
|
551
|
+
frame.SetClipsChildren(true);
|
|
552
|
+
}
|
|
553
|
+
if (style !== undefined && (nativeRoundedArt === true || hasCssSurface(style, paint))) {
|
|
554
|
+
const surface = mountCssSurface(scope, frame, style, paint, options.rounded, environment, liveStyle, nativeRoundedArt);
|
|
555
|
+
if (!surface.ok) return surface;
|
|
556
|
+
return bindStatePaint(scope, paint, { environment, motion, reduceMotion: options.reduceMotion, liveStyle, buttonTiming },
|
|
557
|
+
{ parent: frame, anchor: frame, base: style, css: surface.value }, color);
|
|
558
|
+
}
|
|
559
|
+
if (liveStyle !== undefined && mediaPaint(style, "backgroundColor")) {
|
|
560
|
+
return bindStatePaint(scope, paint, { environment, motion, reduceMotion: options.reduceMotion, liveStyle, buttonTiming },
|
|
561
|
+
{ parent: frame, anchor: frame, base: { backgroundColor: style.backgroundColor ?? "" } }, color);
|
|
562
|
+
}
|
|
563
|
+
if (paint === undefined) return mountBackground(frame, style?.backgroundColor, scope, environment);
|
|
564
|
+
return bindStatePaint(scope, paint, { environment, motion, reduceMotion: options.reduceMotion, liveStyle, buttonTiming },
|
|
565
|
+
{ parent: frame, anchor: frame }, color);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function bindControlPaint(frame: Frame, style: Layout["style"], paint: NativePaintState | undefined, scope: RuntimeScope, options: MountOptions,
|
|
569
|
+
motion?: TransitionOptions, environment?: StyleEnvironment, liveStyle?: ReadCssStyle, color?: NativeStateColor) {
|
|
570
|
+
const mounted = bindFramePaint(frame, style, paint, scope, options, motion, environment, liveStyle, color);
|
|
571
|
+
if (mounted !== undefined || paint === undefined) return mounted;
|
|
572
|
+
return bindElementEvents(frame, {}, scope, options.newEventScope, options.elementEvents, undefined, true, undefined, paint);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function bindRegionPaint(parent: Frame, region: Region, style: Layout["style"], paint: NativePaintState | undefined, scope: RuntimeScope,
|
|
576
|
+
options: MountOptions, motion?: TransitionOptions, environment?: StyleEnvironment, liveStyle?: ReadCssStyle, color?: NativeStateColor) {
|
|
577
|
+
if (options.regionsOnly === true && (style?.border !== undefined || style?.backgroundColor !== undefined
|
|
578
|
+
|| style?.backgroundImage !== undefined || paint?.usesBackgroundColor === true || paint?.usesBackgroundImage === true)) {
|
|
579
|
+
return fail("Native region mounts use region tint for paint, without a separate CSS surface");
|
|
580
|
+
}
|
|
581
|
+
if (style !== undefined && (style.border !== undefined || style.borderRadius !== undefined) && hasCssSurface(style, paint)) {
|
|
582
|
+
const host = createFrame("Frame", undefined, parent);
|
|
583
|
+
host.SetAllPoints(region);
|
|
584
|
+
scope.onDispose(() => host.Hide());
|
|
585
|
+
return bindFramePaint(host, style, paint, scope, options, motion, environment, liveStyle, color);
|
|
586
|
+
}
|
|
587
|
+
if (paint === undefined && style?.backgroundImage === undefined) return;
|
|
588
|
+
return bindStatePaint(scope, paint, { environment, motion, reduceMotion: options.reduceMotion, liveStyle },
|
|
589
|
+
{ parent, anchor: region, base: style }, color);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
type VertexChannel = Parameters<Texture["SetVertexColor"]>[0];
|
|
593
|
+
|
|
594
|
+
function hasVertexChannel(value: VertexChannel | undefined): value is VertexChannel {
|
|
595
|
+
return isSecret(value) || value !== undefined;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function captureImageTint(texture: Texture) {
|
|
599
|
+
// The texture setter accepts the original opaque channels.
|
|
600
|
+
const [red, green, blue, alpha] = texture.GetVertexColor();
|
|
601
|
+
if (!hasVertexChannel(red) || !hasVertexChannel(green) || !hasVertexChannel(blue) || !hasVertexChannel(alpha)) return;
|
|
602
|
+
return () => texture.SetVertexColor(red, green, blue, alpha);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function captureStatusBarTint(bar: StatusBar) {
|
|
606
|
+
const [rawRed, rawGreen, rawBlue, rawAlpha] = bar.GetStatusBarColor();
|
|
607
|
+
const red = reveal(rawRed), green = reveal(rawGreen), blue = reveal(rawBlue), alpha = reveal(rawAlpha);
|
|
608
|
+
if (red === undefined || green === undefined || blue === undefined || alpha === undefined) return;
|
|
609
|
+
return () => bar.SetStatusBarColor(red, green, blue, alpha);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
function bindNativeTint(scope: RuntimeScope, style: Layout["style"], paint: NativePaintState | undefined, options: MountOptions,
|
|
613
|
+
setTint: NativeStateColor["write"], captureTint: (this: void) => (() => void) | undefined,
|
|
614
|
+
motion?: TransitionOptions, environment?: StyleEnvironment, liveStyle?: ReadCssStyle, inheritedColor?: NativeTextStyle["color"],
|
|
615
|
+
variables?: StyleVariables, buttonTiming?: ButtonPaintTiming, visible?: (this: void) => boolean) {
|
|
616
|
+
const hasColor = inheritedColor !== undefined || style?.color !== undefined || paint?.usesColor === true
|
|
617
|
+
|| mediaPaint(style, "color");
|
|
618
|
+
if (!hasColor) return;
|
|
619
|
+
|
|
620
|
+
let restoreTint: ((this: void) => void) | undefined;
|
|
621
|
+
return bindStatePaint(scope, paint, { environment, motion, reduceMotion: options.reduceMotion, buttonTiming, visible }, undefined, {
|
|
622
|
+
fallback: () => {
|
|
623
|
+
const current = liveStyle?.() ?? style;
|
|
624
|
+
const authored = current?.color;
|
|
625
|
+
if (inheritedColor === undefined) return ok(authored);
|
|
626
|
+
if (authored === undefined) return inheritedColor();
|
|
627
|
+
let unset = false;
|
|
628
|
+
const value = resolveStyleValue(authored, name => {
|
|
629
|
+
const resolved = environment?.(name) ?? ok(undefined);
|
|
630
|
+
if (resolved.ok && resolved.value === undefined && variables?.[name] !== undefined) unset = true;
|
|
631
|
+
return resolved;
|
|
632
|
+
});
|
|
633
|
+
// A local binding can explicitly clear the authored color. With no binding, keep the CSS fallback.
|
|
634
|
+
return value.ok && (unset || value.value === undefined) ? inheritedColor() : value;
|
|
635
|
+
},
|
|
636
|
+
write: (r, g, b, a) => {
|
|
637
|
+
restoreTint ??= captureTint();
|
|
638
|
+
if (restoreTint !== undefined) setTint(r, g, b, a);
|
|
639
|
+
},
|
|
640
|
+
restore: () => {
|
|
641
|
+
restoreTint?.();
|
|
642
|
+
restoreTint = undefined;
|
|
643
|
+
},
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
type ImageSize = Binding<number | "auto"> | undefined;
|
|
648
|
+
/** An image's manual size: a static percent needs a flow, so out of flow it counts as auto. */
|
|
649
|
+
function fixedSize<T>(size: T): Exclude<T, `${number}%`> | undefined {
|
|
650
|
+
return typeof size === "string" && size.endsWith("%") ? undefined : size as Exclude<T, `${number}%`>;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
const inlineBlocks: Partial<Record<UIElement["kind"], true>> = {
|
|
654
|
+
button: true, checkbox: true, range: true, listbox: true, editbox: true, image: true, statusbar: true,
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* CSS defaults for `cssFlow`: a frame is a block, text is inline, a control is inline-block. Anchored and absolutely
|
|
659
|
+
* positioned nodes keep theirs: they are placed by hand, and their children keep that placement too.
|
|
660
|
+
*/
|
|
661
|
+
function withDefaultDisplay(node: UIElement): UIElement {
|
|
662
|
+
const props = node.props as { anchor?: unknown; style?: NativeStyle };
|
|
663
|
+
if (props.anchor !== undefined || props.style?.position === "absolute" || props.style?.display !== undefined
|
|
664
|
+
|| props.style?.layoutDisplay !== undefined) return node;
|
|
665
|
+
const display = node.kind === "frame" ? "block" : node.kind === "text" ? "inline" : inlineBlocks[node.kind] ? "inline-block" : undefined;
|
|
666
|
+
if (display === undefined) return node;
|
|
667
|
+
return { ...node as OwnedRecord<UIElement>,
|
|
668
|
+
props: { ...node.props as OwnedRecord<typeof node.props>, style: { ...props.style as OwnedRecord<NativeStyle> | undefined, display } } } as UIElement;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
function flowContainer(display: NativeStyle["display"]) {
|
|
672
|
+
return display === "flex" || display === "grid" || display === "block" || display === "inline" || display === "inline-block";
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
function hideStockControlArt(control: Frame, caption?: FontString) {
|
|
676
|
+
for (const raw of [...control.GetRegions(), ...control.GetChildren()]) {
|
|
677
|
+
const region = reveal(raw) as Pick<Frame, "Hide"> | undefined;
|
|
678
|
+
if (region !== undefined && region !== caption) region.Hide();
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function mountRangeArtView(slider: FrameMap["Slider"], size: number, render: NativeRangeSkin["render"], scope: RuntimeScope,
|
|
683
|
+
options: MountOptions, group: LogicalGroup, environment?: StyleEnvironment) {
|
|
684
|
+
const art = mountRangeArt(slider, size, scope);
|
|
685
|
+
if (!art.ok) return art;
|
|
686
|
+
const visual = withReactiveScope(scope, render);
|
|
687
|
+
if (!visual.ok) return visual;
|
|
688
|
+
const failure = mountChild(art.value.track, visual.value.track, scope, options, group, undefined, environment)
|
|
689
|
+
?? mountChild(art.value.fill, visual.value.fill, scope, options, group, undefined, environment)
|
|
690
|
+
?? mountChild(art.value.thumb, visual.value.thumb, scope, options, group, undefined, environment);
|
|
691
|
+
return failure ?? art;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function hideCheckboxArt(check: FrameMap["CheckButton"], caption?: FontString) {
|
|
695
|
+
hideStockControlArt(check, caption);
|
|
696
|
+
check.ClearNormalTexture();
|
|
697
|
+
check.ClearPushedTexture();
|
|
698
|
+
check.ClearHighlightTexture();
|
|
699
|
+
check.ClearDisabledTexture();
|
|
700
|
+
reveal(check.GetCheckedTexture())?.SetAlpha(0);
|
|
701
|
+
reveal(check.GetDisabledCheckedTexture())?.SetAlpha(0);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function bindSkinCaption(caption: FontString, label: string, style: StyleClass, scope: RuntimeScope,
|
|
705
|
+
options: NativeViewOptions, environment?: StyleEnvironment,
|
|
706
|
+
position?: { parent: Frame; onTextPaint?: Parameters<typeof bindTextColor>[3] }) {
|
|
707
|
+
const prepared = prepareCssStyle(scope, { style: resolveStyleClasses(style).style }, environment, false);
|
|
708
|
+
if (!prepared.ok) return prepared;
|
|
709
|
+
const props = prepared.value.props;
|
|
710
|
+
if (position !== undefined && props.style?.position === "absolute") {
|
|
711
|
+
caption.ClearAllPoints();
|
|
712
|
+
const placed = place(caption, position.parent, props, scope);
|
|
713
|
+
if (placed !== undefined) return placed;
|
|
714
|
+
}
|
|
715
|
+
options.text?.(caption, { ...props as OwnedRecord<typeof props>, value: label }, scope);
|
|
716
|
+
const appearance = inheritTextStyle(undefined, props.style, environment, undefined, undefined, prepared.value.read);
|
|
717
|
+
return bindTextTypography(caption, scope, {}, appearance, options)
|
|
718
|
+
?? bindTextColor(caption, scope, appearance?.color, position?.onTextPaint);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function mountFrame(frame: Frame, parent: FrameParent, node: Element<"frame">, scope: RuntimeScope,
|
|
722
|
+
options: MountOptions, group: LogicalGroup, motion?: TransitionOptions, environment?: StyleEnvironment, skipStyleLevel = false,
|
|
723
|
+
flow?: NativeLayoutGroup, typography?: NativeTextStyle, liveStyle?: ReadCssStyle, unanchored = false): Failure | undefined {
|
|
724
|
+
const { style } = node.props;
|
|
725
|
+
const display = style?.display;
|
|
726
|
+
const container = flowContainer(display) && style?.overflow !== "scroll";
|
|
727
|
+
const decorativeBorder = node.props.nativeRoundedArt === true;
|
|
728
|
+
let geometry: Layout = includeCssBorderPadding(scope, node.props, liveStyle, decorativeBorder);
|
|
729
|
+
if (unanchored) geometry = { ...geometry as OwnedRecord<typeof geometry>, unanchored: true };
|
|
730
|
+
// A block that is not in a flow (a view root) takes its parent's width, as a block in the page does.
|
|
731
|
+
if (options.cssFlow === true && flow === undefined && display === "block"
|
|
732
|
+
&& geometry.width === undefined && geometry.style?.width === undefined) geometry = { ...geometry as OwnedRecord<typeof geometry>, fullWidth: true };
|
|
733
|
+
const flex = flow !== undefined && node.props.anchor === undefined && node.props.style?.position !== "absolute"
|
|
734
|
+
? attachLayoutItem(flow, frame, parent, geometry, scope, container)
|
|
735
|
+
: container ? mountLayoutRoot(frame, parent, geometry, scope, options.layoutDiagnostics, options.stageInitialLayout) : undefined;
|
|
736
|
+
if (flex?.ok === false) return flex;
|
|
737
|
+
const paint = createNativePaintState(style, environment);
|
|
738
|
+
const endBefore = options.frameEndBefore?.(parent, node.props);
|
|
739
|
+
const placed = placeFrame(frame, parent, geometry, scope, motion, skipStyleLevel, flex?.value, paint, undefined,
|
|
740
|
+
endBefore === undefined ? undefined : { kind: "frame", target: endBefore })
|
|
741
|
+
?? bindFramePaint(frame, style, paint, scope, options, motion, environment, liveStyle, undefined, node.props.nativeRoundedArt);
|
|
742
|
+
if (placed) return placed;
|
|
743
|
+
options?.frame?.(frame, node.props, scope);
|
|
744
|
+
const logical = mountViewNode(scope, group, "frame", frame, node.props);
|
|
745
|
+
const appearance = inheritTextStyle(typography, style, environment, paint, undefined, liveStyle);
|
|
746
|
+
let childParent = frame;
|
|
747
|
+
let childrenLayout = container ? flex?.value.group : undefined;
|
|
748
|
+
if (style !== undefined && (style.border !== undefined || style.overflow !== undefined)) {
|
|
749
|
+
const content = mountCssContent(scope, frame, style, childrenLayout, options.scrollArea, liveStyle, decorativeBorder, options.stageInitialLayout);
|
|
750
|
+
if (!content.ok) return content;
|
|
751
|
+
childParent = content.value.frame;
|
|
752
|
+
childrenLayout = content.value.layout;
|
|
753
|
+
}
|
|
754
|
+
if (node.props.nativeImageLayers !== undefined) {
|
|
755
|
+
const layers = mountImageLayers(childParent, scope, node.props.nativeImageLayers);
|
|
756
|
+
if (layers !== undefined) return layers;
|
|
757
|
+
}
|
|
758
|
+
const childOptions = container && options.media !== undefined ? { ...options as OwnedRecord<MountOptions>, mediaContainer: frame } : options;
|
|
759
|
+
for (const child of node.children as NativeChildren) {
|
|
760
|
+
const failure = mountChild(childParent, child, scope, childOptions, logical, undefined, environment, childrenLayout, appearance);
|
|
761
|
+
if (failure) return failure;
|
|
762
|
+
}
|
|
763
|
+
return attachRef(scope, node.props.ref, frame)
|
|
764
|
+
?? bindElementEvents(frame, node.props, scope, options.newEventScope, options.elementEvents, undefined, false, logical, paint)
|
|
765
|
+
?? finishViewNode(scope, logical, node.props.nodeRef);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
function imageFillsAxis(length: NativeStyle["width"], start: NativeStyle["left"], end: NativeStyle["right"]): boolean {
|
|
769
|
+
if (start === undefined || end === undefined) return false;
|
|
770
|
+
const value = reveal(length);
|
|
771
|
+
// With auto sizing, two insets determine the rendered dimension. Keep the existing edge-to-edge 100% form.
|
|
772
|
+
return length === undefined || value === "auto" || value === "100%" && reveal(start) === 0 && reveal(end) === 0;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function mountText(parent: Frame, node: Element<"text">, scope: RuntimeScope, options: MountOptions, group: LogicalGroup,
|
|
776
|
+
motion?: TransitionOptions, environment?: StyleEnvironment, flow?: NativeLayoutGroup, typography?: NativeTextStyle,
|
|
777
|
+
liveStyle?: ReadCssStyle): Failure | undefined {
|
|
778
|
+
const { value, align, font, fontSize, heading, style } = node.props;
|
|
779
|
+
const color = node.props.color ?? style?.color;
|
|
780
|
+
const order = style?.zIndex;
|
|
781
|
+
const text = parent.CreateFontString(undefined, "OVERLAY", font ?? "GameFontNormal",
|
|
782
|
+
order === undefined || !Number.isInteger(order) ? undefined : drawOrder(order));
|
|
783
|
+
if (options.regionsOnly === true) scope.onDispose(() => text.Hide());
|
|
784
|
+
if (node.props.nativeMaxLines !== undefined) {
|
|
785
|
+
const maxLines = reveal(node.props.nativeMaxLines);
|
|
786
|
+
if (maxLines !== undefined && Number.isInteger(maxLines) && maxLines > 0) text.SetMaxLines?.(maxLines);
|
|
787
|
+
}
|
|
788
|
+
const typographyStyle = inheritTextStyle(typography, style, environment, undefined, node.props.color, liveStyle);
|
|
789
|
+
const content = createTextContent(text, style, typographyStyle, options);
|
|
790
|
+
const measure = node.props.anchor === undefined ? flow?.textMeasure(text, content?.measureText) : undefined;
|
|
791
|
+
const minimum = measure === undefined ? undefined : () => reveal(text.CanWordWrap()) === true ? 0 : undefined;
|
|
792
|
+
const paint = createNativePaintState(style, environment);
|
|
793
|
+
const startAfter = options.textStartAfter?.(parent, node.props);
|
|
794
|
+
const endBefore = options.textEndBefore?.(parent, node.props);
|
|
795
|
+
const placed = place(text, parent, node.props, scope, motion, flow, measure, minimum, paint, content?.width,
|
|
796
|
+
startAfter === undefined ? undefined : { kind: "text", target: startAfter },
|
|
797
|
+
endBefore === undefined ? undefined : { kind: "text", target: endBefore });
|
|
798
|
+
if (placed) return placed;
|
|
799
|
+
const logical = mountViewNode(scope, group, "text", text, node.props);
|
|
800
|
+
options?.text?.(text, node.props, scope);
|
|
801
|
+
function changedMetrics(this: void) {
|
|
802
|
+
content?.refresh();
|
|
803
|
+
if (measure !== undefined) flow?.enqueue();
|
|
804
|
+
}
|
|
805
|
+
const size = fontSize ?? style?.fontSize ?? (heading === undefined ? undefined : headingSizes[heading - 1]);
|
|
806
|
+
if (typographyStyle === undefined && align !== undefined) text.SetJustifyH(align);
|
|
807
|
+
const configured = typographyStyle !== undefined
|
|
808
|
+
? bindTextTypography(text, scope, node.props, typographyStyle, options, changedMetrics)
|
|
809
|
+
: size === undefined ? undefined : bind(scope, size, next => {
|
|
810
|
+
if (isSecret(next) || !Number.isFinite(next) || next <= 0) return;
|
|
811
|
+
if (options?.fontSize) options.fontSize(text, next);
|
|
812
|
+
else text.SetTextHeight(next);
|
|
813
|
+
changedMetrics();
|
|
814
|
+
});
|
|
815
|
+
if (configured !== undefined) return configured;
|
|
816
|
+
const spacing = reveal(node.props.nativeTextSpacing);
|
|
817
|
+
if (spacing !== undefined && Number.isFinite(spacing)) text.SetSpacing(spacing);
|
|
818
|
+
const vertical = reveal(node.props.nativeTextVerticalAlign);
|
|
819
|
+
if (vertical !== undefined) text.SetJustifyV(vertical);
|
|
820
|
+
return (paint?.usesColor === true ? undefined : bindTextColor(text, scope, typographyStyle?.color,
|
|
821
|
+
undefined, typographyStyle?.colorMotion, options.reduceMotion, typographyStyle?.buttonTiming))
|
|
822
|
+
?? bindRegionPaint(parent, text, style, paint, scope, options, motion, environment, liveStyle, paint?.usesColor !== true ? undefined
|
|
823
|
+
: { base: color, fallback: typographyStyle?.color, read: () => text.GetTextColor(),
|
|
824
|
+
write: (r, g, b, a) => text.SetTextColor(r, g, b, a) })
|
|
825
|
+
?? content?.watchTransform(scope, changedMetrics)
|
|
826
|
+
?? bind(scope, value, next => {
|
|
827
|
+
if (content === undefined) text.SetText(next);
|
|
828
|
+
else content.set(next);
|
|
829
|
+
if (measure !== undefined) flow?.enqueue();
|
|
830
|
+
}, next => isSecret(next) || typeof next === "string" ? undefined : fail("Native text requires a string value"))
|
|
831
|
+
?? attachRef(scope, node.props.ref, text) ?? bindRegionEvents(parent, text, node.props, scope, options, logical, paint)
|
|
832
|
+
?? finishViewNode(scope, logical, node.props.nodeRef);
|
|
833
|
+
}
|
|
834
|
+
|
|
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;
|
|
839
|
+
const automatic = flow !== undefined && node.props.anchor === undefined;
|
|
840
|
+
const absolute = node.props.anchor === undefined && style?.position === "absolute"
|
|
841
|
+
&& style.margin === undefined && style.autoMargin === undefined;
|
|
842
|
+
const widthInsets = absolute && width === undefined && imageFillsAxis(style.width, style.left, style.right);
|
|
843
|
+
const heightInsets = absolute && height === undefined && imageFillsAxis(style.height, style.top, style.bottom);
|
|
844
|
+
// A single stretched axis is explicit, so intrinsic image sizes still work as before.
|
|
845
|
+
const fillsWidth = widthInsets && (heightInsets || (style?.width === "auto" && src.width === undefined));
|
|
846
|
+
const fillsHeight = heightInsets && (widthInsets || (style?.height === "auto" && src.height === undefined));
|
|
847
|
+
const dimensions = automatic || (fillsWidth && fillsHeight) ? undefined
|
|
848
|
+
: manualImageSize(scope, src, fixedSize(width ?? style?.width) as ImageSize,
|
|
849
|
+
fixedSize(height ?? style?.height) as ImageSize, fillsWidth, fillsHeight);
|
|
850
|
+
if (dimensions?.ok === false) return dimensions;
|
|
851
|
+
const order = style?.zIndex;
|
|
852
|
+
const texture = order === undefined || !Number.isInteger(order)
|
|
853
|
+
? parent.CreateTexture(undefined, "ARTWORK")
|
|
854
|
+
: parent.CreateTexture(undefined, "OVERLAY", undefined, drawOrder(order));
|
|
855
|
+
if (options.regionsOnly === true) scope.onDispose(() => texture.Hide());
|
|
856
|
+
if (nativePixelSnap === false) {
|
|
857
|
+
texture.SetSnapToPixelGrid?.(false);
|
|
858
|
+
texture.SetTexelSnappingBias?.(0);
|
|
859
|
+
}
|
|
860
|
+
texture.SetTexture(src.path);
|
|
861
|
+
texture.SetTexCoord(0, src.uMax ?? 1, 0, src.vMax ?? 1);
|
|
862
|
+
const paint = createNativePaintState(style, environment);
|
|
863
|
+
// Both native points carry the parent size, including resizes after this image is mounted.
|
|
864
|
+
const geometry = fillsWidth || fillsHeight
|
|
865
|
+
? { ...node.props as OwnedRecord<typeof node.props>, ...dimensions?.value as OwnedRecord<Partial<Layout>> | undefined, style: {
|
|
866
|
+
...style as OwnedRecord<NativeStyle> | undefined, width: fillsWidth ? "auto" as const : style?.width, height: fillsHeight ? "auto" as const : style?.height,
|
|
867
|
+
} }
|
|
868
|
+
: dimensions === undefined ? node.props : { ...node.props as OwnedRecord<typeof node.props>, ...dimensions.value as OwnedRecord<typeof dimensions.value> };
|
|
869
|
+
const placed = place(texture, parent, geometry, scope, motion, flow,
|
|
870
|
+
automatic ? width => {
|
|
871
|
+
const natural = imageSize(src, width);
|
|
872
|
+
return { width: natural.width ?? 0, height: natural.height ?? 0 };
|
|
873
|
+
} : undefined, undefined, paint);
|
|
874
|
+
if (placed) return placed;
|
|
875
|
+
const logical = mountViewNode(scope, group, "image", texture, node.props);
|
|
876
|
+
if (nativeDesaturated !== undefined) {
|
|
877
|
+
const desaturated = bind(scope, nativeDesaturated, value => texture.SetDesaturated(value));
|
|
878
|
+
if (desaturated !== undefined) return desaturated;
|
|
879
|
+
}
|
|
880
|
+
if (verticalGradient !== undefined) {
|
|
881
|
+
const createColor = api.CreateColor;
|
|
882
|
+
const hasGradient = createColor !== undefined && texture.SetGradient !== undefined;
|
|
883
|
+
if (hasGradient) texture.SetColorTexture(1, 1, 1, 1);
|
|
884
|
+
const gradientFailure = bindValue(scope, verticalGradient, gradient => {
|
|
885
|
+
if (hasGradient) texture.SetGradient?.("VERTICAL", createColor(...gradient.bottom), createColor(...gradient.top));
|
|
886
|
+
else texture.SetColorTexture(...gradient.fallback);
|
|
887
|
+
});
|
|
888
|
+
if (gradientFailure !== undefined) return gradientFailure;
|
|
889
|
+
}
|
|
890
|
+
options?.image?.(texture, parent, node.props);
|
|
891
|
+
const inherited = node.props.inheritColor === true ? typography : undefined;
|
|
892
|
+
return bindNativeTint(scope, style, paint, options, (r, g, b, a) => texture.SetVertexColor(r, g, b, a),
|
|
893
|
+
() => captureImageTint(texture), motion, environment, liveStyle, inherited?.color,
|
|
894
|
+
node.props.cssVars, inherited?.buttonTiming, inherited?.buttonTiming === undefined ? undefined : () => reveal(texture.IsVisible()) === true)
|
|
895
|
+
?? bindRegionPaint(parent, texture, style, paint, scope, options, motion, environment, liveStyle)
|
|
896
|
+
?? attachRef(scope, node.props.ref, texture) ?? bindRegionEvents(parent, texture, node.props, scope, options, logical, paint)
|
|
897
|
+
?? finishViewNode(scope, logical, node.props.nodeRef);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
function hasInteractivePaint(style: NativeStyle | undefined, kind: UIElement["kind"]) {
|
|
901
|
+
if (kind !== "button" && kind !== "editbox") return false;
|
|
902
|
+
const variants = style?.stateStyles as OwnedReadonlyArray<StateStyleVariant> | undefined;
|
|
903
|
+
if (variants === undefined) return false;
|
|
904
|
+
for (const variant of variants) {
|
|
905
|
+
for (const state of variant.when as OwnedReadonlyArray<StyleState>) {
|
|
906
|
+
if (state === "hover" || state === "active" || state === "disabled" || (kind === "editbox" && state === "focus")) return true;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return false;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function mountChild(parent: Frame, node: UIElement, scope: RuntimeScope, options: MountOptions, group: LogicalGroup,
|
|
913
|
+
motion?: TransitionOptions, inherited?: StyleEnvironment, flow?: NativeLayoutGroup, typography?: NativeTextStyle,
|
|
914
|
+
rootControl?: { unanchored?: boolean; attach(this: void, frame: Frame): void }): Failure | undefined {
|
|
915
|
+
const checkboxSkin = node.kind === "checkbox" ? options.checkboxSkin : undefined;
|
|
916
|
+
const rangeSkin = node.kind === "range" ? options.rangeSkin : undefined;
|
|
917
|
+
const listboxSkin = node.kind === "listbox" ? options.listboxSkin : undefined;
|
|
918
|
+
const inputSkin = node.kind === "editbox" ? options.inputSkin : undefined;
|
|
919
|
+
const styledInput = node.kind === "editbox" && (node.props.unstyled !== true || inputSkin?.unstyled === true) ? inputSkin : undefined;
|
|
920
|
+
const skin = checkboxSkin ?? rangeSkin ?? listboxSkin ?? styledInput;
|
|
921
|
+
if (skin !== undefined && (node.kind === "checkbox" || node.kind === "range" || node.kind === "listbox" || node.kind === "editbox")) {
|
|
922
|
+
const { style } = resolveStyleClasses(skin.control, node.props.style);
|
|
923
|
+
node = { ...node as OwnedRecord<UIElement>, props: { ...node.props as OwnedRecord<typeof node.props>, style } } as UIElement;
|
|
924
|
+
}
|
|
925
|
+
const props = "style" in node.props ? node.props as Pick<Element<"frame">["props"], "style" | "shown" | "opacity"> : undefined;
|
|
926
|
+
let style = props?.style;
|
|
927
|
+
const interactive = hasInteractivePaint(style, node.kind);
|
|
928
|
+
const skinnedHint = inputSkin !== undefined && node.kind === "editbox" && node.props.placeholder !== undefined
|
|
929
|
+
&& (node.props.placeholder !== "" || styledInput?.emptyCaption === true);
|
|
930
|
+
const decorated = skin !== undefined || skinnedHint;
|
|
931
|
+
const manualText = options.manualTextBindings;
|
|
932
|
+
const captureText = manualText !== undefined && node.kind === "text" && node.props.part === manualText.part;
|
|
933
|
+
const manualControl = decorated || interactive || captureText
|
|
934
|
+
? options.manualControl?.(scope, decorated || captureText) : undefined;
|
|
935
|
+
scope = manualControl?.scope ?? scope;
|
|
936
|
+
const theme = (skin ?? (skinnedHint ? inputSkin : undefined))?.defaultTheme;
|
|
937
|
+
const defaults = extendStyleEnvironment(undefined, typeof theme === "function" ? theme(parent, scope, manualControl?.flush) : theme, isSecret);
|
|
938
|
+
const parentEnvironment: StyleEnvironment | undefined = inherited === undefined || defaults === undefined
|
|
939
|
+
? inherited ?? defaults
|
|
940
|
+
: name => {
|
|
941
|
+
const value = inherited(name);
|
|
942
|
+
return value.ok && value.value === undefined ? defaults(name) : value;
|
|
943
|
+
};
|
|
944
|
+
const environment = "cssVars" in node.props ? extendStyleEnvironment(parentEnvironment, node.props.cssVars, isSecret) : parentEnvironment;
|
|
945
|
+
const media = node.mediaReads !== undefined || style?.mediaStyles !== undefined ? bindViewMedia(node, scope, options) : undefined;
|
|
946
|
+
if (media?.ok === false) return media;
|
|
947
|
+
let liveStyle: ReadCssStyle | undefined;
|
|
948
|
+
if (props && (style?.mediaStyles !== undefined || style?.styleTokens !== undefined && environment !== undefined)) {
|
|
949
|
+
const prepared = prepareCssStyle(scope, props, environment, node.kind === "frame", media?.value);
|
|
950
|
+
if (!prepared.ok) return prepared;
|
|
951
|
+
liveStyle = prepared.value.read;
|
|
952
|
+
style = prepared.value.props.style;
|
|
953
|
+
node = { ...node as OwnedRecord<UIElement>, props: prepared.value.props } as UIElement;
|
|
954
|
+
}
|
|
955
|
+
if (options.cssFlow === true) {
|
|
956
|
+
node = withDefaultDisplay(node);
|
|
957
|
+
style = "style" in node.props ? (node.props as { style?: NativeStyle }).style : style;
|
|
958
|
+
// A block outside any flow (the view root) starts at its parent's top-left corner, as the page's first box does.
|
|
959
|
+
if (node.kind === "frame" && flow === undefined && node.props.anchor === undefined && style?.position !== "absolute") {
|
|
960
|
+
node = { ...node as OwnedRecord<typeof node>, props: { ...node.props as OwnedRecord<typeof node.props>, anchor: { point: "TOPLEFT" } } };
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
if (node.kind !== "frame" && (style?.display === "flex" || style?.display === "grid" || style?.display === "block")) {
|
|
964
|
+
return fail("Layout containers require a native frame");
|
|
965
|
+
}
|
|
966
|
+
if (node.kind !== "frame" && style?.overflow === "scroll") {
|
|
967
|
+
return fail("CSS overflow scroll requires a native frame");
|
|
968
|
+
}
|
|
969
|
+
switch (node.kind) {
|
|
970
|
+
case "fragment": {
|
|
971
|
+
for (const child of node.children as NativeChildren) {
|
|
972
|
+
const failure = mountChild(parent, child, scope, options, group, motion, environment, flow, typography);
|
|
973
|
+
if (failure) return failure;
|
|
974
|
+
}
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
case "keyedList": {
|
|
978
|
+
const list = mountLogicalGroup(scope, group);
|
|
979
|
+
if (flow !== undefined) return mountLayoutRows(parent, node, scope, flow, options, list, motion, environment, typography);
|
|
980
|
+
return node.props.mount(scope, {
|
|
981
|
+
mount: (tree, rowScope) => {
|
|
982
|
+
const row = createFrame("Frame", undefined, parent);
|
|
983
|
+
const rowGroup = mountLogicalGroup(rowScope, list, false);
|
|
984
|
+
row.Hide();
|
|
985
|
+
rowScope.onDispose(() => row.Hide());
|
|
986
|
+
row.SetAllPoints(parent);
|
|
987
|
+
const failure = mountChild(row, tree, rowScope, options, rowGroup, motion, environment, undefined, typography);
|
|
988
|
+
return failure ?? ok({ frame: row, logical: rowGroup });
|
|
989
|
+
},
|
|
990
|
+
order: rows => {
|
|
991
|
+
orderLogicalRows(list, rows);
|
|
992
|
+
for (const { frame } of rows as OwnedReadonlyArray<(typeof rows)[number]>) if (!frame.IsShown()) frame.Show();
|
|
993
|
+
},
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
case "transition": {
|
|
997
|
+
const child = onlyChild(node);
|
|
998
|
+
return child ? mountChild(parent, child, scope, options, group, node.props, environment, flow, typography)
|
|
999
|
+
: fail("Transition expects exactly one child");
|
|
1000
|
+
}
|
|
1001
|
+
case "portal":
|
|
1002
|
+
return mountPortal(parent, node, scope, options, group, environment, typography);
|
|
1003
|
+
case "frame": {
|
|
1004
|
+
const frame = createFrame("Frame", undefined, parent);
|
|
1005
|
+
return bindFrameScale(frame, scope, node.props.nativeScale)
|
|
1006
|
+
?? mountFrame(frame, parent, node, scope, options, group, motion, environment, false, flow, typography, liveStyle);
|
|
1007
|
+
}
|
|
1008
|
+
case "scrollview": {
|
|
1009
|
+
const scroll = mountScrollView(parent, scope, node.props, options?.scrollArea);
|
|
1010
|
+
const paint = createNativePaintState(node.props.style, environment);
|
|
1011
|
+
const failure = placeFrame(scroll.frame, parent, node.props, scope, motion, false, flow, paint)
|
|
1012
|
+
?? scroll.failure ?? bindControlPaint(scroll.frame, node.props.style, paint, scope, options, motion, environment, liveStyle);
|
|
1013
|
+
if (failure) return failure;
|
|
1014
|
+
const logical = mountViewNode(scope, group, "scrollview", scroll.frame, node.props);
|
|
1015
|
+
const appearance = inheritTextStyle(typography, node.props.style, environment, paint, undefined, liveStyle);
|
|
1016
|
+
const childOptions = options.media === undefined ? options : { ...options as OwnedRecord<MountOptions>, mediaContainer: scroll.frame };
|
|
1017
|
+
for (const child of node.children as NativeChildren) {
|
|
1018
|
+
const failed = mountChild(scroll.content, child, scope, childOptions, logical, undefined, environment, undefined, appearance);
|
|
1019
|
+
if (failed) return failed;
|
|
1020
|
+
}
|
|
1021
|
+
scroll.notifyVisible();
|
|
1022
|
+
return attachRef(scope, node.props.ref, scroll.frame) ?? finishViewNode(scope, logical, node.props.nodeRef);
|
|
1023
|
+
}
|
|
1024
|
+
case "slot": {
|
|
1025
|
+
const borrowed = options.borrowedSlot?.(parent, node.props.name);
|
|
1026
|
+
if (borrowed !== undefined) return bindBorrowedSlot(parent, borrowed, scope, group, node.props, motion !== undefined);
|
|
1027
|
+
const widget = options?.slot?.(parent, node.props.name, scope);
|
|
1028
|
+
if (widget === undefined) {
|
|
1029
|
+
if (node.props.optional === true) return;
|
|
1030
|
+
return fail(`No native widget for slot '${node.props.name}'`);
|
|
1031
|
+
}
|
|
1032
|
+
return place(widget, parent, node.props, scope, motion, flow)
|
|
1033
|
+
?? finishViewNode(scope, mountViewNode(scope, group, "slot", widget, node.props), node.props.nodeRef);
|
|
1034
|
+
}
|
|
1035
|
+
case "text": {
|
|
1036
|
+
const failure = mountText(parent, node, scope, options, group, motion, environment, flow, typography, liveStyle);
|
|
1037
|
+
if (failure === undefined && captureText && manualControl !== undefined) manualText.capture(manualControl.flush);
|
|
1038
|
+
return failure;
|
|
1039
|
+
}
|
|
1040
|
+
case "image":
|
|
1041
|
+
return mountImage(parent, node, scope, options, group, motion, environment, flow, typography, liveStyle);
|
|
1042
|
+
case "statusbar": {
|
|
1043
|
+
const bar = createFrame("StatusBar", undefined, parent);
|
|
1044
|
+
scope.onDispose(() => bar.Hide());
|
|
1045
|
+
bar.SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar");
|
|
1046
|
+
const paint = createNativePaintState(node.props.style, environment);
|
|
1047
|
+
const placed = placeFrame(bar, parent, node.props, scope, motion, false, flow, paint);
|
|
1048
|
+
if (placed) return placed;
|
|
1049
|
+
const logical = mountViewNode(scope, group, "statusbar", bar, node.props);
|
|
1050
|
+
options?.statusbar?.(bar, node.props, scope);
|
|
1051
|
+
return bindStatusBar(scope, bar, node.props)
|
|
1052
|
+
?? bindNativeTint(scope, style, paint, options, (r, g, b, a) => bar.SetStatusBarColor(r, g, b, a),
|
|
1053
|
+
() => captureStatusBarTint(bar), motion, environment, liveStyle)
|
|
1054
|
+
?? bindFramePaint(bar, style, paint, scope, options, motion, environment, liveStyle)
|
|
1055
|
+
?? attachRef(scope, node.props.ref, bar)
|
|
1056
|
+
?? bindElementEvents(bar, node.props, scope, options.newEventScope, options.elementEvents, undefined, false, logical, paint)
|
|
1057
|
+
?? finishViewNode(scope, logical, node.props.nodeRef);
|
|
1058
|
+
}
|
|
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
|
+
}
|
|
1241
|
+
case "checkbox": {
|
|
1242
|
+
const { checked, disabled, label, onChange } = node.props;
|
|
1243
|
+
const check = createFrame("CheckButton", undefined, parent, "UICheckButtonTemplate");
|
|
1244
|
+
const caption = label === undefined || label === "" ? undefined : check.CreateFontString(undefined, "OVERLAY", "GameFontNormal");
|
|
1245
|
+
if (caption !== undefined) {
|
|
1246
|
+
caption.SetPoint("LEFT", check, "RIGHT", 4, 0);
|
|
1247
|
+
caption.SetText(label);
|
|
1248
|
+
}
|
|
1249
|
+
if (checkboxSkin !== undefined) hideCheckboxArt(check, caption);
|
|
1250
|
+
let current = false;
|
|
1251
|
+
const paint = createNativePaintState(node.props.style, environment);
|
|
1252
|
+
function applyChecked(value: boolean) {
|
|
1253
|
+
if (isSecret(value)) return;
|
|
1254
|
+
if (current !== value || reveal(check.GetChecked()) !== value) check.SetChecked(value);
|
|
1255
|
+
current = value;
|
|
1256
|
+
paint?.set("checked", value);
|
|
1257
|
+
}
|
|
1258
|
+
const failure = placeFrame(check, parent, node.props, scope, motion, false, flow, paint)
|
|
1259
|
+
?? bind(scope, checked, applyChecked) ?? bind(scope, disabled ?? false, value => {
|
|
1260
|
+
if (isSecret(value)) return;
|
|
1261
|
+
const enabled = !value && onChange !== undefined;
|
|
1262
|
+
check.SetEnabled(enabled);
|
|
1263
|
+
paint?.set("disabled", !enabled);
|
|
1264
|
+
});
|
|
1265
|
+
if (failure) return failure;
|
|
1266
|
+
if (caption !== undefined) options.checkbox?.(check, caption, node.props, scope);
|
|
1267
|
+
if (onChange !== undefined) {
|
|
1268
|
+
check.SetScript("OnClick", () => {
|
|
1269
|
+
if (!scope.isActive()) return;
|
|
1270
|
+
const next = reveal(check.GetChecked());
|
|
1271
|
+
if (next === undefined || next === current) return;
|
|
1272
|
+
const changed = scope.protect(() => onChange(next));
|
|
1273
|
+
if (scope.isActive()) {
|
|
1274
|
+
const snapshot = typeof checked === "boolean" ? checked : checked.value;
|
|
1275
|
+
const accepted = typeof snapshot === "boolean" ? reveal(snapshot) : snapshot.ok ? reveal(snapshot.value) : undefined;
|
|
1276
|
+
applyChecked(accepted ?? current);
|
|
1277
|
+
}
|
|
1278
|
+
if (!changed.ok) api.geterrorhandler()(changed.reason);
|
|
1279
|
+
});
|
|
1280
|
+
scope.onDispose(() => check.SetScript("OnClick", undefined));
|
|
1281
|
+
}
|
|
1282
|
+
const logical = mountViewNode(scope, group, "checkbox", check, node.props);
|
|
1283
|
+
if (checkboxSkin !== undefined) {
|
|
1284
|
+
let shownState = reveal(check.GetChecked()) === true;
|
|
1285
|
+
const visual = ref(shownState);
|
|
1286
|
+
const hooked = hookSecureMethod(check, "SetChecked", native => {
|
|
1287
|
+
const next = reveal(native.GetChecked());
|
|
1288
|
+
if (next === undefined || next === shownState) return;
|
|
1289
|
+
shownState = next;
|
|
1290
|
+
visual.value = next;
|
|
1291
|
+
paint?.set("checked", next);
|
|
1292
|
+
manualControl?.flush();
|
|
1293
|
+
}, scope);
|
|
1294
|
+
if (!hooked.ok) return hooked;
|
|
1295
|
+
const appearance = inheritTextStyle(typography, node.props.style, environment, paint, undefined, liveStyle);
|
|
1296
|
+
const art = withReactiveScope(scope, () => checkboxSkin.render(check, visual, manualControl?.flush));
|
|
1297
|
+
if (!art.ok) return art;
|
|
1298
|
+
// CheckButton uses ButtonScripts even though its stock texture accessors have different types.
|
|
1299
|
+
const buttonEvents = check as unknown as FrameMap["Button"];
|
|
1300
|
+
return (caption === undefined ? undefined : bindSkinCaption(caption, label ?? "", checkboxSkin.caption, scope, options, environment))
|
|
1301
|
+
?? mountChild(check, art.value, scope, options, logical, undefined, environment, undefined, appearance)
|
|
1302
|
+
?? bindFramePaint(check, node.props.style, paint, scope, options, motion, environment, liveStyle)
|
|
1303
|
+
?? bindElementEvents(check, {}, scope, options.newEventScope, options.elementEvents, buttonEvents, false,
|
|
1304
|
+
logical, interactiveControlPaint(paint, manualControl?.flush), true)
|
|
1305
|
+
?? finishViewNode(scope, logical, node.props.nodeRef);
|
|
1306
|
+
}
|
|
1307
|
+
return bindControlPaint(check, node.props.style, paint, scope, options, motion, environment, liveStyle, paint?.usesColor !== true || caption === undefined
|
|
1308
|
+
? undefined : { read: () => caption.GetTextColor(), write: (r, g, b, a) => caption.SetTextColor(r, g, b, a) })
|
|
1309
|
+
?? finishViewNode(scope, logical, node.props.nodeRef);
|
|
1310
|
+
}
|
|
1311
|
+
case "range": {
|
|
1312
|
+
const { value, disabled, label, hideLabel, min, max, step = 1, onChange } = node.props;
|
|
1313
|
+
if (!Number.isFinite(min) || !Number.isFinite(max) || !Number.isFinite(step) || max <= min || step <= 0) {
|
|
1314
|
+
return fail("Invalid slider range");
|
|
1315
|
+
}
|
|
1316
|
+
const slider = createFrame("Slider", undefined, parent, "OptionsSliderTemplate");
|
|
1317
|
+
slider.SetOrientation("HORIZONTAL");
|
|
1318
|
+
slider.SetMinMaxValues(min, max);
|
|
1319
|
+
slider.SetValueStep(step);
|
|
1320
|
+
slider.SetObeyStepOnDrag(true);
|
|
1321
|
+
const caption = hideLabel ? undefined : slider.CreateFontString(undefined, "OVERLAY", "GameFontNormal");
|
|
1322
|
+
if (caption !== undefined) {
|
|
1323
|
+
caption.SetPoint("BOTTOM", slider, "TOP", 0, 4);
|
|
1324
|
+
caption.SetText(label);
|
|
1325
|
+
}
|
|
1326
|
+
let current = min;
|
|
1327
|
+
const paint = createNativePaintState(node.props.style, environment);
|
|
1328
|
+
const failure = placeFrame(slider, parent, node.props, scope, motion, false, flow, paint) ?? bind(scope, value, next => {
|
|
1329
|
+
if (isSecret(next) || !Number.isFinite(next)) return;
|
|
1330
|
+
slider.SetValue(next, false);
|
|
1331
|
+
current = reveal(slider.GetValue()) ?? min;
|
|
1332
|
+
}) ?? bind(scope, disabled ?? false, next => {
|
|
1333
|
+
if (isSecret(next)) return;
|
|
1334
|
+
const enabled = !next && onChange !== undefined;
|
|
1335
|
+
slider.SetEnabled(enabled);
|
|
1336
|
+
paint?.set("disabled", !enabled);
|
|
1337
|
+
});
|
|
1338
|
+
if (failure) return failure;
|
|
1339
|
+
if (rangeSkin !== undefined) hideStockControlArt(slider, caption);
|
|
1340
|
+
if (caption !== undefined) options.range?.(slider, caption, node.props, scope);
|
|
1341
|
+
if (onChange !== undefined) {
|
|
1342
|
+
slider.SetScript("OnValueChanged", (_, raw, userInput) => {
|
|
1343
|
+
if (!userInput || !scope.isActive()) return;
|
|
1344
|
+
const next = reveal(raw);
|
|
1345
|
+
if (next === undefined || next === current) return;
|
|
1346
|
+
slider.SetValue(current, false);
|
|
1347
|
+
onChange(next);
|
|
1348
|
+
});
|
|
1349
|
+
scope.onDispose(() => slider.SetScript("OnValueChanged", undefined));
|
|
1350
|
+
}
|
|
1351
|
+
const logical = mountViewNode(scope, group, "range", slider, node.props);
|
|
1352
|
+
if (rangeSkin !== undefined) {
|
|
1353
|
+
const backdrop = slider as unknown as { SetBackdrop?(this: object, info?: unknown): void };
|
|
1354
|
+
backdrop.SetBackdrop?.(undefined);
|
|
1355
|
+
const eventPaint = interactiveControlPaint(paint, manualControl?.flush);
|
|
1356
|
+
if (eventPaint?.needs("disabled") === true) {
|
|
1357
|
+
const hooked = hookSecureMethod(slider, "SetEnabled", native => {
|
|
1358
|
+
const enabled = reveal(native.IsEnabled());
|
|
1359
|
+
if (enabled !== undefined) eventPaint.set("disabled", !enabled);
|
|
1360
|
+
}, scope);
|
|
1361
|
+
if (!hooked.ok) return hooked;
|
|
1362
|
+
}
|
|
1363
|
+
const captionFailure = caption === undefined ? undefined : bindSkinCaption(caption, label, rangeSkin.caption, scope, options, environment);
|
|
1364
|
+
if (captionFailure !== undefined) return captionFailure;
|
|
1365
|
+
const art = mountRangeArtView(slider, rangeSkin.thumbSize, rangeSkin.render, scope, options, logical, environment);
|
|
1366
|
+
if (!art.ok) return art;
|
|
1367
|
+
return bindFramePaint(slider, node.props.style, paint, scope, options, motion, environment, liveStyle)
|
|
1368
|
+
?? bindElementEvents(slider, {}, scope, options.newEventScope, options.elementEvents, undefined, false,
|
|
1369
|
+
logical, eventPaint, true)
|
|
1370
|
+
?? art.value.installThumb()
|
|
1371
|
+
?? finishViewNode(scope, logical, node.props.nodeRef);
|
|
1372
|
+
}
|
|
1373
|
+
return bindControlPaint(slider, node.props.style, paint, scope, options, motion, environment, liveStyle, paint?.usesColor !== true || caption === undefined
|
|
1374
|
+
? undefined : { read: () => caption.GetTextColor(), write: (r, g, b, a) => caption.SetTextColor(r, g, b, a) })
|
|
1375
|
+
?? finishViewNode(scope, logical, node.props.nodeRef);
|
|
1376
|
+
}
|
|
1377
|
+
case "listbox": {
|
|
1378
|
+
const { value, disabled, label, items: choices = [], placeholder = label, onChange } = node.props;
|
|
1379
|
+
const items = choices as OwnedReadonlyArray<(typeof choices)[number]>;
|
|
1380
|
+
const dropdown = createFrame("DropdownButton", undefined, parent, "WowStyle1DropdownTemplate");
|
|
1381
|
+
let current: string | undefined;
|
|
1382
|
+
const paint = createNativePaintState(node.props.style, environment);
|
|
1383
|
+
const failure = placeFrame(dropdown, parent, node.props, scope, motion, false, flow, paint)
|
|
1384
|
+
?? bind(scope, disabled ?? false, next => {
|
|
1385
|
+
if (isSecret(next)) return;
|
|
1386
|
+
const enabled = !next && onChange !== undefined;
|
|
1387
|
+
dropdown.SetEnabled(enabled);
|
|
1388
|
+
paint?.set("disabled", !enabled);
|
|
1389
|
+
});
|
|
1390
|
+
if (failure) return failure;
|
|
1391
|
+
const art = listboxSkin === undefined ? undefined : prepareDropdownArt(dropdown, scope);
|
|
1392
|
+
if (art?.ok === false) return art;
|
|
1393
|
+
options?.listbox?.(dropdown, node.props, scope);
|
|
1394
|
+
dropdown.SetupMenu((_, menu) => {
|
|
1395
|
+
for (const { key, label } of items) menu.CreateRadio(label, () => current === key, () => {
|
|
1396
|
+
if (scope.isActive() && dropdown.IsEnabled() && current !== key) onChange?.(key);
|
|
1397
|
+
});
|
|
1398
|
+
});
|
|
1399
|
+
scope.onDispose(() => dropdown.SetupMenu(() => {}));
|
|
1400
|
+
const selection = bind(scope, value, next => {
|
|
1401
|
+
if (isSecret(next)) return;
|
|
1402
|
+
current = next;
|
|
1403
|
+
dropdown.SetDefaultText(items.find(item => item.key === next)?.label ?? placeholder);
|
|
1404
|
+
dropdown.GenerateMenu();
|
|
1405
|
+
});
|
|
1406
|
+
if (selection !== undefined) return selection;
|
|
1407
|
+
const logical = mountViewNode(scope, group, "listbox", dropdown, node.props);
|
|
1408
|
+
if (listboxSkin !== undefined && art?.ok === true) {
|
|
1409
|
+
const visual = withReactiveScope(scope, listboxSkin.render);
|
|
1410
|
+
if (!visual.ok) return visual;
|
|
1411
|
+
const { caption, onTextPaint } = art.value;
|
|
1412
|
+
return (caption === undefined ? undefined : bindSkinCaption(caption, label, listboxSkin.caption, scope,
|
|
1413
|
+
options, environment, { parent: dropdown, onTextPaint }))
|
|
1414
|
+
?? mountChild(dropdown, visual.value, scope, options, logical, undefined, environment)
|
|
1415
|
+
?? bindFramePaint(dropdown, node.props.style, paint, scope, options, motion, environment, liveStyle)
|
|
1416
|
+
?? bindElementEvents(dropdown, {}, scope, options.newEventScope, options.elementEvents, dropdown, false,
|
|
1417
|
+
logical, interactiveControlPaint(paint, manualControl?.flush), true)
|
|
1418
|
+
?? finishViewNode(scope, logical, node.props.nodeRef);
|
|
1419
|
+
}
|
|
1420
|
+
return bindControlPaint(dropdown, node.props.style, paint, scope, options, motion, environment, liveStyle)
|
|
1421
|
+
?? finishViewNode(scope, logical, node.props.nodeRef);
|
|
1422
|
+
}
|
|
1423
|
+
default:
|
|
1424
|
+
return fail(`Cannot mount '${node.kind}' inside a native frame`);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
function mountLayoutRows(parent: Frame, node: Element<"keyedList">, scope: RuntimeScope, flow: NativeLayoutGroup,
|
|
1429
|
+
options: MountOptions, logical: LogicalGroup, motion?: TransitionOptions, environment?: StyleEnvironment,
|
|
1430
|
+
typography?: NativeTextStyle): Failure | undefined {
|
|
1431
|
+
const list = { rows: [] as readonly NativeLayoutItem[] };
|
|
1432
|
+
flow.children.push(list);
|
|
1433
|
+
scope.onDispose(() => {
|
|
1434
|
+
const index = flow.children.indexOf(list);
|
|
1435
|
+
if (index >= 0) flow.children.splice(index, 1);
|
|
1436
|
+
flow.enqueue();
|
|
1437
|
+
});
|
|
1438
|
+
return node.props.mount(scope, {
|
|
1439
|
+
mount: (tree, rowScope): Result<{ item?: NativeLayoutItem; logical: LogicalGroup }> => {
|
|
1440
|
+
const frame = createFrame("Frame", undefined, parent);
|
|
1441
|
+
const style = "style" in tree.props ? tree.props.style : undefined;
|
|
1442
|
+
const row = mountLogicalGroup(rowScope, logical, false);
|
|
1443
|
+
if (style && "position" in style && style.position === "absolute") {
|
|
1444
|
+
frame.SetAllPoints(parent);
|
|
1445
|
+
rowScope.onDispose(() => frame.Hide());
|
|
1446
|
+
const failure = mountChild(frame, tree, rowScope, options, row, motion, environment, undefined, typography);
|
|
1447
|
+
return failure ?? ok({ logical: row });
|
|
1448
|
+
}
|
|
1449
|
+
const gridColumn = style && "gridColumn" in style ? style.gridColumn : undefined;
|
|
1450
|
+
const item = attachLayoutItem(flow, frame, parent, { style: { display: "flex", flexDirection: "column", gridColumn } },
|
|
1451
|
+
rowScope, true, undefined, true);
|
|
1452
|
+
if (!item.ok) return item;
|
|
1453
|
+
const failure = mountChild(frame, tree, rowScope, options, row, motion, environment, item.value.group, typography);
|
|
1454
|
+
return failure ?? ok({ item: item.value, logical: row });
|
|
1455
|
+
},
|
|
1456
|
+
order: rows => {
|
|
1457
|
+
orderLogicalRows(logical, rows);
|
|
1458
|
+
const items: NativeLayoutItem[] = [];
|
|
1459
|
+
for (const { item } of rows as OwnedReadonlyArray<(typeof rows)[number]>) if (item !== undefined) items.push(item);
|
|
1460
|
+
list.rows = items;
|
|
1461
|
+
flow.enqueue();
|
|
1462
|
+
},
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
function manualImageSize(scope: RuntimeScope, src: Element<"image">["props"]["src"],
|
|
1467
|
+
width: Binding<number | "auto"> | undefined,
|
|
1468
|
+
height: Binding<number | "auto"> | undefined,
|
|
1469
|
+
fillsWidth: boolean, fillsHeight: boolean) {
|
|
1470
|
+
const size = bindImageSize(scope, src, width, height);
|
|
1471
|
+
const w = fillsWidth ? ok(undefined) : positiveImageDimension(scope, size.width);
|
|
1472
|
+
if (!w.ok) return w;
|
|
1473
|
+
const h = fillsHeight ? ok(undefined) : positiveImageDimension(scope, size.height);
|
|
1474
|
+
return h.ok ? ok({ width: w.value, height: h.value }) : h;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
function manualBindings(scope: RuntimeScope) {
|
|
1478
|
+
type Batches = OwnedReadonlyArray<OwnedSet<Job>>;
|
|
1479
|
+
const effects = ownedSet<Job>();
|
|
1480
|
+
const localBatches = ownedMap<RuntimeScope, Batches>();
|
|
1481
|
+
let flushing = false;
|
|
1482
|
+
// Keep host commits in mount order and let an interaction refresh only its control subtree.
|
|
1483
|
+
function bindingScope(batches?: Batches): RuntimeScope {
|
|
1484
|
+
return {
|
|
1485
|
+
...scope as OwnedRecord<RuntimeScope>,
|
|
1486
|
+
watchEffect(this: void, effect: Job) {
|
|
1487
|
+
const first = scope.protect(effect);
|
|
1488
|
+
if (!first.ok) return first;
|
|
1489
|
+
if (first.value) return first.value;
|
|
1490
|
+
effects.add(effect);
|
|
1491
|
+
if (batches !== undefined) for (const batch of batches) batch.add(effect);
|
|
1492
|
+
return ok(() => {
|
|
1493
|
+
effects.delete(effect);
|
|
1494
|
+
if (batches !== undefined) for (const batch of batches) batch.delete(effect);
|
|
1495
|
+
});
|
|
1496
|
+
},
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
const owner = bindingScope();
|
|
1500
|
+
scope.onDispose(() => effects.clear());
|
|
1501
|
+
|
|
1502
|
+
function flush(batch: OwnedSet<Job> = effects) {
|
|
1503
|
+
if (flushing || !scope.isActive()) return ok(undefined);
|
|
1504
|
+
flushing = true;
|
|
1505
|
+
const result = scope.protect(() => {
|
|
1506
|
+
for (const effect of batch) {
|
|
1507
|
+
const failure = effect();
|
|
1508
|
+
if (failure) return failure;
|
|
1509
|
+
}
|
|
1510
|
+
});
|
|
1511
|
+
flushing = false;
|
|
1512
|
+
return result.ok ? result.value ?? ok(undefined) : result;
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
function control(parent: RuntimeScope, nested: boolean): { scope: RuntimeScope; flush(this: void): ReturnType<typeof flush> } | undefined {
|
|
1516
|
+
const ancestors = nested ? localBatches.get(parent) : undefined;
|
|
1517
|
+
if (parent !== owner && ancestors === undefined) return;
|
|
1518
|
+
const local = ownedSet<Job>();
|
|
1519
|
+
// A parent interaction still paints its full subtree. A nested check can flush just its own art.
|
|
1520
|
+
const batches = (ancestors === undefined ? [local] : [...ancestors, local]) as unknown as Batches;
|
|
1521
|
+
const bindings = bindingScope(batches);
|
|
1522
|
+
localBatches.set(bindings, batches);
|
|
1523
|
+
scope.onDispose(() => { localBatches.delete(bindings); local.clear(); });
|
|
1524
|
+
return { scope: bindings, flush: () => flush(local) };
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
return { scope: owner, flush: () => flush(), control };
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
/** Mount decorative art on a host-owned horizontal slider. The host owns the native input. */
|
|
1531
|
+
export function mountNativeRangeArt(this: void, slider: FrameMap["Slider"], owner: RuntimeScope, thumbSize: number,
|
|
1532
|
+
render: NativeRangeSkin["render"], options?: NativeRangeArtOptions) {
|
|
1533
|
+
const scope = owner.fork();
|
|
1534
|
+
if (!scope.isActive()) return fail("The reactive scope has been disposed");
|
|
1535
|
+
const manual = options?.bindings === "manual" ? manualBindings(scope) : undefined;
|
|
1536
|
+
const bindings = manual?.scope ?? scope;
|
|
1537
|
+
const result = scope.protect(() => {
|
|
1538
|
+
const mountedOptions: MountOptions = { ...options as OwnedRecord<NativeRangeArtOptions> | undefined, newEventScope: () => scope.fork() };
|
|
1539
|
+
const theme = extendStyleEnvironment(undefined, options?.theme, isSecret);
|
|
1540
|
+
const art = mountRangeArtView(slider, thumbSize, render, bindings, mountedOptions, { scope: bindings }, theme);
|
|
1541
|
+
if (!art.ok) return art;
|
|
1542
|
+
const failure = art.value.installThumb();
|
|
1543
|
+
return failure ?? ok({ dispose: scope.dispose, flushBindings: manual?.flush });
|
|
1544
|
+
});
|
|
1545
|
+
const mounted = result.ok ? result.value : result;
|
|
1546
|
+
if (!mounted.ok) scope.dispose();
|
|
1547
|
+
return mounted;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
function readRootLayer(layer: NativeRootLayer): Result<NativeRootLayer> {
|
|
1551
|
+
const checked = protect(() => {
|
|
1552
|
+
if (isSecret(layer) || typeof layer !== "object" || layer === null) return fail("Native root layer is unreadable");
|
|
1553
|
+
const strata = reveal(layer.strata);
|
|
1554
|
+
if (typeof strata !== "string" || !frameStrata.includes(strata)) return fail("Invalid native root strata");
|
|
1555
|
+
const level = layer.level;
|
|
1556
|
+
if (isSecret(level) || (level !== undefined && (!Number.isInteger(level) || level < 0 || level > maximumFrameLevel))) {
|
|
1557
|
+
return fail("Native root level must be an integer between 0 and " + maximumFrameLevel);
|
|
1558
|
+
}
|
|
1559
|
+
return ok({ strata, level });
|
|
1560
|
+
});
|
|
1561
|
+
return checked.ok ? checked.value : checked;
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
type LayerRegion = Pick<Frame, "IsForbidden" | "IsProtected">;
|
|
1565
|
+
|
|
1566
|
+
function accessibleLayerRegion(region: FrameParent): region is FrameParent & LayerRegion {
|
|
1567
|
+
const readable = reveal(region) as Partial<LayerRegion> | undefined;
|
|
1568
|
+
return readable !== undefined && typeof readable.IsForbidden === "function" && typeof readable.IsProtected === "function"
|
|
1569
|
+
&& canAccessRegion(readable as LayerRegion);
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
function unprotected(region: LayerRegion): boolean {
|
|
1573
|
+
const [state] = region.IsProtected();
|
|
1574
|
+
return reveal(state) === false;
|
|
1575
|
+
}
|
|
1576
|
+
|
|
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");
|
|
1580
|
+
scope.onDispose(() => frame.Hide());
|
|
1581
|
+
return frame;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
function createLayeredRoot(parent: FrameParent, scope: RuntimeScope, { strata, level }: NativeRootLayer,
|
|
1585
|
+
backdrop?: NativeViewOptions["rootBackdrop"]): Result<Frame> {
|
|
1586
|
+
const created = protect(() => {
|
|
1587
|
+
if (!accessibleLayerRegion(parent)) return fail("Native root parent is inaccessible");
|
|
1588
|
+
const inCombat = reveal(api.InCombatLockdown());
|
|
1589
|
+
if (typeof inCombat !== "boolean") return fail("Combat lockdown is unreadable");
|
|
1590
|
+
if (inCombat && !unprotected(parent)) return fail("Cannot layer a native root under a protected parent in combat");
|
|
1591
|
+
|
|
1592
|
+
const frame = createRootFrame(parent, scope, backdrop);
|
|
1593
|
+
if (!accessibleLayerRegion(frame)) return fail("Native root frame is inaccessible");
|
|
1594
|
+
if (inCombat && !unprotected(frame)) return fail("Cannot layer a protected native root in combat");
|
|
1595
|
+
|
|
1596
|
+
frame.SetFrameStrata(strata);
|
|
1597
|
+
if (reveal(frame.GetFrameStrata()) !== strata) return fail("The client did not confirm the native root strata");
|
|
1598
|
+
if (level !== undefined) {
|
|
1599
|
+
frame.SetFrameLevel(level);
|
|
1600
|
+
if (reveal(frame.GetFrameLevel()) !== level) return fail("The client did not confirm the native root level");
|
|
1601
|
+
}
|
|
1602
|
+
return ok(frame);
|
|
1603
|
+
});
|
|
1604
|
+
return created.ok ? created.value : created;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
function isNativeRegionTree(tree: UIElement): boolean {
|
|
1608
|
+
const children = tree.children as NativeChildren;
|
|
1609
|
+
if (tree.kind === "fragment") return children.every(child => isNativeRegionTree(child));
|
|
1610
|
+
return (tree.kind === "text" || tree.kind === "image") && children.length === 0;
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
function initialLayoutQueue() {
|
|
1614
|
+
const jobs = new Set<Job>();
|
|
1615
|
+
let staging = true;
|
|
1616
|
+
const stage: StageInitialLayout = job => {
|
|
1617
|
+
if (staging) jobs.add(job);
|
|
1618
|
+
return staging;
|
|
1619
|
+
};
|
|
1620
|
+
function commit() {
|
|
1621
|
+
const result = protect(() => {
|
|
1622
|
+
for (let pass = 0; jobs.size > 0; pass++) {
|
|
1623
|
+
if (pass === 16) return fail("Initial native layout did not settle");
|
|
1624
|
+
const pending = [...jobs];
|
|
1625
|
+
jobs.clear();
|
|
1626
|
+
for (const job of pending) {
|
|
1627
|
+
const failure = job();
|
|
1628
|
+
if (failure !== undefined) return failure;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
});
|
|
1632
|
+
staging = false;
|
|
1633
|
+
jobs.clear();
|
|
1634
|
+
return result.ok ? result.value : result;
|
|
1635
|
+
}
|
|
1636
|
+
return { stage, commit };
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
/** Mount a WoW frame tree, an unstyled control, or scoped regions on a borrowed frame. */
|
|
1640
|
+
export function mountNative(parent: FrameParent, runtime: Runtime, render: (this: void, scope: RuntimeScope) => UIElement,
|
|
1641
|
+
options?: NativeViewOptions) {
|
|
1642
|
+
const requestedLayer = options?.rootLayer;
|
|
1643
|
+
const checkedLayer = requestedLayer === undefined ? undefined : readRootLayer(requestedLayer);
|
|
1644
|
+
if (checkedLayer?.ok === false) return checkedLayer;
|
|
1645
|
+
const layer = checkedLayer?.value;
|
|
1646
|
+
const scope = runtime.scope();
|
|
1647
|
+
const manual = options?.bindings === "manual" ? manualBindings(scope) : undefined;
|
|
1648
|
+
const initial = options?.initialLayout === "sync" ? initialLayoutQueue() : undefined;
|
|
1649
|
+
let mountedTree = false;
|
|
1650
|
+
const result = withReactiveScope(scope, () => {
|
|
1651
|
+
const mark = markMediaReads();
|
|
1652
|
+
let tree = attachMediaReads(render(scope), mark);
|
|
1653
|
+
const mountedOptions: MountOptions = { ...options as OwnedRecord<NativeViewOptions> | undefined, newEventScope: () => runtime.scope(), stageInitialLayout: initial?.stage };
|
|
1654
|
+
if (manual !== undefined) mountedOptions.manualControl = (owner, nested) => {
|
|
1655
|
+
const control = manual.control(owner, nested);
|
|
1656
|
+
if (control === undefined) return;
|
|
1657
|
+
return { scope: control.scope, flush: () => {
|
|
1658
|
+
if (!mountedTree) return;
|
|
1659
|
+
const flushed = control.flush();
|
|
1660
|
+
if (!flushed.ok) api.geterrorhandler()(flushed.reason);
|
|
1661
|
+
} };
|
|
1662
|
+
};
|
|
1663
|
+
const owner = manual?.scope ?? scope;
|
|
1664
|
+
if (options?.regionsOnly === true) {
|
|
1665
|
+
if (layer !== undefined || options.rootScale !== undefined || options.rootBackdrop !== undefined) {
|
|
1666
|
+
return fail("Native root layer, scale and backdrop require a frame root");
|
|
1667
|
+
}
|
|
1668
|
+
if (!isNativeRegionTree(tree)) return fail("Native region mounts accept only text, images and fragments");
|
|
1669
|
+
if (!accessibleLayerRegion(parent)) return fail("Native region mounts require an accessible frame parent");
|
|
1670
|
+
const frame = parent as Frame;
|
|
1671
|
+
if (typeof frame.CreateTexture !== "function" || typeof frame.CreateFontString !== "function") {
|
|
1672
|
+
return fail("Native region mounts require a frame parent");
|
|
1673
|
+
}
|
|
1674
|
+
const theme = extendStyleEnvironment(undefined, options.theme, isSecret);
|
|
1675
|
+
const failure = mountChild(frame, tree, owner, mountedOptions, { scope: owner }, undefined, theme);
|
|
1676
|
+
if (failure !== undefined) return failure;
|
|
1677
|
+
mountedTree = true;
|
|
1678
|
+
return ok({ frame, dispose: scope.dispose, flushBindings: manual?.flush });
|
|
1679
|
+
}
|
|
1680
|
+
let motion: TransitionOptions | undefined;
|
|
1681
|
+
while (tree.kind === "transition" || tree.kind === "fragment") {
|
|
1682
|
+
if (tree.mediaReads !== undefined) {
|
|
1683
|
+
const media = bindViewMedia(tree, owner, mountedOptions);
|
|
1684
|
+
if (!media.ok) return media;
|
|
1685
|
+
}
|
|
1686
|
+
if (tree.kind === "transition") motion = tree.props;
|
|
1687
|
+
const children = tree.children as NativeChildren;
|
|
1688
|
+
const child = children.length === 1 ? children[0] : undefined;
|
|
1689
|
+
if (!child) return fail("A native view must return one root frame");
|
|
1690
|
+
tree = child;
|
|
1691
|
+
}
|
|
1692
|
+
if ((tree.kind === "button" || tree.kind === "editbox") && tree.props.unstyled === true) {
|
|
1693
|
+
const kind = tree.kind === "button" ? "button" : "edit box";
|
|
1694
|
+
if (layer !== undefined || options?.rootScale !== undefined) {
|
|
1695
|
+
return fail("Native root layer and scale require a frame root");
|
|
1696
|
+
}
|
|
1697
|
+
if (options?.rootBackdrop !== undefined) return fail("Native root backdrop requires a frame root");
|
|
1698
|
+
if (!accessibleLayerRegion(parent)) return fail(`Native root ${kind} requires an accessible frame parent`);
|
|
1699
|
+
let frame: Frame | undefined;
|
|
1700
|
+
const theme = extendStyleEnvironment(undefined, options?.theme, isSecret);
|
|
1701
|
+
const failure = mountChild(parent as Frame, tree, owner, mountedOptions, { scope: owner }, motion, theme, undefined, undefined, {
|
|
1702
|
+
unanchored: options?.unanchoredRoot,
|
|
1703
|
+
attach(this: void, control: Frame) {
|
|
1704
|
+
frame = control;
|
|
1705
|
+
scope.onDispose(() => control.Hide());
|
|
1706
|
+
},
|
|
1707
|
+
});
|
|
1708
|
+
if (failure !== undefined) return failure;
|
|
1709
|
+
if (frame === undefined) return fail(`Native root ${kind} was not mounted`);
|
|
1710
|
+
mountedTree = true;
|
|
1711
|
+
return ok({ frame, dispose: scope.dispose, flushBindings: manual?.flush });
|
|
1712
|
+
}
|
|
1713
|
+
if (tree.kind !== "frame") return fail("A native view must return a frame");
|
|
1714
|
+
let frame: Frame;
|
|
1715
|
+
if (layer === undefined) {
|
|
1716
|
+
frame = createRootFrame(parent, scope, options?.rootBackdrop);
|
|
1717
|
+
} else {
|
|
1718
|
+
const created = createLayeredRoot(parent, scope, layer, options?.rootBackdrop);
|
|
1719
|
+
if (!created.ok) return created;
|
|
1720
|
+
frame = created.value;
|
|
1721
|
+
}
|
|
1722
|
+
const rootScale = options?.rootScale;
|
|
1723
|
+
const scaleFailure = bindFrameScale(frame, rootScale === undefined ? owner : scope, rootScale ?? tree.props.nativeScale);
|
|
1724
|
+
if (scaleFailure !== undefined) return scaleFailure;
|
|
1725
|
+
const theme = extendStyleEnvironment(extendStyleEnvironment(undefined, options?.theme, isSecret), tree.props.cssVars, isSecret);
|
|
1726
|
+
const media = tree.mediaReads !== undefined || tree.props.style?.mediaStyles !== undefined
|
|
1727
|
+
? bindViewMedia(tree, owner, mountedOptions) : undefined;
|
|
1728
|
+
if (media?.ok === false) return media;
|
|
1729
|
+
let liveStyle: ReadCssStyle | undefined;
|
|
1730
|
+
if (tree.props.style?.mediaStyles !== undefined || tree.props.style?.styleTokens !== undefined && theme !== undefined) {
|
|
1731
|
+
const styled = prepareCssStyle(owner, tree.props, theme, true, media?.value);
|
|
1732
|
+
if (!styled.ok) return styled;
|
|
1733
|
+
tree = { ...tree as OwnedRecord<typeof tree>, props: styled.value.props };
|
|
1734
|
+
liveStyle = styled.value.read;
|
|
1735
|
+
}
|
|
1736
|
+
const failure = mountFrame(frame, parent, tree, owner, mountedOptions, { scope: owner }, motion, theme,
|
|
1737
|
+
layer?.level !== undefined, undefined, undefined, liveStyle, options?.unanchoredRoot);
|
|
1738
|
+
if (failure) return failure;
|
|
1739
|
+
mountedTree = true;
|
|
1740
|
+
return ok({ frame, dispose: scope.dispose, flushBindings: manual?.flush });
|
|
1741
|
+
});
|
|
1742
|
+
let mounted = result.ok ? result.value : result;
|
|
1743
|
+
if (mounted.ok && initial !== undefined) mounted = initial.commit() ?? mounted;
|
|
1744
|
+
if (!mounted.ok) protect(scope.dispose);
|
|
1745
|
+
return mounted;
|
|
1746
|
+
}
|