@promptctl/rich-js 0.17.0 → 0.18.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.
Files changed (147) hide show
  1. package/README.md +13 -26
  2. package/dist/core/anchor.d.ts +45 -0
  3. package/dist/core/anchor.js +39 -0
  4. package/dist/core/ansi.d.ts +65 -0
  5. package/dist/core/ansi.js +231 -0
  6. package/dist/core/box.d.ts +0 -1
  7. package/dist/core/box.js +6 -18
  8. package/dist/core/cells.d.ts +16 -5
  9. package/dist/core/cells.js +31 -10
  10. package/dist/core/color.d.ts +4 -8
  11. package/dist/core/color.js +28 -19
  12. package/dist/core/console.d.ts +13 -4
  13. package/dist/core/console.js +91 -36
  14. package/dist/core/export-html.d.ts +40 -5
  15. package/dist/core/export-html.js +111 -17
  16. package/dist/core/markup.d.ts +27 -5
  17. package/dist/core/markup.js +282 -170
  18. package/dist/core/measure.d.ts +1 -1
  19. package/dist/core/measure.js +2 -1
  20. package/dist/core/place.d.ts +30 -0
  21. package/dist/core/place.js +51 -0
  22. package/dist/core/pretty.d.ts +3 -0
  23. package/dist/core/pretty.js +5 -1
  24. package/dist/core/protocol.d.ts +136 -6
  25. package/dist/core/protocol.js +64 -2
  26. package/dist/core/render.d.ts +2 -2
  27. package/dist/core/render.js +2 -2
  28. package/dist/core/segment.d.ts +23 -4
  29. package/dist/core/segment.js +75 -16
  30. package/dist/core/spinnerData.d.ts +2 -0
  31. package/dist/core/spinnerData.js +3 -1
  32. package/dist/core/strip.d.ts +3 -7
  33. package/dist/core/strip.js +32 -35
  34. package/dist/core/style.d.ts +25 -0
  35. package/dist/core/style.js +61 -89
  36. package/dist/core/text.d.ts +16 -15
  37. package/dist/core/text.js +62 -76
  38. package/dist/host/app.d.ts +121 -0
  39. package/dist/host/app.js +255 -0
  40. package/dist/host/host-environment.d.ts +26 -0
  41. package/dist/host/host-environment.js +44 -0
  42. package/dist/host/index.d.ts +4 -2
  43. package/dist/host/index.js +2 -1
  44. package/dist/host/terminal-host.d.ts +43 -7
  45. package/dist/host/terminal-host.js +57 -3
  46. package/dist/index.d.ts +7 -3
  47. package/dist/index.js +4 -1
  48. package/dist/node/terminal-host.d.ts +31 -2
  49. package/dist/node/terminal-host.js +69 -2
  50. package/dist/node/traceback.d.ts +16 -6
  51. package/dist/node/traceback.js +30 -8
  52. package/dist/renderables/align.d.ts +2 -2
  53. package/dist/renderables/align.js +6 -19
  54. package/dist/renderables/columns.js +4 -20
  55. package/dist/renderables/embed.d.ts +50 -0
  56. package/dist/renderables/embed.js +71 -0
  57. package/dist/renderables/group.js +3 -1
  58. package/dist/renderables/layout.js +31 -34
  59. package/dist/renderables/live.d.ts +6 -3
  60. package/dist/renderables/live.js +89 -45
  61. package/dist/renderables/markdown.d.ts +1 -1
  62. package/dist/renderables/markdown.js +6 -4
  63. package/dist/renderables/padding.js +3 -2
  64. package/dist/renderables/panel.js +26 -41
  65. package/dist/renderables/progress.js +5 -8
  66. package/dist/renderables/progressBar.js +6 -5
  67. package/dist/renderables/rule.d.ts +3 -2
  68. package/dist/renderables/rule.js +9 -9
  69. package/dist/renderables/spinner.d.ts +5 -3
  70. package/dist/renderables/spinner.js +14 -8
  71. package/dist/renderables/syntax.d.ts +1 -1
  72. package/dist/renderables/syntax.js +2 -1
  73. package/dist/renderables/table.d.ts +26 -14
  74. package/dist/renderables/table.js +239 -141
  75. package/dist/renderables/traceback.js +8 -9
  76. package/dist/renderables/tree.d.ts +17 -3
  77. package/dist/renderables/tree.js +62 -71
  78. package/dist/renderables/viewport.d.ts +114 -0
  79. package/dist/renderables/viewport.js +198 -0
  80. package/dist/template-bindings/color-funcs.js +11 -13
  81. package/dist/template-bindings/index.js +4 -2
  82. package/dist/template-bindings/palette-funcs.js +6 -16
  83. package/dist/template-bindings/style-funcs.js +4 -0
  84. package/dist/themes/data/ansi-tables.d.ts +14 -0
  85. package/dist/themes/data/ansi-tables.js +49 -0
  86. package/dist/themes/data/atom-one-dark.js +19 -0
  87. package/dist/themes/data/atom-one-light.js +19 -0
  88. package/dist/themes/data/catppuccin-frappe.js +19 -0
  89. package/dist/themes/data/catppuccin-latte.js +19 -0
  90. package/dist/themes/data/catppuccin-macchiato.js +19 -0
  91. package/dist/themes/data/catppuccin-mocha.js +19 -0
  92. package/dist/themes/data/cyberpunk.js +2 -0
  93. package/dist/themes/data/default.js +2 -0
  94. package/dist/themes/data/dracula.js +19 -0
  95. package/dist/themes/data/flexoki.js +19 -0
  96. package/dist/themes/data/gruvbox.js +19 -0
  97. package/dist/themes/data/monokai.js +19 -0
  98. package/dist/themes/data/nord.js +19 -0
  99. package/dist/themes/data/rose-pine-dawn.js +19 -0
  100. package/dist/themes/data/rose-pine-moon.js +19 -0
  101. package/dist/themes/data/rose-pine.js +19 -0
  102. package/dist/themes/data/solarized-dark.js +19 -0
  103. package/dist/themes/data/solarized-light.js +19 -0
  104. package/dist/themes/data/svg-export.js +19 -0
  105. package/dist/themes/data/textual-ansi.js +2 -0
  106. package/dist/themes/data/textual-dark.js +2 -0
  107. package/dist/themes/data/textual-light.js +2 -0
  108. package/dist/themes/data/tokyo-night.js +19 -0
  109. package/dist/themes/data/types.d.ts +16 -0
  110. package/dist/themes/data/types.js +10 -1
  111. package/dist/themes/registry.d.ts +3 -2
  112. package/dist/themes/registry.js +13 -1
  113. package/dist/themes/terminalThemes.d.ts +2 -7
  114. package/dist/themes/terminalThemes.js +4 -9
  115. package/dist/widgets/button.d.ts +1 -1
  116. package/dist/widgets/button.js +4 -2
  117. package/dist/widgets/checkbox.d.ts +2 -2
  118. package/dist/widgets/checkbox.js +5 -3
  119. package/dist/widgets/dropdown.d.ts +2 -2
  120. package/dist/widgets/dropdown.js +13 -16
  121. package/dist/widgets/event-router.d.ts +21 -28
  122. package/dist/widgets/event-router.js +80 -73
  123. package/dist/widgets/focus-manager.d.ts +25 -6
  124. package/dist/widgets/focus-manager.js +63 -65
  125. package/dist/widgets/hit.d.ts +64 -0
  126. package/dist/widgets/hit.js +113 -0
  127. package/dist/widgets/index.d.ts +5 -7
  128. package/dist/widgets/index.js +3 -4
  129. package/dist/widgets/slider.d.ts +2 -2
  130. package/dist/widgets/slider.js +7 -7
  131. package/dist/widgets/static-item.d.ts +9 -15
  132. package/dist/widgets/static-item.js +9 -15
  133. package/dist/widgets/text-input.d.ts +2 -2
  134. package/dist/widgets/text-input.js +17 -14
  135. package/dist/widgets/toggle.d.ts +1 -1
  136. package/dist/widgets/toggle.js +3 -2
  137. package/dist/widgets/types.d.ts +14 -35
  138. package/dist/widgets/types.js +0 -1
  139. package/dist/widgets/widget-app.d.ts +63 -0
  140. package/dist/widgets/widget-app.js +199 -0
  141. package/dist/widgets/widget-base.d.ts +4 -6
  142. package/dist/widgets/widget-base.js +22 -30
  143. package/package.json +12 -4
  144. package/dist/host/host-stream.d.ts +0 -30
  145. package/dist/host/host-stream.js +0 -35
  146. package/dist/widgets/screen.d.ts +0 -98
  147. package/dist/widgets/screen.js +0 -530
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@promptctl/rich-js",
3
- "version": "0.17.0",
3
+ "version": "0.18.1",
4
4
  "description": "Rich text and beautiful formatting in the terminal — a TypeScript port of Python's Rich",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/brandon-fryslie/rich-js"
