@overmvp/kumi 0.0.0-stage → 0.3.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 +67 -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 +387 -0
- package/builder/css-v1.test.mjs +361 -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 +127 -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 +435 -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 +2336 -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 +381 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +83 -0
- package/builder/src/numbers.lua +76 -0
- package/builder/src/project-front.mjs +3682 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +124 -0
- package/builder/src/setup-store.lua +18 -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-reads.lua +22 -0
- package/builder/src/wow_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -0
- package/builder/style-modules.mjs +93 -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 +59 -0
- package/eslint.mjs +74 -0
- package/form/index.ts +526 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +26 -4
- package/router/index.ts +50 -0
- package/router/navigation.ts +22 -0
- package/router/package.json +12 -0
- package/router/router-view.ts +134 -0
- package/router/routes.ts +64 -0
- package/scripts/addon-build.mjs +364 -0
- package/scripts/addon-project.mjs +78 -0
- package/scripts/kumi-cli.mjs +105 -0
- package/scripts/link-addons.mjs +61 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +239 -0
- package/src/css-v1.ts +68 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +505 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +336 -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 +29 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +29 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +366 -0
- package/src/media-query.ts +144 -0
- package/src/module-ui.ts +147 -0
- package/src/module.ts +311 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +52 -0
- package/src/providers.ts +241 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +275 -0
- package/src/result.ts +64 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +63 -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 +9 -0
- package/state/package.json +12 -0
- package/state/setup-store-persistence.ts +206 -0
- package/state/setup-store-view.ts +10 -0
- package/state/setup-store.ts +342 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +84 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/AGENTS.md +34 -0
- package/templates/addon/Assets/Art/Corner10.tga +0 -0
- package/templates/addon/Assets/Art/Corner11.tga +0 -0
- package/templates/addon/Assets/Art/Corner12.tga +0 -0
- package/templates/addon/Assets/Art/Corner13.tga +0 -0
- package/templates/addon/Assets/Art/Corner14.tga +0 -0
- package/templates/addon/Assets/Art/Corner15.tga +0 -0
- package/templates/addon/Assets/Art/Corner16.tga +0 -0
- package/templates/addon/Assets/Art/Corner2.tga +0 -0
- package/templates/addon/Assets/Art/Corner3.tga +0 -0
- package/templates/addon/Assets/Art/Corner4.tga +0 -0
- package/templates/addon/Assets/Art/Corner5.tga +0 -0
- package/templates/addon/Assets/Art/Corner6.tga +0 -0
- package/templates/addon/Assets/Art/Corner7.tga +0 -0
- package/templates/addon/Assets/Art/Corner8.tga +0 -0
- package/templates/addon/Assets/Art/Corner9.tga +0 -0
- package/templates/addon/Assets/Art/Dot.tga +0 -0
- package/templates/addon/Assets/Art/Gear.tga +0 -0
- package/templates/addon/Assets/Art/Grip.tga +0 -0
- package/templates/addon/Assets/Art/Outline10.tga +0 -0
- package/templates/addon/Assets/Art/Outline12.tga +0 -0
- package/templates/addon/Assets/Art/Outline13.tga +0 -0
- package/templates/addon/Assets/Art/Outline14.tga +0 -0
- package/templates/addon/Assets/Art/Outline15.tga +0 -0
- package/templates/addon/Assets/Art/Outline2.tga +0 -0
- package/templates/addon/Assets/Art/Outline3.tga +0 -0
- package/templates/addon/Assets/Art/Outline5.tga +0 -0
- package/templates/addon/Assets/Art/Outline7.tga +0 -0
- package/templates/addon/Assets/Art/Outline9.tga +0 -0
- package/templates/addon/Assets/Art/Round11.tga +0 -0
- package/templates/addon/Assets/Art/Round11Border.tga +0 -0
- package/templates/addon/Assets/Art/Round4.tga +0 -0
- package/templates/addon/Assets/Art/Round4Border.tga +0 -0
- package/templates/addon/Assets/Art/Round6.tga +0 -0
- package/templates/addon/Assets/Art/Round6Border.tga +0 -0
- package/templates/addon/Assets/Art/Round8.tga +0 -0
- package/templates/addon/Assets/Art/Round8Border.tga +0 -0
- package/templates/addon/Assets/Art/Search.tga +0 -0
- package/templates/addon/CLAUDE.md +1 -0
- package/templates/addon/README.md +49 -0
- package/templates/addon/eslint.config.mjs +6 -0
- package/templates/addon/gitignore +9 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +20 -0
- package/templates/addon/src/app/app.module.ts +18 -0
- package/templates/addon/src/app/commands.store.ts +11 -0
- package/templates/addon/src/app/layout/AppWindow.module.scss +92 -0
- package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
- package/templates/addon/src/app/main.ts +5 -0
- package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
- package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
- package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
- package/templates/addon/src/app/theme.ts +6 -0
- package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
- package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
- package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
- package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
- package/templates/addon/src/modules/greeting/ui/Greeting.module.scss +105 -0
- package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
- package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
- package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
- package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
- package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
- package/templates/addon/src/modules/playtime/ui/Playtime.module.scss +25 -0
- package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
- package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
- package/templates/addon/src/shared/api/native-art.ts +28 -0
- package/templates/addon/src/shared/assets/close.png +0 -0
- package/templates/addon/src/shared/lib/format.ts +20 -0
- package/templates/addon/src/shared/styles/_tokens.scss +12 -0
- package/templates/addon/src/shared/ui/Button.tsx +29 -0
- package/templates/addon/src/shared/ui/Choice.tsx +34 -0
- package/templates/addon/src/shared/ui/Controls.module.scss +93 -0
- package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
- package/templates/addon/src/shared/ui/Slider.tsx +25 -0
- package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
- package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
- package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
- package/templates/addon/tsconfig.json +63 -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/action-bar-layout.ts +108 -0
- package/wow/action-button.ts +219 -0
- package/wow/action-catalog.ts +98 -0
- package/wow/addon-manifest.ts +36 -0
- package/wow/animation.ts +428 -0
- package/wow/app-ui.ts +221 -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/cooldown-timing.ts +24 -0
- package/wow/css-box.ts +144 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +603 -0
- package/wow/css-text.ts +399 -0
- package/wow/cursor.ts +45 -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 +53 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frame-timing.ts +13 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/hooks.ts +133 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +111 -0
- package/wow/layout-view.ts +663 -0
- package/wow/locale-font.ts +15 -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 +153 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/protect.ts +48 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/protected-view.ts +103 -0
- package/wow/range-art.ts +81 -0
- package/wow/readable-api.ts +120 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +183 -0
- package/wow/saved-variables.ts +109 -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/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +122 -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 +1864 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
import type { Binding, Element, RuntimeScope } from "../src";
|
|
2
|
+
import { layoutPercent, solveLayout, type FlexLayout, type FlexNode, type LayoutStyle, type LayoutRect, type LayoutSize } from "../src/flex-layout";
|
|
3
|
+
import { parseGridSpan, parseGridTracks } from "../src/grid-tracks";
|
|
4
|
+
import type { OwnedArray, OwnedLuaArray, OwnedReadonlyArray, OwnedRecord, OwnedSet } from "../src/owned-collections";
|
|
5
|
+
import { fail, ok, type Failure, type Result } from "../src/result";
|
|
6
|
+
import type { Job } from "../src/scheduler";
|
|
7
|
+
import { canAccessRegion } from "./frame-access";
|
|
8
|
+
import type { FontString, Frame, FrameParent } from "./frames";
|
|
9
|
+
import { api, isSecret, reveal } from "./native";
|
|
10
|
+
import { hookScript } from "./native-hooks";
|
|
11
|
+
import { physicalPixel, watchDisplayMetrics } from "./pixel";
|
|
12
|
+
import { protect } from "./protect";
|
|
13
|
+
import { createProtectedLayoutUpdate, type ProtectedLayoutUpdate } from "./protected-layout";
|
|
14
|
+
|
|
15
|
+
type Layout = Omit<Element<"frame">["props"], "ref">;
|
|
16
|
+
type Geometry = Pick<FontString, "ClearAllPoints" | "SetPoint" | "SetSize" | "SetShown" | "IsShown" | "GetSize" | "IsForbidden" | "GetObjectType">
|
|
17
|
+
& Partial<Pick<Frame, "IsProtected" | "CanChangeProtectedState" | "IsAnchoringRestricted" | "GetDebugName">>
|
|
18
|
+
& { IsRectValid?(this: Geometry): unknown; IsVisible?(this: Geometry): unknown };
|
|
19
|
+
type RectParent = { IsRectValid?(this: RectParent): unknown };
|
|
20
|
+
type Measure = NonNullable<FlexNode["measure"]>;
|
|
21
|
+
type Role = "region" | "anchor" | "ancestor";
|
|
22
|
+
type LayoutFailure = Failure & { readonly combat?: true };
|
|
23
|
+
type LayoutWrites = { count: number };
|
|
24
|
+
|
|
25
|
+
export interface NativeLayoutDiagnostics {
|
|
26
|
+
enabled(this: void): boolean;
|
|
27
|
+
committed(this: void, writes: number): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const layoutJob = { label: "Native layout" };
|
|
31
|
+
const numberKeys = ["gap", "rowGap", "columnGap", "flexGrow", "flexShrink", "minWidth", "minHeight", "maxWidth", "maxHeight"] as const;
|
|
32
|
+
const lengthKeys = ["width", "height", "flexBasis"] as const;
|
|
33
|
+
const insetKeys = ["top", "right", "bottom", "left"] as const;
|
|
34
|
+
const alignment = ["flex-start", "center", "flex-end", "stretch"] as const;
|
|
35
|
+
const enums = {
|
|
36
|
+
flexDirection: ["row", "column"],
|
|
37
|
+
flexWrap: ["nowrap", "wrap"],
|
|
38
|
+
position: ["static", "relative", "absolute"],
|
|
39
|
+
justifyContent: ["flex-start", "center", "flex-end", "space-between"],
|
|
40
|
+
alignItems: ["start", "end", ...alignment],
|
|
41
|
+
justifyItems: ["start", "center", "end", "stretch"],
|
|
42
|
+
alignSelf: ["auto", ...alignment],
|
|
43
|
+
} as const;
|
|
44
|
+
const layoutEnums = Object.entries(enums);
|
|
45
|
+
const missingLayoutValue = ok(undefined);
|
|
46
|
+
const empty: LayoutSize = { width: 0, height: 0 };
|
|
47
|
+
// The client gives a region with a zero side no rect, and its anchored children none either (a browser still paints
|
|
48
|
+
// an empty box's overflow). Laid-out boxes keep a sliver instead (2026-11-21, owner's /ku probe dumps).
|
|
49
|
+
const sliver = 0.01;
|
|
50
|
+
const repairJob = { label: "Native layout anchors" };
|
|
51
|
+
// Frames a stale anchor is waited on: the page body around it gets its rect within a few frames.
|
|
52
|
+
const repairFrames = 20;
|
|
53
|
+
|
|
54
|
+
export function readLayoutValue<T>(this: void, binding: Binding<T> | undefined): Result<T | undefined> {
|
|
55
|
+
if (isSecret(binding)) return fail("Layout properties require readable values");
|
|
56
|
+
if (binding === undefined) return missingLayoutValue;
|
|
57
|
+
if (binding === null) return fail("Invalid layout binding");
|
|
58
|
+
if (typeof binding !== "object" || !("value" in binding)) return ok(binding as T);
|
|
59
|
+
const value = binding.value;
|
|
60
|
+
if (isSecret(value)) return fail("Layout properties require readable values");
|
|
61
|
+
if (typeof value === "object" && value !== null && "ok" in value) {
|
|
62
|
+
const state = value as Result<T>;
|
|
63
|
+
if (state.ok && isSecret(state.value)) return fail("Layout properties require readable values");
|
|
64
|
+
return state;
|
|
65
|
+
}
|
|
66
|
+
return ok(value as T);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function validNumber(value: unknown, signed = false): value is number {
|
|
70
|
+
return !isSecret(value) && typeof value === "number" && Number.isFinite(value) && (signed || value >= 0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function insets(value: unknown, signed: boolean): boolean {
|
|
74
|
+
if (validNumber(value, signed)) return true;
|
|
75
|
+
if (isSecret(value) || !Array.isArray(value)) return false;
|
|
76
|
+
const amounts = value as OwnedLuaArray<unknown>;
|
|
77
|
+
const length = amounts.length;
|
|
78
|
+
if (length < 2 || length > 4) return false;
|
|
79
|
+
for (let index = 0; index < length; index++) {
|
|
80
|
+
if (!validNumber(amounts[index], signed)) return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function resolveLayout(props: Layout): Result<LayoutStyle> {
|
|
86
|
+
const { style } = props;
|
|
87
|
+
let display = style?.display;
|
|
88
|
+
if (style?.layoutDisplay !== undefined) {
|
|
89
|
+
const flow = readLayoutValue(style.layoutDisplay);
|
|
90
|
+
if (!flow.ok) return flow;
|
|
91
|
+
display = flow.value;
|
|
92
|
+
}
|
|
93
|
+
const result: LayoutStyle = { display: display === "none" ? undefined : display };
|
|
94
|
+
for (const key of numberKeys) {
|
|
95
|
+
const next = readLayoutValue(style?.[key]);
|
|
96
|
+
if (!next.ok) return next;
|
|
97
|
+
if (next.value === undefined) continue;
|
|
98
|
+
if (!validNumber(next.value)) return fail("Invalid layout " + key);
|
|
99
|
+
result[key] = next.value;
|
|
100
|
+
}
|
|
101
|
+
for (const key of lengthKeys) {
|
|
102
|
+
const size = readLayoutValue(key === "flexBasis" ? style?.flexBasis : props[key] ?? style?.[key]);
|
|
103
|
+
if (!size.ok) return size;
|
|
104
|
+
if (size.value === undefined) continue;
|
|
105
|
+
if (size.value !== "auto" && !validNumber(size.value) && (key === "flexBasis" || layoutPercent(size.value) === undefined)) {
|
|
106
|
+
return fail("Invalid layout " + key);
|
|
107
|
+
}
|
|
108
|
+
result[key] = size.value;
|
|
109
|
+
}
|
|
110
|
+
for (const key of insetKeys) {
|
|
111
|
+
const inset = readLayoutValue(style?.[key]);
|
|
112
|
+
if (!inset.ok) return inset;
|
|
113
|
+
if (inset.value === undefined) continue;
|
|
114
|
+
if (!validNumber(inset.value, true)) return fail("Invalid layout " + key);
|
|
115
|
+
result[key] = inset.value;
|
|
116
|
+
}
|
|
117
|
+
for (const key of ["padding", "margin"] as const) {
|
|
118
|
+
const next = readLayoutValue(style?.[key]);
|
|
119
|
+
if (!next.ok) return next;
|
|
120
|
+
if (next.value === undefined) continue;
|
|
121
|
+
if (!insets(next.value, key === "margin")) return fail("Invalid layout " + key);
|
|
122
|
+
result[key] = next.value;
|
|
123
|
+
}
|
|
124
|
+
for (const [key, choices] of layoutEnums) {
|
|
125
|
+
const next = readLayoutValue(style?.[key as keyof typeof enums]);
|
|
126
|
+
if (!next.ok) return next;
|
|
127
|
+
if (next.value === undefined) continue;
|
|
128
|
+
if (!(choices as readonly string[] as OwnedReadonlyArray<string>).includes(next.value)) return fail("Invalid layout " + key);
|
|
129
|
+
(result as Record<string, unknown>)[key] = next.value;
|
|
130
|
+
}
|
|
131
|
+
for (const key of ["gridTemplateColumns", "gridTemplateRows"] as const) {
|
|
132
|
+
const value = readLayoutValue(style?.[key]);
|
|
133
|
+
if (!value.ok) return value;
|
|
134
|
+
if (value.value === undefined) continue;
|
|
135
|
+
const tracks = typeof value.value === "string" ? parseGridTracks(value.value) : undefined;
|
|
136
|
+
if (tracks === undefined) return fail("Invalid " + key);
|
|
137
|
+
result[key] = tracks;
|
|
138
|
+
}
|
|
139
|
+
const span = readLayoutValue(style?.gridColumn);
|
|
140
|
+
if (!span.ok) return span;
|
|
141
|
+
if (span.value !== undefined) {
|
|
142
|
+
const parsed = typeof span.value === "string" ? parseGridSpan(span.value) : undefined;
|
|
143
|
+
if (parsed === undefined) return fail("Invalid gridColumn");
|
|
144
|
+
result.gridColumn = parsed;
|
|
145
|
+
}
|
|
146
|
+
return ok(result);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function sameLayoutValue(previous: unknown, current: unknown): boolean {
|
|
150
|
+
if (previous === current) return true;
|
|
151
|
+
if (Array.isArray(previous) && Array.isArray(current)) {
|
|
152
|
+
const before = previous as OwnedLuaArray<unknown>;
|
|
153
|
+
const after = current as OwnedLuaArray<unknown>;
|
|
154
|
+
const length = before.length;
|
|
155
|
+
if (length !== after.length) return false;
|
|
156
|
+
for (let index = 0; index < length; index++) {
|
|
157
|
+
if (!sameLayoutValue(before[index], after[index])) return false;
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
if (typeof previous !== "object" || previous === null || typeof current !== "object" || current === null) return false;
|
|
162
|
+
const fields = Object.entries(previous);
|
|
163
|
+
const next = current as Record<string, unknown>;
|
|
164
|
+
return fields.length === Object.keys(next).length && fields.every(([key, value]) => sameLayoutValue(value, next[key]));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function layoutFailure(region: Geometry, kind: string, role: Role, reason: string, combat?: true): LayoutFailure {
|
|
168
|
+
const name = protect(() => readableString(region.GetDebugName?.()));
|
|
169
|
+
const description = name.ok && name.value !== undefined && name.value !== "" ? `${kind} ${name.value}` : kind;
|
|
170
|
+
return { ok: false, reason: `${reason} (layout ${role}: ${description})`, combat };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function acceptRegion(region: Geometry, role: Role = "region", placement?: "absolute"): Result<void> {
|
|
174
|
+
if (!canAccessRegion(region)) return fail("Layout region is inaccessible");
|
|
175
|
+
const kind = reveal(region.GetObjectType());
|
|
176
|
+
if (kind === undefined) return fail("Layout region is unreadable");
|
|
177
|
+
if (kind !== "FontString" && kind !== "Texture" && typeof region.IsProtected !== "function") {
|
|
178
|
+
return layoutFailure(region, kind, role, "Layout requires readable frame protection. Use an explicit anchor.");
|
|
179
|
+
}
|
|
180
|
+
// Protection propagates up to parents and anchor targets, never down to children. Layout only inspects
|
|
181
|
+
// an ancestor and writes no geometry to it, so its protection (UIParent is explicitly protected) is irrelevant.
|
|
182
|
+
if (role === "ancestor") return ok(undefined);
|
|
183
|
+
if (typeof region.IsProtected === "function") {
|
|
184
|
+
const [state, explicit] = region.IsProtected();
|
|
185
|
+
const protectedState = reveal(state);
|
|
186
|
+
const explicitState = reveal(explicit);
|
|
187
|
+
if (role === "anchor" && placement === "absolute" && protectedState === true && explicitState === true) {
|
|
188
|
+
// Absolute placement changes the child only. A protected parent can be its anchor outside combat.
|
|
189
|
+
if (reveal(api.InCombatLockdown()) !== false) {
|
|
190
|
+
return layoutFailure(region, kind, role, "Absolute layout is waiting for its protected anchor to leave combat.", true);
|
|
191
|
+
}
|
|
192
|
+
return ok(undefined);
|
|
193
|
+
}
|
|
194
|
+
const inherited = protectedState === true && explicitState === false;
|
|
195
|
+
const unsafe = "Layout requires unprotected frames. Use an explicit anchor for protected frames.";
|
|
196
|
+
if (explicitState === true || protectedState !== false && !inherited) return layoutFailure(region, kind, role, unsafe);
|
|
197
|
+
const restricted = region.IsAnchoringRestricted?.();
|
|
198
|
+
if ((region.IsAnchoringRestricted !== undefined || inherited) && reveal(restricted) !== false) {
|
|
199
|
+
return layoutFailure(region, kind, role, "Layout requires a readable and unrestricted anchor.");
|
|
200
|
+
}
|
|
201
|
+
if (inherited) {
|
|
202
|
+
if (reveal(api.InCombatLockdown()) !== false) {
|
|
203
|
+
return layoutFailure(region, kind, role, "Layout is waiting for inherited protection to clear after combat.", true);
|
|
204
|
+
}
|
|
205
|
+
if (reveal(region.CanChangeProtectedState?.()) !== true) return layoutFailure(region, kind, role, unsafe);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return ok(undefined);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function acceptParent(parent: FrameParent, initialRole: Role = "anchor", placement?: "absolute"): Result<Frame> {
|
|
212
|
+
let current = reveal(parent) as Frame | undefined;
|
|
213
|
+
if (current === undefined) return fail("Layout requires a readable native parent");
|
|
214
|
+
const initial = current;
|
|
215
|
+
const visited = new Set<Frame>();
|
|
216
|
+
while (current !== undefined) {
|
|
217
|
+
if (visited.has(current) || typeof current.IsProtected !== "function") return fail("Layout requires readable parent protection");
|
|
218
|
+
const accessible = acceptRegion(current, current === initial ? initialRole : "ancestor", placement);
|
|
219
|
+
if (!accessible.ok) return accessible;
|
|
220
|
+
visited.add(current);
|
|
221
|
+
const owner = current.GetParent();
|
|
222
|
+
if (isSecret(owner)) return fail("Layout requires readable parent protection");
|
|
223
|
+
current = owner as Frame | undefined;
|
|
224
|
+
}
|
|
225
|
+
return ok(initial);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function validateLayoutParent(this: void, region: Geometry, parent: FrameParent, placement?: "absolute"): Result<Frame> {
|
|
229
|
+
const safe = acceptRegion(region);
|
|
230
|
+
return safe.ok ? acceptParent(parent, "anchor", placement) : safe;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function readSize(region: Pick<Geometry, "GetSize">): LayoutSize {
|
|
234
|
+
const [width, height] = region.GetSize();
|
|
235
|
+
return { width: validNumber(width) ? width : 0, height: validNumber(height) ? height : 0 };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
type Flow = NativeLayoutItem | { rows: readonly NativeLayoutItem[] };
|
|
239
|
+
|
|
240
|
+
export interface NativeLayoutGroup {
|
|
241
|
+
readonly enqueue: (this: void) => void;
|
|
242
|
+
readonly children: OwnedArray<Flow>;
|
|
243
|
+
readonly visibility: OwnedSet<NativeLayoutItem>;
|
|
244
|
+
readonly textMeasure: (this: void, text: FontString, source?: (this: void) => string | undefined) => Measure;
|
|
245
|
+
}
|
|
246
|
+
export type StageInitialLayout = (this: void, job: Job) => boolean;
|
|
247
|
+
|
|
248
|
+
export class NativeLayoutItem {
|
|
249
|
+
readonly group: NativeLayoutGroup;
|
|
250
|
+
private style?: LayoutStyle;
|
|
251
|
+
private shown = true;
|
|
252
|
+
private visual = true;
|
|
253
|
+
private lastRect?: LayoutRect;
|
|
254
|
+
private naturalSize?: LayoutSize;
|
|
255
|
+
|
|
256
|
+
constructor(readonly region: Geometry, readonly parent: FrameParent, readonly inFlow: boolean,
|
|
257
|
+
readonly fullWidth: boolean, readonly isContainer: boolean, group: NativeLayoutGroup, private readonly measure?: Measure,
|
|
258
|
+
private readonly minContentWidth?: FlexNode["minContentWidth"], private readonly afterWidth?: (this: void, width: number) => void) {
|
|
259
|
+
this.group = { ...group as OwnedRecord<NativeLayoutGroup>, children: [] as Flow[] as OwnedArray<Flow> };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
bind(props: Layout, scope: RuntimeScope): Result<void> {
|
|
263
|
+
const sub = scope.watchEffect(() => {
|
|
264
|
+
const next = resolveLayout(props);
|
|
265
|
+
if (!next.ok) return next;
|
|
266
|
+
const shown = props.style?.display === "none" ? ok(false) : readLayoutValue(props.shown);
|
|
267
|
+
if (!shown.ok) return shown;
|
|
268
|
+
const visible = shown.value !== false;
|
|
269
|
+
const changed = this.style === undefined || !sameLayoutValue(this.style, next.value);
|
|
270
|
+
if (visible === this.shown && !changed) return;
|
|
271
|
+
const visibilityChanged = visible !== this.shown;
|
|
272
|
+
this.style = next.value;
|
|
273
|
+
this.shown = visible;
|
|
274
|
+
if (visibilityChanged && (!visible || !this.inFlow && !changed)) this.updateVisibility();
|
|
275
|
+
if (changed || this.inFlow) this.group.enqueue();
|
|
276
|
+
});
|
|
277
|
+
if (!sub.ok) return sub;
|
|
278
|
+
this.region.SetShown(false);
|
|
279
|
+
return ok(undefined);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
visibility(shown: boolean): void {
|
|
283
|
+
this.visual = shown;
|
|
284
|
+
this.updateVisibility();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
private updateVisibility() {
|
|
288
|
+
if (this.lastRect === undefined) return;
|
|
289
|
+
if (acceptRegion(this.region).ok) this.commitVisibility();
|
|
290
|
+
else {
|
|
291
|
+
this.group.visibility.add(this);
|
|
292
|
+
this.group.enqueue();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
commitVisibility(writes?: LayoutWrites): void {
|
|
297
|
+
this.region.SetShown(this.shown && this.visual);
|
|
298
|
+
if (writes !== undefined) writes.count++;
|
|
299
|
+
this.group.visibility.delete(this);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
snapshot(): Snapshot {
|
|
303
|
+
const entries = this.isContainer ? this.visibleChildren() : undefined;
|
|
304
|
+
return {
|
|
305
|
+
item: this,
|
|
306
|
+
entries,
|
|
307
|
+
node: {
|
|
308
|
+
style: this.style ?? {},
|
|
309
|
+
fullWidth: this.fullWidth,
|
|
310
|
+
children: entries === undefined ? undefined : entries.map(({ node }) => node),
|
|
311
|
+
measure: this.isContainer ? undefined : this.measure ?? (() => this.naturalSize ??= readSize(this.region)),
|
|
312
|
+
minContentWidth: this.minContentWidth,
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
private visibleChildren(): OwnedArray<Snapshot> {
|
|
318
|
+
const entries = [] as Snapshot[] as OwnedArray<Snapshot>;
|
|
319
|
+
for (const child of this.group.children) {
|
|
320
|
+
const items = child instanceof NativeLayoutItem ? [child] : child.rows as OwnedReadonlyArray<NativeLayoutItem>;
|
|
321
|
+
for (const item of items) {
|
|
322
|
+
if (item.shown) entries.push(item.snapshot());
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return entries;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** Places the region; true when its anchor or size changed (a candidate for `repairAnchor`). */
|
|
329
|
+
commit(rect: LayoutRect, writes?: LayoutWrites): boolean {
|
|
330
|
+
const previous = this.lastRect;
|
|
331
|
+
const { region, parent } = this;
|
|
332
|
+
let moved = false;
|
|
333
|
+
if (this.inFlow && (previous === undefined || previous.x !== rect.x || previous.y !== rect.y)) {
|
|
334
|
+
if (previous === undefined) region.ClearAllPoints();
|
|
335
|
+
region.SetPoint("TOPLEFT", parent, "TOPLEFT", rect.x, -rect.y);
|
|
336
|
+
if (writes !== undefined) writes.count += previous === undefined ? 2 : 1;
|
|
337
|
+
moved = true;
|
|
338
|
+
}
|
|
339
|
+
if (previous === undefined || previous.width !== rect.width || previous.height !== rect.height) {
|
|
340
|
+
region.SetSize(Math.max(sliver, rect.width), Math.max(sliver, rect.height));
|
|
341
|
+
if (writes !== undefined) writes.count++;
|
|
342
|
+
moved = true;
|
|
343
|
+
}
|
|
344
|
+
if (previous === undefined || previous.width !== rect.width) this.afterWidth?.(rect.width);
|
|
345
|
+
this.lastRect = rect;
|
|
346
|
+
if (previous === undefined || reveal(region.IsShown()) !== (this.shown && this.visual)) {
|
|
347
|
+
this.commitVisibility(writes);
|
|
348
|
+
}
|
|
349
|
+
return moved && this.inFlow;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* The client can leave a shown region without a rect when its anchor was set while the parent had none yet (a page
|
|
354
|
+
* body still being placed), and does not resolve it again on its own: the first section of a settings page stays
|
|
355
|
+
* invisible and leaves a gap above the rest (2026-11-21; 2026-11-22 owner's /ku probe dumps - the probe sets the same
|
|
356
|
+
* anchor again and the section appears). Set the anchor again once the parent has a rect. "done" also covers
|
|
357
|
+
* regions that need nothing or never will (hidden, or a parent that is hidden); "wait" while the parent has no rect.
|
|
358
|
+
*/
|
|
359
|
+
repairAnchor(): "done" | "wait" {
|
|
360
|
+
const last = this.lastRect;
|
|
361
|
+
const { region } = this;
|
|
362
|
+
if (last === undefined || reveal(region.IsVisible?.()) !== true) return "done";
|
|
363
|
+
if (reveal(region.IsRectValid?.()) !== false) return "done";
|
|
364
|
+
const parent = reveal(this.parent) as RectParent | undefined;
|
|
365
|
+
if (parent === undefined) return "done";
|
|
366
|
+
if (reveal(parent.IsRectValid?.()) !== true) return "wait";
|
|
367
|
+
if (!acceptRegion(region).ok) return "done";
|
|
368
|
+
region.ClearAllPoints();
|
|
369
|
+
region.SetPoint("TOPLEFT", this.parent, "TOPLEFT", last.x, -last.y);
|
|
370
|
+
return "done";
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
interface Snapshot {
|
|
375
|
+
item: NativeLayoutItem;
|
|
376
|
+
node: FlexNode;
|
|
377
|
+
entries?: OwnedArray<Snapshot>;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function validateTree(tree: Snapshot): Result<void> {
|
|
381
|
+
const own = acceptRegion(tree.item.region);
|
|
382
|
+
if (!own.ok) return own;
|
|
383
|
+
if (tree.item.inFlow) {
|
|
384
|
+
const anchor = reveal(tree.item.parent) as Frame | undefined;
|
|
385
|
+
if (anchor === undefined) return fail("Layout requires a readable native parent");
|
|
386
|
+
const accepted = acceptRegion(anchor, "anchor");
|
|
387
|
+
if (!accepted.ok) return accepted;
|
|
388
|
+
}
|
|
389
|
+
for (const child of tree.entries ?? []) {
|
|
390
|
+
const nested = validateTree(child);
|
|
391
|
+
if (!nested.ok) return nested;
|
|
392
|
+
}
|
|
393
|
+
return ok(undefined);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function snappedRect(rect: LayoutRect, point: LayoutRect, pixel: number): LayoutRect {
|
|
397
|
+
const snap = (edge: number) => Math.floor(edge / pixel + 0.5) * pixel;
|
|
398
|
+
const x = point.x + rect.x;
|
|
399
|
+
const y = point.y + rect.y;
|
|
400
|
+
const left = snap(x);
|
|
401
|
+
const top = snap(y);
|
|
402
|
+
return {
|
|
403
|
+
x: left - snap(point.x), y: top - snap(point.y),
|
|
404
|
+
width: snap(x + rect.width) - left, height: snap(y + rect.height) - top,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function finiteLayout(result: FlexLayout): boolean {
|
|
409
|
+
const { x, y, width, height } = result.rect;
|
|
410
|
+
return Number.isFinite(x) && Number.isFinite(y) && validNumber(width) && validNumber(height)
|
|
411
|
+
&& (result.children as OwnedReadonlyArray<FlexLayout>).every(child => finiteLayout(child));
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function commitTree(tree: Snapshot, result: FlexLayout, origin: LayoutRect, pixel: number,
|
|
415
|
+
moved: OwnedArray<NativeLayoutItem>, writes?: LayoutWrites): void {
|
|
416
|
+
const rect = result.rect;
|
|
417
|
+
if (tree.item.commit(snappedRect(rect, origin, pixel), writes)) moved.push(tree.item);
|
|
418
|
+
const entries = tree.entries;
|
|
419
|
+
if (entries === undefined) return;
|
|
420
|
+
const point = { ...rect as OwnedRecord<LayoutRect>, x: origin.x + rect.x, y: origin.y + rect.y };
|
|
421
|
+
const children = result.children as OwnedReadonlyArray<FlexLayout>;
|
|
422
|
+
for (let index = 0; index < entries.length; index++) commitTree(entries[index], children[index], point, pixel, moved, writes);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function readableString(value: unknown): string | undefined {
|
|
426
|
+
const plain = reveal(value);
|
|
427
|
+
return typeof plain === "string" ? plain : undefined;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function createTextMeasurer(root: Frame, retry: (this: void) => void, pixel: (this: void) => number): NativeLayoutGroup["textMeasure"] {
|
|
431
|
+
let scratch: FontString | undefined;
|
|
432
|
+
return (text, source) => {
|
|
433
|
+
let lastText: string | undefined;
|
|
434
|
+
let lastPath: string | undefined;
|
|
435
|
+
let lastSize: number | undefined;
|
|
436
|
+
let lastFlags: string | undefined;
|
|
437
|
+
let lastSpacing: number | undefined;
|
|
438
|
+
let lastWrap = false;
|
|
439
|
+
let lastWidth: number | undefined;
|
|
440
|
+
let natural: LayoutSize | undefined;
|
|
441
|
+
let snapped: LayoutSize | undefined;
|
|
442
|
+
let measuredPixel: number | undefined;
|
|
443
|
+
let wrapped: LayoutSize | undefined;
|
|
444
|
+
let fallback = empty;
|
|
445
|
+
let retried = false;
|
|
446
|
+
|
|
447
|
+
function measure(width: number | undefined): LayoutSize | undefined {
|
|
448
|
+
if (lastText === undefined || lastPath === undefined || lastSize === undefined || lastSize <= 0) return;
|
|
449
|
+
scratch ??= root.CreateFontString();
|
|
450
|
+
const measurement = scratch;
|
|
451
|
+
measurement.SetShown(false);
|
|
452
|
+
measurement.SetFont(lastPath, lastSize, lastFlags);
|
|
453
|
+
if (lastSpacing !== undefined) measurement.SetSpacing(lastSpacing);
|
|
454
|
+
measurement.SetWordWrap(lastWrap);
|
|
455
|
+
measurement.SetWidth(0);
|
|
456
|
+
measurement.SetText(lastText);
|
|
457
|
+
const naturalWidth = measurement.GetStringWidth();
|
|
458
|
+
if (width !== undefined && width > 0) measurement.SetWidth(width);
|
|
459
|
+
const height = measurement.GetStringHeight();
|
|
460
|
+
if (validNumber(naturalWidth) && naturalWidth > 0 && validNumber(height) && height > 0) {
|
|
461
|
+
return { width: naturalWidth, height };
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return width => {
|
|
466
|
+
const content = source === undefined ? readableString(text.GetText()) : source();
|
|
467
|
+
const [rawPath, rawSize, rawFlags] = text.GetFont();
|
|
468
|
+
const path = readableString(rawPath), flags = readableString(rawFlags);
|
|
469
|
+
const size = reveal(rawSize), spacing = reveal(text.GetSpacing());
|
|
470
|
+
const wrap = reveal(text.CanWordWrap()) === true;
|
|
471
|
+
if (content !== lastText || path !== lastPath || size !== lastSize || flags !== lastFlags
|
|
472
|
+
|| spacing !== lastSpacing || wrap !== lastWrap) {
|
|
473
|
+
lastText = content;
|
|
474
|
+
lastPath = path;
|
|
475
|
+
lastSize = validNumber(size) ? size : undefined;
|
|
476
|
+
lastFlags = flags;
|
|
477
|
+
lastSpacing = validNumber(spacing, true) ? spacing : undefined;
|
|
478
|
+
lastWrap = wrap;
|
|
479
|
+
natural = undefined;
|
|
480
|
+
snapped = undefined;
|
|
481
|
+
wrapped = undefined;
|
|
482
|
+
retried = false;
|
|
483
|
+
}
|
|
484
|
+
if (content === "" || content === undefined) return empty;
|
|
485
|
+
if (width === undefined || !wrap) {
|
|
486
|
+
natural ??= measure(undefined);
|
|
487
|
+
if (natural !== undefined) {
|
|
488
|
+
if (wrap) return fallback = natural;
|
|
489
|
+
// The native box snaps both edges independently. Reserve enough pixels for the full label.
|
|
490
|
+
const unit = pixel();
|
|
491
|
+
if (snapped === undefined || unit !== measuredPixel) {
|
|
492
|
+
measuredPixel = unit;
|
|
493
|
+
snapped = { width: Math.ceil(natural.width / unit) * unit, height: natural.height };
|
|
494
|
+
}
|
|
495
|
+
return fallback = snapped;
|
|
496
|
+
}
|
|
497
|
+
} else {
|
|
498
|
+
if (lastWidth !== width) {
|
|
499
|
+
lastWidth = width;
|
|
500
|
+
wrapped = undefined;
|
|
501
|
+
}
|
|
502
|
+
wrapped ??= measure(width);
|
|
503
|
+
if (wrapped !== undefined) return fallback = wrapped;
|
|
504
|
+
}
|
|
505
|
+
if (!retried) {
|
|
506
|
+
retried = true;
|
|
507
|
+
retry();
|
|
508
|
+
}
|
|
509
|
+
return fallback;
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
export function isAbsoluteFill(this: void, props: Layout): boolean {
|
|
515
|
+
const { style } = props;
|
|
516
|
+
return props.anchor === undefined && style?.position === "absolute"
|
|
517
|
+
&& style.top === 0 && style.right === 0 && style.bottom === 0 && style.left === 0 && style.autoMargin === undefined
|
|
518
|
+
&& props.width === undefined && style.width === undefined && props.height === undefined && style.height === undefined;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
export function mountLayoutRoot(this: void, frame: Frame, parent: FrameParent, props: Layout, scope: RuntimeScope,
|
|
522
|
+
diagnostics?: NativeLayoutDiagnostics, stageInitial?: StageInitialLayout): Result<NativeLayoutItem> {
|
|
523
|
+
// The root keeps its own anchors. A zero-inset absolute root gets both axes from its containing block.
|
|
524
|
+
const supported = acceptParent(parent, "ancestor");
|
|
525
|
+
if (!supported.ok) return supported;
|
|
526
|
+
const safe = acceptRegion(frame);
|
|
527
|
+
if (!safe.ok) return safe;
|
|
528
|
+
const owner = supported.value;
|
|
529
|
+
const key = {};
|
|
530
|
+
const fillsParent = isAbsoluteFill(props);
|
|
531
|
+
const readWidth = fillsParent || props.fullWidth === true;
|
|
532
|
+
const measured = readWidth ? readSize(owner) : empty;
|
|
533
|
+
let availableWidth = readWidth ? measured.width : undefined;
|
|
534
|
+
let availableHeight = fillsParent ? measured.height : undefined;
|
|
535
|
+
let scale = reveal(frame.GetEffectiveScale());
|
|
536
|
+
let committing = false;
|
|
537
|
+
let waiting = false;
|
|
538
|
+
let deferred: ProtectedLayoutUpdate | undefined;
|
|
539
|
+
let lastFailure: string | undefined;
|
|
540
|
+
let root: NativeLayoutItem;
|
|
541
|
+
const visibility = new Set<NativeLayoutItem>() as OwnedSet<NativeLayoutItem>;
|
|
542
|
+
const initial = stageInitial === undefined ? undefined : () => layout(true);
|
|
543
|
+
const enqueue = () => {
|
|
544
|
+
if (!scope.isActive() || waiting) return;
|
|
545
|
+
if (initial !== undefined && stageInitial?.(initial) === true) return;
|
|
546
|
+
scope.frameJobs.queue(key, layout, layoutJob);
|
|
547
|
+
};
|
|
548
|
+
// Only the regions the last layout moved are checked, parents first, for a few frames at most; a region drops out
|
|
549
|
+
// as soon as it has a rect or has been anchored again (A279 walked the whole tree for up to 120 frames).
|
|
550
|
+
const repairKey = {};
|
|
551
|
+
let pending = [] as NativeLayoutItem[] as OwnedArray<NativeLayoutItem>;
|
|
552
|
+
let repairs = 0;
|
|
553
|
+
function repair(this: void) {
|
|
554
|
+
const attempt = protect(() => {
|
|
555
|
+
const waiting = [] as NativeLayoutItem[] as OwnedArray<NativeLayoutItem>;
|
|
556
|
+
for (const item of pending) if (item.repairAnchor() === "wait") waiting.push(item);
|
|
557
|
+
return ok(waiting);
|
|
558
|
+
});
|
|
559
|
+
pending = attempt.ok && attempt.value.ok ? attempt.value.value : [] as NativeLayoutItem[] as OwnedArray<NativeLayoutItem>;
|
|
560
|
+
if (pending.length > 0 && scope.isActive() && ++repairs < repairFrames) scope.frameJobs.queue(repairKey, repair, repairJob);
|
|
561
|
+
else pending = [] as NativeLayoutItem[] as OwnedArray<NativeLayoutItem>;
|
|
562
|
+
}
|
|
563
|
+
let pixel = 1;
|
|
564
|
+
const textMeasure = createTextMeasurer(frame, () => scope.nextTick(enqueue), () => pixel);
|
|
565
|
+
|
|
566
|
+
function layout(this: void, initial?: true) {
|
|
567
|
+
const attempt = protect(() => {
|
|
568
|
+
const live = acceptParent(owner, "ancestor");
|
|
569
|
+
if (!live.ok) return live;
|
|
570
|
+
const tree = root.snapshot();
|
|
571
|
+
const allowed = validateTree(tree);
|
|
572
|
+
if (!allowed.ok) return allowed;
|
|
573
|
+
for (const item of visibility) {
|
|
574
|
+
const safe = acceptRegion(item.region);
|
|
575
|
+
if (!safe.ok) return safe;
|
|
576
|
+
}
|
|
577
|
+
pixel = physicalPixel(frame);
|
|
578
|
+
const result = solveLayout(tree.node, { width: availableWidth, height: availableHeight });
|
|
579
|
+
if (!finiteLayout(result)) return fail("Layout resolved nonfinite geometry");
|
|
580
|
+
committing = true;
|
|
581
|
+
const moved = [] as NativeLayoutItem[] as OwnedArray<NativeLayoutItem>;
|
|
582
|
+
const writes = diagnostics?.enabled() === true ? { count: 0 } : undefined;
|
|
583
|
+
commitTree(tree, result, { ...empty, x: 0, y: 0 }, pixel, moved, writes);
|
|
584
|
+
for (const item of [...visibility]) item.commitVisibility(writes);
|
|
585
|
+
if (moved.length > 0) {
|
|
586
|
+
const queued = new Set(pending);
|
|
587
|
+
for (const item of moved) if (!queued.has(item)) pending.push(item);
|
|
588
|
+
repairs = 0;
|
|
589
|
+
scope.frameJobs.queue(repairKey, repair, repairJob);
|
|
590
|
+
}
|
|
591
|
+
if (writes !== undefined) diagnostics?.committed(writes.count);
|
|
592
|
+
return ok(undefined);
|
|
593
|
+
});
|
|
594
|
+
committing = false;
|
|
595
|
+
const result = attempt.ok ? attempt.value : attempt;
|
|
596
|
+
if (result.ok) { lastFailure = undefined; return; }
|
|
597
|
+
if (initial === true) return result;
|
|
598
|
+
if ((result as LayoutFailure).combat === true) {
|
|
599
|
+
if (deferred === undefined) {
|
|
600
|
+
const update = createProtectedLayoutUpdate(() => {
|
|
601
|
+
waiting = false;
|
|
602
|
+
return layout();
|
|
603
|
+
}, { scope, label: layoutJob.label });
|
|
604
|
+
if (!update.ok) return update;
|
|
605
|
+
deferred = update.value;
|
|
606
|
+
}
|
|
607
|
+
waiting = true;
|
|
608
|
+
const next = deferred.request();
|
|
609
|
+
if (!next.ok) { waiting = false; return next; }
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
if (lastFailure !== result.reason) {
|
|
613
|
+
lastFailure = result.reason;
|
|
614
|
+
return result;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
root = new NativeLayoutItem(frame, parent, false, props.fullWidth === true, true,
|
|
619
|
+
{ enqueue, children: [] as Flow[] as OwnedArray<Flow>, visibility, textMeasure });
|
|
620
|
+
const cleanup = scope.onDispose(() => {
|
|
621
|
+
scope.frameJobs.cancel(key);
|
|
622
|
+
scope.frameJobs.cancel(repairKey);
|
|
623
|
+
pending = [] as NativeLayoutItem[] as OwnedArray<NativeLayoutItem>;
|
|
624
|
+
});
|
|
625
|
+
if (!cleanup.ok) return cleanup;
|
|
626
|
+
const resize = hookScript(owner, "OnSizeChanged", () => {
|
|
627
|
+
if (committing) return;
|
|
628
|
+
const size = readWidth ? readSize(owner) : empty;
|
|
629
|
+
const width = readWidth ? size.width : undefined;
|
|
630
|
+
const height = fillsParent ? size.height : undefined;
|
|
631
|
+
const currentScale = reveal(frame.GetEffectiveScale());
|
|
632
|
+
if (width === availableWidth && height === availableHeight && currentScale === scale) return;
|
|
633
|
+
availableWidth = width;
|
|
634
|
+
availableHeight = height;
|
|
635
|
+
scale = currentScale;
|
|
636
|
+
enqueue();
|
|
637
|
+
}, scope);
|
|
638
|
+
if (!resize.ok) return resize;
|
|
639
|
+
const metrics = watchDisplayMetrics(scope, enqueue);
|
|
640
|
+
if (!metrics.ok) return metrics;
|
|
641
|
+
const installed = root.bind(props, scope);
|
|
642
|
+
return installed.ok ? ok(root) : installed;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
export function attachLayoutItem(this: void, group: NativeLayoutGroup, region: Geometry, parent: FrameParent, props: Layout,
|
|
646
|
+
scope: RuntimeScope, container = false, measure?: Measure, detached = false, minContentWidth?: FlexNode["minContentWidth"],
|
|
647
|
+
afterWidth?: (this: void, width: number) => void): Result<NativeLayoutItem> {
|
|
648
|
+
const safe = validateLayoutParent(region, parent);
|
|
649
|
+
if (!safe.ok) return safe;
|
|
650
|
+
const item = new NativeLayoutItem(region, parent, true, props.fullWidth === true, container, group, measure, minContentWidth, afterWidth);
|
|
651
|
+
const remove = scope.onDispose(() => {
|
|
652
|
+
const index = group.children.indexOf(item);
|
|
653
|
+
if (index >= 0) group.children.splice(index, 1);
|
|
654
|
+
group.visibility.delete(item);
|
|
655
|
+
if (acceptRegion(region).ok) region.SetShown(false);
|
|
656
|
+
group.enqueue();
|
|
657
|
+
});
|
|
658
|
+
if (!remove.ok) return remove;
|
|
659
|
+
const installed = item.bind(props, scope);
|
|
660
|
+
if (!installed.ok) return installed;
|
|
661
|
+
if (!detached) group.children.push(item);
|
|
662
|
+
return ok(item);
|
|
663
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { readFontPath } from "./frame-access";
|
|
2
|
+
import type { FontString, FrameMap } from "./frames";
|
|
3
|
+
import { api } from "./native";
|
|
4
|
+
|
|
5
|
+
/** Apply a UI family while keeping Blizzard's existing glyph coverage in localized clients. */
|
|
6
|
+
export function createLocaleFont(this: void, family: string) {
|
|
7
|
+
return (target: FontString | FrameMap["EditBox"], size: number) => {
|
|
8
|
+
const previous = readFontPath(target);
|
|
9
|
+
const locale = api.GetLocale();
|
|
10
|
+
const path = locale === "ruRU" || locale === "koKR" || locale === "zhCN" || locale === "zhTW"
|
|
11
|
+
? previous ?? family : family;
|
|
12
|
+
if (!target.SetFont(path, size, "") && previous !== undefined && path !== previous) target.SetFont(previous, size, "");
|
|
13
|
+
target.SetShadowOffset(0, 0);
|
|
14
|
+
};
|
|
15
|
+
}
|