@promptctl/rich-js 0.24.1 → 0.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/core/anchor.d.ts +5 -0
- package/dist/core/anchor.js +11 -4
- package/dist/core/animation.d.ts +175 -10
- package/dist/core/animation.js +283 -15
- package/dist/core/ansi.js +2 -2
- package/dist/core/box.d.ts +7 -7
- package/dist/core/cells.d.ts +23 -13
- package/dist/core/cells.js +58 -48
- package/dist/core/clock.d.ts +2 -2
- package/dist/core/clock.js +6 -4
- package/dist/core/color.d.ts +27 -10
- package/dist/core/color.js +24 -33
- package/dist/core/console.d.ts +28 -17
- package/dist/core/console.js +44 -39
- package/dist/core/easing.d.ts +30 -0
- package/dist/core/easing.js +65 -20
- package/dist/core/emoji.d.ts +1 -1
- package/dist/core/emoji.js +1 -2
- package/dist/core/export-html.js +2 -1
- package/dist/core/export-lines.js +3 -3
- package/dist/core/highlighter.d.ts +9 -8
- package/dist/core/highlighter.js +3 -2
- package/dist/core/json.js +2 -2
- package/dist/core/markup.js +16 -12
- package/dist/core/measure.js +2 -2
- package/dist/core/memo.d.ts +11 -2
- package/dist/core/memo.js +16 -0
- package/dist/core/oklch.js +17 -6
- package/dist/core/osc8.d.ts +1 -1
- package/dist/core/osc8.js +4 -5
- package/dist/core/paint.d.ts +2 -1
- package/dist/core/paint.js +4 -3
- package/dist/core/pattern.d.ts +21 -0
- package/dist/core/pattern.js +21 -0
- package/dist/core/pretty.js +9 -10
- package/dist/core/protocol.d.ts +100 -39
- package/dist/core/protocol.js +167 -21
- package/dist/core/render.d.ts +15 -2
- package/dist/core/render.js +25 -5
- package/dist/core/segment.d.ts +13 -5
- package/dist/core/segment.js +23 -9
- package/dist/core/spinnerData.d.ts +1 -1
- package/dist/core/state.d.ts +53 -0
- package/dist/core/state.js +82 -0
- package/dist/core/strip.d.ts +98 -29
- package/dist/core/strip.js +211 -150
- package/dist/core/style.d.ts +47 -14
- package/dist/core/style.js +57 -28
- package/dist/core/text.d.ts +5 -8
- package/dist/core/text.js +116 -124
- package/dist/core/timeline.d.ts +30 -5
- package/dist/core/timeline.js +43 -7
- package/dist/core/tween.d.ts +1 -1
- package/dist/core/tween.js +5 -3
- package/dist/core/view.d.ts +92 -0
- package/dist/core/view.js +83 -0
- package/dist/host/app.d.ts +49 -21
- package/dist/host/app.js +71 -37
- package/dist/host/input.js +3 -4
- package/dist/index.d.ts +24 -12
- package/dist/index.js +9 -4
- package/dist/node/traceback.js +4 -3
- package/dist/renderables/align.d.ts +2 -3
- package/dist/renderables/align.js +0 -3
- package/dist/renderables/change.d.ts +42 -0
- package/dist/renderables/change.js +112 -0
- package/dist/renderables/columns.d.ts +3 -4
- package/dist/renderables/columns.js +2 -7
- package/dist/renderables/constrain.d.ts +2 -3
- package/dist/renderables/constrain.js +0 -3
- package/dist/renderables/effect.d.ts +158 -63
- package/dist/renderables/effect.js +378 -155
- package/dist/renderables/effects.d.ts +122 -11
- package/dist/renderables/effects.js +238 -94
- package/dist/renderables/embed.d.ts +1 -1
- package/dist/renderables/embed.js +16 -8
- package/dist/renderables/flexStrip.d.ts +2 -3
- package/dist/renderables/flexStrip.js +0 -4
- package/dist/renderables/frames.d.ts +35 -54
- package/dist/renderables/frames.js +43 -58
- package/dist/renderables/glyph-effect.d.ts +158 -0
- package/dist/renderables/glyph-effect.js +237 -0
- package/dist/renderables/glyph-effects.d.ts +147 -0
- package/dist/renderables/glyph-effects.js +283 -0
- package/dist/renderables/group.d.ts +3 -4
- package/dist/renderables/group.js +0 -3
- package/dist/renderables/layout.d.ts +12 -12
- package/dist/renderables/layout.js +40 -46
- package/dist/renderables/lifecycle.d.ts +77 -0
- package/dist/renderables/lifecycle.js +132 -0
- package/dist/renderables/list-view.d.ts +4 -5
- package/dist/renderables/list-view.js +9 -13
- package/dist/renderables/live.d.ts +36 -21
- package/dist/renderables/live.js +88 -41
- package/dist/renderables/markdown-parse.d.ts +4 -4
- package/dist/renderables/markdown-parse.js +52 -46
- package/dist/renderables/markdown-url.js +11 -11
- package/dist/renderables/padding.d.ts +4 -5
- package/dist/renderables/padding.js +0 -3
- package/dist/renderables/panel.d.ts +14 -16
- package/dist/renderables/panel.js +6 -14
- package/dist/renderables/progress.d.ts +83 -34
- package/dist/renderables/progress.js +182 -95
- package/dist/renderables/progressBar.d.ts +22 -12
- package/dist/renderables/progressBar.js +32 -9
- package/dist/renderables/prompt.js +3 -2
- package/dist/renderables/python-space.js +2 -1
- package/dist/renderables/scroll.d.ts +50 -0
- package/dist/renderables/scroll.js +106 -0
- package/dist/renderables/spinner.d.ts +35 -14
- package/dist/renderables/spinner.js +65 -25
- package/dist/renderables/status.js +1 -1
- package/dist/renderables/syntax.d.ts +10 -9
- package/dist/renderables/syntax.js +3 -2
- package/dist/renderables/table.d.ts +34 -40
- package/dist/renderables/table.js +41 -63
- package/dist/renderables/traceback.d.ts +2 -2
- package/dist/renderables/traceback.js +6 -5
- package/dist/renderables/tree.d.ts +27 -25
- package/dist/renderables/tree.js +104 -58
- package/dist/renderables/viewport.d.ts +75 -44
- package/dist/renderables/viewport.js +145 -82
- package/dist/template-bindings/animation-funcs.d.ts +78 -9
- package/dist/template-bindings/animation-funcs.js +132 -14
- package/dist/template-bindings/index.d.ts +5 -5
- package/dist/template-bindings/index.js +5 -5
- package/dist/themes/ramp.d.ts +46 -3
- package/dist/themes/ramp.js +61 -4
- package/dist/themes/registry.js +5 -7
- package/dist/widgets/button.js +3 -2
- package/dist/widgets/checkbox.js +4 -3
- package/dist/widgets/dropdown.d.ts +3 -1
- package/dist/widgets/dropdown.js +20 -15
- package/dist/widgets/event-router.js +4 -2
- package/dist/widgets/focus-manager.d.ts +2 -0
- package/dist/widgets/focus-manager.js +6 -4
- package/dist/widgets/hit.d.ts +6 -0
- package/dist/widgets/hit.js +8 -1
- package/dist/widgets/observable.d.ts +23 -0
- package/dist/widgets/observable.js +43 -0
- package/dist/widgets/slider.d.ts +1 -1
- package/dist/widgets/slider.js +12 -3
- package/dist/widgets/static-item.d.ts +2 -3
- package/dist/widgets/static-item.js +0 -3
- package/dist/widgets/text-input.d.ts +28 -32
- package/dist/widgets/text-input.js +360 -346
- package/dist/widgets/themed-widget.js +2 -1
- package/dist/widgets/toggle.js +4 -3
- package/dist/widgets/types.d.ts +10 -4
- package/dist/widgets/types.js +8 -2
- package/dist/widgets/widget-app.d.ts +14 -4
- package/dist/widgets/widget-app.js +36 -7
- package/dist/widgets/widget-base.d.ts +2 -2
- package/dist/widgets/widget-base.js +29 -18
- package/package.json +8 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { cellLen, setCellSize, splitText, chopCells, cellFit, graphemes, asCellCol, asCodePoint, } from "./core/cells.js";
|
|
2
2
|
export type { CellCol, CodeUnit, CodePoint } from "./core/cells.js";
|
|
3
3
|
export { ColorRgba, ColorTable, ColorDepth, ColorSpec, ColorParseError, TerminalTheme, parseRgbHex, parseRgbaHex, parseHexColor, blendRgb, resolveColorSystem, detectColorSystem, resolveDestination, STANDARD_TABLE, EIGHT_BIT_TABLE, WINDOWS_TABLE, ANSI_COLOR_NAMES, } from "./core/color.js";
|
|
4
|
-
export type { ColorSystemName, DetectColorOptions, Destination } from "./core/color.js";
|
|
4
|
+
export type { ColorSystemName, DetectColorOptions, Destination, DestinationOptions } from "./core/color.js";
|
|
5
5
|
export { Oklch, IDENTITY, INVERT_LIGHTNESS, isIdentityKey, } from "./core/oklch.js";
|
|
6
6
|
export type { ThemeKey, OklchWeights } from "./core/oklch.js";
|
|
7
7
|
export { Palette } from "./themes/palette.js";
|
|
@@ -14,16 +14,18 @@ export type { ThemeName } from "./themes/registry.js";
|
|
|
14
14
|
export { transposePalette, themeKeyForRoot, isAnchored, ANCHORED_ROOTS, } from "./themes/transpose.js";
|
|
15
15
|
export { lighten, darken, relativeLuminance, contrastRatio, contrastFor, ensureContrast, ensureDrawn, drawnColour, } from "./themes/colorMath.js";
|
|
16
16
|
export { ColorRamp } from "./themes/ramp.js";
|
|
17
|
-
export type { ColorStop } from "./themes/ramp.js";
|
|
17
|
+
export type { ColorStop, RampMotion } from "./themes/ramp.js";
|
|
18
18
|
export { EASES, Phase, beat, cubicBezier, parseEase, spring, steps } from "./core/easing.js";
|
|
19
19
|
export type { Beat, Ease, SpringOptions, StepPosition, Timing } from "./core/easing.js";
|
|
20
20
|
export { Animation } from "./core/animation.js";
|
|
21
|
+
export type { Timed } from "./core/animation.js";
|
|
21
22
|
export { tween } from "./core/tween.js";
|
|
22
23
|
export { Timeline } from "./core/timeline.js";
|
|
24
|
+
export type { View } from "./core/view.js";
|
|
23
25
|
export { frameRate, systemClock } from "./core/clock.js";
|
|
24
26
|
export type { Clock, FrameRate } from "./core/clock.js";
|
|
25
27
|
export { Style, StyleSyntaxError, StyleStack, Theme, NULL_STYLE, DEFAULT_STYLES, } from "./core/style.js";
|
|
26
|
-
export type { StyleOptions, TextStyle, LayeredStyle } from "./core/style.js";
|
|
28
|
+
export type { Attributes, Hold, StyleOptions, TextStyle, LayeredStyle } from "./core/style.js";
|
|
27
29
|
export { Segment, ControlType, } from "./core/segment.js";
|
|
28
30
|
export type { ControlCode } from "./core/segment.js";
|
|
29
31
|
export type { Anchor } from "./core/anchor.js";
|
|
@@ -31,7 +33,7 @@ export { Box } from "./core/box.js";
|
|
|
31
33
|
export type { EdgeChars, ContentChars, RowLevel, SubstituteOptions } from "./core/box.js";
|
|
32
34
|
export { ASCII, ASCII2, ASCII_DOUBLE_HEAD, SQUARE, SQUARE_DOUBLE_HEAD, MINIMAL, MINIMAL_HEAVY_HEAD, MINIMAL_DOUBLE_HEAD, SIMPLE, SIMPLE_HEAD, SIMPLE_HEAVY, HORIZONTALS, ROUNDED, HEAVY, HEAVY_EDGE, HEAVY_HEAD, DOUBLE, DOUBLE_EDGE, MARKDOWN, } from "./core/box.js";
|
|
33
35
|
export { render, isRenderable, isMeasurable, withCellWidth, withBoundedWidth, insetHeight, stackedHeight, regionRows, fitHeight, getStyle, } from "./core/protocol.js";
|
|
34
|
-
export type { RenderOptions, OverflowMethod, Height, Renderable, Measurable,
|
|
36
|
+
export type { RenderOptions, OverflowMethod, Height, Renderable, Measurable, Presence, StyleErrorHandler, FrameHost, } from "./core/protocol.js";
|
|
35
37
|
export type { Unsubscribe } from "./core/subscription.js";
|
|
36
38
|
export { Measurement, measureRenderables } from "./core/measure.js";
|
|
37
39
|
export { Span, RichText } from "./core/text.js";
|
|
@@ -58,10 +60,20 @@ export { Console } from "./core/console.js";
|
|
|
58
60
|
export type { ConsoleOptions, ConsoleSink, ConsoleStream, ConsoleEnvironment, LiveRegion, PrintOptions, } from "./core/console.js";
|
|
59
61
|
export type { Env } from "./core/env.js";
|
|
60
62
|
export { Constrain } from "./renderables/constrain.js";
|
|
61
|
-
export { Effected, confined, drawnOf
|
|
62
|
-
export type { CellColors, Drawn, Effect, EffectCell, EffectedOptions, EffectFrame, Pair, Placed } from "./renderables/effect.js";
|
|
63
|
-
export { EFFECT_CATALOGUE, EFFECT_CURVES, EFFECT_LIGHTS, dissolveOut, fadeIn, onColors, pulse, shimmer, sparkle, steppedInk, wheel, } from "./renderables/effects.js";
|
|
64
|
-
export type { ColorStep, Curve, EffectTarget, Field, Loop, LoopName, Touch, Transition, TransitionName } from "./renderables/effects.js";
|
|
63
|
+
export { Effected, confined, drawnOf } from "./renderables/effect.js";
|
|
64
|
+
export type { CellAttributes, CellColors, CellLook, Drawn, Effect, EffectCell, EffectedOptions, EffectFrame, Pair, Placed } from "./renderables/effect.js";
|
|
65
|
+
export { ATTRIBUTE_DEFAULTS, EFFECT_CATALOGUE, EFFECT_CURVES, EFFECT_LIGHTS, blink, dissolveOut, fadeIn, gradient, onBeat, onColors, pulse, shimmer, sparkle, steppedInk, wheel, } from "./renderables/effects.js";
|
|
66
|
+
export type { AttributeLoopName, Blink, ColorStep, Curve, EffectTarget, Field, Loop, LoopName, Touch, Transition, TransitionName } from "./renderables/effects.js";
|
|
67
|
+
export { crossfade, wipe } from "./renderables/change.js";
|
|
68
|
+
export type { Between, Change } from "./renderables/change.js";
|
|
69
|
+
export { lifecycle, throughColors, throughGlyphs } from "./renderables/lifecycle.js";
|
|
70
|
+
export type { Lifecycle, LifecycleOptions, Veil } from "./renderables/lifecycle.js";
|
|
71
|
+
export { scroll } from "./renderables/scroll.js";
|
|
72
|
+
export type { ScrollOptions } from "./renderables/scroll.js";
|
|
73
|
+
export { GlyphEffected } from "./renderables/glyph-effect.js";
|
|
74
|
+
export type { DrawnGlyphs, GlyphCell, GlyphEffect, GlyphEffectedOptions, GlyphFrame } from "./renderables/glyph-effect.js";
|
|
75
|
+
export { GLYPH_DEFAULTS, GLYPH_EFFECT_CATALOGUE, backspace, caseWave, particles, scramble, scrambleOut, typewriter } from "./renderables/glyph-effects.js";
|
|
76
|
+
export type { CaseWave, GlyphLoopName, GlyphTransition, GlyphTransitionName, Particles } from "./renderables/glyph-effects.js";
|
|
65
77
|
export { Align } from "./renderables/align.js";
|
|
66
78
|
export type { Alignment } from "./core/place.js";
|
|
67
79
|
export { Padding } from "./renderables/padding.js";
|
|
@@ -80,9 +92,9 @@ export { ProgressBar } from "./renderables/progressBar.js";
|
|
|
80
92
|
export type { ProgressBarOptions } from "./renderables/progressBar.js";
|
|
81
93
|
export { Spinner } from "./renderables/spinner.js";
|
|
82
94
|
export type { SpinnerOptions } from "./renderables/spinner.js";
|
|
83
|
-
export { FrameSequence
|
|
84
|
-
export type { Frame
|
|
85
|
-
export { Table, Column } from "./renderables/table.js";
|
|
95
|
+
export { FrameSequence } from "./renderables/frames.js";
|
|
96
|
+
export type { Frame } from "./renderables/frames.js";
|
|
97
|
+
export { Table, type Column } from "./renderables/table.js";
|
|
86
98
|
export type { TableOptions, ColumnOptions } from "./renderables/table.js";
|
|
87
99
|
export { Tree } from "./renderables/tree.js";
|
|
88
100
|
export type { TreeOptions } from "./renderables/tree.js";
|
|
@@ -91,7 +103,7 @@ export type { ColumnsOptions } from "./renderables/columns.js";
|
|
|
91
103
|
export { FlexStrip } from "./renderables/flexStrip.js";
|
|
92
104
|
export type { FlexStripOptions, FlexAlign } from "./renderables/flexStrip.js";
|
|
93
105
|
export { Live } from "./renderables/live.js";
|
|
94
|
-
export type { LiveOptions
|
|
106
|
+
export type { LiveOptions } from "./renderables/live.js";
|
|
95
107
|
export { Status } from "./renderables/status.js";
|
|
96
108
|
export type { StatusOptions } from "./renderables/status.js";
|
|
97
109
|
export { Progress, TextColumn, BarColumn, TaskProgressColumn, TimeRemainingColumn, TimeElapsedColumn, SpinnerColumn, MofNCompleteColumn, track, } from "./renderables/progress.js";
|
package/dist/index.js
CHANGED
|
@@ -78,8 +78,13 @@ export { SPINNERS, DEFAULT_SPINNER } from "./core/spinnerData.js";
|
|
|
78
78
|
export { Console } from "./core/console.js";
|
|
79
79
|
// Renderables
|
|
80
80
|
export { Constrain } from "./renderables/constrain.js";
|
|
81
|
-
export { Effected, confined, drawnOf
|
|
82
|
-
export { EFFECT_CATALOGUE, EFFECT_CURVES, EFFECT_LIGHTS, dissolveOut, fadeIn, onColors, pulse, shimmer, sparkle, steppedInk, wheel, } from "./renderables/effects.js";
|
|
81
|
+
export { Effected, confined, drawnOf } from "./renderables/effect.js";
|
|
82
|
+
export { ATTRIBUTE_DEFAULTS, EFFECT_CATALOGUE, EFFECT_CURVES, EFFECT_LIGHTS, blink, dissolveOut, fadeIn, gradient, onBeat, onColors, pulse, shimmer, sparkle, steppedInk, wheel, } from "./renderables/effects.js";
|
|
83
|
+
export { crossfade, wipe } from "./renderables/change.js";
|
|
84
|
+
export { lifecycle, throughColors, throughGlyphs } from "./renderables/lifecycle.js";
|
|
85
|
+
export { scroll } from "./renderables/scroll.js";
|
|
86
|
+
export { GlyphEffected } from "./renderables/glyph-effect.js";
|
|
87
|
+
export { GLYPH_DEFAULTS, GLYPH_EFFECT_CATALOGUE, backspace, caseWave, particles, scramble, scrambleOut, typewriter } from "./renderables/glyph-effects.js";
|
|
83
88
|
export { Align } from "./renderables/align.js";
|
|
84
89
|
export { Padding } from "./renderables/padding.js";
|
|
85
90
|
export { Viewport, ViewportPerKey, SCROLLBAR } from "./renderables/viewport.js";
|
|
@@ -90,8 +95,8 @@ export { Panel } from "./renderables/panel.js";
|
|
|
90
95
|
export { Group } from "./renderables/group.js";
|
|
91
96
|
export { ProgressBar } from "./renderables/progressBar.js";
|
|
92
97
|
export { Spinner } from "./renderables/spinner.js";
|
|
93
|
-
export { FrameSequence
|
|
94
|
-
export { Table
|
|
98
|
+
export { FrameSequence } from "./renderables/frames.js";
|
|
99
|
+
export { Table } from "./renderables/table.js";
|
|
95
100
|
export { Tree } from "./renderables/tree.js";
|
|
96
101
|
export { Columns } from "./renderables/columns.js";
|
|
97
102
|
export { FlexStrip } from "./renderables/flexStrip.js";
|
package/dist/node/traceback.js
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
*/
|
|
30
30
|
import { Console } from "../core/console.js";
|
|
31
31
|
import { Traceback } from "../renderables/traceback.js";
|
|
32
|
+
import { State } from "../core/state.js";
|
|
32
33
|
/**
|
|
33
34
|
* The handler currently registered, or a no-op standing in for "none yet".
|
|
34
35
|
*
|
|
@@ -41,7 +42,7 @@ import { Traceback } from "../renderables/traceback.js";
|
|
|
41
42
|
* unregistered listener does nothing, so the first call needs no null check
|
|
42
43
|
* and no "have we installed yet" branch. There is no absent case to handle.
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
+
const installed = new State(() => { });
|
|
45
46
|
/**
|
|
46
47
|
* An unhandled rejection, raised as the uncaught exception it becomes when
|
|
47
48
|
* nobody listens — its reason unwrapped, which node's own conversion would
|
|
@@ -90,9 +91,9 @@ export function installTraceback(options) {
|
|
|
90
91
|
process.exit(1);
|
|
91
92
|
});
|
|
92
93
|
};
|
|
93
|
-
process.off("uncaughtException", installed);
|
|
94
|
+
process.off("uncaughtException", installed.get());
|
|
94
95
|
process.off("unhandledRejection", escalate);
|
|
95
96
|
process.on("uncaughtException", report);
|
|
96
97
|
process.on("unhandledRejection", escalate);
|
|
97
|
-
installed
|
|
98
|
+
installed.set(report);
|
|
98
99
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Align — wraps a renderable and places its output horizontally, as one block.
|
|
3
3
|
*/
|
|
4
4
|
import { Segment } from "../core/segment.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { Renderable, Measurable, RenderOptions } from "../core/protocol.js";
|
|
6
6
|
import { type Alignment } from "../core/place.js";
|
|
7
|
-
export declare class Align implements Renderable, Measurable
|
|
7
|
+
export declare class Align implements Renderable, Measurable {
|
|
8
8
|
readonly renderable: Renderable;
|
|
9
9
|
readonly align: Alignment;
|
|
10
10
|
constructor(renderable: Renderable, align?: Alignment);
|
|
@@ -13,5 +13,4 @@ export declare class Align implements Renderable, Measurable, Composite {
|
|
|
13
13
|
minimum: number;
|
|
14
14
|
maximum: number;
|
|
15
15
|
};
|
|
16
|
-
contents(): Iterable<Renderable>;
|
|
17
16
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A change from one renderable to another in the same slot — a status that
|
|
3
|
+
* goes from "building" to "done", a number that becomes a different number —
|
|
4
|
+
* drawn as a crossfade or a wipe instead of a cut.
|
|
5
|
+
*
|
|
6
|
+
* Both are one shape [LAW:one-type-per-behavior]: how far each cell is through
|
|
7
|
+
* the change at `t`, from 0, the old renderable as drawn, to 1, the new one as
|
|
8
|
+
* drawn. A cell under a half shows the old one and from a half the new one,
|
|
9
|
+
* veiled toward the terminal's ground by how near the half it is (`veiled`,
|
|
10
|
+
* `./effects.ts`), so every cell passes through the ground and none jumps from
|
|
11
|
+
* one glyph to another. A crossfade has every cell at one place in the change;
|
|
12
|
+
* a wipe sends a front across the element's columns with the new renderable
|
|
13
|
+
* behind it.
|
|
14
|
+
*
|
|
15
|
+
* The change is drawn at the new renderable's size from its first frame: the
|
|
16
|
+
* old one is cut or padded to the new one's rows, so what sits beside the
|
|
17
|
+
* element moves once, at the cut, and never while the change runs. Once done
|
|
18
|
+
* it is the new renderable itself, byte for byte, and never changes again.
|
|
19
|
+
*
|
|
20
|
+
* [LAW:no-ambient-temporal-coupling] Pure in `t`: nothing is kept from one
|
|
21
|
+
* frame to the next, so the same `t` draws the same bytes at any frame rate.
|
|
22
|
+
*/
|
|
23
|
+
import { Animation } from "../core/animation.js";
|
|
24
|
+
import type { TerminalTheme } from "../core/color.js";
|
|
25
|
+
import type { Renderable } from "../core/protocol.js";
|
|
26
|
+
import { type Curve, type Transition } from "./effects.js";
|
|
27
|
+
/** What a change is between: the renderable drawn until now, the one drawn from now on, and the terminal whose ground the change passes through. */
|
|
28
|
+
export interface Between {
|
|
29
|
+
readonly from: Renderable;
|
|
30
|
+
readonly to: Renderable;
|
|
31
|
+
readonly theme: TerminalTheme;
|
|
32
|
+
}
|
|
33
|
+
/** A change from one renderable to another: what it draws at each moment, from `t = 0` on its own clock. */
|
|
34
|
+
export type Change = (between: Between) => Animation<Renderable>;
|
|
35
|
+
/** A crossfade: the old renderable fades to the terminal's ground and the new one rises from it, every cell together, over `curve`. */
|
|
36
|
+
export declare function crossfade(curve: Curve): Transition<Change>;
|
|
37
|
+
/**
|
|
38
|
+
* A wipe: a front crossing the element's columns from left to right over
|
|
39
|
+
* `curve`, the new renderable behind it, the old one ahead of it, and the
|
|
40
|
+
* cells within `edge` columns of it passing through the terminal's ground.
|
|
41
|
+
*/
|
|
42
|
+
export declare function wipe(curve: Curve, edge?: number): Transition<Change>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A change from one renderable to another in the same slot — a status that
|
|
3
|
+
* goes from "building" to "done", a number that becomes a different number —
|
|
4
|
+
* drawn as a crossfade or a wipe instead of a cut.
|
|
5
|
+
*
|
|
6
|
+
* Both are one shape [LAW:one-type-per-behavior]: how far each cell is through
|
|
7
|
+
* the change at `t`, from 0, the old renderable as drawn, to 1, the new one as
|
|
8
|
+
* drawn. A cell under a half shows the old one and from a half the new one,
|
|
9
|
+
* veiled toward the terminal's ground by how near the half it is (`veiled`,
|
|
10
|
+
* `./effects.ts`), so every cell passes through the ground and none jumps from
|
|
11
|
+
* one glyph to another. A crossfade has every cell at one place in the change;
|
|
12
|
+
* a wipe sends a front across the element's columns with the new renderable
|
|
13
|
+
* behind it.
|
|
14
|
+
*
|
|
15
|
+
* The change is drawn at the new renderable's size from its first frame: the
|
|
16
|
+
* old one is cut or padded to the new one's rows, so what sits beside the
|
|
17
|
+
* element moves once, at the cut, and never while the change runs. Once done
|
|
18
|
+
* it is the new renderable itself, byte for byte, and never changes again.
|
|
19
|
+
*
|
|
20
|
+
* [LAW:no-ambient-temporal-coupling] Pure in `t`: nothing is kept from one
|
|
21
|
+
* frame to the next, so the same `t` draws the same bytes at any frame rate.
|
|
22
|
+
*/
|
|
23
|
+
import { Animation } from "../core/animation.js";
|
|
24
|
+
import { Measurement } from "../core/measure.js";
|
|
25
|
+
import { render } from "../core/protocol.js";
|
|
26
|
+
import { Segment } from "../core/segment.js";
|
|
27
|
+
import { Recolored } from "./effect.js";
|
|
28
|
+
import { requireCurve, transition, veiled } from "./effects.js";
|
|
29
|
+
const clamp01 = (x) => Math.min(1, Math.max(0, x));
|
|
30
|
+
/** How much of a cell `p` of the way through a change shows: all of it at either end, none at the half, where the old gives way to the new. */
|
|
31
|
+
const shows = (p) => Math.abs(2 * p - 1);
|
|
32
|
+
/** The change over `curve`, each cell as far through it as `progress` says. */
|
|
33
|
+
function change(curve, progress) {
|
|
34
|
+
requireCurve(curve);
|
|
35
|
+
return transition(curve.seconds, ({ from, to, theme }) => Animation.sequence(Animation.continuous((t) => new ChangeFrame(from, to, theme, progress, t, curve.swing)), curve.seconds, Animation.constant(to)));
|
|
36
|
+
}
|
|
37
|
+
/** A crossfade: the old renderable fades to the terminal's ground and the new one rises from it, every cell together, over `curve`. */
|
|
38
|
+
export function crossfade(curve) {
|
|
39
|
+
return change(curve, (t) => {
|
|
40
|
+
const p = clamp01(curve.ease(clamp01(t / curve.seconds)));
|
|
41
|
+
return () => p;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** How many columns a wipe's front is soft over at its default: each cell passes through the ground as the front crosses it. */
|
|
45
|
+
const WIPE_EDGE = 6;
|
|
46
|
+
/**
|
|
47
|
+
* A wipe: a front crossing the element's columns from left to right over
|
|
48
|
+
* `curve`, the new renderable behind it, the old one ahead of it, and the
|
|
49
|
+
* cells within `edge` columns of it passing through the terminal's ground.
|
|
50
|
+
*/
|
|
51
|
+
export function wipe(curve, edge = WIPE_EDGE) {
|
|
52
|
+
if (!(Number.isFinite(edge) && edge > 0))
|
|
53
|
+
throw new RangeError(`wipe: edge must be a positive number of columns, got ${edge}`);
|
|
54
|
+
return change(curve, (t, width) => {
|
|
55
|
+
// The front starts `edge` columns before the first cell turns and ends with the last one turned.
|
|
56
|
+
const front = curve.ease(clamp01(t / curve.seconds)) * (width + edge);
|
|
57
|
+
return (_row, col) => clamp01((front - col) / edge);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** One frame of a change at `t`: `from` and `to` spliced cell by cell, each veiled by how near the half its cell is. */
|
|
61
|
+
class ChangeFrame {
|
|
62
|
+
from;
|
|
63
|
+
to;
|
|
64
|
+
theme;
|
|
65
|
+
progress;
|
|
66
|
+
t;
|
|
67
|
+
swing;
|
|
68
|
+
constructor(from, to, theme, progress, t, swing) {
|
|
69
|
+
this.from = from;
|
|
70
|
+
this.to = to;
|
|
71
|
+
this.theme = theme;
|
|
72
|
+
this.progress = progress;
|
|
73
|
+
this.t = t;
|
|
74
|
+
this.swing = swing;
|
|
75
|
+
}
|
|
76
|
+
render(options) {
|
|
77
|
+
const before = Segment.splitLines(render(this.from, options));
|
|
78
|
+
const drawn = [...render(this.to, options)];
|
|
79
|
+
const after = Segment.splitLines(drawn);
|
|
80
|
+
// [LAW:one-source-of-truth] The new renderable's rows are the shape of every frame, its last row ending as it ends.
|
|
81
|
+
const lengths = after.map((line) => Segment.getLineLength(line));
|
|
82
|
+
const ended = drawn.filter((segment) => !segment.isControl).at(-1)?.text.endsWith("\n") ?? false;
|
|
83
|
+
const width = Math.max(0, ...lengths);
|
|
84
|
+
const at = this.progress(this.t, width);
|
|
85
|
+
const rows = after.flatMap((line, row) => [
|
|
86
|
+
...splice(Segment.adjustLineLength(before[row] ?? [], lengths[row]), line, (col) => at(row, col) >= 0.5),
|
|
87
|
+
...(row < after.length - 1 || ended ? [Segment.line()] : []),
|
|
88
|
+
]);
|
|
89
|
+
// The frame says nothing of when it changes: the change's own animation says it moves every frame.
|
|
90
|
+
const veil = veiled(() => (cell) => shows(at(cell.row, cell.col)), this.swing);
|
|
91
|
+
return render(new Recolored({ render: () => rows }, veil, { t: this.t, key: "change", theme: this.theme }), options);
|
|
92
|
+
}
|
|
93
|
+
measure(options) {
|
|
94
|
+
return Measurement.get(options, this.to);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* One row from two of the same width, each column from `after` where `isAfter`
|
|
99
|
+
* says and from `before` elsewhere. Cut at every column the side changes, so
|
|
100
|
+
* a wide glyph a cut falls in is blanked (`Segment.divide`), never halved.
|
|
101
|
+
*/
|
|
102
|
+
function splice(before, after, isAfter) {
|
|
103
|
+
const width = Segment.getLineLength(after);
|
|
104
|
+
const cuts = [];
|
|
105
|
+
for (let col = 1; col < width; col++)
|
|
106
|
+
if (isAfter(col) !== isAfter(col - 1))
|
|
107
|
+
cuts.push(col);
|
|
108
|
+
const from = Segment.divide(before, cuts);
|
|
109
|
+
const to = Segment.divide(after, cuts);
|
|
110
|
+
const starts = [0, ...cuts];
|
|
111
|
+
return starts.flatMap((start, i) => (isAfter(start) ? (to[i] ?? []) : (from[i] ?? [])));
|
|
112
|
+
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import type { Segment } from "../core/segment.js";
|
|
12
12
|
import type { PaddingDimensions } from "./padding.js";
|
|
13
|
-
import type {
|
|
13
|
+
import type { Renderable, Measurable, RenderOptions } from "../core/protocol.js";
|
|
14
14
|
export interface ColumnsOptions {
|
|
15
15
|
expand?: boolean;
|
|
16
16
|
equal?: boolean;
|
|
@@ -18,8 +18,8 @@ export interface ColumnsOptions {
|
|
|
18
18
|
padding?: PaddingDimensions;
|
|
19
19
|
columnFirst?: boolean;
|
|
20
20
|
}
|
|
21
|
-
export declare class Columns implements Renderable, Measurable
|
|
22
|
-
renderables: (Renderable & Partial<Measurable>)[];
|
|
21
|
+
export declare class Columns implements Renderable, Measurable {
|
|
22
|
+
readonly renderables: readonly (Renderable & Partial<Measurable>)[];
|
|
23
23
|
readonly expand: boolean;
|
|
24
24
|
readonly equal: boolean;
|
|
25
25
|
readonly colWidth: number | undefined;
|
|
@@ -27,7 +27,6 @@ export declare class Columns implements Renderable, Measurable, Composite {
|
|
|
27
27
|
private readonly padding;
|
|
28
28
|
constructor(items?: Iterable<unknown>, options?: ColumnsOptions);
|
|
29
29
|
render(rawOptions: RenderOptions): Iterable<Segment>;
|
|
30
|
-
contents(): Iterable<Renderable>;
|
|
31
30
|
measure(rawOptions: RenderOptions): {
|
|
32
31
|
minimum: number;
|
|
33
32
|
maximum: number;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { Measurement } from "../core/measure.js";
|
|
12
12
|
import { normalizePadding } from "./padding.js";
|
|
13
|
-
import { render, withBoundedWidth, withCellWidth } from "../core/protocol.js";
|
|
13
|
+
import { measure, render, withBoundedWidth, withCellWidth } from "../core/protocol.js";
|
|
14
14
|
import { cellCount } from "../core/cells.js";
|
|
15
15
|
import { EmbeddedText, embed } from "./embed.js";
|
|
16
16
|
import { Constrain } from "./constrain.js";
|
|
@@ -70,11 +70,6 @@ export class Columns {
|
|
|
70
70
|
const options = withBoundedWidth(rawOptions, this);
|
|
71
71
|
yield* render(this._grid(options), options);
|
|
72
72
|
}
|
|
73
|
-
// The items, in the order they were given. Laid out column-first, the grid
|
|
74
|
-
// draws them in an order its width decides, and handed no column it has none.
|
|
75
|
-
contents() {
|
|
76
|
-
return this.renderables;
|
|
77
|
-
}
|
|
78
73
|
measure(rawOptions) {
|
|
79
74
|
// The maximum is the grid's, which reports its width before `expand`: a
|
|
80
75
|
// stretch is what a Columns does with a width it is given, not a width it
|
|
@@ -89,7 +84,7 @@ export class Columns {
|
|
|
89
84
|
const parsed = withCellWidth(rawOptions);
|
|
90
85
|
if (this.renderables.length === 0)
|
|
91
86
|
return { minimum: 0, maximum: 0 };
|
|
92
|
-
const { maximum } = this._grid(parsed)
|
|
87
|
+
const { maximum } = measure(this._grid(parsed), parsed);
|
|
93
88
|
return { minimum: Math.min(1, maximum), maximum };
|
|
94
89
|
}
|
|
95
90
|
/**
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
* Constrain — wraps a renderable and constrains its maximum width.
|
|
3
3
|
*/
|
|
4
4
|
import { Segment } from "../core/segment.js";
|
|
5
|
-
import type {
|
|
6
|
-
export declare class Constrain implements Renderable, Measurable
|
|
5
|
+
import type { Renderable, Measurable, RenderOptions } from "../core/protocol.js";
|
|
6
|
+
export declare class Constrain implements Renderable, Measurable {
|
|
7
7
|
readonly renderable: Renderable;
|
|
8
8
|
readonly width: number | undefined;
|
|
9
9
|
constructor(renderable: Renderable, width?: number);
|
|
10
10
|
render(options: RenderOptions): Iterable<Segment>;
|
|
11
|
-
contents(): Iterable<Renderable>;
|
|
12
11
|
measure(options: RenderOptions): {
|
|
13
12
|
minimum: number;
|
|
14
13
|
maximum: number;
|
|
@@ -21,9 +21,6 @@ export class Constrain {
|
|
|
21
21
|
};
|
|
22
22
|
yield* render(this.renderable, innerOptions);
|
|
23
23
|
}
|
|
24
|
-
*contents() {
|
|
25
|
-
yield this.renderable;
|
|
26
|
-
}
|
|
27
24
|
measure(options) {
|
|
28
25
|
// Measured at the width it will be drawn at, as Rich's `update_width` does;
|
|
29
26
|
// `Measurement.get` then holds the answer inside that offer.
|