wuira 0.1.0 → 0.1.2
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/README.md +204 -18
- package/cli/wuira.mjs +67 -0
- package/config/tsconfig.json +27 -0
- package/lib/Console.d.ts +5 -0
- package/lib/Console.lua +20 -0
- package/lib/console-polyfill.d.ts +9 -0
- package/lib/console-polyfill.lua +39 -0
- package/lib/datasources/DataSource.d.ts +17 -0
- package/lib/datasources/DataSource.lua +199 -0
- package/lib/datasources/NativeNumberSource.d.ts +7 -0
- package/lib/datasources/NativeNumberSource.lua +50 -0
- package/lib/datasources/ProgressSource.d.ts +23 -0
- package/lib/datasources/ProgressSource.lua +79 -0
- package/lib/datasources/Resources.d.ts +27 -0
- package/lib/datasources/Resources.lua +102 -0
- package/lib/datasources/index.d.ts +4 -0
- package/lib/datasources/index.lua +18 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.lua +12 -0
- package/{src → lib}/platform/forever.d.ts +17 -17
- package/{src/types/Anchor.ts → lib/types/Anchor.d.ts} +6 -7
- package/lib/types/Anchor.lua +8 -0
- package/lib/types/Color.lua +3 -0
- package/lib/types/Position.d.ts +21 -0
- package/lib/types/Position.lua +3 -0
- package/lib/types/Spacing.d.ts +14 -0
- package/lib/types/Spacing.lua +20 -0
- package/{src/types/Texture.ts → lib/types/Texture.d.ts} +0 -2
- package/lib/types/Texture.lua +3 -0
- package/{src/ui/Cell.tsx → lib/ui/Cell.d.ts} +6 -8
- package/lib/ui/Cell.lua +9 -0
- package/{src/ui/FlowLayout.tsx → lib/ui/FlowLayout.d.ts} +3 -8
- package/lib/ui/FlowLayout.lua +8 -0
- package/{src/ui/GridLayout.tsx → lib/ui/GridLayout.d.ts} +3 -8
- package/lib/ui/GridLayout.lua +8 -0
- package/{src/ui/Layout.ts → lib/ui/Layout.d.ts} +4 -3
- package/lib/ui/Layout.lua +3 -0
- package/{src/ui/ProgressBar.tsx → lib/ui/ProgressBar.d.ts} +4 -7
- package/lib/ui/ProgressBar.lua +8 -0
- package/lib/ui/decorations/Background.d.ts +10 -0
- package/lib/ui/decorations/Background.lua +76 -0
- package/lib/ui/decorations/Border.d.ts +18 -0
- package/lib/ui/decorations/Border.lua +188 -0
- package/lib/ui/decorations/Decoration.d.ts +13 -0
- package/lib/ui/decorations/Decoration.lua +81 -0
- package/{src/ui/decorations/Decorations.ts → lib/ui/decorations/Decorations.d.ts} +0 -1
- package/lib/ui/decorations/Decorations.lua +3 -0
- package/lib/ui/decorations/Glow.d.ts +14 -0
- package/lib/ui/decorations/Glow.lua +63 -0
- package/lib/ui/decorations/backgroundTextures.d.ts +25 -0
- package/lib/ui/decorations/backgroundTextures.lua +10 -0
- package/lib/ui/decorations/borderTextures.d.ts +41 -0
- package/lib/ui/decorations/borderTextures.lua +12 -0
- package/lib/ui/decorations/statusBarTextures.d.ts +12 -0
- package/lib/ui/decorations/statusBarTextures.lua +9 -0
- package/lib/ui/index.d.ts +11 -0
- package/lib/ui/index.lua +35 -0
- package/lib/ui/layout/calculateFlow.d.ts +12 -0
- package/lib/ui/layout/calculateFlow.lua +36 -0
- package/lib/ui/layout/calculateGrid.d.ts +9 -0
- package/lib/ui/layout/calculateGrid.lua +47 -0
- package/lib/ui/layout/measureLayout.d.ts +19 -0
- package/lib/ui/layout/measureLayout.lua +215 -0
- package/lib/ui/mount.d.ts +5 -0
- package/lib/ui/mount.lua +486 -0
- package/lib/ui/primitives/jsx.d.ts +38 -0
- package/lib/ui/primitives/jsx.lua +66 -0
- package/lib/wuira.d.ts +8 -0
- package/lib/wuira.lua +36 -0
- package/package.json +55 -5
- package/templates/addon/README.md +13 -0
- package/templates/addon/addon.toc.in +4 -0
- package/templates/addon/gitignore +3 -0
- package/templates/addon/package.json +11 -0
- package/templates/addon/src/index.tsx +7 -0
- package/templates/addon/tsconfig.json +8 -0
- package/templates/addon/wuira.config.mjs +4 -0
- package/tools/build-library.mjs +15 -0
- package/tools/module-loader.lua +3 -3
- package/tools/{wow-modules.cjs → wow-modules.mjs} +27 -11
- package/tsconfig.json +1 -1
- package/tsconfig.lib.json +8 -0
- package/addon.toc.in +0 -4
- package/cli/uira.cjs +0 -55
- package/src/Console.ts +0 -10
- package/src/UIra.ts +0 -18
- package/src/console-polyfill.ts +0 -25
- package/src/datasources/DataSource.ts +0 -42
- package/src/datasources/NativeNumberSource.ts +0 -7
- package/src/datasources/ProgressSource.ts +0 -46
- package/src/datasources/Resources.ts +0 -41
- package/src/examples/ProgressBars.tsx +0 -24
- package/src/index.tsx +0 -3
- package/src/playground/PlayerFrame.ts +0 -271
- package/src/types/Position.ts +0 -21
- package/src/types/Spacing.ts +0 -14
- package/src/ui/decorations/Background.ts +0 -29
- package/src/ui/decorations/Border.ts +0 -71
- package/src/ui/decorations/Decoration.ts +0 -59
- package/src/ui/decorations/Glow.ts +0 -25
- package/src/ui/decorations/backgroundTextures.ts +0 -10
- package/src/ui/decorations/borderTextures.ts +0 -13
- package/src/ui/decorations/statusBarTextures.ts +0 -11
- package/src/ui/layout/calculateFlow.ts +0 -33
- package/src/ui/layout/calculateGrid.ts +0 -22
- package/src/ui/layout/measureLayout.ts +0 -87
- package/src/ui/mount.ts +0 -138
- package/src/ui/primitives/jsx.ts +0 -75
- /package/{src/types/Color.ts → lib/types/Color.d.ts} +0 -0
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { ICell, Size } from "../Cell";
|
|
2
|
-
import type { IFlowLayout } from "../FlowLayout";
|
|
3
|
-
import type { IGridLayout } from "../GridLayout";
|
|
4
|
-
import type { Element } from "../primitives/jsx";
|
|
5
|
-
import { resolveSpacing, Insets } from "../../types/Spacing";
|
|
6
|
-
import { calculateFlow } from "./calculateFlow";
|
|
7
|
-
import { calculateGrid } from "./calculateGrid";
|
|
8
|
-
|
|
9
|
-
export interface MeasuredCell {
|
|
10
|
-
cell: ICell;
|
|
11
|
-
width: number;
|
|
12
|
-
height: number;
|
|
13
|
-
margin: Insets;
|
|
14
|
-
children: MeasuredCell[];
|
|
15
|
-
placements?: ({ x: number; y: number } | undefined)[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function resolveSize(value: Size, available: number | undefined, margin: number): number {
|
|
19
|
-
if (value === "inherit") {
|
|
20
|
-
if (available === undefined) error("Cannot inherit a size from an unconstrained content-sized parent");
|
|
21
|
-
return Math.max(0, available - margin);
|
|
22
|
-
}
|
|
23
|
-
if (!Number.isFinite(value) || value < 0) error("Cell sizes must be finite and non-negative");
|
|
24
|
-
return value;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Resolve available space top-down and content bounds bottom-up. */
|
|
28
|
-
export function measureLayout(
|
|
29
|
-
element: Element,
|
|
30
|
-
available: { width?: number; height?: number } = {},
|
|
31
|
-
ancestors: Element[] = [],
|
|
32
|
-
): MeasuredCell {
|
|
33
|
-
if (ancestors.includes(element)) error("Layout children contain a cycle");
|
|
34
|
-
if (element.kind !== "cell" && element.kind !== "flow" && element.kind !== "grid" && element.kind !== "progress") {
|
|
35
|
-
error(`Unsupported UI element: ${element.kind}`);
|
|
36
|
-
}
|
|
37
|
-
const cell = element as ICell;
|
|
38
|
-
const props = cell.props;
|
|
39
|
-
const margin = resolveSpacing(props.margin);
|
|
40
|
-
const padding = resolveSpacing(props.padding);
|
|
41
|
-
let width = resolveSize(props.width, available.width, margin.left + margin.right);
|
|
42
|
-
let height = resolveSize(props.height, available.height, margin.top + margin.bottom);
|
|
43
|
-
const isLayout = element.kind === "flow" || element.kind === "grid";
|
|
44
|
-
const layout = isLayout ? element as IFlowLayout | IGridLayout : undefined;
|
|
45
|
-
const contentSizing = layout?.props.sizing === "content";
|
|
46
|
-
const contentWidth = contentSizing && props.width === 0 ? undefined : Math.max(0, width - padding.left - padding.right);
|
|
47
|
-
const contentHeight = contentSizing && props.height === 0 ? undefined : Math.max(0, height - padding.top - padding.bottom);
|
|
48
|
-
const sourceChildren = layout !== undefined ? layout.children : cell.child === undefined ? [] : [cell.child];
|
|
49
|
-
let childWidth = contentWidth;
|
|
50
|
-
let childHeight = contentHeight;
|
|
51
|
-
if (layout?.kind === "grid") {
|
|
52
|
-
const grid = layout.props;
|
|
53
|
-
if (!Number.isFinite(grid.columns) || grid.columns < 1 || Math.floor(grid.columns) !== grid.columns) error("GridLayout columns must be a positive integer");
|
|
54
|
-
const rows = Math.max(1, Math.ceil(sourceChildren.length / grid.columns));
|
|
55
|
-
childWidth = grid.cellWidth ?? (contentWidth === undefined ? undefined : Math.max(0,
|
|
56
|
-
(contentWidth - (grid.columnGap ?? grid.gap ?? 0) * (grid.columns - 1)) / grid.columns));
|
|
57
|
-
childHeight = grid.cellHeight ?? (contentHeight === undefined ? undefined : Math.max(0,
|
|
58
|
-
(contentHeight - (grid.rowGap ?? grid.gap ?? 0) * (rows - 1)) / rows));
|
|
59
|
-
}
|
|
60
|
-
const path = [...ancestors, element];
|
|
61
|
-
const children = sourceChildren.map(child => measureLayout(child, { width: childWidth, height: childHeight }, path));
|
|
62
|
-
let placements: MeasuredCell["placements"];
|
|
63
|
-
if (layout !== undefined) {
|
|
64
|
-
const sizes = children.map(child => ({
|
|
65
|
-
width: child.width + child.margin.left + child.margin.right,
|
|
66
|
-
height: child.height + child.margin.top + child.margin.bottom,
|
|
67
|
-
}));
|
|
68
|
-
const positions = layout.kind === "flow"
|
|
69
|
-
? calculateFlow({ ...layout.props, width: contentWidth ?? 0, height: contentHeight ?? 0 }, sizes)
|
|
70
|
-
: calculateGrid(layout.props, sizes);
|
|
71
|
-
placements = positions.map(point => ({ x: point.x + padding.left, y: point.y + padding.top }));
|
|
72
|
-
if (contentSizing) {
|
|
73
|
-
width = padding.left + padding.right;
|
|
74
|
-
height = padding.top + padding.bottom;
|
|
75
|
-
for (let i = 0; i < children.length; i += 1) {
|
|
76
|
-
width = Math.max(width, positions[i].x + sizes[i].width + padding.left + padding.right);
|
|
77
|
-
height = Math.max(height, positions[i].y + sizes[i].height + padding.top + padding.bottom);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
} else if (children.length > 0) {
|
|
81
|
-
const position = children[0].cell.props;
|
|
82
|
-
if (position.mode === "relative" && position.relativeTo === undefined) {
|
|
83
|
-
placements = [{ x: padding.left + position.offset.x, y: padding.top + position.offset.y }];
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return { cell, width, height, margin, children, placements };
|
|
87
|
-
}
|
package/src/ui/mount.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { CellProps, ICell } from "./Cell";
|
|
2
|
-
import type { Element } from "./primitives/jsx";
|
|
3
|
-
import type { Decoration } from "./decorations/Decoration";
|
|
4
|
-
import { measureLayout, MeasuredCell } from "./layout/measureLayout";
|
|
5
|
-
import type { IProgressBar } from "./ProgressBar";
|
|
6
|
-
import type { Anchor } from "../types/Position";
|
|
7
|
-
import { Background } from "./decorations/Background";
|
|
8
|
-
import { Border } from "./decorations/Border";
|
|
9
|
-
import { resolveStatusBarTexture } from "./decorations/statusBarTextures";
|
|
10
|
-
|
|
11
|
-
const mountedFrames = new Map<CellProps, UiraNativeFrame>();
|
|
12
|
-
const mountedTrees = new Map<UiraNativeFrame, { frames: UiraNativeFrame[]; cells: ICell[]; decorations: Decoration[] }>();
|
|
13
|
-
|
|
14
|
-
export function unmount(frame: UiraNativeFrame): void {
|
|
15
|
-
const tree = mountedTrees.get(frame);
|
|
16
|
-
if (tree === undefined) return;
|
|
17
|
-
for (const decoration of tree.decorations) decoration.dispose();
|
|
18
|
-
for (const child of tree.frames) {
|
|
19
|
-
child.UnregisterAllEvents();
|
|
20
|
-
child.SetScript("OnEvent", undefined);
|
|
21
|
-
child.Hide();
|
|
22
|
-
}
|
|
23
|
-
for (const cell of tree.cells) mountedFrames.delete(cell.props);
|
|
24
|
-
mountedTrees.delete(frame);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Creates the tree before resolving anchors. Positive y moves down. */
|
|
28
|
-
export function mount(element: Element, parent: UiraNativeFrame = UIParent, rootAnchor?: Anchor): UiraNativeFrame {
|
|
29
|
-
const frames = new Map<CellProps, UiraNativeFrame>();
|
|
30
|
-
const pending: { cell: ICell; width: number; height: number; margin: MeasuredCell["margin"]; frame: UiraNativeFrame; parent: UiraNativeFrame; placement?: { x: number; y: number } }[] = [];
|
|
31
|
-
|
|
32
|
-
function create(measured: MeasuredCell, parent: UiraNativeFrame, placement?: { x: number; y: number }): UiraNativeFrame {
|
|
33
|
-
const { cell, width, height } = measured;
|
|
34
|
-
if (frames.has(cell.props) || mountedFrames.has(cell.props)) error("A Cell can only be mounted once at a time");
|
|
35
|
-
const frame = cell.kind === "progress"
|
|
36
|
-
? CreateFrame("StatusBar", undefined, parent)
|
|
37
|
-
: CreateFrame("Frame", undefined, parent);
|
|
38
|
-
frame.Hide();
|
|
39
|
-
frame.EnableMouse(!(cell.props.clickThrough ?? true));
|
|
40
|
-
frames.set(cell.props, frame);
|
|
41
|
-
pending.push({ cell, width, height, margin: measured.margin, frame, parent, placement });
|
|
42
|
-
frame.SetSize(width, height);
|
|
43
|
-
for (let index = 0; index < measured.children.length; index += 1) {
|
|
44
|
-
create(measured.children[index], frame, measured.placements?.[index]);
|
|
45
|
-
}
|
|
46
|
-
return frame;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const rootProps = (element as ICell).props;
|
|
50
|
-
const root = create(measureLayout(element, {
|
|
51
|
-
width: rootProps.width === "inherit" ? parent.GetWidth() : undefined,
|
|
52
|
-
height: rootProps.height === "inherit" ? parent.GetHeight() : undefined,
|
|
53
|
-
}), parent);
|
|
54
|
-
const anchors = new Map<UiraNativeFrame, UiraNativeFrame>();
|
|
55
|
-
for (const item of pending) {
|
|
56
|
-
const position = item.cell.props;
|
|
57
|
-
if (item.placement !== undefined) {
|
|
58
|
-
anchors.set(item.frame, item.parent);
|
|
59
|
-
} else if (position.mode === "absolute") {
|
|
60
|
-
anchors.set(item.frame, UIParent);
|
|
61
|
-
} else {
|
|
62
|
-
const target = position.relativeTo === undefined
|
|
63
|
-
? item.parent
|
|
64
|
-
: frames.get(position.relativeTo.props);
|
|
65
|
-
if (target === undefined) error("relativeTo must reference a Cell in the same mounted tree");
|
|
66
|
-
if (target === item.frame) error("A Cell cannot anchor to itself");
|
|
67
|
-
anchors.set(item.frame, target);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// Reject indirect anchor cycles before asking the client to apply them.
|
|
71
|
-
for (const item of pending) {
|
|
72
|
-
let target = anchors.get(item.frame);
|
|
73
|
-
while (target !== undefined) {
|
|
74
|
-
if (target === item.frame) error("Cell positioning contains an anchor cycle");
|
|
75
|
-
target = anchors.get(target);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const tree = { frames: pending.map(item => item.frame), cells: pending.map(item => item.cell), decorations: [] as Decoration[] };
|
|
79
|
-
mountedTrees.set(root, tree);
|
|
80
|
-
try {
|
|
81
|
-
for (const item of pending) {
|
|
82
|
-
const position = item.cell.props;
|
|
83
|
-
const target = anchors.get(item.frame)!;
|
|
84
|
-
const x = item.placement?.x ?? (position.mode === "absolute" ? position.x : position.offset.x);
|
|
85
|
-
const y = item.placement?.y ?? (position.mode === "absolute" ? position.y : position.offset.y);
|
|
86
|
-
const overrideAnchor = item.frame === root ? rootAnchor : undefined;
|
|
87
|
-
const anchor = overrideAnchor ?? (item.placement !== undefined ? "TOPLEFT" : position.anchor ?? "TOPLEFT");
|
|
88
|
-
const relativeAnchor = overrideAnchor ?? (item.placement !== undefined ? "TOPLEFT" : position.relativeAnchor ?? anchor);
|
|
89
|
-
item.frame.SetPoint(anchor, target, relativeAnchor, x + item.margin.left, -(y + item.margin.top));
|
|
90
|
-
if (item.cell.kind === "progress") {
|
|
91
|
-
const props = (item.cell as IProgressBar).props;
|
|
92
|
-
const bar = item.frame as UiraNativeStatusBar;
|
|
93
|
-
const color = props.foreground?.color ?? props.color;
|
|
94
|
-
bar.SetStatusBarTexture(resolveStatusBarTexture(props.foreground?.texture ?? props.texture ?? "solid"));
|
|
95
|
-
bar.SetStatusBarColor(color?.r ?? 1, color?.g ?? 1, color?.b ?? 1, color?.a ?? 1);
|
|
96
|
-
if (props.foreground !== undefined) {
|
|
97
|
-
const fill = bar.GetStatusBarTexture();
|
|
98
|
-
fill.SetHorizTile(props.foreground.tileX ?? false);
|
|
99
|
-
fill.SetVertTile(props.foreground.tileY ?? false);
|
|
100
|
-
fill.SetBlendMode(props.foreground.blendMode ?? "BLEND");
|
|
101
|
-
const uv = props.foreground.texCoords ?? [0, 1, 0, 1];
|
|
102
|
-
fill.SetTexCoord(uv[0], uv[1], uv[2], uv[3]);
|
|
103
|
-
}
|
|
104
|
-
bar.SetOrientation(props.orientation === "vertical" ? "VERTICAL" : "HORIZONTAL");
|
|
105
|
-
bar.SetReverseFill(props.reverse ?? false);
|
|
106
|
-
bar.SetMinMaxValues(props.min ?? 0, props.max ?? 100);
|
|
107
|
-
const source = item.cell.source ?? props.source;
|
|
108
|
-
if (source !== undefined) {
|
|
109
|
-
source.BindTo(bar, {
|
|
110
|
-
min: props.min, max: props.max, current: props.current ?? props.value,
|
|
111
|
-
});
|
|
112
|
-
} else {
|
|
113
|
-
bar.SetValue(props.current ?? props.value ?? 0);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const decorations = item.cell.props.decorations;
|
|
117
|
-
// Explicit slots: Lua arrays with nil entries cannot be iterated safely.
|
|
118
|
-
function attach(decoration: Decoration | undefined): void {
|
|
119
|
-
if (decoration !== undefined) {
|
|
120
|
-
decoration.mount(item.frame, item.width, item.height);
|
|
121
|
-
tree.decorations.push(decoration);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const progress = item.cell.kind === "progress" ? (item.cell as IProgressBar).props : undefined;
|
|
125
|
-
attach(progress?.background === false ? undefined
|
|
126
|
-
: progress?.background !== undefined ? new Background(progress.background) : decorations?.background);
|
|
127
|
-
attach(progress?.backdrop === false ? undefined
|
|
128
|
-
: progress?.backdrop !== undefined ? new Border(progress.backdrop) : decorations?.border);
|
|
129
|
-
attach(decorations?.glow);
|
|
130
|
-
mountedFrames.set(item.cell.props, item.frame);
|
|
131
|
-
item.frame.Show();
|
|
132
|
-
}
|
|
133
|
-
} catch (failure) {
|
|
134
|
-
unmount(root);
|
|
135
|
-
throw failure;
|
|
136
|
-
}
|
|
137
|
-
return root;
|
|
138
|
-
}
|
package/src/ui/primitives/jsx.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { CellProps } from "../Cell";
|
|
2
|
-
import type { FlowLayoutProps } from "../FlowLayout";
|
|
3
|
-
import type { GridLayoutProps } from "../GridLayout";
|
|
4
|
-
import type { ProgressBarProps } from "../ProgressBar";
|
|
5
|
-
import type { ProgressSource } from "../../datasources/ProgressSource";
|
|
6
|
-
|
|
7
|
-
/** Declarative UI description; native frames are created by mount. */
|
|
8
|
-
export interface Element {
|
|
9
|
-
kind: string;
|
|
10
|
-
props: object;
|
|
11
|
-
child?: Element;
|
|
12
|
-
children?: Element[];
|
|
13
|
-
source?: ProgressSource;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type Component<P extends object> = (props: P, child?: Element) => Element;
|
|
17
|
-
|
|
18
|
-
export namespace UI {
|
|
19
|
-
export function Fragment(): Element {
|
|
20
|
-
return { kind: "empty", props: {} };
|
|
21
|
-
}
|
|
22
|
-
export function createElement<P extends object>(
|
|
23
|
-
component: Component<P> | "cell" | "flow" | "grid" | "progress",
|
|
24
|
-
props: P | undefined,
|
|
25
|
-
...children: (Element | Element[])[]
|
|
26
|
-
): Element {
|
|
27
|
-
const elements: Element[] = [];
|
|
28
|
-
for (const child of children) {
|
|
29
|
-
if (Array.isArray(child)) {
|
|
30
|
-
for (const element of child) elements.push(element);
|
|
31
|
-
} else {
|
|
32
|
-
elements.push(child);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const properties = props ?? ({} as P);
|
|
36
|
-
if (typeof component === "string") {
|
|
37
|
-
const input = properties as unknown as Partial<FlowLayoutProps & GridLayoutProps & ProgressBarProps>;
|
|
38
|
-
const resolved = {
|
|
39
|
-
...properties,
|
|
40
|
-
width: input.width ?? (input.sizing === "content" ? 0 : "inherit"),
|
|
41
|
-
height: input.height ?? (input.sizing === "content" ? 0 : "inherit"),
|
|
42
|
-
mode: input.mode ?? "relative",
|
|
43
|
-
...(input.mode === "absolute"
|
|
44
|
-
? { x: input.x ?? 0, y: input.y ?? 0 }
|
|
45
|
-
: { offset: input.offset ?? { x: 0, y: 0 } }),
|
|
46
|
-
...(component === "flow" ? { direction: input.direction ?? "vertical" } : {}),
|
|
47
|
-
...(component === "grid" ? { columns: input.columns ?? 1 } : {}),
|
|
48
|
-
};
|
|
49
|
-
if (component === "flow" || component === "grid") {
|
|
50
|
-
return { kind: component, props: resolved, children: elements };
|
|
51
|
-
}
|
|
52
|
-
if (elements.length > 1) throw "Cell accepts at most one child; use FlowLayout for multiple children";
|
|
53
|
-
return {
|
|
54
|
-
kind: component, props: resolved, child: elements[0],
|
|
55
|
-
source: (properties as unknown as { source?: ProgressSource }).source,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
const componentProps = children.length === 0 ? properties
|
|
59
|
-
: { ...properties, child: elements.length === 1 ? elements[0] : elements };
|
|
60
|
-
if (component === Fragment && elements.length !== 0) throw "Only empty fragments are supported for now";
|
|
61
|
-
return component(componentProps, elements[0]);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Keep JSX types beside the factory so TSX files only need one import.
|
|
65
|
-
export namespace JSX {
|
|
66
|
-
export type Element = import("./jsx").Element;
|
|
67
|
-
export interface ElementChildrenAttribute { child: {}; }
|
|
68
|
-
export interface IntrinsicElements {
|
|
69
|
-
cell: Partial<CellProps> & { child?: Element };
|
|
70
|
-
flow: Partial<FlowLayoutProps> & { child?: Element | Element[] };
|
|
71
|
-
grid: Partial<GridLayoutProps> & { child?: Element | Element[] };
|
|
72
|
-
progress: Partial<ProgressBarProps> & { child?: Element };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
File without changes
|