@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
package/src/elements.ts
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import type { ImageAsset, ImageVerticalGradient, NativeImageLayer } from "./images";
|
|
2
|
+
import type { KumiNode, MountedElementKind, NodeRef } from "./element-node";
|
|
3
|
+
import type { CssV1Style } from "./css-v1";
|
|
4
|
+
import type { StateStyleVariant } from "./style-states";
|
|
5
|
+
import { resolveStyleClasses, type ClassNames } from "./style-classes";
|
|
6
|
+
import type { LayoutStyle } from "./flex-layout";
|
|
7
|
+
import type { MountKeyedList } from "./keyed-list";
|
|
8
|
+
import { attachMediaReads, markMediaReads, type MediaQuery, type MediaRead } from "./media-query";
|
|
9
|
+
import { ownedArray, type OwnedArray, type OwnedLuaArray, type OwnedReadonlyArray, type OwnedRecord } from "./owned-collections";
|
|
10
|
+
import type { ReadonlyRef } from "./reactivity";
|
|
11
|
+
import type { Result } from "./result";
|
|
12
|
+
import type { StyleVariables } from "./style-variables";
|
|
13
|
+
import { TextBinding, type TextRef } from "./text-children";
|
|
14
|
+
import type { TransitionOptions } from "./transition";
|
|
15
|
+
|
|
16
|
+
export type ColumnCount = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
17
|
+
|
|
18
|
+
export interface Style {
|
|
19
|
+
height?: number;
|
|
20
|
+
gap?: number;
|
|
21
|
+
columns?: ColumnCount;
|
|
22
|
+
maxScale?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface Choice {
|
|
26
|
+
key: string;
|
|
27
|
+
label: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface Anchor {
|
|
31
|
+
point: "TOP" | "BOTTOM" | "LEFT" | "RIGHT" | "CENTER" | "TOPLEFT" | "TOPRIGHT" | "BOTTOMLEFT" | "BOTTOMRIGHT";
|
|
32
|
+
x?: number;
|
|
33
|
+
y?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type Binding<T> = T | ReadonlyRef<T> | ReadonlyRef<Result<T>>;
|
|
37
|
+
export type TextureSource = string | number | undefined;
|
|
38
|
+
export type TextureCoordinates = readonly [left: number, right: number, bottom: number, top: number];
|
|
39
|
+
export type ActionSlot = Readonly<{ kind: "item" | "spell" | "toy"; id: number }>;
|
|
40
|
+
export type CooldownValue = Readonly<{ start: number; duration: number; rate: number }>;
|
|
41
|
+
|
|
42
|
+
declare const nativeStatusBarValue: unique symbol;
|
|
43
|
+
|
|
44
|
+
/** A numeric value or an opaque number supplied by a native host. */
|
|
45
|
+
export type StatusBarValue = number | {
|
|
46
|
+
readonly [nativeStatusBarValue]: true;
|
|
47
|
+
readonly nativeValue: unknown;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export interface FocusTarget {
|
|
51
|
+
focus(this: void): boolean;
|
|
52
|
+
blur?(this: void): void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type FocusRef = (this: void, target?: FocusTarget) => void;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Native handles by element kind. A platform adapter fills it in by declaration merging; `@kumi/wow`
|
|
59
|
+
* maps `frame` to its Frame type, `image` to Texture and so on. Kinds it leaves out receive `unknown`.
|
|
60
|
+
*/
|
|
61
|
+
export interface NativeHandles {}
|
|
62
|
+
export type NativeHandle<Kind extends string> = Kind extends keyof NativeHandles ? NativeHandles[Kind] : unknown;
|
|
63
|
+
/** Called with the native handle after the element and its children mount, and with nothing when it is released. */
|
|
64
|
+
export type ElementRef<Kind extends string> = (this: void, handle?: NativeHandle<Kind>) => void;
|
|
65
|
+
|
|
66
|
+
export type MouseButton = "LeftButton" | "RightButton" | "MiddleButton" | "Button4" | "Button5";
|
|
67
|
+
export interface ClickEvent {
|
|
68
|
+
readonly button: MouseButton;
|
|
69
|
+
readonly shift: boolean;
|
|
70
|
+
readonly ctrl: boolean;
|
|
71
|
+
readonly alt: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type HitTarget = NativeHandle<"frame" | "statusbar" | "button" | "scrollview"> | KumiNode;
|
|
75
|
+
export type InsideTarget = HitTarget | ReadonlyRef<HitTarget | undefined>;
|
|
76
|
+
|
|
77
|
+
export type TooltipLine = string | Readonly<{ text?: string; style?: string; color?: string }>;
|
|
78
|
+
export type ElementTooltipContent = string | readonly TooltipLine[]
|
|
79
|
+
| Readonly<{ kind: "item" | "spell"; id: number }>;
|
|
80
|
+
|
|
81
|
+
export interface ElementTooltip {
|
|
82
|
+
readonly content: ElementTooltipContent | ((this: void) => ElementTooltipContent | undefined);
|
|
83
|
+
readonly delaySeconds?: number;
|
|
84
|
+
readonly position?: "CURSOR" | Anchor;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface ElementEvents {
|
|
88
|
+
onClick?(this: void, event: ClickEvent): void;
|
|
89
|
+
onPointerEnter?(this: void): void;
|
|
90
|
+
onPointerLeave?(this: void): void;
|
|
91
|
+
onClickOutside?(this: void, event: ClickEvent): void;
|
|
92
|
+
onDismiss?(this: void, reason: "outside" | "escape"): void;
|
|
93
|
+
layerKind?: "transient" | "window";
|
|
94
|
+
dismissOn?: { outside?: boolean; escape?: boolean };
|
|
95
|
+
inside?: readonly InsideTarget[];
|
|
96
|
+
ignoreOutside?: boolean;
|
|
97
|
+
/** Explicitly disabling propagation captures native clicks even without an onClick action. */
|
|
98
|
+
propagateClicks?: boolean;
|
|
99
|
+
tooltip?: ElementTooltip;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Combine callback refs for one element. */
|
|
103
|
+
export function mergeRefs<Handle>(this: void, ...refs: readonly (((this: void, handle?: Handle) => void) | undefined)[]) {
|
|
104
|
+
return (handle?: Handle) => {
|
|
105
|
+
for (const ref of refs) ref?.(handle);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
109
|
+
type HeadingTag = `h${HeadingLevel}`;
|
|
110
|
+
const headingLevels: Record<HeadingTag, HeadingLevel> = { h1: 1, h2: 2, h3: 3, h4: 4, h5: 5, h6: 6 };
|
|
111
|
+
export type ElementKey = string | number;
|
|
112
|
+
|
|
113
|
+
type LayoutBindings = Omit<LayoutStyle, "display" | "gridTemplateColumns" | "gridTemplateRows" | "gridColumn"
|
|
114
|
+
| "position" | "top" | "right" | "bottom" | "left">;
|
|
115
|
+
type NativeLayoutStyle = { [Key in keyof LayoutBindings]: Binding<NonNullable<LayoutBindings[Key]>> };
|
|
116
|
+
|
|
117
|
+
export interface NativeStyle extends NativeLayoutStyle, CssV1Style {
|
|
118
|
+
display?: LayoutStyle["display"] | "none";
|
|
119
|
+
gridTemplateColumns?: Binding<string>;
|
|
120
|
+
gridTemplateRows?: Binding<string>;
|
|
121
|
+
gridColumn?: Binding<`span ${number}`>;
|
|
122
|
+
zIndex?: number;
|
|
123
|
+
fontSize?: number;
|
|
124
|
+
opacity?: number;
|
|
125
|
+
color?: string;
|
|
126
|
+
backgroundColor?: string;
|
|
127
|
+
stateStyles?: readonly StateStyleVariant[];
|
|
128
|
+
mediaStyles?: readonly MediaStyleVariant[];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface MediaStyleVariant {
|
|
132
|
+
readonly when: MediaQuery<string>;
|
|
133
|
+
readonly style: Readonly<Omit<NativeStyle, "mediaStyles">>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
interface NativeLayout {
|
|
137
|
+
width?: Binding<number>;
|
|
138
|
+
height?: Binding<number>;
|
|
139
|
+
fullWidth?: boolean;
|
|
140
|
+
anchor?: Binding<Anchor>;
|
|
141
|
+
shown?: Binding<boolean>;
|
|
142
|
+
opacity?: Binding<number>;
|
|
143
|
+
id?: string;
|
|
144
|
+
part?: string;
|
|
145
|
+
className?: string;
|
|
146
|
+
data?: Readonly<Record<string, string>>;
|
|
147
|
+
[attribute: `data-${string}`]: string | undefined;
|
|
148
|
+
cssVars?: StyleVariables;
|
|
149
|
+
style?: NativeStyle;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
type ElementLayout<Kind extends MountedElementKind> = NativeLayout & { nodeRef?: NodeRef<Kind> };
|
|
153
|
+
|
|
154
|
+
interface NativeProps {
|
|
155
|
+
frame: ElementLayout<"frame"> & ElementEvents & {
|
|
156
|
+
ref?: ElementRef<"frame">;
|
|
157
|
+
/** The native frame's own scale in parent coordinates. */
|
|
158
|
+
nativeScale?: Binding<number>;
|
|
159
|
+
/** Lay out this keyed frame directly in its parent CSS container. */
|
|
160
|
+
directKeyedLayout?: true;
|
|
161
|
+
/** Decorative artwork for WoW, reconciled as a single layer without child frames. */
|
|
162
|
+
nativeImageLayers?: Binding<readonly NativeImageLayer[]>;
|
|
163
|
+
/** Use the host's two native nine-slice textures for a rounded fill and decorative 1px border. */
|
|
164
|
+
nativeRoundedArt?: true;
|
|
165
|
+
onShow?(this: void): void;
|
|
166
|
+
onHide?(this: void): void;
|
|
167
|
+
};
|
|
168
|
+
image: ElementLayout<"image"> & ElementEvents & {
|
|
169
|
+
src: ImageAsset;
|
|
170
|
+
alt?: string;
|
|
171
|
+
inheritColor?: boolean;
|
|
172
|
+
verticalGradient?: Binding<ImageVerticalGradient>;
|
|
173
|
+
/** Disable native texture snapping for geometry already measured in physical pixels. */
|
|
174
|
+
nativePixelSnap?: false;
|
|
175
|
+
/** Bind the texture's native desaturated state. */
|
|
176
|
+
nativeDesaturated?: Binding<boolean>;
|
|
177
|
+
ref?: ElementRef<"image">;
|
|
178
|
+
};
|
|
179
|
+
texture: Omit<NativeProps["image"], "src"> & {
|
|
180
|
+
src: Binding<TextureSource>;
|
|
181
|
+
texCoords?: TextureCoordinates;
|
|
182
|
+
onSourceChange?(this: void, source: TextureSource): void;
|
|
183
|
+
};
|
|
184
|
+
cooldown: NativeLayout & {
|
|
185
|
+
value: Binding<CooldownValue | undefined>;
|
|
186
|
+
};
|
|
187
|
+
scrollview: ElementLayout<"scrollview"> & {
|
|
188
|
+
contentHeight: Binding<number>;
|
|
189
|
+
ref?: ElementRef<"scrollview">;
|
|
190
|
+
onScroll?(this: void, offset: number): void;
|
|
191
|
+
onShow?(this: void): void;
|
|
192
|
+
onHide?(this: void): void;
|
|
193
|
+
};
|
|
194
|
+
text: ElementLayout<"text"> & ElementEvents & {
|
|
195
|
+
value: Binding<string>;
|
|
196
|
+
/** Limit the visible native FontString lines while retaining ordinary wrapping. */
|
|
197
|
+
nativeMaxLines?: number;
|
|
198
|
+
nativeTextSpacing?: number;
|
|
199
|
+
nativeTextVerticalAlign?: "TOP" | "MIDDLE" | "BOTTOM";
|
|
200
|
+
font?: string;
|
|
201
|
+
fontSize?: Binding<number>;
|
|
202
|
+
color?: Binding<string>;
|
|
203
|
+
align?: "LEFT" | "CENTER" | "RIGHT";
|
|
204
|
+
heading?: HeadingLevel;
|
|
205
|
+
ref?: ElementRef<"text">;
|
|
206
|
+
};
|
|
207
|
+
statusbar: ElementLayout<"statusbar"> & ElementEvents & {
|
|
208
|
+
min: Binding<StatusBarValue>;
|
|
209
|
+
max: Binding<StatusBarValue>;
|
|
210
|
+
value: Binding<StatusBarValue>;
|
|
211
|
+
smooth?: boolean;
|
|
212
|
+
ref?: ElementRef<"statusbar">;
|
|
213
|
+
};
|
|
214
|
+
button: ElementLayout<"button"> & ElementEvents & {
|
|
215
|
+
value: Binding<string>;
|
|
216
|
+
ariaLabel?: string;
|
|
217
|
+
unstyled?: boolean;
|
|
218
|
+
/** Use the host's two native nine-slice textures for a rounded fill and decorative 1px border. */
|
|
219
|
+
nativeRoundedArt?: true;
|
|
220
|
+
disabled?: Binding<boolean>;
|
|
221
|
+
checked?: Binding<boolean>;
|
|
222
|
+
ref?: ElementRef<"button">;
|
|
223
|
+
secureAction?: Binding<ActionSlot | undefined>;
|
|
224
|
+
/** An anchored secure button keeps its identity and mounts paint and children on its first show. */
|
|
225
|
+
deferContentUntilShown?: true;
|
|
226
|
+
/** Lay out this keyed button directly in its parent CSS container. */
|
|
227
|
+
directKeyedLayout?: true;
|
|
228
|
+
onReceiveDrag?(this: void): Result<boolean> | void;
|
|
229
|
+
onMove?(this: void, x: number, y: number): void;
|
|
230
|
+
onMoveEnd?(this: void, x: number, y: number): void;
|
|
231
|
+
onMoveCancel?(this: void): void;
|
|
232
|
+
onDrag?(this: void, offsetY: number): void;
|
|
233
|
+
onDragEnd?(this: void, offsetY: number): void;
|
|
234
|
+
onDragCancel?(this: void): void;
|
|
235
|
+
};
|
|
236
|
+
editbox: ElementLayout<"editbox"> & {
|
|
237
|
+
value: Binding<string>;
|
|
238
|
+
type?: "text" | "search" | "password";
|
|
239
|
+
label?: string;
|
|
240
|
+
placeholder?: string;
|
|
241
|
+
unstyled?: boolean;
|
|
242
|
+
nativeImageLayers?: Binding<readonly NativeImageLayer[]>;
|
|
243
|
+
nativeRoundedArt?: true;
|
|
244
|
+
disabled?: Binding<boolean>;
|
|
245
|
+
maxLetters?: number;
|
|
246
|
+
ref?: FocusRef;
|
|
247
|
+
onChange?(this: void, value: string): void;
|
|
248
|
+
onFocus?(this: void): void;
|
|
249
|
+
onBlur?(this: void): void;
|
|
250
|
+
onEnter?(this: void, value: string): void;
|
|
251
|
+
onEscape?(this: void): void;
|
|
252
|
+
};
|
|
253
|
+
checkbox: ElementLayout<"checkbox"> & {
|
|
254
|
+
checked: Binding<boolean>;
|
|
255
|
+
disabled?: Binding<boolean>;
|
|
256
|
+
label?: string;
|
|
257
|
+
ariaLabel?: string;
|
|
258
|
+
onChange?(this: void, checked: boolean): void;
|
|
259
|
+
};
|
|
260
|
+
range: ElementLayout<"range"> & {
|
|
261
|
+
value: Binding<number>;
|
|
262
|
+
disabled?: Binding<boolean>;
|
|
263
|
+
label: string;
|
|
264
|
+
/** The label may be presented by the containing field. */
|
|
265
|
+
hideLabel?: true;
|
|
266
|
+
min: number;
|
|
267
|
+
max: number;
|
|
268
|
+
step?: number;
|
|
269
|
+
onChange?(this: void, value: number): void;
|
|
270
|
+
/** Runs after a pointer adjustment that changed the value. */
|
|
271
|
+
onCommit?(this: void): void;
|
|
272
|
+
};
|
|
273
|
+
listbox: ElementLayout<"listbox"> & {
|
|
274
|
+
value: Binding<string>;
|
|
275
|
+
disabled?: Binding<boolean>;
|
|
276
|
+
label: string;
|
|
277
|
+
items?: readonly Choice[];
|
|
278
|
+
placeholder?: string;
|
|
279
|
+
onChange?(this: void, value: string): void;
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
type LabelProps<Props> = Omit<Props, "value"> & {
|
|
284
|
+
value?: Binding<string>;
|
|
285
|
+
children?: UINode;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
type HeadingElements = Record<HeadingTag, LabelProps<Omit<NativeProps["text"], "heading">>>;
|
|
289
|
+
|
|
290
|
+
type TextInput = NativeProps["editbox"] & { type?: "text" | "search" | "password" };
|
|
291
|
+
type CheckboxInput = NativeProps["checkbox"] & { type: "checkbox"; value?: never };
|
|
292
|
+
type RangeInput = NativeProps["range"] & { type: "range"; checked?: never };
|
|
293
|
+
|
|
294
|
+
interface IntrinsicProps extends Omit<NativeProps, "text" | "button">, HeadingElements {
|
|
295
|
+
frame: PropsWithChildren<NativeProps["frame"]>;
|
|
296
|
+
scrollview: PropsWithChildren<NativeProps["scrollview"]>;
|
|
297
|
+
box: PropsWithChildren<NativeProps["frame"]>;
|
|
298
|
+
div: PropsWithChildren<NativeProps["frame"]>;
|
|
299
|
+
text: LabelProps<NativeProps["text"]>;
|
|
300
|
+
span: LabelProps<NativeProps["text"]>;
|
|
301
|
+
button: Omit<NativeProps["button"], "value"> & { value?: Binding<string>; children?: UINode };
|
|
302
|
+
input: (TextInput & { checked?: never }) | CheckboxInput | RangeInput;
|
|
303
|
+
select: PropsWithChildren<NativeProps["listbox"]>;
|
|
304
|
+
option: { value: string; children?: string | number };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
type WithStyleClasses<Props> = Props extends { className?: string }
|
|
308
|
+
? Omit<Props, "className"> & { className?: ClassNames }
|
|
309
|
+
: Props;
|
|
310
|
+
|
|
311
|
+
export type NativeIntrinsicElements = { [Tag in keyof IntrinsicProps]: WithStyleClasses<IntrinsicProps[Tag]> & { key?: ElementKey } };
|
|
312
|
+
export type NativeTag = keyof NativeIntrinsicElements;
|
|
313
|
+
export type NativeKind<Tag extends NativeTag> = Tag extends "box" | "div" ? "frame"
|
|
314
|
+
: Tag extends HeadingTag | "span" ? "text"
|
|
315
|
+
: Tag extends "input" ? "editbox" | "checkbox" | "range"
|
|
316
|
+
: Tag extends "select" ? "listbox" : Tag extends "option" ? "selectItem" : Tag;
|
|
317
|
+
|
|
318
|
+
export interface CustomElements {}
|
|
319
|
+
|
|
320
|
+
interface BuiltInProps extends NativeProps {
|
|
321
|
+
fragment: Record<never, never>;
|
|
322
|
+
keyedList: { mount: MountKeyedList };
|
|
323
|
+
transition: TransitionOptions;
|
|
324
|
+
portal: { target?: KumiNode<"frame"> };
|
|
325
|
+
selectItem: { value: string; label: string };
|
|
326
|
+
slot: ElementLayout<"slot"> & { name: string; optional?: true };
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
type CustomTag = Exclude<Extract<keyof CustomElements, string>, NativeTag | keyof BuiltInProps>;
|
|
330
|
+
type CustomIntrinsicElements = {
|
|
331
|
+
[Tag in CustomTag]: PropsWithChildren<CustomElements[Tag]> & { key?: ElementKey };
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
export type IntrinsicElements = NativeIntrinsicElements & CustomIntrinsicElements;
|
|
335
|
+
export type IntrinsicTag = keyof IntrinsicElements;
|
|
336
|
+
export type IntrinsicKind<Tag extends IntrinsicTag> = Tag extends NativeTag ? NativeKind<Tag> : Tag;
|
|
337
|
+
|
|
338
|
+
type Props = BuiltInProps & CustomElements;
|
|
339
|
+
type Kind = keyof Props;
|
|
340
|
+
export interface Element<K extends Kind> {
|
|
341
|
+
kind: K;
|
|
342
|
+
key?: ElementKey;
|
|
343
|
+
props: Props[K];
|
|
344
|
+
children: UIElement[];
|
|
345
|
+
readonly mediaReads?: readonly MediaRead[];
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export type UIElement = { [K in Kind]: Element<K> }[Kind];
|
|
349
|
+
export type UINode = UIElement | readonly UINode[] | TextRef | string | number | boolean | null | undefined;
|
|
350
|
+
type RenderChild = (this: void, ...args: never[]) => UIElement;
|
|
351
|
+
type Children = { children?: UINode };
|
|
352
|
+
export type PropsWithChildren<Props extends object = object> = Props & Children;
|
|
353
|
+
export type FC<Props extends object = object, Output extends UIElement = UIElement> =
|
|
354
|
+
(this: void, props: PropsWithChildren<Props>) => Output;
|
|
355
|
+
|
|
356
|
+
function isElement(node: UINode): node is UIElement {
|
|
357
|
+
return node != null && typeof node === "object" && "kind" in node;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function isNodeList(node: readonly UINode[] | TextRef): node is readonly UINode[] {
|
|
361
|
+
if (Object.getOwnPropertyDescriptor(node, "length") !== undefined && Array.isArray(node)) return true;
|
|
362
|
+
// TSTL arrays have numeric keys, including when the first child is nil.
|
|
363
|
+
// Empty getter-backed refs can have no own keys in Lua.
|
|
364
|
+
return node.constructor === undefined && Object.getOwnPropertyDescriptor(node, "value") === undefined
|
|
365
|
+
&& Object.keys(node as OwnedLuaArray<UINode>).every(key => typeof key === "number");
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function appendChild(child: UINode, result: OwnedArray<UIElement>): void {
|
|
369
|
+
if (child == null || typeof child === "boolean" || typeof child === "function") return;
|
|
370
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
371
|
+
result.push({ kind: "text", props: { value: String(child) }, children: [] });
|
|
372
|
+
} else if (isElement(child)) {
|
|
373
|
+
if (child.kind === "fragment" && child.key === undefined) {
|
|
374
|
+
for (const node of child.children as OwnedArray<UIElement>) result.push(node);
|
|
375
|
+
} else result.push(child);
|
|
376
|
+
} else if (isNodeList(child)) {
|
|
377
|
+
// Lua's nil entries can leave holes in a JSX list. Keep the remaining children in order.
|
|
378
|
+
const entries = Object.entries(child as OwnedLuaArray<UINode>);
|
|
379
|
+
entries.sort((left, right) => Number(left[0]) - Number(right[0]));
|
|
380
|
+
for (const [, item] of entries) appendChild(item, result);
|
|
381
|
+
} else {
|
|
382
|
+
result.push({ kind: "text", props: { value: new TextBinding([child]) }, children: [] });
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function normalizeChildren(children?: UINode): OwnedArray<UIElement> {
|
|
387
|
+
if (children != null && typeof children === "object" && !isElement(children) && isNodeList(children)
|
|
388
|
+
&& Object.keys(children as OwnedLuaArray<UINode>).length === (children as OwnedLuaArray<UINode>).length
|
|
389
|
+
&& !(children as OwnedReadonlyArray<UINode>).some(child => !isElement(child) || child.kind === "fragment" && child.key === undefined)) {
|
|
390
|
+
return children as OwnedArray<UIElement>;
|
|
391
|
+
}
|
|
392
|
+
const nodes = ownedArray<UIElement>();
|
|
393
|
+
appendChild(children, nodes);
|
|
394
|
+
return nodes;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function textChildren(nodes: UIElement[]): Binding<string> {
|
|
398
|
+
let text = "";
|
|
399
|
+
let parts: OwnedArray<Binding<string>> | undefined;
|
|
400
|
+
function collect(children: UIElement[]): void {
|
|
401
|
+
for (const node of children as OwnedArray<UIElement>) {
|
|
402
|
+
if (node.kind === "fragment") collect(node.children);
|
|
403
|
+
else if (node.kind === "text") {
|
|
404
|
+
const { value } = node.props;
|
|
405
|
+
if (parts) parts.push(value);
|
|
406
|
+
else if (typeof value === "string") text += value;
|
|
407
|
+
else parts = (text === "" ? [value] : [text, value]) as OwnedArray<Binding<string>>;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
collect(nodes);
|
|
412
|
+
return parts ? TextBinding.join(parts) : text;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function optionLabel(nodes: OwnedReadonlyArray<UIElement>): string {
|
|
416
|
+
let text = "";
|
|
417
|
+
for (const node of nodes) if (node.kind === "text" && typeof node.props.value === "string") text += node.props.value;
|
|
418
|
+
return text;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function createElement<K extends IntrinsicTag>(
|
|
422
|
+
this: void, component: K, props: IntrinsicElements[K] | (K extends NativeTag ? undefined : never), ...children: UINode[]
|
|
423
|
+
): Element<IntrinsicKind<K>>;
|
|
424
|
+
export function createElement<P, E extends UIElement>(
|
|
425
|
+
this: void,
|
|
426
|
+
component: (this: void, props: P) => E,
|
|
427
|
+
props: P | undefined,
|
|
428
|
+
...children: (UINode | RenderChild)[]
|
|
429
|
+
): E;
|
|
430
|
+
export function createElement<P>(
|
|
431
|
+
this: void,
|
|
432
|
+
component: IntrinsicTag | ((this: void, props: P) => UIElement),
|
|
433
|
+
props: P | undefined,
|
|
434
|
+
...children: (UINode | RenderChild)[]
|
|
435
|
+
): UIElement {
|
|
436
|
+
let inputs = props === undefined ? {} as P : props;
|
|
437
|
+
const { key } = inputs as { key?: ElementKey };
|
|
438
|
+
const supplied = (inputs as { children?: UINode | RenderChild }).children;
|
|
439
|
+
// Lua's array length can skip explicit children after nil entries.
|
|
440
|
+
const hasChildren = children.length > 0 || Object.keys(children).length > 0;
|
|
441
|
+
const child = hasChildren ? children[0] : supplied;
|
|
442
|
+
if (typeof component !== "string" && typeof child === "function"
|
|
443
|
+
&& (!hasChildren || Object.keys(children).length === 1)) {
|
|
444
|
+
const mark = markMediaReads();
|
|
445
|
+
return attachMediaReads(assignKey(component({ ...inputs as OwnedRecord<P & object>, children: child }), key), mark);
|
|
446
|
+
}
|
|
447
|
+
const nodes = normalizeChildren(hasChildren ? children as UINode[] : supplied as UINode);
|
|
448
|
+
if (typeof component === "string") {
|
|
449
|
+
const { className, style } = inputs as { className?: ClassNames; style?: NativeStyle };
|
|
450
|
+
if (className !== undefined && typeof className !== "string") {
|
|
451
|
+
inputs = { ...inputs as OwnedRecord<P & object>, ...resolveStyleClasses(className, style) };
|
|
452
|
+
}
|
|
453
|
+
if (component === "box" || component === "div") return { kind: "frame", key, props: inputs, children: nodes } as UIElement;
|
|
454
|
+
if (component === "input") {
|
|
455
|
+
const { type } = inputs as NativeIntrinsicElements["input"];
|
|
456
|
+
const kind = type === "checkbox" || type === "range" ? type : "editbox";
|
|
457
|
+
return { kind, key, props: inputs, children: [] } as UIElement;
|
|
458
|
+
}
|
|
459
|
+
if (component === "option") {
|
|
460
|
+
const { value } = inputs as NativeIntrinsicElements["option"];
|
|
461
|
+
const label = optionLabel(nodes);
|
|
462
|
+
return { kind: "selectItem", key, props: { value, label: label !== "" ? label : value }, children: [] };
|
|
463
|
+
}
|
|
464
|
+
if (component === "select") {
|
|
465
|
+
const items = nodes.flatMap(node => node.kind === "selectItem" ? [{ key: node.props.value, label: node.props.label }] : []);
|
|
466
|
+
const props = inputs as PropsWithChildren<NativeProps["listbox"]>;
|
|
467
|
+
return { kind: "listbox", key, props: { ...props as OwnedRecord<typeof props>, items: props.items ?? items }, children: [] };
|
|
468
|
+
}
|
|
469
|
+
const heading = headingLevels[component as HeadingTag];
|
|
470
|
+
if (component === "text" || component === "span" || component === "button" || heading !== undefined) {
|
|
471
|
+
const kind = component === "button" ? "button" : "text";
|
|
472
|
+
const label = (inputs as { value?: Binding<string> }).value;
|
|
473
|
+
if (component === "button" && (inputs as NativeIntrinsicElements["button"]).unstyled === true) {
|
|
474
|
+
return { kind, key, props: { ...inputs as OwnedRecord<P & object>, value: label ?? "" }, children: nodes } as UIElement;
|
|
475
|
+
}
|
|
476
|
+
if (label !== undefined && heading === undefined) return { kind, key, props: inputs, children: nodes } as UIElement;
|
|
477
|
+
return { kind, key, props: { ...inputs as OwnedRecord<P & object>, value: label ?? textChildren(nodes), heading }, children: [] } as UIElement;
|
|
478
|
+
}
|
|
479
|
+
return { kind: component, key, props: inputs, children: nodes } as UIElement;
|
|
480
|
+
}
|
|
481
|
+
const mark = markMediaReads();
|
|
482
|
+
return attachMediaReads(assignKey(component({ ...inputs as OwnedRecord<P & object>, children: nodes }), key), mark);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function assignKey(element: UIElement, key: ElementKey | undefined): UIElement {
|
|
486
|
+
return key === undefined || element.key === key ? element : { ...element as OwnedRecord<UIElement>, key };
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export function createNode<K extends Kind>(this: void, kind: K, props: PropsWithChildren<Props[K]>): Element<K> {
|
|
490
|
+
return { kind, props, children: normalizeChildren(props.children) };
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function define<K extends Kind>(kind: K) {
|
|
494
|
+
return (props: PropsWithChildren<Props[K]>): Element<K> => createNode(kind, props);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export const Fragment = define("fragment");
|
|
498
|
+
export const Transition = define("transition");
|
|
499
|
+
/** A host widget placed in the view; like the intrinsic elements it takes style classes. */
|
|
500
|
+
export const Slot = (props: WithStyleClasses<PropsWithChildren<Props["slot"]>>): Element<"slot"> => {
|
|
501
|
+
const { className, style } = props;
|
|
502
|
+
return createNode("slot", (className === undefined || typeof className === "string" ? props
|
|
503
|
+
: { ...props as OwnedRecord<typeof props>, ...resolveStyleClasses(className, style) }) as PropsWithChildren<Props["slot"]>);
|
|
504
|
+
};
|
|
505
|
+
export const Portal = define("portal");
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { fail, ok, type Result } from "./result";
|
|
2
|
+
import type { RuntimeScope } from "./runtime";
|
|
3
|
+
import type { Cancel } from "./scheduler";
|
|
4
|
+
|
|
5
|
+
export interface FeatureParticipant {
|
|
6
|
+
enable?(this: void, scope: RuntimeScope): Result<void> | void;
|
|
7
|
+
disable?: Cancel;
|
|
8
|
+
subscribe?(this: void, scope: RuntimeScope, ready: (this: void) => boolean): Result<void> | void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface FeatureLifecycle {
|
|
12
|
+
add(this: void, participant: FeatureParticipant): void;
|
|
13
|
+
setEnabled(this: void, enabled: boolean): Result<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createFeatureLifecycle(parent: RuntimeScope): Result<FeatureLifecycle> {
|
|
17
|
+
const participants: FeatureParticipant[] = [];
|
|
18
|
+
let current: RuntimeScope | undefined;
|
|
19
|
+
let transitioning = false;
|
|
20
|
+
|
|
21
|
+
function close() {
|
|
22
|
+
const scope = current;
|
|
23
|
+
current = undefined;
|
|
24
|
+
return scope?.dispose() ?? ok(undefined);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function open(): Result<void> {
|
|
28
|
+
const scope = parent.fork();
|
|
29
|
+
if (!scope.isActive()) return fail("The owning module scope is closed");
|
|
30
|
+
current = scope;
|
|
31
|
+
scope.onDispose(() => { if (current === scope) current = undefined; });
|
|
32
|
+
let ready = false;
|
|
33
|
+
const disable: Cancel[] = [];
|
|
34
|
+
|
|
35
|
+
const started = scope.protect(() => {
|
|
36
|
+
for (const participant of participants) {
|
|
37
|
+
if (!scope.isActive()) return fail("Feature scope closed during enable");
|
|
38
|
+
if (participant.disable !== undefined) disable.push(participant.disable);
|
|
39
|
+
const result = participant.enable?.(scope);
|
|
40
|
+
if (result?.ok === false) return result;
|
|
41
|
+
}
|
|
42
|
+
for (const participant of participants) {
|
|
43
|
+
if (!scope.isActive()) return fail("Feature scope closed during subscription");
|
|
44
|
+
const result = participant.subscribe?.(scope, () => ready && scope.isActive());
|
|
45
|
+
if (result?.ok === false) return result;
|
|
46
|
+
}
|
|
47
|
+
return scope.isActive() ? ok(undefined) : fail("Feature scope closed during enable");
|
|
48
|
+
});
|
|
49
|
+
let result = started.ok ? started.value : started;
|
|
50
|
+
|
|
51
|
+
for (const stop of disable) {
|
|
52
|
+
const registered = scope.onDispose(stop);
|
|
53
|
+
if (registered.ok) continue;
|
|
54
|
+
const stopped = parent.protect(stop);
|
|
55
|
+
if (!stopped.ok) {
|
|
56
|
+
result = result.ok ? stopped : fail(result.reason + "\nFeature cleanup: " + stopped.reason);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!result.ok) {
|
|
61
|
+
const closed = close();
|
|
62
|
+
return closed.ok ? result : fail(result.reason + "\nFeature cleanup: " + closed.reason);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
ready = true;
|
|
66
|
+
return ok(undefined);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const linked = parent.onDispose(close);
|
|
70
|
+
if (!linked.ok) return linked;
|
|
71
|
+
return ok({
|
|
72
|
+
add: participant => { participants.push(participant); },
|
|
73
|
+
setEnabled: enabled => {
|
|
74
|
+
if (transitioning) return fail("The feature is already changing state");
|
|
75
|
+
if (enabled === (current?.isActive() === true)) return ok(undefined);
|
|
76
|
+
transitioning = true;
|
|
77
|
+
const result = enabled ? open() : close();
|
|
78
|
+
transitioning = false;
|
|
79
|
+
return result;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|