@textui/core 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.
- package/LICENSE +21 -0
- package/README.md +67 -0
- package/dist/adapters/index.d.ts +12 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +11 -0
- package/dist/app/app.d.ts +200 -0
- package/dist/app/app.d.ts.map +1 -0
- package/dist/app/app.js +980 -0
- package/dist/core/animation.d.ts +34 -0
- package/dist/core/animation.d.ts.map +1 -0
- package/dist/core/animation.js +125 -0
- package/dist/core/clipboard.d.ts +29 -0
- package/dist/core/clipboard.d.ts.map +1 -0
- package/dist/core/clipboard.js +30 -0
- package/dist/core/commands.d.ts +42 -0
- package/dist/core/commands.d.ts.map +1 -0
- package/dist/core/commands.js +146 -0
- package/dist/core/components.d.ts +27 -0
- package/dist/core/components.d.ts.map +1 -0
- package/dist/core/components.js +78 -0
- package/dist/core/events.d.ts +23 -0
- package/dist/core/events.d.ts.map +1 -0
- package/dist/core/events.js +77 -0
- package/dist/core/focus.d.ts +69 -0
- package/dist/core/focus.d.ts.map +1 -0
- package/dist/core/focus.js +336 -0
- package/dist/core/i18n.d.ts +27 -0
- package/dist/core/i18n.d.ts.map +1 -0
- package/dist/core/i18n.js +88 -0
- package/dist/core/keybindings.d.ts +53 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +163 -0
- package/dist/core/layers.d.ts +28 -0
- package/dist/core/layers.d.ts.map +1 -0
- package/dist/core/layers.js +84 -0
- package/dist/core/manifest.d.ts +22 -0
- package/dist/core/manifest.d.ts.map +1 -0
- package/dist/core/manifest.js +85 -0
- package/dist/core/navigation.d.ts +47 -0
- package/dist/core/navigation.d.ts.map +1 -0
- package/dist/core/navigation.js +110 -0
- package/dist/core/resources.d.ts +115 -0
- package/dist/core/resources.d.ts.map +1 -0
- package/dist/core/resources.js +321 -0
- package/dist/core/services.d.ts +21 -0
- package/dist/core/services.d.ts.map +1 -0
- package/dist/core/services.js +63 -0
- package/dist/core/store.d.ts +60 -0
- package/dist/core/store.d.ts.map +1 -0
- package/dist/core/store.js +593 -0
- package/dist/core/surfaces.d.ts +81 -0
- package/dist/core/surfaces.d.ts.map +1 -0
- package/dist/core/surfaces.js +237 -0
- package/dist/core/syntax.d.ts +49 -0
- package/dist/core/syntax.d.ts.map +1 -0
- package/dist/core/syntax.js +172 -0
- package/dist/core/when.d.ts +15 -0
- package/dist/core/when.d.ts.map +1 -0
- package/dist/core/when.js +224 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/jsx/factory.d.ts +27 -0
- package/dist/jsx/factory.d.ts.map +1 -0
- package/dist/jsx/factory.js +102 -0
- package/dist/jsx/intrinsics.d.ts +96 -0
- package/dist/jsx/intrinsics.d.ts.map +1 -0
- package/dist/jsx/intrinsics.js +1 -0
- package/dist/jsx/jsx-dev-runtime.d.ts +13 -0
- package/dist/jsx/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx/jsx-dev-runtime.js +12 -0
- package/dist/jsx/jsx-runtime.d.ts +42 -0
- package/dist/jsx/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx/jsx-runtime.js +16 -0
- package/dist/render/buffer.d.ts +77 -0
- package/dist/render/buffer.d.ts.map +1 -0
- package/dist/render/buffer.js +275 -0
- package/dist/render/color.d.ts +35 -0
- package/dist/render/color.d.ts.map +1 -0
- package/dist/render/color.js +160 -0
- package/dist/render/diff.d.ts +37 -0
- package/dist/render/diff.d.ts.map +1 -0
- package/dist/render/diff.js +66 -0
- package/dist/render/layout.d.ts +72 -0
- package/dist/render/layout.d.ts.map +1 -0
- package/dist/render/layout.js +633 -0
- package/dist/render/static.d.ts +63 -0
- package/dist/render/static.d.ts.map +1 -0
- package/dist/render/static.js +209 -0
- package/dist/runtime/bindings.d.ts +46 -0
- package/dist/runtime/bindings.d.ts.map +1 -0
- package/dist/runtime/bindings.js +116 -0
- package/dist/runtime/hooks.d.ts +284 -0
- package/dist/runtime/hooks.d.ts.map +1 -0
- package/dist/runtime/hooks.js +846 -0
- package/dist/runtime/instance.d.ts +106 -0
- package/dist/runtime/instance.d.ts.map +1 -0
- package/dist/runtime/instance.js +181 -0
- package/dist/runtime/paint.d.ts +27 -0
- package/dist/runtime/paint.d.ts.map +1 -0
- package/dist/runtime/paint.js +567 -0
- package/dist/runtime/reconcile.d.ts +23 -0
- package/dist/runtime/reconcile.d.ts.map +1 -0
- package/dist/runtime/reconcile.js +260 -0
- package/dist/runtime/runtime.d.ts +42 -0
- package/dist/runtime/runtime.d.ts.map +1 -0
- package/dist/runtime/runtime.js +1 -0
- package/dist/runtime/style.d.ts +55 -0
- package/dist/runtime/style.d.ts.map +1 -0
- package/dist/runtime/style.js +143 -0
- package/dist/themes/borders.d.ts +10 -0
- package/dist/themes/borders.d.ts.map +1 -0
- package/dist/themes/borders.js +88 -0
- package/dist/themes/builtin.d.ts +31 -0
- package/dist/themes/builtin.d.ts.map +1 -0
- package/dist/themes/builtin.js +291 -0
- package/dist/themes/glyphs.d.ts +15 -0
- package/dist/themes/glyphs.d.ts.map +1 -0
- package/dist/themes/glyphs.js +97 -0
- package/dist/themes/index.d.ts +5 -0
- package/dist/themes/index.d.ts.map +1 -0
- package/dist/themes/index.js +4 -0
- package/dist/themes/registry.d.ts +20 -0
- package/dist/themes/registry.d.ts.map +1 -0
- package/dist/themes/registry.js +204 -0
- package/dist/types/adapter.d.ts +38 -0
- package/dist/types/adapter.d.ts.map +1 -0
- package/dist/types/adapter.js +1 -0
- package/dist/types/animation.d.ts +31 -0
- package/dist/types/animation.d.ts.map +1 -0
- package/dist/types/animation.js +1 -0
- package/dist/types/app.d.ts +148 -0
- package/dist/types/app.d.ts.map +1 -0
- package/dist/types/app.js +1 -0
- package/dist/types/async.d.ts +30 -0
- package/dist/types/async.d.ts.map +1 -0
- package/dist/types/async.js +1 -0
- package/dist/types/capabilities.d.ts +44 -0
- package/dist/types/capabilities.d.ts.map +1 -0
- package/dist/types/capabilities.js +33 -0
- package/dist/types/cells.d.ts +72 -0
- package/dist/types/cells.d.ts.map +1 -0
- package/dist/types/cells.js +10 -0
- package/dist/types/command.d.ts +127 -0
- package/dist/types/command.d.ts.map +1 -0
- package/dist/types/command.js +1 -0
- package/dist/types/component-registry.d.ts +77 -0
- package/dist/types/component-registry.d.ts.map +1 -0
- package/dist/types/component-registry.js +1 -0
- package/dist/types/disposable.d.ts +8 -0
- package/dist/types/disposable.d.ts.map +1 -0
- package/dist/types/disposable.js +1 -0
- package/dist/types/focus.d.ts +72 -0
- package/dist/types/focus.d.ts.map +1 -0
- package/dist/types/focus.js +1 -0
- package/dist/types/geometry.d.ts +28 -0
- package/dist/types/geometry.d.ts.map +1 -0
- package/dist/types/geometry.js +14 -0
- package/dist/types/graph.d.ts +129 -0
- package/dist/types/graph.d.ts.map +1 -0
- package/dist/types/graph.js +31 -0
- package/dist/types/i18n.d.ts +23 -0
- package/dist/types/i18n.d.ts.map +1 -0
- package/dist/types/i18n.js +1 -0
- package/dist/types/index.d.ts +32 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +31 -0
- package/dist/types/input.d.ts +65 -0
- package/dist/types/input.d.ts.map +1 -0
- package/dist/types/input.js +1 -0
- package/dist/types/keybinding.d.ts +49 -0
- package/dist/types/keybinding.d.ts.map +1 -0
- package/dist/types/keybinding.js +1 -0
- package/dist/types/layer.d.ts +54 -0
- package/dist/types/layer.d.ts.map +1 -0
- package/dist/types/layer.js +1 -0
- package/dist/types/manifest.d.ts +114 -0
- package/dist/types/manifest.d.ts.map +1 -0
- package/dist/types/manifest.js +1 -0
- package/dist/types/markdown.d.ts +58 -0
- package/dist/types/markdown.d.ts.map +1 -0
- package/dist/types/markdown.js +1 -0
- package/dist/types/navigation.d.ts +40 -0
- package/dist/types/navigation.d.ts.map +1 -0
- package/dist/types/navigation.js +1 -0
- package/dist/types/render.d.ts +72 -0
- package/dist/types/render.d.ts.map +1 -0
- package/dist/types/render.js +1 -0
- package/dist/types/resource.d.ts +170 -0
- package/dist/types/resource.d.ts.map +1 -0
- package/dist/types/resource.js +1 -0
- package/dist/types/services.d.ts +24 -0
- package/dist/types/services.d.ts.map +1 -0
- package/dist/types/services.js +3 -0
- package/dist/types/shell.d.ts +32 -0
- package/dist/types/shell.d.ts.map +1 -0
- package/dist/types/shell.js +1 -0
- package/dist/types/store.d.ts +124 -0
- package/dist/types/store.d.ts.map +1 -0
- package/dist/types/store.js +1 -0
- package/dist/types/stream.d.ts +18 -0
- package/dist/types/stream.d.ts.map +1 -0
- package/dist/types/stream.js +1 -0
- package/dist/types/style.d.ts +166 -0
- package/dist/types/style.d.ts.map +1 -0
- package/dist/types/style.js +1 -0
- package/dist/types/surface.d.ts +97 -0
- package/dist/types/surface.d.ts.map +1 -0
- package/dist/types/surface.js +1 -0
- package/dist/types/syntax.d.ts +68 -0
- package/dist/types/syntax.d.ts.map +1 -0
- package/dist/types/syntax.js +5 -0
- package/dist/types/terminal.d.ts +52 -0
- package/dist/types/terminal.d.ts.map +1 -0
- package/dist/types/terminal.js +1 -0
- package/dist/types/theme.d.ts +117 -0
- package/dist/types/theme.d.ts.map +1 -0
- package/dist/types/theme.js +1 -0
- package/dist/types/when.d.ts +19 -0
- package/dist/types/when.d.ts.map +1 -0
- package/dist/types/when.js +1 -0
- package/dist/ui/primitives.d.ts +56 -0
- package/dist/ui/primitives.d.ts.map +1 -0
- package/dist/ui/primitives.js +108 -0
- package/dist/ui/screen.d.ts +23 -0
- package/dist/ui/screen.d.ts.map +1 -0
- package/dist/ui/screen.js +18 -0
- package/dist/util/disposable.d.ts +6 -0
- package/dist/util/disposable.d.ts.map +1 -0
- package/dist/util/disposable.js +49 -0
- package/dist/util/markdown.d.ts +24 -0
- package/dist/util/markdown.d.ts.map +1 -0
- package/dist/util/markdown.js +220 -0
- package/dist/util/paths.d.ts +47 -0
- package/dist/util/paths.d.ts.map +1 -0
- package/dist/util/paths.js +134 -0
- package/dist/util/stream.d.ts +32 -0
- package/dist/util/stream.d.ts.map +1 -0
- package/dist/util/stream.js +206 -0
- package/dist/util/text.d.ts +65 -0
- package/dist/util/text.d.ts.map +1 -0
- package/dist/util/text.js +419 -0
- package/package.json +70 -0
- package/src/adapters/index.ts +11 -0
- package/src/app/app.ts +1096 -0
- package/src/core/animation.ts +144 -0
- package/src/core/clipboard.ts +40 -0
- package/src/core/commands.ts +169 -0
- package/src/core/components.ts +91 -0
- package/src/core/events.ts +95 -0
- package/src/core/focus.ts +358 -0
- package/src/core/i18n.ts +107 -0
- package/src/core/keybindings.ts +184 -0
- package/src/core/layers.ts +94 -0
- package/src/core/manifest.ts +84 -0
- package/src/core/navigation.ts +135 -0
- package/src/core/resources.ts +362 -0
- package/src/core/services.ts +69 -0
- package/src/core/store.ts +640 -0
- package/src/core/surfaces.ts +292 -0
- package/src/core/syntax.ts +200 -0
- package/src/core/when.ts +238 -0
- package/src/index.ts +76 -0
- package/src/jsx/factory.ts +124 -0
- package/src/jsx/intrinsics.ts +99 -0
- package/src/jsx/jsx-dev-runtime.ts +23 -0
- package/src/jsx/jsx-runtime.ts +76 -0
- package/src/render/buffer.ts +318 -0
- package/src/render/color.ts +180 -0
- package/src/render/diff.ts +99 -0
- package/src/render/layout.ts +764 -0
- package/src/render/static.ts +290 -0
- package/src/runtime/bindings.ts +150 -0
- package/src/runtime/hooks.ts +1057 -0
- package/src/runtime/instance.ts +284 -0
- package/src/runtime/paint.ts +737 -0
- package/src/runtime/reconcile.ts +335 -0
- package/src/runtime/runtime.ts +47 -0
- package/src/runtime/style.ts +205 -0
- package/src/themes/borders.ts +95 -0
- package/src/themes/builtin.ts +301 -0
- package/src/themes/glyphs.ts +101 -0
- package/src/themes/index.ts +4 -0
- package/src/themes/registry.ts +224 -0
- package/src/types/adapter.ts +41 -0
- package/src/types/animation.ts +34 -0
- package/src/types/app.ts +149 -0
- package/src/types/async.ts +35 -0
- package/src/types/capabilities.ts +79 -0
- package/src/types/cells.ts +79 -0
- package/src/types/command.ts +139 -0
- package/src/types/component-registry.ts +82 -0
- package/src/types/disposable.ts +8 -0
- package/src/types/focus.ts +77 -0
- package/src/types/geometry.ts +50 -0
- package/src/types/graph.ts +174 -0
- package/src/types/i18n.ts +25 -0
- package/src/types/index.ts +31 -0
- package/src/types/input.ts +81 -0
- package/src/types/keybinding.ts +51 -0
- package/src/types/layer.ts +46 -0
- package/src/types/manifest.ts +101 -0
- package/src/types/markdown.ts +47 -0
- package/src/types/navigation.ts +42 -0
- package/src/types/render.ts +86 -0
- package/src/types/resource.ts +185 -0
- package/src/types/services.ts +28 -0
- package/src/types/shell.ts +30 -0
- package/src/types/store.ts +148 -0
- package/src/types/stream.ts +24 -0
- package/src/types/style.ts +205 -0
- package/src/types/surface.ts +119 -0
- package/src/types/syntax.ts +93 -0
- package/src/types/terminal.ts +58 -0
- package/src/types/theme.ts +121 -0
- package/src/types/when.ts +21 -0
- package/src/ui/primitives.ts +118 -0
- package/src/ui/screen.ts +41 -0
- package/src/util/disposable.ts +49 -0
- package/src/util/markdown.ts +225 -0
- package/src/util/paths.ts +138 -0
- package/src/util/stream.ts +213 -0
- package/src/util/text.ts +428 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { BindingPath, ComponentNode } from '../types/graph.js';
|
|
2
|
+
import type { ComponentDefinition } from '../types/component-registry.js';
|
|
3
|
+
import type { Disposable } from '../types/disposable.js';
|
|
4
|
+
import type { FunctionComponent, HostComponent } from '../types/render.js';
|
|
5
|
+
import type { LayoutBox } from '../render/layout.js';
|
|
6
|
+
import type { Rect, Size } from '../types/geometry.js';
|
|
7
|
+
import type { Runtime } from './runtime.js';
|
|
8
|
+
import { type ResolveContext } from './bindings.js';
|
|
9
|
+
export type HookSlot = {
|
|
10
|
+
kind: string;
|
|
11
|
+
value: unknown;
|
|
12
|
+
deps?: unknown[];
|
|
13
|
+
cleanup?: (() => void) | void;
|
|
14
|
+
};
|
|
15
|
+
export type InstanceKind = 'function' | 'host' | 'template' | 'missing';
|
|
16
|
+
/**
|
|
17
|
+
* One mounted node.
|
|
18
|
+
*
|
|
19
|
+
* The tree is retained between frames, which is the whole reason hooks can
|
|
20
|
+
* hold state and the renderer can diff rather than redraw: an instance whose
|
|
21
|
+
* node and props are unchanged is not re-rendered at all.
|
|
22
|
+
*/
|
|
23
|
+
export interface Instance {
|
|
24
|
+
id: string;
|
|
25
|
+
component: string;
|
|
26
|
+
kind: InstanceKind;
|
|
27
|
+
key: string | number | undefined;
|
|
28
|
+
node: ComponentNode;
|
|
29
|
+
props: Record<string, unknown>;
|
|
30
|
+
fn?: FunctionComponent;
|
|
31
|
+
host?: HostComponent;
|
|
32
|
+
definition?: ComponentDefinition;
|
|
33
|
+
parent: Instance | null;
|
|
34
|
+
children: Instance[];
|
|
35
|
+
hooks: HookSlot[];
|
|
36
|
+
hookIndex: number;
|
|
37
|
+
/** Store paths this instance's props read. Re-render when one changes. */
|
|
38
|
+
reads: Set<string>;
|
|
39
|
+
subscriptions: Disposable[];
|
|
40
|
+
dataContext?: BindingPath;
|
|
41
|
+
/** Context values provided by this instance, by context id. */
|
|
42
|
+
contexts?: Map<string, unknown>;
|
|
43
|
+
dirty: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* A descendant is dirty. Without this the render pass stops at the first
|
|
46
|
+
* clean ancestor and never reaches the component that actually changed -
|
|
47
|
+
* which is exactly what happens when a text field deep inside a mounted
|
|
48
|
+
* surface updates its own state.
|
|
49
|
+
*/
|
|
50
|
+
childDirty: boolean;
|
|
51
|
+
mounted: boolean;
|
|
52
|
+
/** Set when this subtree threw; a boundary renders its fallback instead. */
|
|
53
|
+
error?: unknown;
|
|
54
|
+
/** Why the last render ran. Diagnostics only. */
|
|
55
|
+
renderReason?: string;
|
|
56
|
+
/** Filled by the layout pass for host instances. */
|
|
57
|
+
box?: LayoutBox;
|
|
58
|
+
/** Last content rect observed by `useMeasure`, if this instance asked. */
|
|
59
|
+
measured?: Rect;
|
|
60
|
+
/** Content extent when it overflows that rect, for `useScrollExtent`. */
|
|
61
|
+
scrollExtent?: Size;
|
|
62
|
+
/** The child nodes produced by the last render, for a children-only pass. */
|
|
63
|
+
lastChildren: {
|
|
64
|
+
node: ComponentNode;
|
|
65
|
+
dataContext?: BindingPath;
|
|
66
|
+
}[];
|
|
67
|
+
/** Effects queued during this render, flushed after the frame commits. */
|
|
68
|
+
pendingEffects: (() => void)[];
|
|
69
|
+
runtime: Runtime;
|
|
70
|
+
}
|
|
71
|
+
export declare function createInstance(runtime: Runtime, node: ComponentNode, parent: Instance | null): Instance;
|
|
72
|
+
/** Flatten render output into nodes. Strings and numbers become text nodes. */
|
|
73
|
+
export declare function normalizeChildren(output: unknown): ComponentNode[];
|
|
74
|
+
/**
|
|
75
|
+
* Expand `{ template, path }` into one node per item, each with its own data
|
|
76
|
+
* context - which is what lets one templated node render a hundred rows.
|
|
77
|
+
*/
|
|
78
|
+
export declare function expandTemplate(runtime: Runtime, spec: {
|
|
79
|
+
template: ComponentNode;
|
|
80
|
+
path: BindingPath;
|
|
81
|
+
}, dataContext: BindingPath | undefined): {
|
|
82
|
+
nodes: ComponentNode[];
|
|
83
|
+
contexts: BindingPath[];
|
|
84
|
+
read: string;
|
|
85
|
+
};
|
|
86
|
+
export declare function resolveContextFor(instance: Instance): ResolveContext;
|
|
87
|
+
/** Look up a context value by walking the parent chain. */
|
|
88
|
+
export declare function readContext(instance: Instance, contextId: string): unknown;
|
|
89
|
+
export declare function emptyBox(): LayoutBox;
|
|
90
|
+
/** Depth-first walk, parents before children. */
|
|
91
|
+
export declare function walkInstances(root: Instance, visit: (i: Instance) => void): void;
|
|
92
|
+
export declare function unmountInstance(instance: Instance): void;
|
|
93
|
+
/** Re-resolve props and note which store paths this instance now depends on. */
|
|
94
|
+
export declare function updateProps(instance: Instance, node: ComponentNode): void;
|
|
95
|
+
export declare function findFunction(runtime: Runtime, node: ComponentNode): {
|
|
96
|
+
kind: InstanceKind;
|
|
97
|
+
fn?: FunctionComponent;
|
|
98
|
+
host?: HostComponent;
|
|
99
|
+
definition?: ComponentDefinition;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Mark an instance for re-render, and tell its ancestors a descendant changed
|
|
103
|
+
* so the render pass will walk down to it.
|
|
104
|
+
*/
|
|
105
|
+
export declare function markDirty(instance: Instance, reason: string): void;
|
|
106
|
+
//# sourceMappingURL=instance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../src/runtime/instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAgB,MAAM,oBAAoB,CAAC;AACzF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,OAAO,EAAoC,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAItF,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;AAExE;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MA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Aa,CAAC;IAAC,UAAU,CAAC,EAAE,mBAAmB,CAAA;CAAE,CAkBxG;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAQlE"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { isComponentNode } from '../types/graph.js';
|
|
2
|
+
import { ZERO_EDGES } from '../types/geometry.js';
|
|
3
|
+
import { isTemplateChildren, resolveProps } from './bindings.js';
|
|
4
|
+
import { nodeFunction } from '../jsx/factory.js';
|
|
5
|
+
import { joinPath } from '../util/paths.js';
|
|
6
|
+
let nextId = 1;
|
|
7
|
+
export function createInstance(runtime, node, parent) {
|
|
8
|
+
return {
|
|
9
|
+
id: node.id ?? `n${nextId++}`,
|
|
10
|
+
component: node.component,
|
|
11
|
+
kind: 'missing',
|
|
12
|
+
key: node.key,
|
|
13
|
+
node,
|
|
14
|
+
props: {},
|
|
15
|
+
parent,
|
|
16
|
+
children: [],
|
|
17
|
+
hooks: [],
|
|
18
|
+
hookIndex: 0,
|
|
19
|
+
reads: new Set(),
|
|
20
|
+
subscriptions: [],
|
|
21
|
+
dataContext: parent?.dataContext,
|
|
22
|
+
lastChildren: [],
|
|
23
|
+
dirty: true,
|
|
24
|
+
childDirty: false,
|
|
25
|
+
mounted: false,
|
|
26
|
+
pendingEffects: [],
|
|
27
|
+
runtime,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Flatten render output into nodes. Strings and numbers become text nodes. */
|
|
31
|
+
export function normalizeChildren(output) {
|
|
32
|
+
const out = [];
|
|
33
|
+
const walk = (value) => {
|
|
34
|
+
if (value === null || value === undefined || value === false || value === true)
|
|
35
|
+
return;
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
for (const item of value)
|
|
38
|
+
walk(item);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
42
|
+
const content = String(value);
|
|
43
|
+
if (content !== '')
|
|
44
|
+
out.push({ component: 'text', content });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (isComponentNode(value)) {
|
|
48
|
+
out.push(value);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// Anything else is a programmer error worth seeing rather than swallowing.
|
|
52
|
+
out.push({ component: 'text', content: String(value) });
|
|
53
|
+
};
|
|
54
|
+
walk(output);
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Expand `{ template, path }` into one node per item, each with its own data
|
|
59
|
+
* context - which is what lets one templated node render a hundred rows.
|
|
60
|
+
*/
|
|
61
|
+
export function expandTemplate(runtime, spec, dataContext) {
|
|
62
|
+
const base = spec.path.startsWith('$/')
|
|
63
|
+
? spec.path
|
|
64
|
+
: joinPath(dataContext ?? '$/', spec.path);
|
|
65
|
+
const items = runtime.store.get(base);
|
|
66
|
+
const list = Array.isArray(items) ? items : [];
|
|
67
|
+
const nodes = [];
|
|
68
|
+
const contexts = [];
|
|
69
|
+
for (let i = 0; i < list.length; i++) {
|
|
70
|
+
const item = list[i];
|
|
71
|
+
const key = item && typeof item === 'object' && 'id' in item ? String(item.id) : String(i);
|
|
72
|
+
nodes.push({ ...spec.template, key });
|
|
73
|
+
contexts.push(joinPath(base, String(i)));
|
|
74
|
+
}
|
|
75
|
+
return { nodes, contexts, read: base };
|
|
76
|
+
}
|
|
77
|
+
export function resolveContextFor(instance) {
|
|
78
|
+
return {
|
|
79
|
+
store: instance.runtime.store,
|
|
80
|
+
dataContext: instance.dataContext,
|
|
81
|
+
execute: (id, args) => instance.runtime.execute(id, args),
|
|
82
|
+
emit: (path, payload) => instance.runtime.emit(path, payload),
|
|
83
|
+
reads: new Set(),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** Look up a context value by walking the parent chain. */
|
|
87
|
+
export function readContext(instance, contextId) {
|
|
88
|
+
let cursor = instance;
|
|
89
|
+
while (cursor) {
|
|
90
|
+
const value = cursor.contexts?.get(contextId);
|
|
91
|
+
if (value !== undefined)
|
|
92
|
+
return value;
|
|
93
|
+
cursor = cursor.parent;
|
|
94
|
+
}
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
export function emptyBox() {
|
|
98
|
+
return {
|
|
99
|
+
style: {},
|
|
100
|
+
borderEdges: ZERO_EDGES,
|
|
101
|
+
children: [],
|
|
102
|
+
rect: { x: 0, y: 0, width: 0, height: 0 },
|
|
103
|
+
content: { x: 0, y: 0, width: 0, height: 0 },
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** Depth-first walk, parents before children. */
|
|
107
|
+
export function walkInstances(root, visit) {
|
|
108
|
+
visit(root);
|
|
109
|
+
for (const child of root.children)
|
|
110
|
+
walkInstances(child, visit);
|
|
111
|
+
}
|
|
112
|
+
export function unmountInstance(instance) {
|
|
113
|
+
for (const child of instance.children)
|
|
114
|
+
unmountInstance(child);
|
|
115
|
+
instance.children = [];
|
|
116
|
+
for (const hook of instance.hooks) {
|
|
117
|
+
if (typeof hook.cleanup === 'function') {
|
|
118
|
+
try {
|
|
119
|
+
hook.cleanup();
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
instance.runtime.onError(err, `cleanup in <${instance.component}>`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
instance.hooks = [];
|
|
127
|
+
for (const sub of instance.subscriptions)
|
|
128
|
+
sub.dispose();
|
|
129
|
+
instance.subscriptions = [];
|
|
130
|
+
instance.mounted = false;
|
|
131
|
+
}
|
|
132
|
+
/** Re-resolve props and note which store paths this instance now depends on. */
|
|
133
|
+
export function updateProps(instance, node) {
|
|
134
|
+
const ctx = resolveContextFor(instance);
|
|
135
|
+
const nextContext = node.dataContext;
|
|
136
|
+
if (typeof nextContext === 'string') {
|
|
137
|
+
instance.dataContext = nextContext;
|
|
138
|
+
ctx.dataContext = instance.dataContext;
|
|
139
|
+
}
|
|
140
|
+
instance.node = node;
|
|
141
|
+
instance.props = resolveProps(ctx, node);
|
|
142
|
+
// Children that are a templated list read their source path too.
|
|
143
|
+
const children = instance.props.children;
|
|
144
|
+
if (isTemplateChildren(children)) {
|
|
145
|
+
const expanded = expandTemplate(instance.runtime, children, instance.dataContext);
|
|
146
|
+
ctx.reads.add(expanded.read);
|
|
147
|
+
}
|
|
148
|
+
instance.reads = ctx.reads;
|
|
149
|
+
}
|
|
150
|
+
export function findFunction(runtime, node) {
|
|
151
|
+
const inline = nodeFunction(node);
|
|
152
|
+
if (inline)
|
|
153
|
+
return { kind: 'function', fn: inline };
|
|
154
|
+
const def = runtime.components.get(node.component);
|
|
155
|
+
if (!def)
|
|
156
|
+
return { kind: 'missing' };
|
|
157
|
+
switch (def.renderer.kind) {
|
|
158
|
+
case 'function':
|
|
159
|
+
return { kind: 'function', fn: def.renderer.render, definition: def };
|
|
160
|
+
case 'host':
|
|
161
|
+
return { kind: 'host', host: def.renderer.host, definition: def };
|
|
162
|
+
case 'template':
|
|
163
|
+
return { kind: 'template', definition: def };
|
|
164
|
+
case 'lazy':
|
|
165
|
+
// Not resolved yet; the registry resolves it and asks for another frame.
|
|
166
|
+
return { kind: 'missing', definition: def };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Mark an instance for re-render, and tell its ancestors a descendant changed
|
|
171
|
+
* so the render pass will walk down to it.
|
|
172
|
+
*/
|
|
173
|
+
export function markDirty(instance, reason) {
|
|
174
|
+
instance.dirty = true;
|
|
175
|
+
instance.renderReason = reason;
|
|
176
|
+
let cursor = instance.parent;
|
|
177
|
+
while (cursor && !cursor.childDirty) {
|
|
178
|
+
cursor.childDirty = true;
|
|
179
|
+
cursor = cursor.parent;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Rect } from '../types/geometry.js';
|
|
2
|
+
import type { ResolvedTheme } from '../types/theme.js';
|
|
3
|
+
import type { TerminalCapabilities } from '../types/capabilities.js';
|
|
4
|
+
import type { RenderContext } from '../types/render.js';
|
|
5
|
+
import type { LayoutBox } from '../render/layout.js';
|
|
6
|
+
import type { Instance } from './instance.js';
|
|
7
|
+
import type { Buffer } from '../render/buffer.js';
|
|
8
|
+
import { type PackedColor } from '../render/color.js';
|
|
9
|
+
import { type InteractionState } from './style.js';
|
|
10
|
+
export declare function createRenderContext(theme: ResolvedTheme, capabilities: TerminalCapabilities, state?: InteractionState): RenderContext;
|
|
11
|
+
export interface PaintEnv {
|
|
12
|
+
theme: ResolvedTheme;
|
|
13
|
+
capabilities: TerminalCapabilities;
|
|
14
|
+
/** Interaction state for an instance, resolved by the runtime. */
|
|
15
|
+
stateOf(instance: Instance): InteractionState;
|
|
16
|
+
}
|
|
17
|
+
/** Colour and attributes handed down to a box's children. */
|
|
18
|
+
interface Inherited {
|
|
19
|
+
fg: PackedColor;
|
|
20
|
+
bg: PackedColor;
|
|
21
|
+
attrs: number;
|
|
22
|
+
}
|
|
23
|
+
/** Boxes contributed by an instance. Function components contribute none. */
|
|
24
|
+
export declare function buildBoxes(instance: Instance, env: PaintEnv, inherited?: Inherited): LayoutBox[];
|
|
25
|
+
export declare function paintTree(buffer: Buffer, instance: Instance, env: PaintEnv, clip: Rect): void;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=paint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paint.d.ts","sourceRoot":"","sources":["../../src/runtime/paint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAGrE,OAAO,KAAK,EAA2B,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,M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