8
+ },
5
9
  "type": "module",
6
10
  "sideEffects": false,
7
11
  "main": "dist/index.js",
@@ -53,7 +57,7 @@
53
57
  "THIRD-PARTY-NOTICES"
54
58
  ],
55
59
  "scripts": {
56
- "prepublishOnly": "node scripts/verify-release-tag.mjs",
60
+ "prepublishOnly": "node scripts/verify-release-tag.mjs && node scripts/verify-entry-points.mjs",
57
61
  "build": "npm run clean && tsc",
58
62
  "test": "vitest run",
59
63
  "test:watch": "vitest",
@@ -66,6 +70,7 @@
66
70
  "demo:build": "tsc -p tsconfig.demo.json",
67
71
  "sessions": "tsc -p tsconfig.demo.json && node dist-demo/examples/claude-sessions/index.js",
68
72
  "strip": "tsc -p tsconfig.demo.json && node dist-demo/examples/rich-strip/index.js",
73
+ "viewport": "tsc -p tsconfig.demo.json && node dist-demo/examples/rich-viewport/index.js",
69
74
  "markup-plugins": "tsc -p tsconfig.demo.json && node dist-demo/examples/rich-markup-plugins/index.js",
70
75
  "demo-inputs": "tsc -p tsconfig.demo.json && node dist-demo/examples/rich-config/index.js",
71
76
  "demo:dropdown": "tsc -p tsconfig.demo.json && node dist-demo/examples/dropdown-demo/index.js",
@@ -96,9 +101,12 @@
96
101
  },
