@margoengine/ui 0.0.0-stage → 1.0.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.
Files changed (61) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +1224 -2
  4. package/dist/basic.d.ts +87 -0
  5. package/dist/collections.d.ts +180 -0
  6. package/dist/color.d.ts +24 -0
  7. package/dist/controls.d.ts +130 -0
  8. package/dist/curved.d.ts +41 -0
  9. package/dist/curved.js +105 -0
  10. package/dist/dom-CWJhpotq.js +340 -0
  11. package/dist/dom-host.d.ts +67 -0
  12. package/dist/dom-host.js +563 -0
  13. package/dist/dom-spec.d.ts +21 -0
  14. package/dist/dom.d.ts +63 -0
  15. package/dist/draw.d.ts +107 -0
  16. package/dist/editor.d.ts +83 -0
  17. package/dist/editor.js +323 -0
  18. package/dist/errors-CDgOgzCd.js +7 -0
  19. package/dist/focus.d.ts +12 -0
  20. package/dist/forms.d.ts +114 -0
  21. package/dist/forms.js +354 -0
  22. package/dist/gl-bb768Mje.js +165 -0
  23. package/dist/gl-load-wwKmojhb.js +5 -0
  24. package/dist/gl-load.d.ts +3 -0
  25. package/dist/gl.d.ts +30 -0
  26. package/dist/i18n.d.ts +69 -0
  27. package/dist/i18n.js +117 -0
  28. package/dist/image.d.ts +74 -0
  29. package/dist/image.js +295 -0
  30. package/dist/index.d.ts +36 -0
  31. package/dist/index.js +4 -0
  32. package/dist/input-dom.d.ts +14 -0
  33. package/dist/input.d.ts +92 -0
  34. package/dist/input.js +315 -0
  35. package/dist/interaction.d.ts +106 -0
  36. package/dist/keyboard.d.ts +40 -0
  37. package/dist/keyboard.js +132 -0
  38. package/dist/layout.d.ts +116 -0
  39. package/dist/markup.d.ts +89 -0
  40. package/dist/markup.js +369 -0
  41. package/dist/meters-yaZRtwsX.js +1401 -0
  42. package/dist/meters.d.ts +72 -0
  43. package/dist/mirror.d.ts +30 -0
  44. package/dist/overlays.d.ts +89 -0
  45. package/dist/painter.d.ts +115 -0
  46. package/dist/pass-CAn29pqc.js +15 -0
  47. package/dist/react.d.ts +99 -0
  48. package/dist/react.js +246 -0
  49. package/dist/renderer-Vs-YtiWv.js +1741 -0
  50. package/dist/renderer.d.ts +138 -0
  51. package/dist/rsc/react.js +3 -0
  52. package/dist/shader.d.ts +6 -0
  53. package/dist/theme.d.ts +104 -0
  54. package/dist/ui.d.ts +328 -0
  55. package/dist/virtual.d.ts +81 -0
  56. package/dist/widget.d.ts +196 -0
  57. package/dist/world-gl.d.ts +32 -0
  58. package/dist/world-gl.js +195 -0
  59. package/dist/world.d.ts +216 -0
  60. package/dist/world.js +561 -0
  61. package/package.json +117 -4
