@promptctl/rich-js 0.24.0 → 0.25.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/README.md +7 -0
- package/THIRD-PARTY-NOTICES +29 -1
- package/dist/core/anchor.d.ts +5 -0
- package/dist/core/anchor.js +11 -4
- package/dist/core/animation.d.ts +243 -0
- package/dist/core/animation.js +375 -0
- package/dist/core/ansi.js +2 -2
- package/dist/core/box.d.ts +7 -7
- package/dist/core/cell-widths.d.ts +9 -0
- package/dist/core/cell-widths.js +140 -0
- package/dist/core/cells.d.ts +40 -24
- package/dist/core/cells.js +151 -66
- 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 +21 -29
- package/dist/core/console.d.ts +28 -17
- package/dist/core/console.js +48 -43
- package/dist/core/easing.d.ts +140 -10
- package/dist/core/easing.js +328 -50
- 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 +3 -2
- package/dist/core/markup.js +16 -12
- package/dist/core/measure.js +3 -3
- 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/place.js +2 -1
- package/dist/core/pretty.js +11 -12
- package/dist/core/protocol.d.ts +136 -21
- package/dist/core/protocol.js +203 -16
- package/dist/core/render.d.ts +15 -2
- package/dist/core/render.js +27 -6
- package/dist/core/segment.d.ts +31 -6
- package/dist/core/segment.js +68 -53
- 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 +11 -13
- package/dist/core/strip.js +126 -113
- package/dist/core/style.d.ts +47 -14
- package/dist/core/style.js +74 -34
- package/dist/core/text.d.ts +5 -8
- package/dist/core/text.js +133 -133
- package/dist/core/timeline.d.ts +109 -0
- package/dist/core/timeline.js +180 -0
- package/dist/core/tween.d.ts +49 -0
- package/dist/core/tween.js +71 -0
- 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 +72 -38
- package/dist/host/input.js +3 -4
- package/dist/index.d.ts +30 -15
- package/dist/index.js +20 -6
- package/dist/node/traceback.js +4 -3
- package/dist/renderables/change.d.ts +42 -0
- package/dist/renderables/change.js +112 -0
- package/dist/renderables/columns.d.ts +1 -1
- package/dist/renderables/columns.js +3 -3
- package/dist/renderables/constrain.js +2 -1
- package/dist/renderables/effect.d.ts +155 -92
- package/dist/renderables/effect.js +203 -136
- package/dist/renderables/effects.d.ts +137 -24
- package/dist/renderables/effects.js +276 -113
- package/dist/renderables/embed.d.ts +1 -1
- package/dist/renderables/embed.js +18 -9
- package/dist/renderables/flexStrip.js +2 -1
- package/dist/renderables/frames.d.ts +45 -43
- package/dist/renderables/frames.js +57 -45
- 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 +1 -1
- package/dist/renderables/group.js +2 -2
- package/dist/renderables/html-entities.d.ts +8 -0
- package/dist/renderables/html-entities.js +386 -0
- package/dist/renderables/layout.d.ts +10 -9
- package/dist/renderables/layout.js +42 -35
- package/dist/renderables/lifecycle.d.ts +77 -0
- package/dist/renderables/lifecycle.js +132 -0
- package/dist/renderables/list-view.d.ts +2 -2
- package/dist/renderables/list-view.js +11 -8
- package/dist/renderables/live.d.ts +36 -21
- package/dist/renderables/live.js +89 -42
- package/dist/renderables/markdown-parse.d.ts +109 -0
- package/dist/renderables/markdown-parse.js +1427 -0
- package/dist/renderables/markdown-url.d.ts +19 -0
- package/dist/renderables/markdown-url.js +314 -0
- package/dist/renderables/markdown.d.ts +5 -7
- package/dist/renderables/markdown.js +356 -683
- package/dist/renderables/padding.d.ts +7 -20
- package/dist/renderables/padding.js +29 -50
- package/dist/renderables/panel.d.ts +30 -32
- package/dist/renderables/panel.js +65 -109
- package/dist/renderables/progress.d.ts +83 -32
- package/dist/renderables/progress.js +186 -90
- package/dist/renderables/progressBar.d.ts +22 -12
- package/dist/renderables/progressBar.js +33 -10
- package/dist/renderables/prompt.js +3 -2
- package/dist/renderables/python-space.d.ts +13 -0
- package/dist/renderables/python-space.js +25 -0
- package/dist/renderables/scroll.d.ts +50 -0
- package/dist/renderables/scroll.js +106 -0
- package/dist/renderables/spinner.d.ts +57 -24
- package/dist/renderables/spinner.js +101 -49
- package/dist/renderables/status.js +1 -1
- package/dist/renderables/syntax.d.ts +10 -9
- package/dist/renderables/syntax.js +5 -3
- package/dist/renderables/table.d.ts +48 -46
- package/dist/renderables/table.js +170 -208
- package/dist/renderables/traceback.d.ts +3 -3
- package/dist/renderables/traceback.js +12 -10
- package/dist/renderables/tree.d.ts +28 -25
- package/dist/renderables/tree.js +108 -58
- package/dist/renderables/viewport.d.ts +77 -38
- package/dist/renderables/viewport.js +156 -72
- 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 +7 -6
- package/dist/themes/ramp.d.ts +62 -4
- package/dist/themes/ramp.js +82 -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 +23 -14
- package/dist/widgets/focus-manager.js +34 -33
- package/dist/widgets/hit.d.ts +6 -0
- package/dist/widgets/hit.js +8 -1
- package/dist/widgets/index.d.ts +1 -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 +1 -1
- package/dist/widgets/static-item.js +6 -7
- package/dist/widgets/text-input.d.ts +53 -47
- package/dist/widgets/text-input.js +456 -399
- 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 +32 -6
- package/dist/widgets/widget-app.js +74 -27
- package/dist/widgets/widget-base.d.ts +2 -2
- package/dist/widgets/widget-base.js +29 -21
- package/package.json +9 -5
package/dist/core/style.d.ts
CHANGED
|
@@ -11,6 +11,13 @@ import { type Anchor } from "./anchor.js";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare const ATTRIBUTE_NAMES: readonly ["bold", "dim", "italic", "underline", "blink", "blink2", "reverse", "conceal", "strike", "underline2", "frame", "encircle", "overline"];
|
|
13
13
|
export type AttributeName = (typeof ATTRIBUTE_NAMES)[number];
|
|
14
|
+
/**
|
|
15
|
+
* Each text attribute as a style sets it: on, off, or unset — and an unset
|
|
16
|
+
* one lets a style laid beneath (`Style.add`) show through.
|
|
17
|
+
*/
|
|
18
|
+
export type Attributes = {
|
|
19
|
+
readonly [A in AttributeName]: boolean | undefined;
|
|
20
|
+
};
|
|
14
21
|
export declare const ATTRIBUTE_SGR: Record<AttributeName, number>;
|
|
15
22
|
/**
|
|
16
23
|
* Canonical short-attribute aliases (`b` → `bold`, `i` → `italic`, …).
|
|
@@ -18,7 +25,7 @@ export declare const ATTRIBUTE_SGR: Record<AttributeName, number>;
|
|
|
18
25
|
* bindings — adding an alias here makes it available everywhere.
|
|
19
26
|
* [LAW:one-source-of-truth]
|
|
20
27
|
*/
|
|
21
|
-
export declare const ATTRIBUTE_SHORT_ALIASES: Record<string, AttributeName
|
|
28
|
+
export declare const ATTRIBUTE_SHORT_ALIASES: Readonly<Record<string, AttributeName>>;
|
|
22
29
|
export interface StyleOptions {
|
|
23
30
|
color?: string | ColorSpec;
|
|
24
31
|
bgcolor?: string | ColorSpec;
|
|
@@ -38,7 +45,18 @@ export interface StyleOptions {
|
|
|
38
45
|
link?: string;
|
|
39
46
|
meta?: Record<string, unknown>;
|
|
40
47
|
anchor?: Anchor;
|
|
41
|
-
|
|
48
|
+
/**
|
|
49
|
+
* The hold the style's cells are in, both ends or neither: a cell saying
|
|
50
|
+
* only when it next changes would claim, by default, that it always was,
|
|
51
|
+
* and a timeline run backwards past its change would never wake for it.
|
|
52
|
+
* [LAW:types-are-the-program] Absent, the cells never change.
|
|
53
|
+
*/
|
|
54
|
+
hold?: Hold;
|
|
55
|
+
}
|
|
56
|
+
/** A hold: since when a sample has been what it is, and until when it stays so, on one clock. */
|
|
57
|
+
export interface Hold {
|
|
58
|
+
readonly lastChange: number;
|
|
59
|
+
readonly nextChange: number;
|
|
42
60
|
}
|
|
43
61
|
export declare class StyleSyntaxError extends Error {
|
|
44
62
|
constructor(message: string, options?: ErrorOptions);
|
|
@@ -60,7 +78,7 @@ export declare class Style {
|
|
|
60
78
|
readonly encircle: boolean | undefined;
|
|
61
79
|
readonly overline: boolean | undefined;
|
|
62
80
|
readonly link: string | undefined;
|
|
63
|
-
readonly meta: Record<string, unknown
|
|
81
|
+
readonly meta: Readonly<Record<string, unknown>> | undefined;
|
|
64
82
|
/**
|
|
65
83
|
* Where this style's cells sat in the output of whatever drew them; see
|
|
66
84
|
* `./anchor.ts`. It draws nothing, and it makes two styles that draw alike
|
|
@@ -68,17 +86,19 @@ export declare class Style {
|
|
|
68
86
|
*/
|
|
69
87
|
readonly anchor: Anchor | undefined;
|
|
70
88
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
89
|
+
* The hold this style's cells are in, on the timeline of whoever drew the
|
|
90
|
+
* frame: since when what they show has been what it is (`lastChange`), and
|
|
91
|
+
* when it next changes (`nextChange`) — both `t` for a cell drawn by
|
|
92
|
+
* something that moves every frame, and `-Infinity`/`Infinity` for one
|
|
74
93
|
* that never changes. It draws nothing. Whatever draws for a handed time
|
|
75
|
-
* stamps its cells with it (`
|
|
76
|
-
* through every container as the anchor does (`./anchor.ts`), and
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* asking each container. Two styles
|
|
94
|
+
* stamps its cells with it (`placedRender`, `Effected`), the stamp rides up
|
|
95
|
+
* through every container as the anchor does (`./anchor.ts`), and whoever
|
|
96
|
+
* holds the composed frame reads it off (`Segment.nextChange`, and
|
|
97
|
+
* `Segment.lastChange` for a host running its timeline backwards), so a
|
|
98
|
+
* host knows when to draw again without asking each container. Two styles
|
|
99
|
+
* laid together are in the intersection of their holds.
|
|
80
100
|
*/
|
|
81
|
-
readonly
|
|
101
|
+
readonly hold: Hold;
|
|
82
102
|
constructor(options?: StyleOptions);
|
|
83
103
|
get isNull(): boolean;
|
|
84
104
|
get transparentBackground(): boolean;
|
|
@@ -97,6 +117,19 @@ export declare class Style {
|
|
|
97
117
|
* The same look, drawn from the place `anchor` names, or from nowhere.
|
|
98
118
|
*/
|
|
99
119
|
withAnchor(anchor: Anchor | undefined): Style;
|
|
120
|
+
/** The style's text attributes, each as it sets it. */
|
|
121
|
+
get attributes(): Attributes;
|
|
122
|
+
/**
|
|
123
|
+
* The same style with each attribute `attributes` names set as it says —
|
|
124
|
+
* on, off, or unset — and every other field as it was.
|
|
125
|
+
*/
|
|
126
|
+
withAttributes(attributes: Partial<Attributes>): Style;
|
|
127
|
+
/**
|
|
128
|
+
* This style with its motion taken out, what reduced motion draws: `blink`
|
|
129
|
+
* and `blink2`, the motion a terminal makes on its own, unset, and every
|
|
130
|
+
* other field as it was. A style that does not blink is its own.
|
|
131
|
+
*/
|
|
132
|
+
reduced(): Style;
|
|
100
133
|
/**
|
|
101
134
|
* This style on the cell `cells` to the right: its anchor shifted along its
|
|
102
135
|
* row, or the style itself when it has no anchor.
|
|
@@ -130,7 +163,7 @@ export declare class Style {
|
|
|
130
163
|
/**
|
|
131
164
|
* The look as a canonical string that round-trips through `Style.parse()`:
|
|
132
165
|
* colours, attributes and the link, which is all a style string can spell.
|
|
133
|
-
* What a style carries beyond its look — `meta`, `anchor`, `
|
|
166
|
+
* What a style carries beyond its look — `meta`, `anchor`, `hold` —
|
|
134
167
|
* has no spelling and is not here, so two styles that differ only there
|
|
135
168
|
* read alike; `equals` tells them apart.
|
|
136
169
|
*/
|
|
@@ -198,7 +231,7 @@ export declare class Theme {
|
|
|
198
231
|
resolve(style: TextStyle): Style;
|
|
199
232
|
has(name: string): boolean;
|
|
200
233
|
}
|
|
201
|
-
export declare const DEFAULT_STYLES: Record<string, Style
|
|
234
|
+
export declare const DEFAULT_STYLES: Readonly<Record<string, Style>>;
|
|
202
235
|
/**
|
|
203
236
|
* The theme a render resolves names against when nothing supplied one — what
|
|
204
237
|
* a renderable sees outside a `Console`, as in `renderToString`.
|
package/dist/core/style.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { COLOR_NAMES, ColorSpec, SURFACE_BLACK, } from "./color.js";
|
|
5
5
|
import { shiftAnchor } from "./anchor.js";
|
|
6
6
|
import { Memo } from "./memo.js";
|
|
7
|
+
import { pattern } from "./pattern.js";
|
|
7
8
|
// [LAW:one-way-deps] `core/style` depends only on `core/color`. The substrate
|
|
8
9
|
// a translucent colour is flattened over is `SURFACE_BLACK`, defined beside
|
|
9
10
|
// `compositeOver`.
|
|
@@ -61,6 +62,8 @@ export const ATTRIBUTE_SHORT_ALIASES = {
|
|
|
61
62
|
o: "overline",
|
|
62
63
|
uu: "underline2",
|
|
63
64
|
};
|
|
65
|
+
/** The hold of a cell that never changes: always was, and always will be. */
|
|
66
|
+
const NEVER_CHANGES = { lastChange: Number.NEGATIVE_INFINITY, nextChange: Number.POSITIVE_INFINITY };
|
|
64
67
|
export class StyleSyntaxError extends Error {
|
|
65
68
|
constructor(message, options) {
|
|
66
69
|
super(message, options);
|
|
@@ -95,25 +98,31 @@ export class Style {
|
|
|
95
98
|
*/
|
|
96
99
|
anchor;
|
|
97
100
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
+
* The hold this style's cells are in, on the timeline of whoever drew the
|
|
102
|
+
* frame: since when what they show has been what it is (`lastChange`), and
|
|
103
|
+
* when it next changes (`nextChange`) — both `t` for a cell drawn by
|
|
104
|
+
* something that moves every frame, and `-Infinity`/`Infinity` for one
|
|
101
105
|
* that never changes. It draws nothing. Whatever draws for a handed time
|
|
102
|
-
* stamps its cells with it (`
|
|
103
|
-
* through every container as the anchor does (`./anchor.ts`), and
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* asking each container. Two styles
|
|
106
|
+
* stamps its cells with it (`placedRender`, `Effected`), the stamp rides up
|
|
107
|
+
* through every container as the anchor does (`./anchor.ts`), and whoever
|
|
108
|
+
* holds the composed frame reads it off (`Segment.nextChange`, and
|
|
109
|
+
* `Segment.lastChange` for a host running its timeline backwards), so a
|
|
110
|
+
* host knows when to draw again without asking each container. Two styles
|
|
111
|
+
* laid together are in the intersection of their holds.
|
|
107
112
|
*/
|
|
108
|
-
|
|
113
|
+
hold;
|
|
109
114
|
constructor(options = {}) {
|
|
110
|
-
const
|
|
115
|
+
const hold = options.hold ?? NEVER_CHANGES;
|
|
116
|
+
const { lastChange, nextChange } = hold;
|
|
111
117
|
// [LAW:parse-dont-validate] A time or never, settled where the style is
|
|
112
|
-
// made: NaN and
|
|
118
|
+
// made: NaN and the far infinity fail here, so no reader of a frame meets one.
|
|
113
119
|
if (!(nextChange > Number.NEGATIVE_INFINITY)) {
|
|
114
120
|
throw new RangeError(`Style nextChange must be a time in seconds or Infinity, got ${nextChange}`);
|
|
115
121
|
}
|
|
116
|
-
|
|
122
|
+
if (!(lastChange < Number.POSITIVE_INFINITY)) {
|
|
123
|
+
throw new RangeError(`Style lastChange must be a time in seconds or -Infinity, got ${lastChange}`);
|
|
124
|
+
}
|
|
125
|
+
this.hold = hold;
|
|
117
126
|
this.color = resolveColor(options.color);
|
|
118
127
|
this.bgcolor = resolveBackground(options.bgcolor);
|
|
119
128
|
this.bold = options.bold;
|
|
@@ -129,7 +138,8 @@ export class Style {
|
|
|
129
138
|
this.frame = options.frame;
|
|
130
139
|
this.encircle = options.encircle;
|
|
131
140
|
this.overline = options.overline;
|
|
132
|
-
|
|
141
|
+
// As the reference's `self._link`, read only for truth: an empty URL is no link.
|
|
142
|
+
this.link = options.link || undefined;
|
|
133
143
|
this.meta = options.meta;
|
|
134
144
|
this.anchor = options.anchor;
|
|
135
145
|
}
|
|
@@ -152,7 +162,8 @@ export class Style {
|
|
|
152
162
|
this.link === undefined &&
|
|
153
163
|
this.meta === undefined &&
|
|
154
164
|
this.anchor === undefined &&
|
|
155
|
-
this.nextChange === Number.POSITIVE_INFINITY
|
|
165
|
+
this.hold.nextChange === Number.POSITIVE_INFINITY &&
|
|
166
|
+
this.hold.lastChange === Number.NEGATIVE_INFINITY);
|
|
156
167
|
}
|
|
157
168
|
get transparentBackground() {
|
|
158
169
|
return this.bgcolor === undefined || this.bgcolor.isDefault;
|
|
@@ -188,6 +199,28 @@ export class Style {
|
|
|
188
199
|
withAnchor(anchor) {
|
|
189
200
|
return this.with({ anchor });
|
|
190
201
|
}
|
|
202
|
+
/** The style's text attributes, each as it sets it. */
|
|
203
|
+
get attributes() {
|
|
204
|
+
// [LAW:one-source-of-truth] Keyed by `ATTRIBUTE_NAMES`, whose every name is a key here: the cast is that list's own claim.
|
|
205
|
+
return Object.fromEntries(ATTRIBUTE_NAMES.map((name) => [name, this[name]]));
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The same style with each attribute `attributes` names set as it says —
|
|
209
|
+
* on, off, or unset — and every other field as it was.
|
|
210
|
+
*/
|
|
211
|
+
withAttributes(attributes) {
|
|
212
|
+
// Only the attribute names are read: a wider object — a `Style`, say —
|
|
213
|
+
// satisfies the type and must not carry its colours or anchor in with it.
|
|
214
|
+
return this.with(Object.fromEntries(ATTRIBUTE_NAMES.filter((name) => name in attributes).map((name) => [name, attributes[name]])));
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* This style with its motion taken out, what reduced motion draws: `blink`
|
|
218
|
+
* and `blink2`, the motion a terminal makes on its own, unset, and every
|
|
219
|
+
* other field as it was. A style that does not blink is its own.
|
|
220
|
+
*/
|
|
221
|
+
reduced() {
|
|
222
|
+
return this.blink || this.blink2 ? this.withAttributes({ blink: undefined, blink2: undefined }) : this;
|
|
223
|
+
}
|
|
191
224
|
/**
|
|
192
225
|
* This style on the cell `cells` to the right: its anchor shifted along its
|
|
193
226
|
* row, or the style itself when it has no anchor.
|
|
@@ -224,8 +257,9 @@ export class Style {
|
|
|
224
257
|
? { ...this.meta, ...other.meta }
|
|
225
258
|
: other.meta ?? this.meta,
|
|
226
259
|
anchor: other.anchor ?? this.anchor,
|
|
227
|
-
// Cells under both change when either does: the sooner
|
|
228
|
-
|
|
260
|
+
// Cells under both change when either does: the sooner, and have been
|
|
261
|
+
// what they are since the later — the intersection of the two holds.
|
|
262
|
+
hold: { lastChange: Math.max(this.hold.lastChange, other.hold.lastChange), nextChange: Math.min(this.hold.nextChange, other.hold.nextChange) },
|
|
229
263
|
});
|
|
230
264
|
}
|
|
231
265
|
equals(other) {
|
|
@@ -248,7 +282,8 @@ export class Style {
|
|
|
248
282
|
this.overline === other.overline &&
|
|
249
283
|
this.link === other.link &&
|
|
250
284
|
anchorsEqual(this.anchor, other.anchor) &&
|
|
251
|
-
this.nextChange === other.nextChange
|
|
285
|
+
this.hold.nextChange === other.hold.nextChange &&
|
|
286
|
+
this.hold.lastChange === other.hold.lastChange);
|
|
252
287
|
}
|
|
253
288
|
/**
|
|
254
289
|
* The colours this style puts on screen at `colorSystem`: each flattened
|
|
@@ -298,7 +333,7 @@ export class Style {
|
|
|
298
333
|
/**
|
|
299
334
|
* The look as a canonical string that round-trips through `Style.parse()`:
|
|
300
335
|
* colours, attributes and the link, which is all a style string can spell.
|
|
301
|
-
* What a style carries beyond its look — `meta`, `anchor`, `
|
|
336
|
+
* What a style carries beyond its look — `meta`, `anchor`, `hold` —
|
|
302
337
|
* has no spelling and is not here, so two styles that differ only there
|
|
303
338
|
* read alike; `equals` tells them apart.
|
|
304
339
|
*/
|
|
@@ -389,7 +424,7 @@ export class StyleStack {
|
|
|
389
424
|
}
|
|
390
425
|
}
|
|
391
426
|
// --- Theme ---
|
|
392
|
-
const STYLE_NAME_RE = /^[a-z][a-z0-9._-]
|
|
427
|
+
const STYLE_NAME_RE = pattern(/^[a-z][a-z0-9._-]*$/);
|
|
393
428
|
/**
|
|
394
429
|
* `over` added to `base`, the outer style winning as `Style.add` has it. A
|
|
395
430
|
* `Style` base takes the addition now, and so does `""`, the definition that
|
|
@@ -408,19 +443,14 @@ export function layerStyle(base, over) {
|
|
|
408
443
|
export class Theme {
|
|
409
444
|
styles;
|
|
410
445
|
constructor(definitions = {}, options) {
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
if (inherit) {
|
|
414
|
-
for (const [name, style] of Object.entries(DEFAULT_STYLES)) {
|
|
415
|
-
this.styles.set(name, style);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
for (const [name, def] of Object.entries(definitions)) {
|
|
446
|
+
const inherited = options?.inherit !== false ? Object.entries(DEFAULT_STYLES) : [];
|
|
447
|
+
const defined = Object.entries(definitions).map(([name, def]) => {
|
|
419
448
|
if (!STYLE_NAME_RE.test(name)) {
|
|
420
449
|
throw new Error(`Invalid style name: "${name}" (must be lowercase, start with letter, contain only letters, digits, ".", "-", "_")`);
|
|
421
450
|
}
|
|
422
|
-
|
|
423
|
-
}
|
|
451
|
+
return [name, Style.parse(def)];
|
|
452
|
+
});
|
|
453
|
+
this.styles = new Map([...inherited, ...defined]);
|
|
424
454
|
}
|
|
425
455
|
get(name) {
|
|
426
456
|
return this.styles.get(name);
|
|
@@ -695,16 +725,26 @@ export const DEFAULT_STYLES = {
|
|
|
695
725
|
"syntax.line_number.highlight": Style.parse("bold grey93 on grey27"),
|
|
696
726
|
// Markdown
|
|
697
727
|
"markdown.h1": Style.parse("bold underline"),
|
|
698
|
-
"markdown.h2": Style.parse("
|
|
699
|
-
"markdown.h3": Style.parse("bold
|
|
700
|
-
"markdown.h4": Style.parse("
|
|
728
|
+
"markdown.h2": Style.parse("underline magenta"),
|
|
729
|
+
"markdown.h3": Style.parse("bold magenta"),
|
|
730
|
+
"markdown.h4": Style.parse("italic magenta"),
|
|
731
|
+
"markdown.h5": Style.parse("italic"),
|
|
732
|
+
"markdown.h6": Style.parse("dim"),
|
|
701
733
|
// A fixed cyan, not the theme's: `cyan` is dark enough on some themes to
|
|
702
734
|
// sink into grey11. Bold, as Rich's is: at 16 colours a renderable draws it
|
|
703
735
|
// without its pair (`groundedStyle`), and bold is what still marks code.
|
|
704
736
|
"markdown.code": Style.parse("bold dark_turquoise on grey11"),
|
|
705
|
-
"markdown.
|
|
737
|
+
"markdown.em": Style.parse("italic"),
|
|
738
|
+
"markdown.strong": Style.parse("bold"),
|
|
739
|
+
"markdown.s": Style.parse("strike"),
|
|
740
|
+
"markdown.kbd": Style.parse("bold bright_yellow"),
|
|
741
|
+
"markdown.block_quote": Style.parse("magenta"),
|
|
742
|
+
"markdown.hr": Style.parse("dim"),
|
|
743
|
+
"markdown.item": NULL_STYLE,
|
|
744
|
+
"markdown.item.bullet": Style.parse("bold"),
|
|
745
|
+
"markdown.item.number": Style.parse("cyan"),
|
|
706
746
|
"markdown.link": Style.parse("bright_blue"),
|
|
707
|
-
"markdown.link_url": Style.parse("blue"),
|
|
747
|
+
"markdown.link_url": Style.parse("underline blue"),
|
|
708
748
|
"markdown.table.border": Style.parse("cyan"),
|
|
709
749
|
"markdown.table.header": Style.parse("not bold cyan"),
|
|
710
750
|
// Progress
|
package/dist/core/text.d.ts
CHANGED
|
@@ -33,15 +33,12 @@ export interface RichTextOptions {
|
|
|
33
33
|
noWrap?: boolean;
|
|
34
34
|
}
|
|
35
35
|
export declare class RichText implements Renderable, Measurable {
|
|
36
|
-
private _text;
|
|
37
|
-
private _spans;
|
|
38
|
-
private
|
|
39
|
-
private
|
|
40
|
-
private _overflow;
|
|
41
|
-
private _end;
|
|
42
|
-
private _tabSize;
|
|
43
|
-
private _noWrap;
|
|
36
|
+
private readonly _text;
|
|
37
|
+
private readonly _spans;
|
|
38
|
+
private readonly _format;
|
|
39
|
+
private readonly _tabSize;
|
|
44
40
|
constructor(text?: string, options?: RichTextOptions);
|
|
41
|
+
private _reformat;
|
|
45
42
|
get plain(): string;
|
|
46
43
|
set plain(value: string);
|
|
47
44
|
get length(): number;
|