@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
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { fail, ok, type Failure, type Result } from "../src/result";
|
|
2
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
3
|
+
import type { Cancel } from "../src/scheduler";
|
|
4
|
+
import type { Frame } from "./frames";
|
|
5
|
+
import { validateLayoutParent } from "./layout-view";
|
|
6
|
+
import { api, reveal } from "./native";
|
|
7
|
+
import { hookScript } from "./native-hooks";
|
|
8
|
+
|
|
9
|
+
interface ContainedFrameOptions {
|
|
10
|
+
/** Keep the frame's own scale and dimensions and only center it. */
|
|
11
|
+
readonly centerOnly?: boolean;
|
|
12
|
+
/** Maximum multiplier relative to the frame's scale when the supplier hands it over. */
|
|
13
|
+
readonly maxGrow?: number;
|
|
14
|
+
readonly unmeasuredScale?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type FrameSource = (this: void) => Frame | false | undefined;
|
|
18
|
+
|
|
19
|
+
/** Place a borrowed frame as its owner supplies samples. False keeps the current frame. */
|
|
20
|
+
export function createContainedFrame(this: void, parent: Frame, scope: RuntimeScope, options: ContainedFrameOptions = {}) {
|
|
21
|
+
const { centerOnly, maxGrow, unmeasuredScale } = options;
|
|
22
|
+
if ((maxGrow !== undefined && (!Number.isFinite(maxGrow) || maxGrow <= 0))
|
|
23
|
+
|| (unmeasuredScale !== undefined && (!Number.isFinite(unmeasuredScale) || unmeasuredScale <= 0))) {
|
|
24
|
+
return fail("Invalid contained frame scale");
|
|
25
|
+
}
|
|
26
|
+
let current: Frame | undefined;
|
|
27
|
+
let stopSampleResize: Cancel | undefined;
|
|
28
|
+
let busy = false;
|
|
29
|
+
let active = true;
|
|
30
|
+
let maximum: number | undefined;
|
|
31
|
+
|
|
32
|
+
function measureScale(frame: Frame, host: Frame) {
|
|
33
|
+
const [rawWidth, rawHeight] = frame.GetSize();
|
|
34
|
+
const [rawAvailableWidth, rawAvailableHeight] = host.GetSize();
|
|
35
|
+
const width = reveal(rawWidth) ?? 0;
|
|
36
|
+
const height = reveal(rawHeight) ?? 0;
|
|
37
|
+
const availableWidth = reveal(rawAvailableWidth) ?? 0;
|
|
38
|
+
const availableHeight = reveal(rawAvailableHeight) ?? 0;
|
|
39
|
+
const fitted = width > 0 && height > 0 ? Math.min(availableWidth / width, availableHeight / height, maximum ?? Infinity) : 0;
|
|
40
|
+
return Number.isFinite(fitted) && fitted > 0 ? fitted : unmeasuredScale;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function fit(frame: Frame, place: boolean): Failure | undefined {
|
|
44
|
+
if (busy || (centerOnly && !place)) return;
|
|
45
|
+
const anchor = validateLayoutParent(frame, parent);
|
|
46
|
+
if (!anchor.ok) return anchor;
|
|
47
|
+
const scale = centerOnly ? undefined : measureScale(frame, anchor.value);
|
|
48
|
+
const applied = scale === undefined ? undefined : reveal(frame.GetScale());
|
|
49
|
+
const resize = scale !== undefined && (applied === undefined || Math.abs(applied - scale) > Math.max(1e-6, scale * 1e-6));
|
|
50
|
+
if (!resize && !place) return;
|
|
51
|
+
busy = true;
|
|
52
|
+
const placed = scope.protect(() => {
|
|
53
|
+
if (resize && scale !== undefined) frame.SetScale(scale);
|
|
54
|
+
if (place) {
|
|
55
|
+
frame.ClearAllPoints();
|
|
56
|
+
frame.SetPoint("CENTER", anchor.value, "CENTER");
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
busy = false;
|
|
60
|
+
return placed.ok ? undefined : placed;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function refit(frame: Frame) {
|
|
64
|
+
if (frame !== current) return;
|
|
65
|
+
const failure = fit(frame, false);
|
|
66
|
+
if (failure !== undefined) api.geterrorhandler()(failure.reason);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function disconnectSample() {
|
|
70
|
+
stopSampleResize?.();
|
|
71
|
+
stopSampleResize = undefined;
|
|
72
|
+
current = undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const holder = centerOnly ? undefined
|
|
76
|
+
: hookScript(parent, "OnSizeChanged", () => { if (current !== undefined) refit(current); }, scope);
|
|
77
|
+
if (holder?.ok === false) return holder;
|
|
78
|
+
|
|
79
|
+
function update(this: void, read: FrameSource): Failure | undefined {
|
|
80
|
+
if (!active || busy || !scope.isActive()) return;
|
|
81
|
+
busy = true;
|
|
82
|
+
const next = scope.protect(read);
|
|
83
|
+
busy = false;
|
|
84
|
+
if (!next.ok) return next;
|
|
85
|
+
if (!active || !scope.isActive() || next.value === false) return;
|
|
86
|
+
const frame = next.value;
|
|
87
|
+
if (!centerOnly && frame !== undefined && maxGrow !== undefined) {
|
|
88
|
+
const own = reveal(frame.GetScale()) ?? 1;
|
|
89
|
+
maximum = Number.isFinite(own) && own > 0 ? own * maxGrow : 0;
|
|
90
|
+
}
|
|
91
|
+
if (current === frame) return frame === undefined ? undefined : fit(frame, false);
|
|
92
|
+
disconnectSample();
|
|
93
|
+
if (frame === undefined) return;
|
|
94
|
+
const sample = centerOnly ? undefined : hookScript(frame, "OnSizeChanged", () => refit(frame), scope);
|
|
95
|
+
if (sample?.ok === false) return sample;
|
|
96
|
+
current = frame;
|
|
97
|
+
stopSampleResize = sample?.value;
|
|
98
|
+
const placed = fit(frame, true);
|
|
99
|
+
if (placed !== undefined) disconnectSample();
|
|
100
|
+
return placed;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const stop = () => {
|
|
104
|
+
active = false;
|
|
105
|
+
holder?.value();
|
|
106
|
+
disconnectSample();
|
|
107
|
+
};
|
|
108
|
+
const cleanup = scope.onDispose(stop);
|
|
109
|
+
if (!cleanup.ok) {
|
|
110
|
+
stop();
|
|
111
|
+
return cleanup;
|
|
112
|
+
}
|
|
113
|
+
const dispose = () => { cleanup.value(); stop(); };
|
|
114
|
+
return ok({ update, dispose });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Center and refit the current borrowed frame without taking ownership of it. */
|
|
118
|
+
export function bindContainedFrame(this: void, parent: Frame, scope: RuntimeScope, read: (this: void) => Frame | undefined): Result<Cancel> {
|
|
119
|
+
const created = createContainedFrame(parent, scope);
|
|
120
|
+
if (!created.ok) return created;
|
|
121
|
+
const { update, dispose } = created.value;
|
|
122
|
+
const observed = scope.watchEffect(() => update(read));
|
|
123
|
+
if (!observed.ok) {
|
|
124
|
+
dispose();
|
|
125
|
+
return observed;
|
|
126
|
+
}
|
|
127
|
+
return ok(() => { observed.value(); dispose(); });
|
|
128
|
+
}
|
package/wow/contract.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Cancel, CVars, Result } from "../src";
|
|
2
|
+
import type { WoWEventMap } from "@kumi/wow-generated";
|
|
3
|
+
import type { WoWCVarSchema } from "./cvar-schema";
|
|
4
|
+
|
|
5
|
+
export { wowCVarSchema } from "./cvar-schema";
|
|
6
|
+
export type { WoWCVarName, WoWCVarSchema, WoWCVarValue } from "./cvar-schema";
|
|
7
|
+
|
|
8
|
+
export interface PartyApi {
|
|
9
|
+
inGroup: (this: void, category?: number) => boolean;
|
|
10
|
+
isLeader: (this: void) => boolean;
|
|
11
|
+
isAssistant: (this: void) => boolean;
|
|
12
|
+
readyCheck: (this: void) => void;
|
|
13
|
+
countdown: (this: void, seconds: number) => boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface WoWApi {
|
|
17
|
+
now: (this: void) => number;
|
|
18
|
+
inCombat: (this: void) => boolean;
|
|
19
|
+
spellIcon: (this: void, spellId: number) => number | undefined;
|
|
20
|
+
cvars: CVars<WoWCVarSchema>;
|
|
21
|
+
party: PartyApi;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type { WoWEventMap };
|
|
25
|
+
export type WoWEvent = keyof WoWEventMap;
|
|
26
|
+
|
|
27
|
+
export interface EventScope {
|
|
28
|
+
onDispose: (this: void, stop: Cancel) => Result<(this: void) => boolean>;
|
|
29
|
+
isActive: (this: void) => boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface EventOptions {
|
|
33
|
+
label?: string;
|
|
34
|
+
unit?: string;
|
|
35
|
+
units?: string[];
|
|
36
|
+
coalesce?: "frame" | number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface EventApi {
|
|
40
|
+
on: <E extends WoWEvent>(this: void, scope: EventScope, event: E,
|
|
41
|
+
handler: (this: void, ...payload: WoWEventMap[E]) => void, options?: EventOptions) => Result<Cancel>;
|
|
42
|
+
}
|
package/wow/css-box.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Element, NativeStyle } from "../src/elements";
|
|
2
|
+
import type { OwnedRecord } from "../src/owned-collections";
|
|
3
|
+
import { ok, type Result } from "../src/result";
|
|
4
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
5
|
+
import type { StyleEnvironment } from "../src/style-variables";
|
|
6
|
+
import { createFrame, type Frame, type FrameParent } from "./frames";
|
|
7
|
+
import { borderInsets, createCssSurface, type CssSurface, type CssSurfaceOptions } from "./css-surfaces";
|
|
8
|
+
import type { ReadCssStyle } from "./css-style";
|
|
9
|
+
import { hookScript } from "./native-hooks";
|
|
10
|
+
import { reveal } from "./native";
|
|
11
|
+
import { mountLayoutRoot, readLayoutValue, type NativeLayoutGroup, type StageInitialLayout } from "./layout-view";
|
|
12
|
+
import { mountScrollView, type CreateScrollArea } from "./scroll-view";
|
|
13
|
+
import type { NativePaintState } from "./state-paint";
|
|
14
|
+
|
|
15
|
+
type FrameProps = Element<"frame">["props"];
|
|
16
|
+
type Inset = readonly [top: number, right: number, bottom: number, left: number];
|
|
17
|
+
type Content = { readonly frame: Frame; readonly layout?: NativeLayoutGroup };
|
|
18
|
+
|
|
19
|
+
export function hasCssSurface(this: void, style: NativeStyle, paint?: NativePaintState): boolean {
|
|
20
|
+
return style.border !== undefined || style.backgroundImage !== undefined || (style.borderRadius !== undefined
|
|
21
|
+
&& (style.backgroundColor !== undefined || paint?.usesBackgroundColor === true || paint?.usesBackgroundImage === true));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function mountCssSurface(this: void, scope: RuntimeScope, frame: Frame, style: NativeStyle, paint: NativePaintState | undefined,
|
|
25
|
+
rounded: CssSurfaceOptions["rounded"], environment?: StyleEnvironment, live?: ReadCssStyle, nativeRoundedArt?: true): Result<CssSurface> {
|
|
26
|
+
const created = createCssSurface(scope, frame, {
|
|
27
|
+
rounded, environment, nativeRoundedArt, color: style.backgroundColor !== undefined || paint?.usesBackgroundColor === true,
|
|
28
|
+
image: style.backgroundImage !== undefined || paint?.usesBackgroundImage === true,
|
|
29
|
+
borderState: style.border !== undefined && paint?.usesBorderColor === true,
|
|
30
|
+
});
|
|
31
|
+
if (!created.ok) return created;
|
|
32
|
+
const installed = scope.watchEffect(() => {
|
|
33
|
+
const current = live?.() ?? style;
|
|
34
|
+
const result = created.value.setBorder(current.border, current.borderRadius);
|
|
35
|
+
if (!result.ok) return result;
|
|
36
|
+
});
|
|
37
|
+
return installed.ok ? created : installed;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function padding(style: NativeStyle | undefined, live?: ReadCssStyle, decorativeBorder = false): Result<Inset> {
|
|
41
|
+
const read = readLayoutValue(style?.padding);
|
|
42
|
+
if (!read.ok) return read;
|
|
43
|
+
const [bt, br, bb, bl] = borderInsets(decorativeBorder ? undefined : (live?.() ?? style)?.border);
|
|
44
|
+
const amount = read.value ?? 0;
|
|
45
|
+
if (typeof amount === "number") return ok([amount + bt, amount + br, amount + bb, amount + bl]);
|
|
46
|
+
const [top, right, bottom, left] = amount;
|
|
47
|
+
return ok([top + bt, (right ?? top) + br, (bottom ?? top) + bb, (left ?? right ?? top) + bl]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function includeCssBorderPadding(this: void, scope: RuntimeScope, props: FrameProps, live?: ReadCssStyle, decorativeBorder = false): FrameProps {
|
|
51
|
+
const style = props.style;
|
|
52
|
+
if (decorativeBorder || style?.border === undefined) return props;
|
|
53
|
+
const adjusted = scope.computedResult(() => padding(style, live), "CSS border padding");
|
|
54
|
+
return { ...props as OwnedRecord<FrameProps>, style: { ...style as OwnedRecord<NativeStyle>, padding: adjusted } };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function insetContent(scope: RuntimeScope, frame: Frame, style: NativeStyle, live?: ReadCssStyle, decorativeBorder = false): Result<Frame> {
|
|
58
|
+
const content = createFrame("Frame", undefined, frame);
|
|
59
|
+
let last: Inset | undefined;
|
|
60
|
+
const placed = scope.watchEffect(() => {
|
|
61
|
+
const read = padding(style, live, decorativeBorder);
|
|
62
|
+
if (!read.ok) return read;
|
|
63
|
+
const next = read.value;
|
|
64
|
+
if (last !== undefined && last.every((value, index) => value === next[index])) return;
|
|
65
|
+
const [top, right, bottom, left] = next;
|
|
66
|
+
if (last !== undefined) content.ClearAllPoints();
|
|
67
|
+
content.SetPoint("TOPLEFT", frame, "TOPLEFT", left, -top);
|
|
68
|
+
content.SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -right, bottom);
|
|
69
|
+
last = next;
|
|
70
|
+
});
|
|
71
|
+
return placed.ok ? ok(content) : placed;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Choose native clipping and the standalone flow root for a CSS scrolling box. */
|
|
75
|
+
export function mountCssContent(this: void, scope: RuntimeScope, frame: Frame, style: NativeStyle,
|
|
76
|
+
layout: NativeLayoutGroup | undefined, createScroll?: CreateScrollArea, live?: ReadCssStyle, decorativeBorder = false,
|
|
77
|
+
stageInitial?: StageInitialLayout): Result<Content> {
|
|
78
|
+
const overflow = style.overflow;
|
|
79
|
+
const needsInset = layout === undefined && (decorativeBorder ? style.padding !== undefined : style.border !== undefined);
|
|
80
|
+
const content = needsInset ? insetContent(scope, frame, style, live, decorativeBorder) : ok(frame);
|
|
81
|
+
if (!content.ok) return content;
|
|
82
|
+
if (overflow !== "scroll") return ok({ frame: content.value, layout });
|
|
83
|
+
|
|
84
|
+
const scroll = mountScrollView(content.value, scope, { contentHeight: 1 }, createScroll);
|
|
85
|
+
if (scroll.failure !== undefined) return scroll.failure;
|
|
86
|
+
scroll.frame.SetAllPoints(content.value);
|
|
87
|
+
const display = style.display === "grid" ? "grid" : "flex";
|
|
88
|
+
const contentStyle: NativeStyle = { ...style as OwnedRecord<NativeStyle>, display, flexDirection: style.flexDirection ?? "column" };
|
|
89
|
+
// The viewport uses the declared height. The scroll child uses its content's height.
|
|
90
|
+
contentStyle.width = undefined;
|
|
91
|
+
contentStyle.height = undefined;
|
|
92
|
+
contentStyle.minHeight = undefined;
|
|
93
|
+
contentStyle.maxHeight = undefined;
|
|
94
|
+
contentStyle.overflow = undefined;
|
|
95
|
+
contentStyle.padding = needsInset ? undefined : style.padding;
|
|
96
|
+
let contentHeight = 1;
|
|
97
|
+
const resize = hookScript(scroll.content, "OnSizeChanged", (_, _width, height) => {
|
|
98
|
+
const next = reveal(height);
|
|
99
|
+
if (next === undefined || next === contentHeight) return;
|
|
100
|
+
contentHeight = next;
|
|
101
|
+
scroll.frame.SetContentHeight(Math.max(1, next));
|
|
102
|
+
}, scope);
|
|
103
|
+
if (!resize.ok) return resize;
|
|
104
|
+
// A host can wrap the viewport in a wider frame that owns padding and the scrollbar.
|
|
105
|
+
const viewport = (reveal(scroll.content.GetParent()) as FrameParent | undefined) ?? scroll.frame;
|
|
106
|
+
const root = mountLayoutRoot(scroll.content, viewport, { style: contentStyle, fullWidth: true }, scope, undefined, stageInitial);
|
|
107
|
+
if (!root.ok) return root;
|
|
108
|
+
scroll.notifyVisible();
|
|
109
|
+
return ok({ frame: scroll.content, layout: root.value.group });
|
|
110
|
+
}
|
package/wow/css-color.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { hexToRGB, type RGBA } from "../utils/colors";
|
|
2
|
+
import { isSecret } from "./native";
|
|
3
|
+
|
|
4
|
+
/** CSS colors can carry a separate alpha in the last byte. */
|
|
5
|
+
export function readCssColor(this: void, value: string): RGBA | undefined {
|
|
6
|
+
if (isSecret(value)) return;
|
|
7
|
+
const hasAlpha = value.length === 9 && value.startsWith("#");
|
|
8
|
+
const rgb = hexToRGB(hasAlpha ? value.slice(0, 7) : value);
|
|
9
|
+
if (rgb === undefined) return;
|
|
10
|
+
const alpha = hasAlpha ? hexToRGB(value.slice(7) + "0000")?.[0] : 1;
|
|
11
|
+
if (alpha !== undefined) return [rgb[0], rgb[1], rgb[2], alpha];
|
|
12
|
+
}
|
package/wow/css-style.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { mergeCssTokens, resolveCssTokens } from "../src/css-tokens";
|
|
2
|
+
import type { CssTokenRecipe } from "../src/css-v1";
|
|
3
|
+
import type { Element, NativeStyle } from "../src/elements";
|
|
4
|
+
import type { MediaObserver } from "../src/media-query";
|
|
5
|
+
import { ownedArray, type OwnedArray, type OwnedReadonlyArray, type OwnedRecord } from "../src/owned-collections";
|
|
6
|
+
import { ref } from "../src/reactivity";
|
|
7
|
+
import { fail, ok, type Result } from "../src/result";
|
|
8
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
9
|
+
import type { StyleEnvironment } from "../src/style-variables";
|
|
10
|
+
import { readLayoutValue } from "./layout-view";
|
|
11
|
+
|
|
12
|
+
type Layout = Pick<Element<"frame">["props"], "style" | "shown" | "opacity">;
|
|
13
|
+
type MediaStyle = NonNullable<NativeStyle["mediaStyles"]>[number];
|
|
14
|
+
type ActiveMediaStyle = { style: NativeStyle; active: ReturnType<MediaObserver<string>["matches"]> };
|
|
15
|
+
export type ReadCssStyle = (this: void) => NativeStyle;
|
|
16
|
+
|
|
17
|
+
const layoutValues = new Set<keyof NativeStyle>([
|
|
18
|
+
"top", "right", "bottom", "left", "width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight",
|
|
19
|
+
"padding", "margin", "gap", "rowGap", "columnGap", "flexGrow", "flexShrink", "flexBasis", "flexDirection", "justifyContent",
|
|
20
|
+
"alignItems", "alignSelf", "justifyItems", "gridTemplateColumns", "gridTemplateRows", "gridColumn",
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
/** Bind token-backed layout fields while leaving the renderer's topology fixed. */
|
|
24
|
+
export function prepareCssStyle<Props extends Layout>(this: void, scope: RuntimeScope, props: Props, environment?: StyleEnvironment,
|
|
25
|
+
canContainLayout = false, media?: MediaObserver<string>):
|
|
26
|
+
Result<{ readonly props: Props; readonly read: ReadCssStyle }> {
|
|
27
|
+
const base = props.style!;
|
|
28
|
+
let variants: OwnedArray<ActiveMediaStyle> | undefined;
|
|
29
|
+
const mediaStyles = media === undefined ? undefined : base.mediaStyles;
|
|
30
|
+
if (media !== undefined && mediaStyles !== undefined) {
|
|
31
|
+
const observed = ownedArray<ActiveMediaStyle>();
|
|
32
|
+
for (const variant of mediaStyles as OwnedReadonlyArray<MediaStyle>) {
|
|
33
|
+
observed.push({ style: variant.style, active: media.matches(variant.when) });
|
|
34
|
+
}
|
|
35
|
+
variants = observed;
|
|
36
|
+
}
|
|
37
|
+
const roots = new Set<string>();
|
|
38
|
+
function collectRoots(style: NativeStyle) {
|
|
39
|
+
const recipes = style.styleTokens;
|
|
40
|
+
if (recipes === undefined) return;
|
|
41
|
+
for (const recipe of recipes as OwnedReadonlyArray<CssTokenRecipe>) {
|
|
42
|
+
const field = (recipe.path as OwnedReadonlyArray<string | number>)[0];
|
|
43
|
+
if (typeof field === "string") roots.add(field);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
collectRoots(base);
|
|
47
|
+
if (variants !== undefined) {
|
|
48
|
+
for (const variant of variants) {
|
|
49
|
+
for (const field of Object.keys(variant.style)) roots.add(field);
|
|
50
|
+
collectRoots(variant.style);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function readStyle() {
|
|
54
|
+
if (variants === undefined) return resolveCssTokens(base, environment);
|
|
55
|
+
const current = { ...base as OwnedRecord<NativeStyle> };
|
|
56
|
+
for (const variant of variants) {
|
|
57
|
+
if (!variant.active.value) continue;
|
|
58
|
+
const tokens = mergeCssTokens(current.styleTokens, variant.style);
|
|
59
|
+
Object.assign(current, variant.style as OwnedRecord<NativeStyle>);
|
|
60
|
+
current.styleTokens = tokens;
|
|
61
|
+
}
|
|
62
|
+
return resolveCssTokens(current, environment);
|
|
63
|
+
}
|
|
64
|
+
let initial: NativeStyle | undefined;
|
|
65
|
+
const live = ref<NativeStyle>(base);
|
|
66
|
+
const watched = scope.watchEffect(() => {
|
|
67
|
+
const next = readStyle();
|
|
68
|
+
if (!next.ok) return next;
|
|
69
|
+
if (initial !== undefined && next.value.overflow !== initial.overflow) return fail("CSS overflow is fixed at mount");
|
|
70
|
+
initial ??= next.value;
|
|
71
|
+
live.value = next.value;
|
|
72
|
+
});
|
|
73
|
+
if (!watched.ok) return watched;
|
|
74
|
+
const first = initial;
|
|
75
|
+
if (first === undefined) return fail("CSS style did not initialize");
|
|
76
|
+
const dynamicDisplay = canContainLayout && roots.has("display");
|
|
77
|
+
let display = first.display;
|
|
78
|
+
if (display === "none") {
|
|
79
|
+
display = base.display;
|
|
80
|
+
if (display === "none") display = undefined;
|
|
81
|
+
}
|
|
82
|
+
if (dynamicDisplay && display === undefined) display = "flex";
|
|
83
|
+
const style: NativeStyle = { ...first as OwnedRecord<NativeStyle>, display };
|
|
84
|
+
const rebound = style as Record<string, unknown>;
|
|
85
|
+
for (const field of roots) {
|
|
86
|
+
const key = field as keyof NativeStyle;
|
|
87
|
+
if (!layoutValues.has(key)) continue;
|
|
88
|
+
rebound[field] = scope.computedResult(() => readLayoutValue(live.value[key]), "CSS " + field);
|
|
89
|
+
}
|
|
90
|
+
const nextProps = { ...props as OwnedRecord<Props>, style };
|
|
91
|
+
if (roots.has("opacity") && props.opacity === undefined) {
|
|
92
|
+
nextProps.opacity = scope.computedResult(() => ok(live.value.opacity ?? 1), "CSS opacity");
|
|
93
|
+
}
|
|
94
|
+
if (roots.has("display")) {
|
|
95
|
+
if (dynamicDisplay) {
|
|
96
|
+
const fallback = display === "grid" ? "grid" : "flex";
|
|
97
|
+
style.layoutDisplay = scope.computedResult(() => {
|
|
98
|
+
const mode = live.value.display;
|
|
99
|
+
return ok(mode === undefined || mode === "none" ? fallback : mode);
|
|
100
|
+
}, "CSS layout mode");
|
|
101
|
+
}
|
|
102
|
+
nextProps.shown = scope.computedResult(() => {
|
|
103
|
+
if (live.value.display === "none") return ok(false);
|
|
104
|
+
const value = readLayoutValue(props.shown);
|
|
105
|
+
return value.ok ? ok(value.value !== false) : value;
|
|
106
|
+
}, "CSS display");
|
|
107
|
+
}
|
|
108
|
+
return ok({ props: nextProps, read: () => live.value });
|
|
109
|
+
}
|