@@ -0,0 +1,72 @@
1
+ import type { Rgba } from './color.js';
2
+ import { Widget, type DrawContext, type WidgetOptions } from './widget.js';
3
+ /** Fill colour of a {@link ProgressBar}: a status colour, or `'health'` to move from success to warning to danger as it empties. */
4
+ export type MeterVariant = 'primary' | 'accent' | 'success' | 'warning' | 'danger' | 'info' | 'health';
5
+ /** Options for {@link ProgressBar}. */
6
+ export interface ProgressBarOptions extends WidgetOptions {
7
+ /** Current value in 0..`max`. Default 0. */
8
+ value?: number;
9
+ /** Full value. Default 1. */
10
+ max?: number;
11
+ /** Caption drawn at the left inside the bar, also its accessible name, for example `'HP'`. */
12
+ text?: string;
13
+ /** Default `'primary'`. */
14
+ variant?: MeterVariant;
15
+ /** Show the value inside the bar: `'fraction'` (`72 / 100`), `'percent'` or `'none'`. Default `'percent'`. */
16
+ display?: 'fraction' | 'percent' | 'none';
17
+ /** Animate toward new values. Default true (off with reduced motion). */
18
+ smooth?: boolean;
19
+ /** Show a pale chip that lingers where the bar was before a drop, as in fighting-game health bars. Default false. */
20
+ trail?: boolean;
21
+ }
22
+ /**
23
+ * A horizontal meter. The number is drawn inside the bar, so the state never depends on its colour alone, and the
24
+ * accessible mirror reads it as a progress bar.
25
+ *
26
+ * @example
27
+ * const loading = new ProgressBar({ text: 'Loading', value: 0.4 });
28
+ * loading.value = 0.75;
29
+ */
30
+ export declare class ProgressBar extends Widget {
31
+ readonly max: number;
32
+ private _value;
33
+ private _text;
34
+ private _variant;
35
+ private readonly display;
36
+ private readonly smooth;
37
+ private readonly trail;
38
+ /** The drawn fraction, easing toward `value / max`. */
39
+ protected shown_: number;
40
+ protected chip: number;
41
+ private chipHold;
42
+ /** @throws RangeError when `max` is not above 0 or `value` is not finite. */
43
+ constructor(options?: ProgressBarOptions);
44
+ get text(): string;
45
+ set text(value: string);
46
+ get value(): number;
47
+ /** Set the value, clamped to 0..`max`. @throws RangeError for a value that is not finite. */
48
+ set value(next: number);
49
+ get variant(): MeterVariant;
50
+ set variant(value: MeterVariant);
51
+ /** The value as shown and read aloud, for example `'72%'` or `'72 / 100'`. */
52
+ get valueText(): string;
53
+ measure(): {
54
+ width: number;
55
+ height: number;
56
+ };
57
+ tick(dt: number): boolean;
58
+ /** The status colour for a fraction of the bar. */
59
+ protected fillColor(ui: NonNullable<Widget['ui']>, fraction: number): Rgba;
60
+ draw({ list, ui, theme }: DrawContext): void;
61
+ }
62
+ /** Options for {@link HealthBar}. */
63
+ export interface HealthBarOptions extends Omit<ProgressBarOptions, 'variant' | 'trail'> {
64
+ /** Starting health. Default `max`. */
65
+ value?: number;
66
+ /** Maximum health. Default 100. */
67
+ max?: number;
68
+ }
69
+ /** A {@link ProgressBar} preset for hit points: colour by remaining health, a trailing damage chip, and `72 / 100` text. */
70
+ export declare class HealthBar extends ProgressBar {
71
+ constructor(options?: HealthBarOptions);
72
+ }
@@ -0,0 +1,30 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import { type Detach } from './dom.js';
3
+ import type { Ui } from './ui.js';
4
+ /** Options for {@link attachMirror}. */
5
+ export interface MirrorOptions {
6
+ /** Where to put the mirror. Default: right after the canvas, over it. */
7
+ container?: HTMLElement;
8
+ /** Accessible name of the whole interface. Default `'Game interface'`. */
9
+ label?: string;
10
+ /** Detach when the signal aborts. */
11
+ signal?: AbortSignal;
12
+ }
13
+ /**
14
+ * Give screen readers and other assistive technology the UI that is drawn on the canvas: a real DOM tree of buttons,
15
+ * switches, sliders, progress bars, listboxes, dialogs and text, kept in step with the widgets and laid over the canvas
16
+ * (so touch exploration lands on the right widget). It is invisible, takes no pointer events, and follows the widgets:
17
+ *
18
+ * - Focus is shared. Tab or a screen reader moving to an element focuses its widget (the visible ring follows), and
19
+ * keyboard focus moving in the UI moves DOM focus, so the reader announces it.
20
+ * - Activating an element (Enter, Space, a screen reader's click) activates the widget; a range input sets a slider.
21
+ * - Toasts and {@link Ui.announce} messages go to polite and assertive live regions.
22
+ * - While a dialog is open the rest of the interface is inert; the dialog is `role="dialog"` with `aria-modal`.
23
+ * - A widget's `tooltip` and `description` become `aria-describedby`.
24
+ *
25
+ * {@link UiRenderer} attaches one by default. Returns a function that removes it again; it is also disposable.
26
+ *
27
+ * @example
28
+ * const detach = attachMirror(ui, engine.canvas);
29
+ */
30
+ export declare function attachMirror(ui: Ui, target: HTMLElement, options?: MirrorOptions): Detach;
@@ -0,0 +1,89 @@
1
+ import { Panel } from './basic.js';
2
+ import { type ButtonVariant } from './controls.js';
3
+ import type { Widget, DrawContext, UiCommand } from './widget.js';
4
+ /** A button of a {@link Dialog}. */
5
+ export interface DialogButton {
6
+ /** Caption. */
7
+ label: string;
8
+ /** What the dialog's promise resolves with when this button is chosen. Default the label. */
9
+ value?: unknown;
10
+ /** Default `'primary'` for the first button and `'secondary'` for the others. */
11
+ variant?: ButtonVariant;
12
+ }
13
+ /** Options for `ui.dialog()`. */
14
+ export interface DialogOptions {
15
+ /** Heading. */
16
+ title?: string;
17
+ /** Body text; wraps. */
18
+ message?: string;
19
+ /** Buttons, left to right. Default one `OK` button resolving `true`. */
20
+ buttons?: readonly DialogButton[];
21
+ /** What the promise resolves with on Escape, the gamepad's cancel button or a click on the dimmed area. Default `undefined`. */
22
+ cancelValue?: unknown;
23
+ /** Whether Escape, cancel and clicks outside close the dialog. Default true. */
24
+ dismissible?: boolean;
25
+ /** Width in UI units. Default 440. */
26
+ width?: number;
27
+ /** Closing the signal removes the dialog and rejects the promise with the signal's reason. */
28
+ signal?: AbortSignal;
29
+ }
30
+ /**
31
+ * A modal dialog: dims the game, traps focus inside, closes on Escape, and returns focus to what had it. Make one with
32
+ * `ui.dialog()`, `ui.confirm()` or `ui.alert()`.
33
+ */
34
+ export declare class Dialog extends Panel {
35
+ /** Settles when the dialog closes. */
36
+ readonly result: Promise<unknown>;
37
+ /** True while it is shown. */
38
+ open: boolean;
39
+ private resolve;
40
+ private reject;
41
+ private readonly cancelValue;
42
+ readonly dismissible: boolean;
43
+ private removeAbort?;
44
+ constructor(options?: DialogOptions);
45
+ /** The first button, which takes focus when the dialog opens. */
46
+ get firstButton(): Widget | undefined;
47
+ /** Close the dialog and resolve the promise with `value`. */
48
+ close(value?: unknown): void;
49
+ /** Close the dialog and reject the promise. */
50
+ abort(reason?: unknown): void;
51
+ command(command: UiCommand): boolean;
52
+ }
53
+ /** How a toast looks and is announced. `'danger'` is announced at once; the others politely. */
54
+ export type ToastKind = 'info' | 'success' | 'warning' | 'danger';
55
+ /** Options for `ui.toast()`. */
56
+ export interface ToastOptions {
57
+ /** Default `'info'`. */
58
+ kind?: ToastKind;
59
+ /** Seconds on screen, paused while the pointer or focus is on it. 0 keeps it until dismissed. Default grows with the message length, at least 4. */
60
+ duration?: number;
61
+ /** A button on the toast, for example `'Undo'`. */
62
+ action?: {
63
+ label: string;
64
+ onClick: () => void;
65
+ };
66
+ }
67
+ /** A short message that fades after a few seconds. Make one with `ui.toast()`. */
68
+ export declare class Toast extends Panel {
69
+ readonly kind: ToastKind;
70
+ /** Seconds left; Infinity when persistent. */
71
+ remaining: number;
72
+ readonly message: string;
73
+ private fade;
74
+ private closing;
75
+ constructor(message: string, options?: ToastOptions);
76
+ /** Start fading out; it is removed when the fade ends. */
77
+ dismiss(): void;
78
+ get dismissed(): boolean;
79
+ tick(dt: number): boolean;
80
+ draw(context: DrawContext): void;
81
+ get opacity(): number;
82
+ }
83
+ /** The floating text bubble `ui` shows for a widget's `tooltip`. */
84
+ export declare class Tooltip extends Panel {
85
+ private readonly body;
86
+ constructor();
87
+ get text(): string;
88
+ set text(value: string);
89
+ }
@@ -0,0 +1,115 @@
1
+ import { type AtlasSlot, type GlyphBitmap } from '@margoengine/text';
2
+ import type { DrawList } from './draw.js';
3
+ /** Premultiplied alpha: colour and alpha both blend as source + destination * (1 - source alpha). */
4
+ export declare const PREMULTIPLIED: GPUBlendState;
5
+ /** Floats per rectangle instance: box, fill, border, then radius, border width and blur. */
6
+ export declare const RECT_FLOATS = 16;
7
+ /** Floats per glyph instance: box, atlas rectangle, colour, then page, colour flag and outline width. */
8
+ export declare const GLYPH_FLOATS = 16;
9
+ /** Atlas options of a painter. */
10
+ export interface PainterOptions {
11
+ atlasSize: number;
12
+ colorAtlasSize: number;
13
+ maxPages: number;
14
+ }
15
+ /** The target a painter draws into: its size in pixels, colour format, depth format (none for a plain texture) and samples. */
16
+ export interface PaintTarget {
17
+ width: number;
18
+ height: number;
19
+ format: GPUTextureFormat;
20
+ depthFormat?: GPUTextureFormat;
21
+ samples: number;
22
+ }
23
+ /** Counts for the latest frame. */
24
+ export interface PaintStats {
25
+ rects: number;
26
+ glyphs: number;
27
+ drawCalls: number;
28
+ uploads: number;
29
+ }
30
+ /** Glyph atlas pages a batch places glyphs on: the text package's WebGPU atlas, or the WebGL2 painter's. */
31
+ export interface GlyphPages {
32
+ readonly size: number;
33
+ readonly generation: number;
34
+ place(glyph: GlyphBitmap): AtlasSlot;
35
+ /** Drops the slot of a bitmap that is no longer drawn (an image), so the atlas stops holding it. */
36
+ release?(glyph: GlyphBitmap): boolean;
37
+ }
38
+ /** Consecutive instances of one kind under one clip region, drawn with one call. */
39
+ export interface Run {
40
+ glyphs: boolean;
41
+ first: number;
42
+ count: number;
43
+ clip: readonly [number, number, number, number] | null;
44
+ }
45
+ /**
46
+ * The WebGPU drawing core shared by the screen renderer and world panels: turns a {@link DrawList} into rounded
47
+ * rectangle and SDF glyph instances, uploads them only when the list or the atlases changed, and encodes the instanced
48
+ * draws into a render pass the caller opened.
49
+ * @internal
50
+ */
51
+ export declare class UiPainter {
52
+ private readonly options;
53
+ readonly stats: PaintStats;
54
+ private device?;
55
+ private module?;
56
+ private layout?;
57
+ private pipelineLayout?;
58
+ private sampler?;
59
+ private frameBuffer?;
60
+ private rectBuffer?;
61
+ private glyphBuffer?;
62
+ private group?;
63
+ private groupKey;
64
+ private rectCapacity;
65
+ private glyphCapacity;
66
+ private sdfAtlas?;
67
+ private colorAtlas?;
68
+ private readonly pipelines;
69
+ private readonly frameData;
70
+ private readonly batch;
71
+ private uploaded;
72
+ private uploadedAtlas;
73
+ private fresh;
74
+ constructor(options: PainterOptions, stats: PaintStats);
75
+ /** Create the GPU resources on `device` (again after a device loss). Atlases survive a restore and are re-uploaded. */
76
+ setup(device: GPUDevice): void;
77
+ get ready(): boolean;
78
+ /** The version of the last list uploaded, or -1. */
79
+ get version(): number;
80
+ /** The key of the atlas pages the last upload placed glyphs on; it changes when a page is added or rebuilt. */
81
+ get atlasKey(): string;
82
+ /**
83
+ * Upload `list` when it or the atlases changed since the last call. Returns false when there is nothing to draw.
84
+ * Resets the stats.
85
+ */
86
+ prepare(list: DrawList): boolean;
87
+ /** Encode the prepared draws into `pass`, an open render pass on `target`. */
88
+ encode(pass: GPURenderPassEncoder, target: PaintTarget): void;
89
+ private pipeline;
90
+ private ensureBuffers;
91
+ /** Release the GPU resources; with `atlases`, the glyph atlases too. */
92
+ release(atlases: boolean): void;
93
+ }
94
+ /**
95
+ * The instances of one draw list, shared by the WebGPU and WebGL2 painters: rounded rectangles and glyphs in device
96
+ * pixels, and the runs (one kind, one clip region) that draw them back to front.
97
+ * @internal
98
+ */
99
+ export declare class UiBatch {
100
+ rects: Float32Array<ArrayBuffer>;
101
+ glyphs: Float32Array<ArrayBuffer>;
102
+ readonly runs: Run[];
103
+ rectCount: number;
104
+ glyphCount: number;
105
+ private sdf?;
106
+ private color?;
107
+ /** Image bitmaps the last build drew; one the next build leaves out gives its colour atlas slot back. */
108
+ private images;
109
+ private drawn;
110
+ /** Turn the draw list into rect and glyph instances and the runs that draw them. */
111
+ build(list: Pick<DrawList, 'commands'>, sdf: GlyphPages, color: GlyphPages): void;
112
+ private placeImage;
113
+ /** Place the glyphs of a text command into `this.glyphs` from index `at`; an outline is a layer drawn under the fill. */
114
+ private placeText;
115
+ }
@@ -0,0 +1,15 @@
1
+ //#region ../shared/pass.js
2
+ var e = () => ({
3
+ colorAttachments: [{
4
+ view: void 0,
5
+ loadOp: "load",
6
+ storeOp: "store"
7
+ }],
8
+ depthStencilAttachment: {
9
+ view: void 0,
10
+ depthReadOnly: !0,
11
+ stencilReadOnly: !0
12
+ }
13
+ });
14
+ //#endregion
15
+ export { e as t };
@@ -0,0 +1,99 @@
1
+ import type { EngineKernel } from '@margoengine/core';
2
+ import { type ReactElement, type ReactNode } from 'react';
3
+ import { type UiRendererOptions } from './renderer.js';
4
+ import { Ui, type ScaleOptions, type UiOptions } from './ui.js';
5
+ import type { Theme } from './theme.js';
6
+ import type { UiEvent } from './widget.js';
7
+ import type { LabelOptions, PanelOptions } from './basic.js';
8
+ import type { ButtonOptions, SliderOptions, ToggleOptions } from './controls.js';
9
+ import type { HealthBarOptions, ProgressBarOptions } from './meters.js';
10
+ import type { InventoryOptions, ListOptions, MenuOptions } from './collections.js';
11
+ /**
12
+ * The `Ui` of the enclosing {@link UiRoot}: call `ui.toast()`, `ui.dialog()`, `ui.confirm()` or `ui.announce()` from an event handler.
13
+ * @throws Error when used outside a `UiRoot`.
14
+ */
15
+ export declare function useUi(): Ui;
16
+ /** Props of {@link UiRoot}. */
17
+ export interface UiRootProps {
18
+ /** Draw the UI on this engine (a `UiRenderer` is attached on mount and removed on unmount). Get it from `useEngine()` of `@margoengine/react`. */
19
+ engine?: EngineKernel;
20
+ /** Use a `Ui` you made yourself instead of creating one. It is not disposed on unmount. */
21
+ ui?: Ui;
22
+ /** Options for the `Ui` UiRoot creates (ignored when `ui` is given): size, font, safe area, reduced motion. */
23
+ options?: UiOptions;
24
+ /** Options for the renderer (`input`, `mirror`, `order`, atlas sizes). */
25
+ renderer?: UiRendererOptions;
26
+ /** Restyle the whole UI: `themes.dark`, `themes.highContrast`, or your own. */
27
+ theme?: Theme;
28
+ /** The user's text size, 0.5 to 3. */
29
+ textScale?: number;
30
+ /** Resolution scaling: CSS pixels per UI unit, or a reference size. */
31
+ scale?: number | ScaleOptions;
32
+ children?: ReactNode;
33
+ }
34
+ /**
35
+ * Hosts a game UI in a React tree. It renders no DOM: the widgets you nest inside are drawn on the engine's canvas. Create
36
+ * it where the engine is known, for example in a child of `<Canvas>` that calls `useEngine()`.
37
+ *
38
+ * @example
39
+ * <UiRoot engine={engine} theme={themes.dark}>
40
+ * <Panel background="surface" padding={16} anchor="top-left" margin={16}>
41
+ * <HealthBar value={hp} max={100} width={240} />
42
+ * </Panel>
43
+ * </UiRoot>
44
+ */
45
+ export declare function UiRoot({ engine, ui: given, options, renderer, theme, textScale, scale, children, }: UiRootProps): ReactElement;
46
+ /** Props of {@link Panel}: its options and React children. */
47
+ export type PanelProps = Omit<PanelOptions, 'children'> & {
48
+ children?: ReactNode;
49
+ };
50
+ /** A container with an optional background. Its React children become its child widgets. */
51
+ export declare function Panel(props: PanelProps): ReactElement;
52
+ /** Props of {@link Label}. */
53
+ export type LabelProps = LabelOptions;
54
+ /** Text. */
55
+ export declare function Label(props: LabelProps): ReactElement | null;
56
+ /** Props of {@link Button}. */
57
+ export type ButtonProps = Omit<ButtonOptions, 'onClick'> & {
58
+ onClick?: (event: UiEvent) => void;
59
+ };
60
+ /** A push button. */
61
+ export declare function Button(props: ButtonProps): ReactElement | null;
62
+ /** Props of {@link Toggle}. */
63
+ export type ToggleProps = Omit<ToggleOptions, 'onChange'> & {
64
+ onChange?: (event: UiEvent) => void;
65
+ };
66
+ /** A switch or checkbox; `checked` is controlled: set it from your state, update the state in `onChange`. */
67
+ export declare function Toggle(props: ToggleProps): ReactElement | null;
68
+ /** Props of {@link Slider}. */
69
+ export type SliderProps = Omit<SliderOptions, 'onChange'> & {
70
+ onChange?: (event: UiEvent) => void;
71
+ };
72
+ /** A slider; `value` is controlled like a Toggle's `checked`. */
73
+ export declare function Slider(props: SliderProps): ReactElement | null;
74
+ /** Props of {@link ProgressBar}. */
75
+ export type ProgressBarProps = ProgressBarOptions;
76
+ /** A meter with its value written in it. */
77
+ export declare function ProgressBar(props: ProgressBarProps): ReactElement | null;
78
+ /** Props of {@link HealthBar}. */
79
+ export type HealthBarProps = HealthBarOptions;
80
+ /** A progress bar for hit points, with a damage trail. */
81
+ export declare function HealthBar(props: HealthBarProps): ReactElement | null;
82
+ /** Props of {@link List}. */
83
+ export type ListProps = Omit<ListOptions, 'onSelect' | 'children'> & {
84
+ onSelect?: (event: UiEvent) => void;
85
+ };
86
+ /** A scrolling list of selectable rows; `items` and `selected` are controlled. */
87
+ export declare function List(props: ListProps): ReactElement | null;
88
+ /** Props of {@link Inventory}. */
89
+ export type InventoryProps = Omit<InventoryOptions, 'onSelect' | 'onMove' | 'onUse'> & {
90
+ onSelect?: (event: UiEvent) => void;
91
+ onMove?: (event: UiEvent) => void;
92
+ onUse?: (event: UiEvent) => void;
93
+ };
94
+ /** A grid of item slots; `items` is controlled: update your state in `onMove`. */
95
+ export declare function Inventory(props: InventoryProps): ReactElement | null;
96
+ /** Props of {@link Menu}. */
97
+ export type MenuProps = Omit<MenuOptions, 'children'>;
98
+ /** A titled column of buttons. Entries are created once; give the component a new `key` to change them. */
99
+ export declare function Menu(props: MenuProps): ReactElement | null;
package/dist/react.js ADDED
@@ -0,0 +1,246 @@
1
+ import { t as e } from "./errors-CDgOgzCd.js";
2
+ import { _ as t, c as n, i as r, l as i, n as a, o, r as s, s as c, t as l, v as u } from "./meters-yaZRtwsX.js";
3
+ import { o as d, t as f } from "./renderer-Vs-YtiWv.js";
4
+ import { createContext as p, useContext as m, useEffect as h, useLayoutEffect as g, useRef as _, useState as v } from "react";
5
+ import { jsx as y } from "react/jsx-runtime";
6
+ //#region src/react.tsx
7
+ var b = p(null), x = p(null);
8
+ function S() {
9
+ let t = m(b);
10
+ if (!t) throw e("state", "useUi must be used inside <UiRoot>; wrap the interface in <UiRoot engine={engine}>", "ui");
11
+ return t;
12
+ }
13
+ function C({ engine: e, ui: t, options: n, renderer: r, theme: i, textScale: a, scale: o, children: s }) {
14
+ let [c] = v(() => t ?? new d(n)), l = t ?? c, u = _(!1);
15
+ return h(() => (u.current = !1, () => {
16
+ u.current = !0, t || queueMicrotask(() => {
17
+ u.current && c.dispose();
18
+ });
19
+ }), [t, c]), h(() => {
20
+ if (!e) return;
21
+ let t = f.attach(e, l, r);
22
+ return () => e.removePlugin(t.name);
23
+ }, [e, l]), g(() => {
24
+ i && l.theme !== i && (l.theme = i);
25
+ }, [l, i]), g(() => {
26
+ a !== void 0 && l.textScale !== a && (l.textScale = a);
27
+ }, [l, a]), g(() => {
28
+ o !== void 0 && l.setScale(o);
29
+ }, [l, o]), /* @__PURE__ */ y(b.Provider, {
30
+ value: l,
31
+ children: /* @__PURE__ */ y(x.Provider, {
32
+ value: l.root,
33
+ children: s
34
+ })
35
+ });
36
+ }
37
+ var w = [
38
+ "direction",
39
+ "gap",
40
+ "align",
41
+ "justify",
42
+ "padding",
43
+ "margin",
44
+ "width",
45
+ "height",
46
+ "minWidth",
47
+ "maxWidth",
48
+ "minHeight",
49
+ "maxHeight",
50
+ "grow",
51
+ "shrink",
52
+ "alignSelf",
53
+ "anchor",
54
+ "position",
55
+ "offset",
56
+ "bleed",
57
+ "columns",
58
+ "cellWidth",
59
+ "cellHeight",
60
+ "overflow",
61
+ "wrap"
62
+ ], T = [
63
+ "id",
64
+ "visible",
65
+ "enabled",
66
+ "label",
67
+ "description",
68
+ "tooltip",
69
+ "pointerEvents"
70
+ ];
71
+ function E(e) {
72
+ let t = {};
73
+ for (let n of w) e[n] !== void 0 && (t[n] = e[n]);
74
+ return t;
75
+ }
76
+ function D(t, n, r, i) {
77
+ let a = _(null);
78
+ (!a.current || a.current.key !== n) && (a.current = {
79
+ key: n,
80
+ widget: t()
81
+ });
82
+ let o = a.current.widget, s = m(x);
83
+ g(() => {
84
+ if (!s) throw e("state", "A widget must be inside <UiRoot>; wrap the interface in <UiRoot engine={engine}>", "ui");
85
+ return s.add(o), () => {
86
+ o.removeFromParent();
87
+ };
88
+ }, [s, o]);
89
+ let c = JSON.stringify(E(r)), l = _({
90
+ widget: o,
91
+ style: c
92
+ });
93
+ return g(() => {
94
+ (l.current.widget !== o || l.current.style !== c) && (l.current.widget === o && o.setStyle(JSON.parse(c)), l.current = {
95
+ widget: o,
96
+ style: c
97
+ }), r.visible !== void 0 && (o.visible = r.visible), r.enabled !== void 0 && (o.enabled = r.enabled), (r.tooltip !== void 0 || o.tooltip !== void 0) && (o.tooltip = r.tooltip), r.label !== void 0 && (o.label = r.label), (r.description !== void 0 || o.description !== void 0) && (o.description = r.description), i?.(o);
98
+ }), o;
99
+ }
100
+ function O(e, t, n) {
101
+ let r = _(n);
102
+ r.current = n, h(() => e.on(t, (e) => r.current?.(e)), [e, t]);
103
+ }
104
+ function k({ widget: e, children: t }) {
105
+ return /* @__PURE__ */ y(x.Provider, {
106
+ value: e,
107
+ children: t
108
+ });
109
+ }
110
+ function A(e, t = []) {
111
+ return JSON.stringify([t, e.id]);
112
+ }
113
+ function j(e, t) {
114
+ let n = { ...E(e) };
115
+ for (let r of [...T, ...t]) e[r] !== void 0 && (n[r] = e[r]);
116
+ return n;
117
+ }
118
+ function M(e) {
119
+ let t = e, n = D(() => new u(j(t, [
120
+ "background",
121
+ "border",
122
+ "shadow",
123
+ "radius"
124
+ ])), A(t, [t.radius]), t, (e) => {
125
+ t.background !== void 0 && (e.background = t.background), t.border !== void 0 && (e.border = t.border), t.shadow !== void 0 && (e.shadow = t.shadow);
126
+ });
127
+ return /* @__PURE__ */ y(k, {
128
+ widget: n,
129
+ children: e.children
130
+ });
131
+ }
132
+ function N(e) {
133
+ let n = e;
134
+ return D(() => new t(j(n, [
135
+ "text",
136
+ "size",
137
+ "color",
138
+ "align",
139
+ "wrap",
140
+ "outline",
141
+ "lineHeight"
142
+ ])), A(n), n, (e) => {
143
+ n.text !== void 0 && (e.text = n.text), n.size !== void 0 && (e.size = n.size), n.color !== void 0 && (e.color = n.color), n.align !== void 0 && (e.align = n.align), n.wrap !== void 0 && (e.wrap = n.wrap), n.outline !== void 0 && (e.outline = n.outline);
144
+ }), null;
145
+ }
146
+ function P(e) {
147
+ let t = e;
148
+ return O(D(() => new c(j(t, [
149
+ "text",
150
+ "icon",
151
+ "variant",
152
+ "size"
153
+ ])), A(t), t, (e) => {
154
+ t.text !== void 0 && (e.text = t.text), t.icon !== void 0 && (e.icon = t.icon), t.variant !== void 0 && (e.variant = t.variant);
155
+ }), "click", e.onClick), null;
156
+ }
157
+ function F(e) {
158
+ let t = e;
159
+ return O(D(() => new i(j(t, [
160
+ "text",
161
+ "checked",
162
+ "variant"
163
+ ])), A(t, [t.variant]), t, (e) => {
164
+ t.text !== void 0 && (e.text = t.text), t.checked !== void 0 && (e.checked = t.checked);
165
+ }), "change", e.onChange), null;
166
+ }
167
+ function I(e) {
168
+ let t = e;
169
+ return O(D(() => new n(j(t, [
170
+ "min",
171
+ "max",
172
+ "step",
173
+ "value",
174
+ "text",
175
+ "showValue",
176
+ "format"
177
+ ])), A(t, [
178
+ t.min,
179
+ t.max,
180
+ t.step,
181
+ t.showValue
182
+ ]), t, (e) => {
183
+ t.value !== void 0 && (e.value = t.value);
184
+ }), "change", e.onChange), null;
185
+ }
186
+ function L(e) {
187
+ let t = e;
188
+ return D(() => new a(j(t, [
189
+ "value",
190
+ "max",
191
+ "text",
192
+ "variant",
193
+ "display",
194
+ "smooth",
195
+ "trail"
196
+ ])), A(t, [
197
+ t.max,
198
+ t.display,
199
+ t.trail
200
+ ]), t, (e) => {
201
+ t.value !== void 0 && (e.value = t.value), t.text !== void 0 && (e.text = t.text), t.variant !== void 0 && (e.variant = t.variant);
202
+ }), null;
203
+ }
204
+ function R(e) {
205
+ let t = e;
206
+ return D(() => new l(j(t, [
207
+ "value",
208
+ "max",
209
+ "text",
210
+ "display",
211
+ "smooth"
212
+ ])), A(t, [t.max, t.display]), t, (e) => {
213
+ t.value !== void 0 && (e.value = t.value), t.text !== void 0 && (e.text = t.text);
214
+ }), null;
215
+ }
216
+ function z(e) {
217
+ let t = e;
218
+ return O(D(() => new r(j(t, ["items", "selected"])), A(t), t, (e) => {
219
+ t.items !== void 0 && JSON.stringify(t.items) !== JSON.stringify(e.items) && (e.items = t.items), t.selected !== void 0 && t.selected !== e.selected && e.select(t.selected);
220
+ }), "select", e.onSelect), null;
221
+ }
222
+ function B(e) {
223
+ let t = e, n = D(() => new s(j(t, [
224
+ "columns",
225
+ "slots",
226
+ "slotSize",
227
+ "slotGap",
228
+ "items"
229
+ ])), A(t, [
230
+ t.columns,
231
+ t.slots,
232
+ t.slotSize,
233
+ t.slotGap
234
+ ]), t, (e) => {
235
+ t.items !== void 0 && t.items !== e.items && JSON.stringify(t.items) !== JSON.stringify(e.items) && (e.items = t.items);
236
+ });
237
+ return O(n, "select", e.onSelect), O(n, "move", e.onMove), O(n, "use", e.onUse), null;
238
+ }
239
+ function V(e) {
240
+ let t = e;
241
+ return D(() => new o(j(t, ["title", "items"])), A(t, [JSON.stringify(t.items?.map((e) => e.label))]), t, (e) => {
242
+ t.title !== void 0 && (e.title = t.title);
243
+ }), null;
244
+ }
245
+ //#endregion
246
+ export { P as Button, R as HealthBar, B as Inventory, N as Label, z as List, V as Menu, M as Panel, L as ProgressBar, I as Slider, F as Toggle, C as UiRoot, S as useUi };