gesso-framework 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import { Fragment, JSX, jsx, jsxDEV, jsxs } from "./jsx-runtime.js";
2
+ export { Fragment, type JSX, jsx, jsxDEV, jsxs };
@@ -0,0 +1,2 @@
1
+ import { Fragment, jsx, jsxDEV, jsxs } from "./jsx-runtime.js";
2
+ export { Fragment, jsx, jsxDEV, jsxs };
@@ -0,0 +1,117 @@
1
+ import { N as InputCell, U as Component, a as ComponentType, i as ComponentProps, r as ComponentContext, t as ClassComponent } from "../FunctionComponent-DAyf5HQ6.js";
2
+ import { Observable } from "rxjs";
3
+ import { BoxProps, ButtonProps, ColumnProps, ComponentLikeElement, EditableTextProps, GridProps, PaintElementProps, RowProps, ScrollViewProps, StackProps, TextProps, UiChild, UiElement, UiNodeType } from "gesso-core";
4
+ //#region src/jsx/jsx-runtime.d.ts
5
+ /**
6
+ * The JSX runtime: `<row gap={8}>…</row>` compiles to
7
+ * `jsx('row', { gap: 8, children: … })`, which calls `createElement`;
8
+ * `<Counter label="x" />` calls `createComponent`. There is no virtual
9
+ * DOM and nothing is diffed here — the output is the same UiElement /
10
+ * ComponentElement the factory API produces, so JSX costs nothing at
11
+ * runtime and the two surfaces can be mixed freely.
12
+ *
13
+ * Enabled per project with
14
+ *
15
+ * "jsx": "react-jsx", "jsxImportSource": "gesso"
16
+ *
17
+ * in tsconfig (the repository maps `gesso/jsx-runtime` to this file).
18
+ *
19
+ * Intrinsic tags are the element factories in lowercase: `text`,
20
+ * `editabletext`, `button`, `box`, `stack`, `row`, `column`,
21
+ * `scrollview`, `grid`, `paint`.
22
+ * A `text` or `button` with a string (or Observable string) child
23
+ * takes it as its `text` prop. A `paint` is a box the application
24
+ * draws into, through its `paint` or `path` prop; its children stack
25
+ * over the picture. See `rendering/PaintSurface.ts`.
26
+ */
27
+ /** What may appear between tags: children, or nothing (for conditionals). */
28
+ type JsxChild = UiChild | string | number | boolean | null | undefined;
29
+ type JsxChildren = JsxChild | readonly JsxChildren[];
30
+ type WithChildren<P, C = JsxChildren> = P & {
31
+ children?: C;
32
+ };
33
+ /** A text child: a string, or an Observable of one. */
34
+ type TextChildren = string | number | Observable<string | number>;
35
+ declare const INTRINSIC_TYPES: {
36
+ readonly text: UiNodeType.Text;
37
+ readonly editabletext: UiNodeType.EditableText;
38
+ readonly button: UiNodeType.Button;
39
+ readonly box: UiNodeType.Box;
40
+ readonly stack: UiNodeType.Box;
41
+ readonly row: UiNodeType.Row;
42
+ readonly column: UiNodeType.Column;
43
+ readonly scrollview: UiNodeType.ScrollView;
44
+ readonly grid: UiNodeType.Grid;
45
+ readonly paint: UiNodeType.Paint;
46
+ };
47
+ type IntrinsicTag = keyof typeof INTRINSIC_TYPES;
48
+ declare namespace JSX {
49
+ type Element = UiElement | ComponentLikeElement;
50
+ /** Anything a tag may name. */
51
+ type ElementType = IntrinsicTag | ComponentType;
52
+ /** A class usable as a tag; `Component` satisfies it. */
53
+ interface ElementClass {
54
+ render(): UiChild;
55
+ }
56
+ /** `key` is accepted on every tag and is never a prop. */
57
+ interface IntrinsicAttributes {
58
+ key?: string | number;
59
+ }
60
+ interface ElementChildrenAttribute {
61
+ children: {};
62
+ }
63
+ interface IntrinsicElements {
64
+ text: WithChildren<TextProps, TextChildren>;
65
+ /** Editable text; takes no children — its text is `value`. */
66
+ editabletext: EditableTextProps & {
67
+ children?: never;
68
+ };
69
+ button: WithChildren<ButtonProps, JsxChildren | TextChildren>;
70
+ box: WithChildren<BoxProps>;
71
+ stack: WithChildren<StackProps>;
72
+ row: WithChildren<RowProps>;
73
+ column: WithChildren<ColumnProps>;
74
+ scrollview: WithChildren<ScrollViewProps>;
75
+ grid: WithChildren<GridProps>;
76
+ /** A box the application draws into; see `PaintSurface`. */
77
+ paint: WithChildren<PaintElementProps>;
78
+ }
79
+ /**
80
+ * The attributes a component tag takes: computed from the component
81
+ * itself — a class's `input()` fields or a function's `Inputs<P>`
82
+ * parameter — exactly as `createComponent` types them.
83
+ *
84
+ * TypeScript consults this for intrinsic tags too, handing them in
85
+ * as a synthetic `(props: IntrinsicElements[tag]) => Element`
86
+ * signature. That looks like a functional component, so the check
87
+ * is on the parameter: only a record of input cells is one. Anything
88
+ * else keeps `P`, the attributes TypeScript already found.
89
+ */
90
+ type LibraryManagedAttributes<C, P> = C extends ClassComponent ? ComponentProps<C> : C extends ((props: infer I, ...rest: any[]) => UiChild) ? unknown extends I ? ComponentProps<C> : I extends Record<string, InputCell<any>> ? ComponentProps<C> : P : P;
91
+ }
92
+ type JsxProps = Record<string, unknown> & {
93
+ children?: JsxChildren;
94
+ };
95
+ /**
96
+ * Creates one element. `key` arrives separately, as the compiler
97
+ * passes it; `children` arrives inside props.
98
+ */
99
+ declare function jsx(type: JSX.ElementType, props: JsxProps | null, key?: string | number): JSX.Element;
100
+ /** The compiler's variant for static child lists; identical here. */
101
+ declare const jsxs: typeof jsx;
102
+ /**
103
+ * Development-mode entry (`jsxDEV`), used by Vite in dev. The extra
104
+ * arguments describe the source location and are not needed.
105
+ */
106
+ declare function jsxDEV(type: JSX.ElementType, props: JsxProps | null, key?: string | number): JSX.Element;
107
+ /**
108
+ * `<>…</>` has no node to become. Children of a fragment are spliced
109
+ * into the parent, so it can only be used where a list of children is
110
+ * accepted — which is every container tag.
111
+ */
112
+ declare function Fragment(_props: {
113
+ children?: JsxChildren;
114
+ }): never;
115
+ //#endregion
116
+ export { type Component, type ComponentContext, Fragment, IntrinsicTag, JSX, JsxChild, JsxChildren, jsx, jsxDEV, jsxs };
117
+ //# sourceMappingURL=jsx-runtime.d.ts.map
@@ -0,0 +1,153 @@
1
+ import { a as Each, r as Show, t as createComponent } from "../createComponent-3n1ZSql8.js";
2
+ import { Box, Button, Column, EditableText, Grid, Paint, Row, ScrollView, Stack, Text, UiNodeType } from "gesso-core";
3
+ //#region src/jsx/jsx-runtime.ts
4
+ const INTRINSIC_TYPES = {
5
+ text: UiNodeType.Text,
6
+ editabletext: UiNodeType.EditableText,
7
+ button: UiNodeType.Button,
8
+ box: UiNodeType.Box,
9
+ stack: UiNodeType.Box,
10
+ row: UiNodeType.Row,
11
+ column: UiNodeType.Column,
12
+ scrollview: UiNodeType.ScrollView,
13
+ grid: UiNodeType.Grid,
14
+ paint: UiNodeType.Paint
15
+ };
16
+ /**
17
+ * Creates one element. `key` arrives separately, as the compiler
18
+ * passes it; `children` arrives inside props.
19
+ */
20
+ function jsx(type, props, key) {
21
+ const { children, ...rest } = props ?? {};
22
+ if (typeof type === "string") return intrinsic(type, rest, children, key);
23
+ if (typeof type !== "function") throw new Error(`JSX tag must be an intrinsic name or a component, got ${describe(type)}.`);
24
+ if (type === Each || type === Show) return type({ ...props });
25
+ return createComponent(type, componentProps(type, rest, children), key);
26
+ }
27
+ /**
28
+ * A component's props, with any JSX children folded in as `children`.
29
+ *
30
+ * This used to throw: components took inputs, not children, and the
31
+ * message said to pass them as a prop instead. The advice did not
32
+ * work. `<Card children={x} />` and `<Card>{x}</Card>` compile to the
33
+ * same `jsx(Card, { children: x })`, so the runtime cannot tell them
34
+ * apart and rejected both, which left every component in the library
35
+ * that takes its content as `children` (`Card`, `Tabs`, `Toolbar`,
36
+ * `Accordion`) unusable as a JSX tag. Since the documentation and the
37
+ * examples are JSX, that is most of the component library.
38
+ *
39
+ * It is also inconsistent: no other prop is checked here. A misspelled
40
+ * or wrongly typed prop is a compile error, and `children` already is
41
+ * one too, because `JSX.ElementChildrenAttribute` maps nested children
42
+ * onto the `children` prop and `LibraryManagedAttributes` types it
43
+ * from the component. A component that does not declare `children`
44
+ * therefore cannot be given any.
45
+ *
46
+ * The one rule left is arity. A component's `children` is a `UiChild`,
47
+ * which is one child and not a list, so several children have to be
48
+ * wrapped in a container tag. That is said here rather than left to
49
+ * become a confusing type error at the call site.
50
+ */
51
+ function componentProps(type, props, children) {
52
+ if (children === void 0) return props;
53
+ const list = flattenChildren(children);
54
+ if (list.length === 0) return props;
55
+ if (list.length > 1) throw new Error(`Component '${componentName(type)}' was given ${list.length} children. A component takes one child, so wrap them in a container tag: <${componentName(type)}><column>…</column></${componentName(type)}>.`);
56
+ return {
57
+ ...props,
58
+ children: list[0]
59
+ };
60
+ }
61
+ function componentName(type) {
62
+ return typeof type === "function" ? type.name ?? "anonymous" : String(type);
63
+ }
64
+ /** The compiler's variant for static child lists; identical here. */
65
+ const jsxs = jsx;
66
+ /**
67
+ * Development-mode entry (`jsxDEV`), used by Vite in dev. The extra
68
+ * arguments describe the source location and are not needed.
69
+ */
70
+ function jsxDEV(type, props, key) {
71
+ return jsx(type, props, key);
72
+ }
73
+ /**
74
+ * `<>…</>` has no node to become. Children of a fragment are spliced
75
+ * into the parent, so it can only be used where a list of children is
76
+ * accepted — which is every container tag.
77
+ */
78
+ function Fragment(_props) {
79
+ throw new Error("JSX fragments are not supported: return a list of elements, or wrap them in a container tag.");
80
+ }
81
+ /**
82
+ * The element factories, by tag.
83
+ *
84
+ * JSX calls these rather than `createElement`, so an intrinsic tag and
85
+ * the factory of the same name are the same code path and cannot
86
+ * diverge. They already had: `Button()` injects `BUTTON_INTERACTION`,
87
+ * so every button made with the factory shows hover and press, and a
88
+ * `<button>` made here went straight to `createElement` and showed
89
+ * neither. Nothing caught it, because nothing reads `visualState` yet.
90
+ */
91
+ const INTRINSIC_FACTORIES = {
92
+ text: Text,
93
+ editabletext: EditableText,
94
+ button: Button,
95
+ box: Box,
96
+ stack: Stack,
97
+ row: Row,
98
+ column: Column,
99
+ scrollview: ScrollView,
100
+ grid: Grid,
101
+ paint: Paint
102
+ };
103
+ function intrinsic(tag, props, children, key) {
104
+ const type = INTRINSIC_TYPES[tag];
105
+ const factory = INTRINSIC_FACTORIES[tag];
106
+ if (type === void 0 || factory === void 0) throw new Error(`Unknown JSX tag '${tag}'. Intrinsic tags are ${Object.keys(INTRINSIC_TYPES).map((name) => `'${name}'`).join(", ")}.`);
107
+ const elementProps = key !== void 0 ? {
108
+ ...props,
109
+ key
110
+ } : props;
111
+ if ((type === UiNodeType.Text || type === UiNodeType.Button) && isTextChild(children)) {
112
+ if (elementProps.text !== void 0) throw new Error(`<${tag}> has both a text prop and a text child; use one.`);
113
+ return factory({
114
+ ...elementProps,
115
+ text: typeof children === "number" ? String(children) : children
116
+ });
117
+ }
118
+ return factory(elementProps, ...flattenChildren(children));
119
+ }
120
+ /**
121
+ * Inside <text> and <button> a single string, number or Observable
122
+ * child is the label. An Observable cannot be told apart from an
123
+ * observable child list at runtime, so the rule is by tag: these two
124
+ * take it as text, and a button whose children are observable elements
125
+ * wraps them in a container tag.
126
+ */
127
+ function isTextChild(value) {
128
+ return typeof value === "string" || typeof value === "number" || isObservableValue(value);
129
+ }
130
+ function isObservableValue(value) {
131
+ return typeof value === "object" && value !== null && typeof value.subscribe === "function";
132
+ }
133
+ /**
134
+ * Nested arrays are flattened and `null`, `undefined` and booleans are
135
+ * dropped, so `{cond && <text/>}` and `{items.map(…)}` both work.
136
+ */
137
+ function flattenChildren(children, out = []) {
138
+ if (children === null || children === void 0 || typeof children === "boolean") return out;
139
+ if (Array.isArray(children)) {
140
+ for (const child of children) flattenChildren(child, out);
141
+ return out;
142
+ }
143
+ if (typeof children === "string" || typeof children === "number") throw new Error(`A bare string child ('${String(children)}') is only allowed inside <text> or <button>. Wrap it: <text>{…}</text>.`);
144
+ out.push(children);
145
+ return out;
146
+ }
147
+ function describe(value) {
148
+ return value === null ? "null" : typeof value === "object" ? "an object" : `a ${typeof value}`;
149
+ }
150
+ //#endregion
151
+ export { Fragment, jsx, jsxDEV, jsxs };
152
+
153
+ //# sourceMappingURL=jsx-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime.js","names":[],"sources":["../../src/jsx/jsx-runtime.ts"],"sourcesContent":["import type { Observable } from 'rxjs';\n\nimport {\n type BoxProps,\n type ButtonProps,\n type ColumnProps,\n type EditableTextProps,\n type GridProps,\n type PaintElementProps,\n type RowProps,\n type ScrollViewProps,\n type StackProps,\n type TextProps,\n type ComponentLikeElement,\n type UiChild,\n type UiElement,\n type UiProps,\n Box,\n Button,\n Column,\n EditableText,\n Grid,\n Paint,\n Row,\n ScrollView,\n Stack,\n Text,\n UiNodeType\n} from 'gesso-core';\nimport type { Component } from '../Component';\nimport type { InputCell } from '../Input';\nimport { createComponent } from '../createComponent';\nimport { Each } from '../each';\nimport { Show } from '../show';\nimport type { ClassComponent, ComponentContext, ComponentProps, ComponentType } from '../FunctionComponent';\n\n/**\n * The JSX runtime: `<row gap={8}>…</row>` compiles to\n * `jsx('row', { gap: 8, children: … })`, which calls `createElement`;\n * `<Counter label=\"x\" />` calls `createComponent`. There is no virtual\n * DOM and nothing is diffed here — the output is the same UiElement /\n * ComponentElement the factory API produces, so JSX costs nothing at\n * runtime and the two surfaces can be mixed freely.\n *\n * Enabled per project with\n *\n * \"jsx\": \"react-jsx\", \"jsxImportSource\": \"gesso\"\n *\n * in tsconfig (the repository maps `gesso/jsx-runtime` to this file).\n *\n * Intrinsic tags are the element factories in lowercase: `text`,\n * `editabletext`, `button`, `box`, `stack`, `row`, `column`,\n * `scrollview`, `grid`, `paint`.\n * A `text` or `button` with a string (or Observable string) child\n * takes it as its `text` prop. A `paint` is a box the application\n * draws into, through its `paint` or `path` prop; its children stack\n * over the picture. See `rendering/PaintSurface.ts`.\n */\n\n/** What may appear between tags: children, or nothing (for conditionals). */\nexport type JsxChild = UiChild | string | number | boolean | null | undefined;\nexport type JsxChildren = JsxChild | readonly JsxChildren[];\n\ntype WithChildren<P, C = JsxChildren> = P & { children?: C };\n\n/** A text child: a string, or an Observable of one. */\ntype TextChildren = string | number | Observable<string | number>;\n\nconst INTRINSIC_TYPES = {\n text: UiNodeType.Text,\n editabletext: UiNodeType.EditableText,\n button: UiNodeType.Button,\n box: UiNodeType.Box,\n stack: UiNodeType.Box,\n row: UiNodeType.Row,\n column: UiNodeType.Column,\n scrollview: UiNodeType.ScrollView,\n grid: UiNodeType.Grid,\n paint: UiNodeType.Paint\n} as const satisfies Record<string, UiNodeType>;\n\nexport type IntrinsicTag = keyof typeof INTRINSIC_TYPES;\n\nexport namespace JSX {\n export type Element = UiElement | ComponentLikeElement;\n\n /** Anything a tag may name. */\n export type ElementType = IntrinsicTag | ComponentType;\n\n /** A class usable as a tag; `Component` satisfies it. */\n export interface ElementClass {\n render(): UiChild;\n }\n\n /** `key` is accepted on every tag and is never a prop. */\n export interface IntrinsicAttributes {\n key?: string | number;\n }\n\n export interface ElementChildrenAttribute {\n children: {};\n }\n\n export interface IntrinsicElements {\n text: WithChildren<TextProps, TextChildren>;\n /** Editable text; takes no children — its text is `value`. */\n editabletext: EditableTextProps & { children?: never };\n button: WithChildren<ButtonProps, JsxChildren | TextChildren>;\n box: WithChildren<BoxProps>;\n stack: WithChildren<StackProps>;\n row: WithChildren<RowProps>;\n column: WithChildren<ColumnProps>;\n scrollview: WithChildren<ScrollViewProps>;\n grid: WithChildren<GridProps>;\n /** A box the application draws into; see `PaintSurface`. */\n paint: WithChildren<PaintElementProps>;\n }\n\n /**\n * The attributes a component tag takes: computed from the component\n * itself — a class's `input()` fields or a function's `Inputs<P>`\n * parameter — exactly as `createComponent` types them.\n *\n * TypeScript consults this for intrinsic tags too, handing them in\n * as a synthetic `(props: IntrinsicElements[tag]) => Element`\n * signature. That looks like a functional component, so the check\n * is on the parameter: only a record of input cells is one. Anything\n * else keeps `P`, the attributes TypeScript already found.\n */\n export type LibraryManagedAttributes<C, P> = C extends ClassComponent\n ? ComponentProps<C>\n : C extends (props: infer I, ...rest: any[]) => UiChild\n ? unknown extends I\n ? ComponentProps<C>\n : I extends Record<string, InputCell<any>>\n ? ComponentProps<C>\n : P\n : P;\n}\n\ntype JsxProps = Record<string, unknown> & { children?: JsxChildren };\n\n/**\n * Creates one element. `key` arrives separately, as the compiler\n * passes it; `children` arrives inside props.\n */\nexport function jsx(type: JSX.ElementType, props: JsxProps | null, key?: string | number): JSX.Element {\n const { children, ...rest } = props ?? {};\n if (typeof type === 'string') {\n return intrinsic(type, rest, children, key);\n }\n if (typeof type !== 'function') {\n throw new Error(`JSX tag must be an intrinsic name or a component, got ${describe(type)}.`);\n }\n if (type === (Each as unknown as JSX.ElementType) || type === (Show as unknown as JSX.ElementType)) {\n // The two structural tags. Neither mounts a component: each one\n // returns the observable list of children its parent binds, so\n // `<Show>` really does add no node and `<Each>` adds no anchor\n // beyond the one an observable child already has. They take a\n // function as their child, which is the other reason they cannot\n // go through `componentProps` below.\n return (type as unknown as (props: JsxProps) => JSX.Element)({ ...props });\n }\n return createComponent(\n type as ClassComponent,\n componentProps(type, rest, children) as ComponentProps<ClassComponent>,\n key\n );\n}\n\n/**\n * A component's props, with any JSX children folded in as `children`.\n *\n * This used to throw: components took inputs, not children, and the\n * message said to pass them as a prop instead. The advice did not\n * work. `<Card children={x} />` and `<Card>{x}</Card>` compile to the\n * same `jsx(Card, { children: x })`, so the runtime cannot tell them\n * apart and rejected both, which left every component in the library\n * that takes its content as `children` (`Card`, `Tabs`, `Toolbar`,\n * `Accordion`) unusable as a JSX tag. Since the documentation and the\n * examples are JSX, that is most of the component library.\n *\n * It is also inconsistent: no other prop is checked here. A misspelled\n * or wrongly typed prop is a compile error, and `children` already is\n * one too, because `JSX.ElementChildrenAttribute` maps nested children\n * onto the `children` prop and `LibraryManagedAttributes` types it\n * from the component. A component that does not declare `children`\n * therefore cannot be given any.\n *\n * The one rule left is arity. A component's `children` is a `UiChild`,\n * which is one child and not a list, so several children have to be\n * wrapped in a container tag. That is said here rather than left to\n * become a confusing type error at the call site.\n */\nfunction componentProps(\n type: JSX.ElementType,\n props: Record<string, unknown>,\n children: JsxChildren\n): Record<string, unknown> {\n if (children === undefined) {\n return props;\n }\n const list = flattenChildren(children);\n if (list.length === 0) {\n return props;\n }\n if (list.length > 1) {\n throw new Error(\n `Component '${componentName(type)}' was given ${list.length} children. ` +\n `A component takes one child, so wrap them in a container tag: <${componentName(type)}><column>…</column></${componentName(type)}>.`\n );\n }\n return { ...props, children: list[0] };\n}\n\nfunction componentName(type: JSX.ElementType): string {\n return typeof type === 'function' ? ((type as { name?: string }).name ?? 'anonymous') : String(type);\n}\n\n/** The compiler's variant for static child lists; identical here. */\nexport const jsxs = jsx;\n\n/**\n * Development-mode entry (`jsxDEV`), used by Vite in dev. The extra\n * arguments describe the source location and are not needed.\n */\nexport function jsxDEV(type: JSX.ElementType, props: JsxProps | null, key?: string | number): JSX.Element {\n return jsx(type, props, key);\n}\n\n/**\n * `<>…</>` has no node to become. Children of a fragment are spliced\n * into the parent, so it can only be used where a list of children is\n * accepted — which is every container tag.\n */\nexport function Fragment(_props: { children?: JsxChildren }): never {\n throw new Error('JSX fragments are not supported: return a list of elements, or wrap them in a container tag.');\n}\n\n/**\n * The element factories, by tag.\n *\n * JSX calls these rather than `createElement`, so an intrinsic tag and\n * the factory of the same name are the same code path and cannot\n * diverge. They already had: `Button()` injects `BUTTON_INTERACTION`,\n * so every button made with the factory shows hover and press, and a\n * `<button>` made here went straight to `createElement` and showed\n * neither. Nothing caught it, because nothing reads `visualState` yet.\n */\nconst INTRINSIC_FACTORIES = {\n text: Text,\n editabletext: EditableText,\n button: Button,\n box: Box,\n stack: Stack,\n row: Row,\n column: Column,\n scrollview: ScrollView,\n grid: Grid,\n paint: Paint\n} as const satisfies Record<IntrinsicTag, unknown>;\n\n/** Every factory, seen as the one shape this file calls them with. */\ntype ElementFactory = (props: UiProps, ...children: UiChild[]) => UiElement;\n\nfunction intrinsic(\n tag: string,\n props: Record<string, unknown>,\n children: JsxChildren,\n key?: string | number\n): UiElement {\n const type = (INTRINSIC_TYPES as Record<string, UiNodeType | undefined>)[tag];\n const factory = (INTRINSIC_FACTORIES as Record<string, ElementFactory | undefined>)[tag];\n if (type === undefined || factory === undefined) {\n throw new Error(\n `Unknown JSX tag '${tag}'. Intrinsic tags are ${Object.keys(INTRINSIC_TYPES)\n .map(name => `'${name}'`)\n .join(', ')}.`\n );\n }\n const elementProps: UiProps = key !== undefined ? { ...props, key } : props;\n if ((type === UiNodeType.Text || type === UiNodeType.Button) && isTextChild(children)) {\n if (elementProps.text !== undefined) {\n throw new Error(`<${tag}> has both a text prop and a text child; use one.`);\n }\n return factory({ ...elementProps, text: typeof children === 'number' ? String(children) : children });\n }\n return factory(elementProps, ...flattenChildren(children));\n}\n\n/**\n * Inside <text> and <button> a single string, number or Observable\n * child is the label. An Observable cannot be told apart from an\n * observable child list at runtime, so the rule is by tag: these two\n * take it as text, and a button whose children are observable elements\n * wraps them in a container tag.\n */\nfunction isTextChild(value: JsxChildren | TextChildren): value is TextChildren {\n return typeof value === 'string' || typeof value === 'number' || isObservableValue(value);\n}\n\nfunction isObservableValue(value: unknown): value is Observable<unknown> {\n return typeof value === 'object' && value !== null && typeof (value as Observable<unknown>).subscribe === 'function';\n}\n\n/**\n * Nested arrays are flattened and `null`, `undefined` and booleans are\n * dropped, so `{cond && <text/>}` and `{items.map(…)}` both work.\n */\nfunction flattenChildren(children: JsxChildren, out: UiChild[] = []): UiChild[] {\n if (children === null || children === undefined || typeof children === 'boolean') {\n return out;\n }\n if (Array.isArray(children)) {\n for (const child of children as readonly JsxChildren[]) {\n flattenChildren(child, out);\n }\n return out;\n }\n if (typeof children === 'string' || typeof children === 'number') {\n throw new Error(\n `A bare string child ('${String(children)}') is only allowed inside <text> or <button>. Wrap it: <text>{…}</text>.`\n );\n }\n out.push(children as UiChild);\n return out;\n}\n\nfunction describe(value: unknown): string {\n return value === null ? 'null' : typeof value === 'object' ? 'an object' : `a ${typeof value}`;\n}\n\nexport type { Component, ComponentContext };\n"],"mappings":";;;AAoEA,MAAM,kBAAkB;CACtB,MAAM,WAAW;CACjB,cAAc,WAAW;CACzB,QAAQ,WAAW;CACnB,KAAK,WAAW;CAChB,OAAO,WAAW;CAClB,KAAK,WAAW;CAChB,QAAQ,WAAW;CACnB,YAAY,WAAW;CACvB,MAAM,WAAW;CACjB,OAAO,WAAW;AACpB;;;;;AAmEA,SAAgB,IAAI,MAAuB,OAAwB,KAAoC;CACrG,MAAM,E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