@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,116 @@
1
+ /** A rectangle in UI units: `x` right, `y` down from the top left of the screen. */
2
+ export interface Rect {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ }
8
+ /**
9
+ * A size: a number of UI units, `'auto'` (fit the content), `'fill'` (take the free space along the parent's main
10
+ * axis, or the whole cross axis) or a percentage of the parent's content box such as `'50%'`.
11
+ */
12
+ export type Size = number | 'auto' | 'fill' | `${number}%`;
13
+ /** Spacing around or inside a box: one number, `[vertical, horizontal]` or `[top, right, bottom, left]`. */
14
+ export type Edges = number | readonly [number, number] | readonly [number, number, number, number];
15
+ /** Placement on the cross axis. `'stretch'` fills the cross axis when the size is `'auto'`. */
16
+ export type Align = 'start' | 'center' | 'end' | 'stretch';
17
+ /** Placement of the children along the main axis. */
18
+ export type Justify = 'start' | 'center' | 'end' | 'space-between' | 'space-around' | 'space-evenly';
19
+ /** Where an anchored child sits in its parent's content box. `'stretch'` fills both axes. */
20
+ export type Anchor = 'stretch' | 'top-left' | 'top' | 'top-right' | 'left' | 'center' | 'right' | 'bottom-left' | 'bottom' | 'bottom-right';
21
+ /** How a box lays out and is laid out. Every field is optional; defaults are noted per field. */
22
+ export interface LayoutStyle {
23
+ /** How children are placed: `'column'` (default), `'row'`, `'stack'` (all anchored over each other) or `'grid'`. */
24
+ direction?: 'row' | 'column' | 'stack' | 'grid';
25
+ /** Space between children in `row`, `column` and `grid`: one number or `[column gap, row gap]`. Default 0. */
26
+ gap?: number | readonly [number, number];
27
+ /** Cross-axis placement of the children. Default `'stretch'` in a column and `'center'` in a row. */
28
+ align?: Align;
29
+ /** Main-axis placement of the children when none of them grows. Default `'start'`. */
30
+ justify?: Justify;
31
+ /** Space inside the box. Default 0. */
32
+ padding?: Edges;
33
+ /** Space outside the box. In a stack it is the distance from the anchored edges. Default 0. */
34
+ margin?: Edges;
35
+ /** Default `'auto'`. */
36
+ width?: Size;
37
+ /** Default `'auto'`. */
38
+ height?: Size;
39
+ /** Lower bound of the width in UI units. Default 0. */
40
+ minWidth?: number;
41
+ /** Upper bound of the width. Default unbounded. */
42
+ maxWidth?: number;
43
+ /** Lower bound of the height. Default 0. */
44
+ minHeight?: number;
45
+ /** Upper bound of the height. Default unbounded. */
46
+ maxHeight?: number;
47
+ /** Share of the free main-axis space this child takes. Default 0 (1 for `'fill'` on the main axis). */
48
+ grow?: number;
49
+ /** How readily this child gives up its size when the parent is too small. Default 1. */
50
+ shrink?: number;
51
+ /** Cross-axis placement of this child, overriding the parent's `align`. Default `'auto'` (the parent's). */
52
+ alignSelf?: Align | 'auto';
53
+ /** Anchor in the parent's content box. Children of a `'stack'` default to `'stretch'`; set it elsewhere with `position: 'absolute'`. */
54
+ anchor?: Anchor;
55
+ /** Take the child out of the flow and place it with `anchor` (and `margin`). Default `'flow'`. */
56
+ position?: 'flow' | 'absolute';
57
+ /** Extra shift in UI units after layout; does not affect other boxes. Default `[0, 0]`. */
58
+ offset?: readonly [number, number];
59
+ /** In a stack, ignore the parent's padding (and the safe area), so the child can fill the whole screen. Default false. */
60
+ bleed?: boolean;
61
+ /** Columns of a `'grid'`. Default 1. */
62
+ columns?: number;
63
+ /** Cell width of a `'grid'`. Default the widest child. */
64
+ cellWidth?: number;
65
+ /** Cell height of a `'grid'`. Default the tallest child. */
66
+ cellHeight?: number;
67
+ /** `'scroll'` lets the children exceed the box along the main axis and scroll; `'hidden'` clips. Default `'visible'`. */
68
+ overflow?: 'visible' | 'hidden' | 'scroll';
69
+ /**
70
+ * In a `'row'`, children that do not fit move onto new lines below, as tag lists and toolbars reflow. Each line shares
71
+ * its own free space (`grow`, `shrink`, `justify`) and is as tall as its tallest child, which `align` places
72
+ * children within; the row gap of `gap` separates the lines, and `overflow: 'scroll'` scrolls them vertically.
73
+ * Columns ignore it. Default false.
74
+ */
75
+ wrap?: boolean;
76
+ }
77
+ /** What {@link arrange} needs from a box. {@link Widget} implements it; tests can use plain objects. */
78
+ export interface LayoutNode {
79
+ readonly style: LayoutStyle;
80
+ readonly children: readonly LayoutNode[];
81
+ /** False takes the box out of the layout entirely. Default true. */
82
+ readonly visible?: boolean;
83
+ /**
84
+ * Content size (without padding) of a leaf box wrapped to at most `maxWidth`.
85
+ * Return the same size for the same width during one arrange call; repeated constraints share one measurement.
86
+ */
87
+ measure?(maxWidth: number): {
88
+ width: number;
89
+ height: number;
90
+ };
91
+ /** Written by {@link arrange}. */
92
+ rect: Rect;
93
+ /** Scroll offset in UI units, clamped by {@link arrange}. */
94
+ scrollX?: number;
95
+ /** Scroll offset in UI units, clamped by {@link arrange}. */
96
+ scrollY?: number;
97
+ /** Written by {@link arrange}: the size of the children's extent along the scrolling axis. */
98
+ contentWidth?: number;
99
+ /** Written by {@link arrange}. */
100
+ contentHeight?: number;
101
+ }
102
+ type Insets = readonly [number, number, number, number];
103
+ /** Expand {@link Edges} to `[top, right, bottom, left]`. Throws a TypeError or RangeError for anything else. */
104
+ export declare function edges(value: Edges | undefined): Insets;
105
+ /** Check a style, throwing a TypeError or RangeError that names the field. Returns it unchanged. */
106
+ export declare function validateStyle(style: LayoutStyle): LayoutStyle;
107
+ /**
108
+ * Lay out the tree below `root` into `box` and write every node's `rect` (absolute UI units, y down). The algorithm
109
+ * is a small flexbox: children of a row or column take their base size, then free space is shared by `grow` and
110
+ * a shortage by `shrink`, then `justify` and `align` place them. A stack anchors its children, and a grid fills cells
111
+ * row by row. Measurements are memoized only within this call, so edits are visible on the next call.
112
+ */
113
+ export declare function arrange(root: LayoutNode, box: Rect): void;
114
+ /** Move a laid-out subtree by (dx, dy) UI units, for placing a box after the layout. */
115
+ export declare function translate(node: LayoutNode, dx: number, dy: number): void;
116
+ export {};
@@ -0,0 +1,89 @@
1
+ import type { UiEvent, Widget } from './widget.js';
2
+ /** An element of parsed markup. */
3
+ export interface MarkupElement {
4
+ tag: string;
5
+ attributes: Record<string, string>;
6
+ children: MarkupElement[];
7
+ /** The element's own text, whitespace collapsed. */
8
+ text: string;
9
+ line: number;
10
+ column: number;
11
+ }
12
+ /** One declaration of a style rule. */
13
+ export interface StyleDeclaration {
14
+ property: string;
15
+ value: string;
16
+ line: number;
17
+ }
18
+ /** A parsed style rule: one selector of a list, with its specificity and place in the sheet. */
19
+ export interface StyleRule {
20
+ selector: string;
21
+ specificity: readonly [number, number, number];
22
+ order: number;
23
+ declarations: StyleDeclaration[];
24
+ /** @internal */
25
+ parts: SelectorPart[];
26
+ }
27
+ interface Compound {
28
+ tag: string | null;
29
+ id: string | null;
30
+ classes: string[];
31
+ }
32
+ /** @internal A compound and the combinator that joins it to the compound on its left. */
33
+ export interface SelectorPart {
34
+ compound: Compound;
35
+ combinator: ' ' | '>' | null;
36
+ }
37
+ /** Options for {@link buildScreen}. */
38
+ export interface ScreenOptions {
39
+ /** Style sheet text, or several applied in order (a later sheet wins a tie). */
40
+ styles?: string | readonly string[];
41
+ /** Handlers named by `on-click`, `on-change` and `on-select` attributes. */
42
+ actions?: Readonly<Record<string, (event: UiEvent) => void>>;
43
+ }
44
+ /** Options for {@link loadScreen}: the same as {@link ScreenOptions}, with style sheet URLs and an abort signal. */
45
+ export interface LoadScreenOptions extends Omit<ScreenOptions, 'styles'> {
46
+ /** Style sheet URLs, fetched beside the markup. */
47
+ styles?: string | readonly string[];
48
+ signal?: AbortSignal;
49
+ }
50
+ /** The widgets a markup file built. */
51
+ export interface Screen {
52
+ /** The top-level widgets, in markup order: add them to a `Ui` or a panel. */
53
+ readonly widgets: readonly Widget[];
54
+ /** The widget with an `id` attribute. */
55
+ get(id: string): Widget | undefined;
56
+ }
57
+ /**
58
+ * Parse markup into elements.
59
+ * @throws TypeError naming the line and column of the first error (unclosed or mismatched tags, a bad attribute).
60
+ */
61
+ export declare function parseMarkup(source: string): MarkupElement[];
62
+ /**
63
+ * Parse a style sheet into rules, one per selector of each rule's selector list.
64
+ * @throws TypeError naming the line of the first error (an unsupported selector, a declaration without a colon).
65
+ */
66
+ export declare function parseStyleSheet(source: string, order?: number): StyleRule[];
67
+ /**
68
+ * Build the widgets of a markup screen, styled by `options.styles`.
69
+ *
70
+ * Elements: `panel`, `row` and `column` (panels laid out that way) hold other elements; `label`, `button`, `toggle`,
71
+ * `slider`, `progress` and `health` take their text from their content; `list` and `menu` take `<item>` children
72
+ * (`<item detail="20 g">Rope</item>`). Attributes and declarations are the widgets' options in kebab-case
73
+ * (`min-width`, `show-value`); a list takes spaces (`padding: 8 16`). `class` names classes for the sheet,
74
+ * `on-click`, `on-change` and `on-select` name a handler in `options.actions`.
75
+ *
76
+ * @throws TypeError naming the line of the first error: unknown element, property or action, or a bad value.
77
+ * @example
78
+ * const screen = buildScreen('<panel class="hud"><label id="gold">0</label></panel>', {
79
+ * styles: '.hud { direction: row; anchor: top-left; margin: 16 }',
80
+ * });
81
+ * ui.add(...screen.widgets);
82
+ */
83
+ export declare function buildScreen(markup: string, options?: ScreenOptions): Screen;
84
+ /**
85
+ * Fetch a markup file and its style sheets (relative to the page) and build the screen.
86
+ * @throws TypeError as {@link buildScreen}; rejects with the signal's reason when aborted, or on a failed fetch.
87
+ */
88
+ export declare function loadScreen(url: string | URL, options?: LoadScreenOptions): Promise<Screen>;
89
+ export {};
package/dist/markup.js ADDED
@@ -0,0 +1,369 @@
1
+ import { r as e, t } from "./errors-CDgOgzCd.js";
2
+ import { _ as n, c as r, i, l as a, n as o, o as s, s as c, t as l, v as u } from "./meters-yaZRtwsX.js";
3
+ //#region src/markup.ts
4
+ var d = {
5
+ lt: "<",
6
+ gt: ">",
7
+ amp: "&",
8
+ quot: "\"",
9
+ apos: "'"
10
+ };
11
+ function f(e, t) {
12
+ let n = 1, r = 0;
13
+ for (let i = e.indexOf("\n"); i >= 0 && i < t; i = e.indexOf("\n", i + 1)) n++, r = i + 1;
14
+ return {
15
+ line: n,
16
+ column: t - r + 1
17
+ };
18
+ }
19
+ function p(t, n, r, i = "Markup") {
20
+ let { line: a, column: o } = f(t, n);
21
+ throw e(`${i} line ${a}, column ${o}: ${r}`, "ui");
22
+ }
23
+ function m(e, t, n) {
24
+ return t.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-z]+);|&/g, (t, r) => {
25
+ if (r || p(e, n, "a bare '&' must be written &amp;"), r[0] === "#") {
26
+ let i = r[1] === "x" ? parseInt(r.slice(2), 16) : parseInt(r.slice(1), 10);
27
+ return i === 9 || i === 10 || i === 13 || i >= 32 && i <= 55295 || i >= 57344 && i <= 65533 || i >= 65536 && i <= 1114111 || p(e, n, `${t} is not an XML character; write a code point XML 1.0 allows`), String.fromCodePoint(i);
28
+ }
29
+ let i = d[r];
30
+ return i === void 0 && p(e, n, `unknown reference ${t}; use &lt; &gt; &amp; &quot; &apos; or a number`), i;
31
+ });
32
+ }
33
+ var h = /[A-Za-z_][\w.-]*/y, g = /\s*/y;
34
+ function _(t) {
35
+ if (typeof t != "string") throw e("parseMarkup takes the markup text", "ui");
36
+ let n = [], r = [], i = 0, a = () => {
37
+ g.lastIndex = i, g.exec(t), i = g.lastIndex;
38
+ }, o = (e) => {
39
+ h.lastIndex = i;
40
+ let n = h.exec(t);
41
+ return n || p(t, i, `expected ${e}`), i = h.lastIndex, n[0];
42
+ }, s = (e, n) => {
43
+ let i = m(t, e, n).replace(/\s+/g, " ").trim();
44
+ if (!i) return;
45
+ let a = r.at(-1);
46
+ a || p(t, n, "text outside an element"), a.text = a.text ? `${a.text} ${i}` : i;
47
+ };
48
+ for (; i < t.length;) {
49
+ let e = t.indexOf("<", i);
50
+ if (e < 0) {
51
+ s(t.slice(i), i);
52
+ break;
53
+ }
54
+ if (e > i && s(t.slice(i, e), i), i = e, t.startsWith("<!--", i)) {
55
+ let e = t.indexOf("-->", i + 4);
56
+ e < 0 && p(t, i, "a comment is not closed with -->"), i = e + 3;
57
+ continue;
58
+ }
59
+ if (t.startsWith("<?", i)) {
60
+ let e = t.indexOf("?>", i + 2);
61
+ e < 0 && p(t, i, "a <? declaration is not closed with ?>"), i = e + 2;
62
+ continue;
63
+ }
64
+ if (t.startsWith("<!", i) && p(t, i, "document type declarations and CDATA are not supported"), t[i + 1] === "/") {
65
+ let e = i;
66
+ i += 2;
67
+ let n = o("a closing tag name");
68
+ a(), t[i] !== ">" && p(t, i, `expected > to close </${n}`), i++;
69
+ let s = r.pop();
70
+ s || p(t, e, `</${n}> closes nothing`), s.tag !== n && p(t, e, `</${n}> closes <${s.tag}> from line ${s.line}`);
71
+ continue;
72
+ }
73
+ let c = i;
74
+ i++;
75
+ let l = o("a tag name"), u = {};
76
+ for (; a(), !(t.startsWith("/>", i) || t[i] === ">");) {
77
+ i >= t.length && p(t, c, `<${l}> is not closed with >`);
78
+ let e = i, n = o("an attribute name");
79
+ a(), t[i] !== "=" && p(t, i, `attribute ${n} needs ="value"`), i++, a();
80
+ let r = t[i];
81
+ r !== "\"" && r !== "'" && p(t, i, `the value of ${n} must be in quotes`);
82
+ let s = t.indexOf(r, i + 1);
83
+ s < 0 && p(t, i, `the value of ${n} is not closed`), n in u && p(t, e, `attribute ${n} is given twice`), u[n] = m(t, t.slice(i + 1, s), i), i = s + 1;
84
+ }
85
+ let { line: d, column: h } = f(t, c), g = {
86
+ tag: l,
87
+ attributes: u,
88
+ children: [],
89
+ text: "",
90
+ line: d,
91
+ column: h
92
+ };
93
+ (r.at(-1)?.children ?? n).push(g), t[i] === "/" ? i += 2 : (i++, r.push(g));
94
+ }
95
+ let c = r.pop();
96
+ return c && p(t, t.length, `<${c.tag}> from line ${c.line} is not closed`), n;
97
+ }
98
+ function v(t, n = 0) {
99
+ if (typeof t != "string") throw e("parseStyleSheet takes the style sheet text", "ui");
100
+ let r = t.replace(/\/\*[\s\S]*?(\*\/|$)/g, (e) => e.replace(/[^\n]/g, " ")), i = [], a = 0;
101
+ for (; a < r.length;) {
102
+ let e = r.indexOf("{", a);
103
+ if (e < 0) {
104
+ r.slice(a).trim() && p(t, a, "a selector without a { block }", "Style");
105
+ break;
106
+ }
107
+ let o = r.indexOf("}", e);
108
+ o < 0 && p(t, e, "a rule is not closed with }", "Style");
109
+ let s = r.slice(a, e);
110
+ s.includes("}") && p(t, a + s.indexOf("}"), "a } without a rule", "Style");
111
+ let c = [], l = e + 1;
112
+ for (let n of r.slice(e + 1, o).split(";")) {
113
+ if (n.trim()) {
114
+ let e = n.indexOf(":"), r = f(t, l + n.search(/\S/)).line;
115
+ e < 0 && p(t, l, `declaration '${n.trim()}' needs property: value`, "Style");
116
+ let i = n.slice(0, e).trim(), a = n.slice(e + 1).trim();
117
+ /^[a-z][a-z0-9-]*$/i.test(i) || p(t, l, `'${i}' is not a property name`, "Style"), a || p(t, l, `${i} has no value`, "Style"), c.push({
118
+ property: i,
119
+ value: a,
120
+ line: r
121
+ });
122
+ }
123
+ l += n.length + 1;
124
+ }
125
+ let u = a;
126
+ for (let e of s.split(",")) {
127
+ let r = e.trim().replace(/\s+/g, " ");
128
+ r || p(t, u, "an empty selector", "Style");
129
+ let a = b(r, t, u), o = [
130
+ 0,
131
+ 0,
132
+ 0
133
+ ];
134
+ for (let { compound: e } of a) e.id && o[0]++, o[1] += e.classes.length, e.tag && o[2]++;
135
+ i.push({
136
+ selector: r,
137
+ specificity: o,
138
+ order: n + i.length,
139
+ declarations: c,
140
+ parts: a
141
+ }), u += e.length + 1;
142
+ }
143
+ a = o + 1;
144
+ }
145
+ return i;
146
+ }
147
+ var y = /^(\*|[A-Za-z][\w-]*)?((?:[#.][A-Za-z_][\w-]*)*)$/;
148
+ function b(e, t, n) {
149
+ let r = e.replace(/\s*>\s*/g, " > ").split(" ").filter(Boolean), i = [], a = null;
150
+ for (let o of r) {
151
+ if (o === ">") {
152
+ (!i.length || a === ">") && p(t, n, `'${e}': > needs a selector on each side`, "Style"), a = ">";
153
+ continue;
154
+ }
155
+ let r = y.exec(o);
156
+ r || p(t, n, `'${e}': only type, #id and .class selectors joined by spaces or > are supported, not '${o}'`, "Style");
157
+ let s = r[1] && r[1] !== "*" ? r[1] : null, c = r[2].match(/#[\w-]+/g), l = (r[2].match(/\.[\w-]+/g) ?? []).map((e) => e.slice(1));
158
+ c && c.length > 1 && p(t, n, `'${e}' names two ids`, "Style"), i.push({
159
+ compound: {
160
+ tag: s,
161
+ id: c ? c[0].slice(1) : null,
162
+ classes: l
163
+ },
164
+ combinator: i.length ? a ?? " " : null
165
+ }), a = null;
166
+ }
167
+ return a && p(t, n, `'${e}' ends with >`, "Style"), i;
168
+ }
169
+ var x = (e, t) => {
170
+ if (e.tag && e.tag !== t.tag || e.id && e.id !== t.attributes.id) return !1;
171
+ if (!e.classes.length) return !0;
172
+ let n = (t.attributes.class ?? "").split(/\s+/);
173
+ return e.classes.every((e) => n.includes(e));
174
+ };
175
+ function S(e, t, n) {
176
+ let r = e.parts, i = (e, t, a) => {
177
+ if (!x(r[e].compound, t)) return !1;
178
+ if (e === 0) return !0;
179
+ if (r[e].combinator === ">") return a > 0 && i(e - 1, n[a - 1], a - 1);
180
+ for (let t = a - 1; t >= 0; t--) if (i(e - 1, n[t], t)) return !0;
181
+ return !1;
182
+ };
183
+ return i(r.length - 1, t, n.length);
184
+ }
185
+ var C = /* @__PURE__ */ new Set([
186
+ "id",
187
+ "text",
188
+ "label",
189
+ "description",
190
+ "tooltip",
191
+ "icon",
192
+ "title",
193
+ "variant",
194
+ "display",
195
+ "background",
196
+ "color",
197
+ "direction",
198
+ "align",
199
+ "justify",
200
+ "anchor",
201
+ "position",
202
+ "overflow",
203
+ "alignSelf",
204
+ "pointerEvents",
205
+ "detail"
206
+ ]), w = /* @__PURE__ */ new Set([
207
+ "grow",
208
+ "shrink",
209
+ "minWidth",
210
+ "maxWidth",
211
+ "minHeight",
212
+ "maxHeight",
213
+ "columns",
214
+ "cellWidth",
215
+ "cellHeight",
216
+ "radius",
217
+ "value",
218
+ "min",
219
+ "max",
220
+ "step",
221
+ "selected"
222
+ ]), T = /* @__PURE__ */ new Set([
223
+ "visible",
224
+ "enabled",
225
+ "border",
226
+ "shadow",
227
+ "bleed",
228
+ "wrap",
229
+ "checked",
230
+ "showValue",
231
+ "smooth",
232
+ "trail",
233
+ "outline",
234
+ "disabled"
235
+ ]), E = /* @__PURE__ */ new Set(["width", "height"]), D = {
236
+ padding: [
237
+ 1,
238
+ 2,
239
+ 4
240
+ ],
241
+ margin: [
242
+ 1,
243
+ 2,
244
+ 4
245
+ ],
246
+ gap: [1, 2],
247
+ offset: [2]
248
+ }, O = {
249
+ "on-click": "onClick",
250
+ "on-change": "onChange",
251
+ "on-select": "onSelect"
252
+ }, k = (e) => e.replace(/-([a-z])/g, (e, t) => t.toUpperCase()), A = /^-?(\d+\.?\d*|\.\d+)$/;
253
+ function j(t, n, r) {
254
+ let i = k(t), a = (i) => {
255
+ throw e(`${r}: ${t} takes ${i}, not '${n}'`, "ui");
256
+ };
257
+ if (C.has(i)) return n;
258
+ if (i === "size") return A.test(n) ? Number(n) : n;
259
+ if (w.has(i)) return A.test(n) ? Number(n) : a("a number");
260
+ if (T.has(i)) return n === "true" || n !== "false" && a("true or false");
261
+ if (E.has(i)) return A.test(n) ? Number(n) : n;
262
+ let o = D[i];
263
+ if (o) {
264
+ let e = n.split(/\s+/);
265
+ (!o.includes(e.length) || !e.every((e) => A.test(e))) && a(`${o.join(" or ")} number${o.at(-1) === 1 ? "" : "s"}`);
266
+ let t = e.map(Number);
267
+ return t.length === 1 ? t[0] : t;
268
+ }
269
+ throw e(`${r}: unknown property ${t}; check its spelling against the widget's options`, "ui");
270
+ }
271
+ var M = (e, t) => t.text && e.text === void 0 ? {
272
+ ...e,
273
+ text: t.text
274
+ } : e, N = {
275
+ panel: (e) => new u(e),
276
+ row: (e) => new u({
277
+ direction: "row",
278
+ ...e
279
+ }),
280
+ column: (e) => new u({
281
+ direction: "column",
282
+ ...e
283
+ }),
284
+ label: (e, t) => new n(M(e, t)),
285
+ button: (e, t) => new c(M(e, t)),
286
+ toggle: (e, t) => new a(M(e, t)),
287
+ slider: (e, t) => new r(M(e, t)),
288
+ progress: (e, t) => new o(M(e, t)),
289
+ health: (e, t) => new l(M(e, t)),
290
+ list: (e, t, n) => new i({
291
+ ...e,
292
+ items: n
293
+ }),
294
+ menu: (e, t, n) => new s({
295
+ ...e,
296
+ items: n
297
+ })
298
+ }, P = /* @__PURE__ */ new Set([
299
+ "panel",
300
+ "row",
301
+ "column"
302
+ ]);
303
+ function F(t, n = {}) {
304
+ let r = n.styles === void 0 ? [] : typeof n.styles == "string" ? [n.styles] : n.styles;
305
+ if (!Array.isArray(r) || !r.every((e) => typeof e == "string")) throw e("styles is style sheet text or an array of them", "ui");
306
+ let i = n.actions ?? {}, a = [];
307
+ for (let e of r) a.push(...v(e, a.length));
308
+ a.sort((e, t) => {
309
+ for (let n = 0; n < 3; n++) if (e.specificity[n] !== t.specificity[n]) return e.specificity[n] - t.specificity[n];
310
+ return e.order - t.order;
311
+ });
312
+ let o = /* @__PURE__ */ new Map(), s = (t, n) => {
313
+ let r = {};
314
+ for (let e of a) if (S(e, t, n)) for (let t of e.declarations) r[k(t.property)] = j(t.property, t.value, `Style line ${t.line} (${e.selector})`);
315
+ for (let [n, a] of Object.entries(t.attributes)) {
316
+ let o = `Markup line ${t.line}, <${t.tag}>`;
317
+ if (n === "class") continue;
318
+ let s = O[n];
319
+ if (s) {
320
+ let t = i[a];
321
+ if (typeof t != "function") throw e(`${o}: ${n}="${a}" names no function in actions`, "ui");
322
+ r[s] = t;
323
+ } else r[k(n)] = j(n, a, o);
324
+ }
325
+ return r;
326
+ }, c = (t, n) => {
327
+ let r = N[t.tag];
328
+ if (!r) throw e(`Markup line ${t.line}: unknown element <${t.tag}>; use ${Object.keys(N).join(", ")}`, "ui");
329
+ let i = s(t, n), a = [...n, t], l = [], u = [];
330
+ for (let n of t.children) if (n.tag === "item" && (t.tag === "list" || t.tag === "menu")) {
331
+ let e = s(n, a);
332
+ if (e.label ??= n.text, t.tag === "menu" && e.onSelect) {
333
+ let t = e.onSelect;
334
+ e.onSelect = () => t({
335
+ type: "select",
336
+ target: d
337
+ });
338
+ }
339
+ l.push(e);
340
+ } else if (P.has(t.tag)) u.push(c(n, a));
341
+ else throw e(`Markup line ${n.line}: <${t.tag}> cannot hold <${n.tag}>`, "ui");
342
+ if (t.text && P.has(t.tag)) throw e(`Markup line ${t.line}: <${t.tag}> holds elements, not text; use a <label>`, "ui");
343
+ let d = r(i, t, l);
344
+ u.length && d.add(...u);
345
+ let f = t.attributes.id;
346
+ if (f) {
347
+ if (o.has(f)) throw e(`Markup line ${t.line}: id ${f} is used twice`, "ui");
348
+ o.set(f, d);
349
+ }
350
+ return d;
351
+ };
352
+ return {
353
+ widgets: _(t).map((e) => c(e, [])),
354
+ get: (e) => o.get(e)
355
+ };
356
+ }
357
+ async function I(e, n = {}) {
358
+ let { styles: r, signal: i, ...a } = n, o = async (e) => {
359
+ let n = await fetch(e, { signal: i });
360
+ if (!n.ok) throw t("failed", `Could not fetch ${String(e)}: HTTP ${n.status}; check the URL`, "ui");
361
+ return n.text();
362
+ }, s = r === void 0 ? [] : typeof r == "string" ? [r] : [...r], [c, ...l] = await Promise.all([o(e), ...s.map(o)]);
363
+ return i?.throwIfAborted(), F(c, {
364
+ ...a,
365
+ styles: l
366
+ });
367
+ }
368
+ //#endregion
369
+ export { F as buildScreen, I as loadScreen, _ as parseMarkup, v as parseStyleSheet };