97
102
  "devDependencies": {
98
103
  "@playwright/test": "^1.63.0",
99
- "@promptctl/go-template-js": "^0.9.0",
104
+ "@promptctl/go-template-js": "^0.10.0",
105
+ "@types/markdown-it": "^14.2.0",
100
106
  "@types/node": "^26.5.1",
101
107
  "@types/semver": "^7.8.0",
108
+ "markdown-it": "^14.3.2",
109
+ "markdown-it-container": "^4.0.0",
102
110
  "mobx": "^7.0.3",
103
111
  "semver": "^7.8.5",
104
112
  "strip-ansi": "^7.2.0",
@@ -111,7 +119,7 @@
111
119
  "string-width": "^8.2.2"
112
120
  },
113
121
  "peerDependencies": {
114
- "@promptctl/go-template-js": "^0.9.0",
122
+ "@promptctl/go-template-js": "^0.10.0",
115
123
  "mobx": "^7.0.3"
116
124
  },
117
125
  "peerDependenciesMeta": {
@@ -1,30 +0,0 @@
1
- /**
2
- * hostStream — adapt a `TerminalHost` into the narrow Writable surface that
3
- * Console (and Live) actually exercise.
4
- *
5
- * [LAW:types-are-the-program] The return type matches Console's `ConsoleSink`
6
- * exactly: a single `.write(chunk)` method whose return value Console never
7
- * inspects (so the type leaves it as `unknown`; this implementation happens
8
- * to return `true` to mirror Node's stream contract, but callers may not
9
- * rely on that). Anything wider would lie about what this adapter
10
- * implements; anything narrower would force a cast at the call site.
11
- * Calling `.pipe()`, `.cork()`, `.on('error')`, etc. is a programming error
12
- * that TypeScript will reject at compile time.
13
- *
14
- * [LAW:locality-or-seam] Console + Live access their sink only via `.write()`
15
- * — verified in src/core/console.ts (one `_file.write` call) and
16
- * src/renderables/live.ts (every `this._console.file.write(...)` site). So
17
- * this narrow surface is the entire contract they need.
18
- */
19
- import type { ConsoleSink } from "../core/console.js";
20
- import type { TerminalHost } from "./terminal-host.js";
21
- /**
22
- * Wrap a `TerminalHost` so its output can be threaded into `Console` via the
23
- * existing `file:` option. The returned object implements `.write()` only —
24
- * exactly the surface Console + Live touch.
25
- *
26
- * Pair with `forceTerminal: true` on the Console — without it, Console treats
27
- * any non-undefined `file` option as non-TTY and disables color, which
28
- * defeats the point.
29
- */
30
- export declare function hostStream(host: TerminalHost): ConsoleSink;
@@ -1,35 +0,0 @@
1
- /**
2
- * hostStream — adapt a `TerminalHost` into the narrow Writable surface that
3
- * Console (and Live) actually exercise.
4
- *
5
- * [LAW:types-are-the-program] The return type matches Console's `ConsoleSink`
6
- * exactly: a single `.write(chunk)` method whose return value Console never
7
- * inspects (so the type leaves it as `unknown`; this implementation happens
8
- * to return `true` to mirror Node's stream contract, but callers may not
9
- * rely on that). Anything wider would lie about what this adapter
10
- * implements; anything narrower would force a cast at the call site.
11
- * Calling `.pipe()`, `.cork()`, `.on('error')`, etc. is a programming error
12
- * that TypeScript will reject at compile time.
13
- *
14
- * [LAW:locality-or-seam] Console + Live access their sink only via `.write()`
15
- * — verified in src/core/console.ts (one `_file.write` call) and
16
- * src/renderables/live.ts (every `this._console.file.write(...)` site). So
17
- * this narrow surface is the entire contract they need.
18
- */
19
- /**
20
- * Wrap a `TerminalHost` so its output can be threaded into `Console` via the
21
- * existing `file:` option. The returned object implements `.write()` only —
22
- * exactly the surface Console + Live touch.
23
- *
24
- * Pair with `forceTerminal: true` on the Console — without it, Console treats
25
- * any non-undefined `file` option as non-TTY and disables color, which
26
- * defeats the point.
27
- */
28
- export function hostStream(host) {
29
- return {
30
- write(chunk) {
31
- host.write(chunk);
32
- return true;
33
- },
34
- };
35
- }
@@ -1,98 +0,0 @@
1
- /**
2
- * Screen — owns the render loop and ANSI output for interactive widgets.
3
- *
4
- * [LAW:dataflow-not-control-flow] Same pipeline runs every frame: render
5
- * widgets to Segment[], split into lines, encode to ANSI, write to stdout
6
- * with cursor-up + overwrite. Variability lives in the values (which widgets
7
- * are visible, what they render), never in whether the pipeline runs.
8
- *
9
- * [LAW:one-source-of-truth] Layout (widget bounds) is computed here and
10
- * written to widget.bounds. Mouse hit-testing reads the same bounds — the
11
- * Screen is the single authority on where each widget is drawn.
12
- *
13
- * [LAW:single-enforcer] Cursor management lives in one place: `draw()`
14
- * tracks `lastLineCount` and emits a single `\x1b[<n>A` to reposition.
15
- * Per-line `\x1b[K` (erase to end of line) overwrites old content without
16
- * flicker — no clear-and-redraw cycle.
17
- *
18
- * Reactivity: `mobx.autorun` re-fires on any observable read during render
19
- * (label, focused, hovered, active, disabled, visible, the widget list
20
- * itself). Renders are debounced to a microtask so a burst of state changes
21
- * within one tick produces one frame.
22
- *
23
- * Layout (per-widget Placement):
24
- *
25
- * flow — vertical stack at x=0; advances the layout cursor by the
26
- * widget's measured height. Default placement; preserves the
27
- * historical single-column behavior so existing consumers
28
- * (and the screen tests) need no migration.
29
- * inline — same row as the preceding flow/inline neighbor; x packs
30
- * after that neighbor's right edge plus a one-cell gap. The
31
- * row's height is the max of its members; the cursor advances
32
- * past the tallest member when the next non-inline item is
33
- * placed (or at end of frame).
34
- * fixed — absolute (x, y); independent of the cursor. Used for
35
- * anchored content like status/log rows that the host wants
36
- * placed at a known coordinate regardless of flow growth.
37
- *
38
- * The overlay pass (single enforcer) runs after base layout: any widget
39
- * implementing OverlayRenderable contributes overlay segments anchored
40
- * directly below its inline footprint, and Screen unions the overlay
41
- * area into the widget's bounds for hit-testing.
42
- *
43
- * Design alternatives considered:
44
- * 1. Per-widget Placement (chosen) — smallest type that covers the legal
45
- * variability; one total switch in computeFrame; back-compat default.
46
- * 2. Named regions (header/body/status as flow containers) — adds a
47
- * two-step API surface (declare regions, then mount into them) and
48
- * another concept; rejected as larger than the problem requires.
49
- * 3. Host-supplied layout function — pushes layout out of Screen,
50
- * defeating single-enforcer; rejected.
51
- */
52
- import { ColorDepth } from "../core/color.js";
53
- import type { Screen, InteractiveWidget, FocusManager, MountEntry } from "./types.js";
54
- import type { TerminalHost } from "../host/terminal-host.js";
55
- export type ColorSystemSpec = ColorDepth | "auto" | "truecolor" | "256" | "ansi" | "none" | null;
56
- export interface ScreenOptions {
57
- /**
58
- * The I/O capability the screen renders against. Construct a
59
- * `NodeTerminalHost` for production node demos, or pass a host that
60
- * wraps mock streams for tests. The seam is the type — Screen never
61
- * reaches for `process.*`.
62
- */
63
- host: TerminalHost;
64
- width?: number;
65
- colorSystem?: ColorSystemSpec;
66
- focusManager?: FocusManager;
67
- /**
68
- * When true (default when the host reports `isTTY`), hide the cursor
69
- * on start and restore it on stop. Disable for non-TTY output and tests.
70
- */
71
- manageCursor?: boolean;
72
- }
73
- export declare class DefaultScreen implements Screen {
74
- readonly focusManager: FocusManager;
75
- accessor widgetList: InteractiveWidget[];
76
- private readonly placements;
77
- private _activeOverlays;
78
- private _running;
79
- private autorunDispose;
80
- private renderScheduled;
81
- private pendingFrame;
82
- private lastLineCount;
83
- private readonly host;
84
- private readonly widthOverride;
85
- private readonly destination;
86
- private readonly manageCursor;
87
- constructor(options: ScreenOptions);
88
- get running(): boolean;
89
- get widgets(): readonly InteractiveWidget[];
90
- mount(...entries: MountEntry[]): void;
91
- unmount(widget: InteractiveWidget): void;
92
- start(): void;
93
- stop(): void;
94
- private get width();
95
- private computeFrame;
96
- private scheduleRender;
97
- private draw;
98
- }