@promptctl/rich-js 0.7.0 → 0.9.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.
Files changed (201) hide show
  1. package/README.md +99 -31
  2. package/dist/core/box.d.ts +96 -42
  3. package/dist/core/box.d.ts.map +1 -1
  4. package/dist/core/box.js +348 -490
  5. package/dist/core/box.js.map +1 -1
  6. package/dist/core/cells.d.ts +46 -1
  7. package/dist/core/cells.d.ts.map +1 -1
  8. package/dist/core/cells.js +55 -14
  9. package/dist/core/cells.js.map +1 -1
  10. package/dist/core/color.d.ts.map +1 -1
  11. package/dist/core/color.js +22 -8
  12. package/dist/core/color.js.map +1 -1
  13. package/dist/core/console.d.ts +30 -14
  14. package/dist/core/console.d.ts.map +1 -1
  15. package/dist/core/console.js +176 -104
  16. package/dist/core/console.js.map +1 -1
  17. package/dist/core/highlighter.d.ts +2 -1
  18. package/dist/core/highlighter.d.ts.map +1 -1
  19. package/dist/core/highlighter.js +28 -6
  20. package/dist/core/highlighter.js.map +1 -1
  21. package/dist/{renderables → core}/json.d.ts +8 -3
  22. package/dist/core/json.d.ts.map +1 -0
  23. package/dist/{renderables → core}/json.js +7 -2
  24. package/dist/core/json.js.map +1 -0
  25. package/dist/core/markup.d.ts +6 -9
  26. package/dist/core/markup.d.ts.map +1 -1
  27. package/dist/core/markup.js +153 -47
  28. package/dist/core/markup.js.map +1 -1
  29. package/dist/core/measure.d.ts +11 -0
  30. package/dist/core/measure.d.ts.map +1 -1
  31. package/dist/core/measure.js +15 -3
  32. package/dist/core/measure.js.map +1 -1
  33. package/dist/core/oklch.d.ts +22 -0
  34. package/dist/core/oklch.d.ts.map +1 -1
  35. package/dist/core/oklch.js +62 -18
  36. package/dist/core/oklch.js.map +1 -1
  37. package/dist/core/pretty.d.ts +122 -0
  38. package/dist/core/pretty.d.ts.map +1 -0
  39. package/dist/core/pretty.js +398 -0
  40. package/dist/core/pretty.js.map +1 -0
  41. package/dist/core/protocol.d.ts +80 -0
  42. package/dist/core/protocol.d.ts.map +1 -1
  43. package/dist/core/protocol.js +85 -0
  44. package/dist/core/protocol.js.map +1 -1
  45. package/dist/core/segment.d.ts +26 -0
  46. package/dist/core/segment.d.ts.map +1 -1
  47. package/dist/core/segment.js +45 -0
  48. package/dist/core/segment.js.map +1 -1
  49. package/dist/core/strip.d.ts +9 -5
  50. package/dist/core/strip.d.ts.map +1 -1
  51. package/dist/core/strip.js +39 -41
  52. package/dist/core/strip.js.map +1 -1
  53. package/dist/core/style.d.ts +19 -0
  54. package/dist/core/style.d.ts.map +1 -1
  55. package/dist/core/style.js +46 -38
  56. package/dist/core/style.js.map +1 -1
  57. package/dist/core/subscription.d.ts +13 -0
  58. package/dist/core/subscription.d.ts.map +1 -0
  59. package/dist/core/subscription.js +13 -0
  60. package/dist/core/subscription.js.map +1 -0
  61. package/dist/core/text.d.ts +102 -4
  62. package/dist/core/text.d.ts.map +1 -1
  63. package/dist/core/text.js +332 -162
  64. package/dist/core/text.js.map +1 -1
  65. package/dist/core/wrap.d.ts +42 -0
  66. package/dist/core/wrap.d.ts.map +1 -0
  67. package/dist/core/wrap.js +128 -0
  68. package/dist/core/wrap.js.map +1 -0
  69. package/dist/host/host-stream.d.ts.map +1 -0
  70. package/dist/host/host-stream.js.map +1 -0
  71. package/dist/host/index.d.ts +4 -0
  72. package/dist/host/index.d.ts.map +1 -0
  73. package/dist/host/index.js +3 -0
  74. package/dist/host/index.js.map +1 -0
  75. package/dist/{widgets → host}/terminal-host.d.ts +20 -64
  76. package/dist/host/terminal-host.d.ts.map +1 -0
  77. package/dist/host/terminal-host.js +133 -0
  78. package/dist/host/terminal-host.js.map +1 -0
  79. package/dist/index.d.ts +13 -36
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +35 -22
  82. package/dist/index.js.map +1 -1
  83. package/dist/node/terminal-host.d.ts +85 -0
  84. package/dist/node/terminal-host.d.ts.map +1 -0
  85. package/dist/node/terminal-host.js +161 -0
  86. package/dist/node/terminal-host.js.map +1 -0
  87. package/dist/node/traceback.d.ts +28 -0
  88. package/dist/node/traceback.d.ts.map +1 -0
  89. package/dist/node/traceback.js +113 -0
  90. package/dist/node/traceback.js.map +1 -0
  91. package/dist/renderables/columns.d.ts +24 -2
  92. package/dist/renderables/columns.d.ts.map +1 -1
  93. package/dist/renderables/columns.js +91 -32
  94. package/dist/renderables/columns.js.map +1 -1
  95. package/dist/renderables/layout.d.ts +61 -5
  96. package/dist/renderables/layout.d.ts.map +1 -1
  97. package/dist/renderables/layout.js +191 -19
  98. package/dist/renderables/layout.js.map +1 -1
  99. package/dist/renderables/markdown.d.ts +1 -1
  100. package/dist/renderables/markdown.d.ts.map +1 -1
  101. package/dist/renderables/markdown.js +7 -14
  102. package/dist/renderables/markdown.js.map +1 -1
  103. package/dist/renderables/padding.d.ts +16 -3
  104. package/dist/renderables/padding.d.ts.map +1 -1
  105. package/dist/renderables/padding.js +96 -47
  106. package/dist/renderables/padding.js.map +1 -1
  107. package/dist/renderables/panel.d.ts +48 -7
  108. package/dist/renderables/panel.d.ts.map +1 -1
  109. package/dist/renderables/panel.js +175 -106
  110. package/dist/renderables/panel.js.map +1 -1
  111. package/dist/renderables/progress.d.ts +3 -3
  112. package/dist/renderables/progress.d.ts.map +1 -1
  113. package/dist/renderables/progress.js +11 -9
  114. package/dist/renderables/progress.js.map +1 -1
  115. package/dist/renderables/progressBar.d.ts +3 -3
  116. package/dist/renderables/progressBar.d.ts.map +1 -1
  117. package/dist/renderables/progressBar.js +9 -15
  118. package/dist/renderables/progressBar.js.map +1 -1
  119. package/dist/renderables/prompt.js +1 -1
  120. package/dist/renderables/prompt.js.map +1 -1
  121. package/dist/renderables/rule.d.ts +1 -1
  122. package/dist/renderables/rule.d.ts.map +1 -1
  123. package/dist/renderables/rule.js +5 -10
  124. package/dist/renderables/rule.js.map +1 -1
  125. package/dist/renderables/spinner.d.ts +2 -2
  126. package/dist/renderables/spinner.d.ts.map +1 -1
  127. package/dist/renderables/spinner.js +6 -11
  128. package/dist/renderables/spinner.js.map +1 -1
  129. package/dist/renderables/status.d.ts.map +1 -1
  130. package/dist/renderables/status.js +5 -11
  131. package/dist/renderables/status.js.map +1 -1
  132. package/dist/renderables/table.d.ts +90 -16
  133. package/dist/renderables/table.d.ts.map +1 -1
  134. package/dist/renderables/table.js +481 -223
  135. package/dist/renderables/table.js.map +1 -1
  136. package/dist/renderables/traceback.d.ts +7 -3
  137. package/dist/renderables/traceback.d.ts.map +1 -1
  138. package/dist/renderables/traceback.js +15 -18
  139. package/dist/renderables/traceback.js.map +1 -1
  140. package/dist/renderables/tree.d.ts +29 -4
  141. package/dist/renderables/tree.d.ts.map +1 -1
  142. package/dist/renderables/tree.js +86 -33
  143. package/dist/renderables/tree.js.map +1 -1
  144. package/dist/template-bindings/color-funcs.d.ts +3 -3
  145. package/dist/template-bindings/color-funcs.js +3 -3
  146. package/dist/template-bindings/helpers.d.ts.map +1 -1
  147. package/dist/template-bindings/helpers.js +19 -1
  148. package/dist/template-bindings/helpers.js.map +1 -1
  149. package/dist/template-bindings/index.d.ts +6 -7
  150. package/dist/template-bindings/index.d.ts.map +1 -1
  151. package/dist/template-bindings/index.js +6 -7
  152. package/dist/template-bindings/index.js.map +1 -1
  153. package/dist/template-bindings/palette-funcs.d.ts +17 -5
  154. package/dist/template-bindings/palette-funcs.d.ts.map +1 -1
  155. package/dist/template-bindings/palette-funcs.js +69 -6
  156. package/dist/template-bindings/palette-funcs.js.map +1 -1
  157. package/dist/template-bindings/style-funcs.d.ts +1 -1
  158. package/dist/template-bindings/style-funcs.js +1 -1
  159. package/dist/themes/ramp.d.ts +84 -0
  160. package/dist/themes/ramp.d.ts.map +1 -0
  161. package/dist/themes/ramp.js +123 -0
  162. package/dist/themes/ramp.js.map +1 -0
  163. package/dist/widgets/dropdown.d.ts +1 -1
  164. package/dist/widgets/dropdown.js +1 -1
  165. package/dist/widgets/event-router.d.ts +3 -2
  166. package/dist/widgets/event-router.d.ts.map +1 -1
  167. package/dist/widgets/focus-manager.d.ts +2 -1
  168. package/dist/widgets/focus-manager.d.ts.map +1 -1
  169. package/dist/widgets/index.d.ts +3 -6
  170. package/dist/widgets/index.d.ts.map +1 -1
  171. package/dist/widgets/index.js +4 -3
  172. package/dist/widgets/index.js.map +1 -1
  173. package/dist/widgets/screen.d.ts +1 -1
  174. package/dist/widgets/screen.d.ts.map +1 -1
  175. package/dist/widgets/text-input.d.ts +2 -3
  176. package/dist/widgets/text-input.d.ts.map +1 -1
  177. package/dist/widgets/text-input.js +4 -12
  178. package/dist/widgets/text-input.js.map +1 -1
  179. package/dist/widgets/types.d.ts +1 -1
  180. package/dist/widgets/types.d.ts.map +1 -1
  181. package/dist/widgets/types.js.map +1 -1
  182. package/dist/widgets/widget-base.d.ts +2 -1
  183. package/dist/widgets/widget-base.d.ts.map +1 -1
  184. package/package.json +38 -6
  185. package/dist/renderables/json.d.ts.map +0 -1
  186. package/dist/renderables/json.js.map +0 -1
  187. package/dist/renderables/pretty.d.ts +0 -29
  188. package/dist/renderables/pretty.d.ts.map +0 -1
  189. package/dist/renderables/pretty.js +0 -141
  190. package/dist/renderables/pretty.js.map +0 -1
  191. package/dist/themes/paletteResolver.d.ts +0 -35
  192. package/dist/themes/paletteResolver.d.ts.map +0 -1
  193. package/dist/themes/paletteResolver.js +0 -88
  194. package/dist/themes/paletteResolver.js.map +0 -1
  195. package/dist/widgets/host-stream.d.ts.map +0 -1
  196. package/dist/widgets/host-stream.js.map +0 -1
  197. package/dist/widgets/terminal-host.d.ts.map +0 -1
  198. package/dist/widgets/terminal-host.js +0 -258
  199. package/dist/widgets/terminal-host.js.map +0 -1
  200. /package/dist/{widgets → host}/host-stream.d.ts +0 -0
  201. /package/dist/{widgets → host}/host-stream.js +0 -0
@@ -67,11 +67,26 @@ function clamp01(v) {
67
67
  // Small tolerance so float-fuzz at the gamut edge doesn't trigger needless
68
68
  // chroma reduction on colors that are already representable.
69
69
  const GAMUT_EPS = 1e-4;
70
- // [LAW:one-source-of-truth] Below this chroma a color is treated as
71
- // achromatic, and hue is pinned to 0 so round-trips stay stable. Used
72
- // by `fromRgba` (after polar conversion) and `applyKey` (after chroma
73
- // scaling collapses C toward 0). Same threshold both places.
70
+ // [LAW:one-source-of-truth] Below this chroma a color is achromatic and its
71
+ // hue is pinned to 0 so round-trips stay stable — the one threshold every
72
+ // chroma reader here shares.
74
73
  const ACHROMATIC_EPS = 1e-7;
74
+ // The one spelling of that pin: every producer of an `Oklch` (`fromRgba`,
75
+ // `applyKey`, `mix`) passes its result's chroma and hue through here, so a
76
+ // gray from any of them carries the same hue. The constructor does not —
77
+ // it passes intermediates through by contract. [LAW:single-enforcer]
78
+ const hueOf = (c, h) => (c < ACHROMATIC_EPS ? 0 : h);
79
+ // Endpoint-exact: `t = 0` returns `a` and `t = 1` returns `b` bit-for-bit,
80
+ // which `a + (b - a) * t` does not (the subtraction rounds). One shape for
81
+ // every axis `mix` interpolates. [LAW:one-source-of-truth]
82
+ const lerp = (a, b, t) => a * (1 - t) + b * t;
83
+ // Hue into [0, 360). Exact on a hue already there (fmod is exact), and exact
84
+ // on `x - 360` for a representable x (the sum is x itself), which is what
85
+ // `mix` relies on. One spelling for every producer. [LAW:one-source-of-truth]
86
+ const wrapHue = (h) => {
87
+ const w = h % 360;
88
+ return w < 0 ? w + 360 : w;
89
+ };
75
90
  function inGamut(r, g, b) {
76
91
  return (r >= -GAMUT_EPS && r <= 1 + GAMUT_EPS &&
77
92
  g >= -GAMUT_EPS && g <= 1 + GAMUT_EPS &&
@@ -128,12 +143,8 @@ export class Oklch {
128
143
  const aLab = 1.9779984951 * lCube - 2.4285922050 * mCube + 0.4505937099 * sCube;
129
144
  const bLab = 0.0259040371 * lCube + 0.7827717662 * mCube - 0.8086757660 * sCube;
130
145
  const C = Math.sqrt(aLab * aLab + bLab * bLab);
131
- let H = Math.atan2(bLab, aLab) * (180 / Math.PI);
132
- if (H < 0)
133
- H += 360;
134
- if (C < ACHROMATIC_EPS)
135
- H = 0;
136
- return new Oklch(L, C, H, a);
146
+ const H = wrapHue(Math.atan2(bLab, aLab) * (180 / Math.PI));
147
+ return new Oklch(L, C, hueOf(C, H), a);
137
148
  }
138
149
  /**
139
150
  * Polar → OKLab → linear → sRGB (with chroma-bisection gamut clamping).
@@ -169,14 +180,47 @@ export class Oklch {
169
180
  return this;
170
181
  const newL = clamp01(this.l * k.lightnessScale + k.lightnessShift);
171
182
  const newC = Math.max(0, this.c * k.chromaScale);
172
- let newH = (this.h + k.hueShift) % 360;
173
- if (newH < 0)
174
- newH += 360;
175
- // Same achromatic convention as fromRgba: collapsed chroma → pinned hue,
176
- // so applyKey({chromaScale:0}).toRgba() → fromRgba round-trips stably.
177
- if (newC < ACHROMATIC_EPS)
178
- newH = 0;
179
- return new Oklch(newL, newC, newH, this.alpha);
183
+ const newH = wrapHue(this.h + k.hueShift);
184
+ return new Oklch(newL, newC, hueOf(newC, newH), this.alpha);
185
+ }
186
+ /**
187
+ * The color `t` of the way from this one toward `toward`, in OKLCH.
188
+ * `t = 0` is this color, `t = 1` is `toward`; pure.
189
+ *
190
+ * Lightness, chroma and alpha interpolate linearly. Hue takes the shorter
191
+ * arc around the wheel, so blue → red passes through magenta rather than
192
+ * sweeping across green. An achromatic endpoint has no hue of its own —
193
+ * `fromRgba` pins it to 0, which is red — so it adopts the other
194
+ * endpoint's hue (CSS Color 4's "powerless" rule): gray → red stays a red
195
+ * that gains chroma, instead of rotating through the wheel from 0°.
196
+ *
197
+ * `t` must lie in [0, 1]: this is interpolation, not extrapolation, and a
198
+ * `t` outside it (NaN included) is a RangeError, never a colour off the
199
+ * far end of the segment. [LAW:no-silent-failure]
200
+ *
201
+ * [LAW:one-source-of-truth] Achromatic means the same `ACHROMATIC_EPS`
202
+ * that `fromRgba` and `applyKey` pin hue by, so a gray produced by either
203
+ * is a gray here — and the result's hue goes through the same `hueOf`, so
204
+ * a gray produced HERE (t = 0 from a gray, t = 1 toward one) is a gray
205
+ * there too.
206
+ */
207
+ mix(toward, t) {
208
+ if (!(t >= 0 && t <= 1)) {
209
+ throw new RangeError(`Oklch.mix: t must be in [0, 1]; got ${t}`);
210
+ }
211
+ const thisHasHue = this.c >= ACHROMATIC_EPS;
212
+ const towardHasHue = toward.c >= ACHROMATIC_EPS;
213
+ const fromH = wrapHue(thisHasHue ? this.h : towardHasHue ? toward.h : 0);
214
+ const toH = wrapHue(towardHasHue ? toward.h : fromH);
215
+ // Shorter arc: endpoints more than half a turn apart lerp across 0°, the
216
+ // larger one taken a turn down. `x - 360` for x ≥ 180 is exact
217
+ // (Sterbenz), so the endpoints survive the shift and the wrap bit-for-bit
218
+ // — an addition of 360 would not.
219
+ const arc = toH - fromH;
220
+ const fromU = arc < -180 ? fromH - 360 : fromH;
221
+ const toU = arc > 180 ? toH - 360 : toH;
222
+ const c = lerp(this.c, toward.c, t);
223
+ return new Oklch(lerp(this.l, toward.l, t), c, hueOf(c, wrapHue(lerp(fromU, toU, t))), lerp(this.alpha, toward.alpha, t));
180
224
  }
181
225
  /** Linear-sRGB coordinates for an explicit (l, C, h). Pure; `toRgba` passes
182
226
  * already-normalized values so this never sees out-of-range inputs. */
@@ -1 +1 @@
1
- {"version":3,"file":"oklch.js","sourceRoot":"","sources":["../../src/core/oklch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA2BvC,MAAM,CAAC,MAAM,QAAQ,GAAa,MAAM,CAAC,MAAM,CAAC;IAC9C,QAAQ,EAAE,CAAC;IACX,WAAW,EAAE,CAAC;IACd,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,CAAC;CAClB,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAa,MAAM,CAAC,MAAM,CAAC;IACtD,QAAQ,EAAE,CAAC;IACX,WAAW,EAAE,CAAC;IACd,cAAc,EAAE,CAAC,CAAC;IAClB,cAAc,EAAE,CAAC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Y,GAAG,KAAK;YACtE,CAAC,EAAE,CAAC,YAAY,GAAG,KAAK,GAAG,YAAY,GAAG,KAAK,GAAG,YAAY,GAAG,KAAK;SACvE,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACK,iBAAiB,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;QACvD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACzC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC;QACpD,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5B,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;YAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;YAC1C,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;gBAAE,EAAE,GAAG,GAAG,CAAC;;gBAC5C,EAAE,GAAG,GAAG,CAAC;QAChB,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Pretty — formats JavaScript data structures with highlighting.
3
+ *
4
+ * Lives in `core/` beside `markup` and `emoji` because it does their job: turn
5
+ * foreign input into `RichText`. It composes no other renderable — the trait
6
+ * every file in `renderables/` shares and this one does not — and its imports
7
+ * are core primitives only. `Console.print` accepts `unknown` and must turn any
8
+ * of it into something renderable, so the formatter has to sit where `console`
9
+ * can reach it without an upward edge. [LAW:one-way-deps]
10
+ *
11
+ * Two traversals share this file, and the split is the whole design. `_format`
12
+ * lays a value out across lines; `_oneLine` answers only "does this fit on one
13
+ * line, and if so what is it?". They meet at `_shape`, which describes a
14
+ * container without committing to either layout. One traversal answering both
15
+ * questions is what made this formatter exponential: every child was rendered
16
+ * once to probe it and again to place it, so a node at depth d was visited 2^d
17
+ * times.
18
+ */
19
+ import { Segment } from "./segment.js";
20
+ import type { Highlighter } from "./highlighter.js";
21
+ import type { Renderable, Measurable, RenderOptions } from "./protocol.js";
22
+ export interface PrettyOptions {
23
+ indent?: number;
24
+ expandAll?: boolean;
25
+ maxLength?: number;
26
+ maxString?: number;
27
+ /**
28
+ * How many levels of nesting to descend before eliding. Unbounded by default.
29
+ *
30
+ * `Console.print` supplies a bound because it formats whatever it is handed;
31
+ * a caller constructing a `Pretty` has seen their data and can say what they
32
+ * want. Past the cap a container renders as `[...]`, `{...}`, `Map {...}` or
33
+ * `Set {...}` — visible, so the reader knows the value continues.
34
+ */
35
+ maxDepth?: number;
36
+ indentGuides?: boolean;
37
+ /**
38
+ * Who colours the formatted text. Defaults to a `ReprHighlighter`.
39
+ *
40
+ * Passed rather than imported so a caller's choice survives. `Console.print`
41
+ * routes data arguments through here, and its `highlight` flag and custom
42
+ * `highlighter` have to reach the output the same way they reach a printed
43
+ * string — a `Pretty` reaching for its own singleton would silently outrank
44
+ * both. `NullHighlighter` is the "none" case.
45
+ */
46
+ highlighter?: Highlighter;
47
+ }
48
+ export declare class Pretty implements Renderable, Measurable {
49
+ readonly data: unknown;
50
+ readonly indent: number;
51
+ readonly expandAll: boolean;
52
+ readonly maxLength: number | undefined;
53
+ readonly maxString: number | undefined;
54
+ readonly maxDepth: number;
55
+ readonly indentGuides: boolean;
56
+ readonly highlighter: Highlighter;
57
+ constructor(data: unknown, options?: PrettyOptions);
58
+ render(options: RenderOptions): Iterable<Segment>;
59
+ measure(_options: RenderOptions): {
60
+ minimum: number;
61
+ maximum: number;
62
+ };
63
+ /**
64
+ * The text a value shows without being reflected on, or `null` when it is an
65
+ * object and the shape arms own it.
66
+ *
67
+ * Every kind answered here renders the same wherever it sits — no
68
+ * indentation, no width to fit — which is why one method serves both
69
+ * traversals.
70
+ */
71
+ private _scalar;
72
+ /**
73
+ * A container, or the text standing in for one that is empty or past the
74
+ * depth cap.
75
+ *
76
+ * `positions` is a thunk because both of those answers are reachable from
77
+ * `size` alone, and reaching a position is not free: a `Map` or `Set` reaches
78
+ * its own through an iterator, so enumerating one only to elide it drains a
79
+ * container to print `Set {...}`. `size` also says how many positions were
80
+ * dropped, which is where the elision marker comes from — one derivation, so
81
+ * the count and the bound cannot disagree.
82
+ */
83
+ private _container;
84
+ /**
85
+ * The brackets and positions of an object, layout-free. See `Shape`.
86
+ *
87
+ * `bound` is the most positions the caller could ever use. Laying out passes
88
+ * `Infinity`, because it prints every position it is handed. A probe passes
89
+ * what is left of its line, which is already more positions than a fitting
90
+ * one could hold — `SEPARATOR` charges two cells apiece, so a container with
91
+ * more positions than `budget` overruns however narrow its contents are.
92
+ * Reaching past it only ever feeds a join that returns `null`, and reaching a
93
+ * position is what drains a `Map` or `Set`.
94
+ */
95
+ private _shape;
96
+ /** The laid-out form of a value, expanded across lines wherever one line will not do. */
97
+ private _format;
98
+ /** The arms for a non-null object, with `value` already on the open path. */
99
+ private _formatObject;
100
+ /** One position, with every value in it laid out. */
101
+ private _expandSlot;
102
+ /** The one-line form of a value, or `null` when it will not fit `at.budget`. */
103
+ private _oneLine;
104
+ /**
105
+ * A container's positions on one line, or `null` as soon as they overrun.
106
+ *
107
+ * The budget is spent as it goes and each position is asked for only what is
108
+ * left, so a subtree that has already outgrown the line is abandoned where it
109
+ * outgrew it rather than formatted in full and then measured.
110
+ *
111
+ * The brackets are charged before anything is read, and that ordering is what
112
+ * bounds the traversal: a budget checked only against the finished text still
113
+ * reads the whole subtree to produce text it then throws away. Charged first,
114
+ * every level costs at least the two cells of its own brackets, so a probe
115
+ * descends at most `budget / 2` levels however deep the data goes.
116
+ */
117
+ private _joinOneLine;
118
+ /** One position on one line, or `null` when any value in it will not fit. */
119
+ private _slotOneLine;
120
+ private _addIndentGuides;
121
+ }
122
+ //# sourceMappingURL=pretty.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pretty.d.ts","sourceRoot":"","sources":["../../src/core/pretty.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACd,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAsMD,qBAAa,MAAO,YAAW,UAAU,EAAE,UAAU;IACnD,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;gBAEtB,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa;IAWjD,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC;IAYlD,OAAO,CAAC,QAAQ,EAAE,aAAa,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAUtE;;;;;;;OAOG;IACH,OAAO,CAAC,OAAO;IAyBf;;;;;;;;;;OAUG;IACH,OAAO,CAAC,UAAU;IAelB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,MAAM;IAqDd,yFAAyF;IACzF,OAAO,CAAC,OAAO;IAmBf,6EAA6E;IAC7E,OAAO,CAAC,aAAa;IAoBrB,qDAAqD;IACrD,OAAO,CAAC,WAAW;IAgBnB,gFAAgF;IAChF,OAAO,CAAC,QAAQ;IAkBhB;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,YAAY;IAepB,6EAA6E;IAC7E,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,gBAAgB;CAazB"}
@@ -0,0 +1,398 @@
1
+ /**
2
+ * Pretty — formats JavaScript data structures with highlighting.
3
+ *
4
+ * Lives in `core/` beside `markup` and `emoji` because it does their job: turn
5
+ * foreign input into `RichText`. It composes no other renderable — the trait
6
+ * every file in `renderables/` shares and this one does not — and its imports
7
+ * are core primitives only. `Console.print` accepts `unknown` and must turn any
8
+ * of it into something renderable, so the formatter has to sit where `console`
9
+ * can reach it without an upward edge. [LAW:one-way-deps]
10
+ *
11
+ * Two traversals share this file, and the split is the whole design. `_format`
12
+ * lays a value out across lines; `_oneLine` answers only "does this fit on one
13
+ * line, and if so what is it?". They meet at `_shape`, which describes a
14
+ * container without committing to either layout. One traversal answering both
15
+ * questions is what made this formatter exponential: every child was rendered
16
+ * once to probe it and again to place it, so a node at depth d was visited 2^d
17
+ * times.
18
+ */
19
+ import { cellLen } from "./cells.js";
20
+ import { RichText } from "./text.js";
21
+ import { ReprHighlighter } from "./highlighter.js";
22
+ const reprHighlighter = new ReprHighlighter();
23
+ const rootFrame = (maxWidth) => ({ inset: 0, level: 0, maxWidth, open: new WeakSet() });
24
+ /**
25
+ * The text, when it is a single line no wider than `budget` — otherwise `null`.
26
+ *
27
+ * The one definition of "fits on one line" in this file, and it has to name
28
+ * both halves: `cellLen` scores a newline as zero cells, so a width check alone
29
+ * accepted multi-line text as compact. That is how a `Map` nested in an object
30
+ * used to render as `{ m: Map {` — a one-line object with an expansion wedged
31
+ * inside it and the closing brace back at column 0.
32
+ */
33
+ function fitOneLine(text, budget) {
34
+ return text.includes("\n") || cellLen(text) > budget ? null : text;
35
+ }
36
+ /**
37
+ * The elements of an indexed sequence, or `null` for anything that isn't one.
38
+ *
39
+ * A typed array is an array with a fixed element type, and neither of the two
40
+ * questions asked elsewhere in this file recognises it: `Array.isArray` says
41
+ * false, and its own `toString` answers the bare `1,2,3` — no brackets, nothing
42
+ * for the highlighter to colour per element. Both spellings reach the one arm
43
+ * that knows what a sequence looks like. `DataView` is excluded because it is a
44
+ * window onto bytes, not a sequence of values.
45
+ *
46
+ * Returned as `ArrayLike` rather than a materialised array because both
47
+ * spellings already are one. Converting here would box every element of a
48
+ * multi-megabyte `Buffer` to keep the first `maxLength` of them — bounding the
49
+ * output while leaving the cost of producing it unbounded.
50
+ */
51
+ function indexedElements(value) {
52
+ if (Array.isArray(value))
53
+ return value;
54
+ if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
55
+ return value;
56
+ }
57
+ return null;
58
+ }
59
+ /**
60
+ * The first `limit` items of a sequence, pulled and no more.
61
+ *
62
+ * A `Map` or `Set` reaches its size through `.size`, which iterates nothing, so
63
+ * spreading one only ever served to throw the tail away — `print` of a
64
+ * half-million-entry cache walked all of it to show a hundred. `Infinity` is
65
+ * the unbounded case and never breaks.
66
+ */
67
+ function take(source, limit) {
68
+ const taken = [];
69
+ if (limit <= 0)
70
+ return taken;
71
+ for (const item of source) {
72
+ taken.push(item);
73
+ if (taken.length >= limit)
74
+ break;
75
+ }
76
+ return taken;
77
+ }
78
+ /**
79
+ * What a value renders as when reading it threw instead of producing it.
80
+ *
81
+ * `Pretty` reflects on data it did not create, and every reflection it performs
82
+ * — a property getter, `Object.keys`, an iterator, `toString` — can throw. The
83
+ * message travels into the output, so the failure stays visible and attributed
84
+ * to the position that produced it. [LAW:no-silent-failure] the error is
85
+ * carried rather than swallowed; a marker naming its cause is not an
86
+ * answer-shaped void, and a diagnostic that takes the program down over one
87
+ * lazily-computed field is unusable on the objects it is most wanted for.
88
+ */
89
+ function threw(error) {
90
+ return `[Threw: ${error instanceof Error ? error.message : String(error)}]`;
91
+ }
92
+ /**
93
+ * Does this value carry its own string form, or must we reflect on its keys?
94
+ *
95
+ * A `Date`, an `Error`, a `RegExp`, or any object that defines `toString`
96
+ * answers the display question itself, and reflecting on such a value throws
97
+ * that answer away — `Object.keys(new Date())` is empty, so key-reflection
98
+ * renders it `{}`. Inheriting `Object.prototype.toString` is the opposite
99
+ * signal: it yields `[object Object]`, a non-answer, so the keys are all the
100
+ * information there is.
101
+ *
102
+ * Both clauses are load-bearing. The identity check separates the two
103
+ * populations; the `typeof` check is what makes `Object.create(null)` — which
104
+ * has no `toString` at all — reflect rather than throw.
105
+ */
106
+ function describesItself(value) {
107
+ const asRecord = value;
108
+ return (typeof asRecord[Symbol.toPrimitive] === "function" ||
109
+ (typeof asRecord.toString === "function" &&
110
+ asRecord.toString !== Object.prototype.toString));
111
+ }
112
+ /** What joins a container's positions on one line. Its width is charged for, so it is named once. */
113
+ const SEPARATOR = ", ";
114
+ /** The marker for positions the bound dropped, or nothing when it dropped none. */
115
+ const elided = (dropped) => dropped > 0 ? [{ head: `... +${dropped}`, holes: [] }] : [];
116
+ export class Pretty {
117
+ data;
118
+ indent;
119
+ expandAll;
120
+ maxLength;
121
+ maxString;
122
+ maxDepth;
123
+ indentGuides;
124
+ highlighter;
125
+ constructor(data, options) {
126
+ this.data = data;
127
+ this.indent = options?.indent ?? 4;
128
+ this.expandAll = options?.expandAll ?? false;
129
+ this.maxLength = options?.maxLength;
130
+ this.maxString = options?.maxString;
131
+ this.maxDepth = options?.maxDepth ?? Infinity;
132
+ this.indentGuides = options?.indentGuides !== false;
133
+ this.highlighter = options?.highlighter ?? reprHighlighter;
134
+ }
135
+ *render(options) {
136
+ const formatted = this._format(this.data, rootFrame(options.maxWidth));
137
+ const text = new RichText(formatted, { end: "" });
138
+ this.highlighter.highlight(text);
139
+ if (this.indentGuides) {
140
+ this._addIndentGuides(text);
141
+ }
142
+ yield* text.render(options);
143
+ }
144
+ measure(_options) {
145
+ const formatted = this._format(this.data, rootFrame(_options.maxWidth));
146
+ const lines = formatted.split("\n");
147
+ let max = 0;
148
+ for (const line of lines) {
149
+ max = Math.max(max, cellLen(line));
150
+ }
151
+ return { minimum: 1, maximum: Math.min(max, _options.maxWidth) };
152
+ }
153
+ /**
154
+ * The text a value shows without being reflected on, or `null` when it is an
155
+ * object and the shape arms own it.
156
+ *
157
+ * Every kind answered here renders the same wherever it sits — no
158
+ * indentation, no width to fit — which is why one method serves both
159
+ * traversals.
160
+ */
161
+ _scalar(value) {
162
+ if (value === null)
163
+ return "null";
164
+ if (value === undefined)
165
+ return "undefined";
166
+ switch (typeof value) {
167
+ case "string": {
168
+ let str = value;
169
+ if (this.maxString !== undefined && str.length > this.maxString) {
170
+ str = str.slice(0, this.maxString) + `+${value.length - this.maxString}`;
171
+ }
172
+ return JSON.stringify(str);
173
+ }
174
+ case "number":
175
+ case "bigint":
176
+ case "boolean":
177
+ return String(value);
178
+ case "symbol":
179
+ return value.toString();
180
+ case "function":
181
+ return `[Function: ${value.name || "anonymous"}]`;
182
+ }
183
+ return null;
184
+ }
185
+ /**
186
+ * A container, or the text standing in for one that is empty or past the
187
+ * depth cap.
188
+ *
189
+ * `positions` is a thunk because both of those answers are reachable from
190
+ * `size` alone, and reaching a position is not free: a `Map` or `Set` reaches
191
+ * its own through an iterator, so enumerating one only to elide it drains a
192
+ * container to print `Set {...}`. `size` also says how many positions were
193
+ * dropped, which is where the elision marker comes from — one derivation, so
194
+ * the count and the bound cannot disagree.
195
+ */
196
+ _container(open, close, pad, size, level, positions) {
197
+ if (size === 0)
198
+ return { kind: "text", text: open + close };
199
+ if (level >= this.maxDepth)
200
+ return { kind: "text", text: open + "..." + close };
201
+ const slots = positions();
202
+ return { kind: "container", open, close, pad, slots: [...slots, ...elided(size - slots.length)] };
203
+ }
204
+ /**
205
+ * The brackets and positions of an object, layout-free. See `Shape`.
206
+ *
207
+ * `bound` is the most positions the caller could ever use. Laying out passes
208
+ * `Infinity`, because it prints every position it is handed. A probe passes
209
+ * what is left of its line, which is already more positions than a fitting
210
+ * one could hold — `SEPARATOR` charges two cells apiece, so a container with
211
+ * more positions than `budget` overruns however narrow its contents are.
212
+ * Reaching past it only ever feeds a join that returns `null`, and reaching a
213
+ * position is what drains a `Map` or `Set`.
214
+ */
215
+ _shape(value, level, bound) {
216
+ // Clamped because a probe's budget goes negative once a line is overrun,
217
+ // and `slice` reads a negative end as counting from the far end — it would
218
+ // keep all but the last few keys where the other arms take none.
219
+ const cap = Math.max(0, Math.min(this.maxLength ?? Infinity, bound));
220
+ const elements = indexedElements(value);
221
+ if (elements !== null) {
222
+ return this._container("[", "]", "", elements.length, level, () => {
223
+ // Positions rather than values: each index is read in its own slot, so
224
+ // one throwing accessor costs its own slot, not the whole sequence.
225
+ const shown = Math.min(elements.length, cap);
226
+ return Array.from({ length: shown }, (_, i) => ({
227
+ head: "",
228
+ holes: [{ read: () => elements[i], tail: "" }],
229
+ }));
230
+ });
231
+ }
232
+ if (value instanceof Map) {
233
+ return this._container("Map {", "}", " ", value.size, level, () => take(value.entries(), cap).map(([k, v]) => ({
234
+ head: "",
235
+ holes: [{ read: () => k, tail: " => " }, { read: () => v, tail: "" }],
236
+ })));
237
+ }
238
+ if (value instanceof Set) {
239
+ return this._container("Set {", "}", " ", value.size, level, () => take(value, cap).map((v) => ({
240
+ head: "",
241
+ holes: [{ read: () => v, tail: "" }],
242
+ })));
243
+ }
244
+ // Objects that answer the display question themselves. Sits below the
245
+ // Array/Map/Set arms deliberately: an array also overrides `toString`, but
246
+ // "1,2,3" is a poorer answer than the structural form above.
247
+ if (describesItself(value))
248
+ return { kind: "text", text: String(value) };
249
+ // Plain objects — no self-description, so the keys are the whole story.
250
+ const obj = value;
251
+ const keys = Object.keys(obj);
252
+ return this._container("{", "}", " ", keys.length, level, () => keys.slice(0, cap).map((k) => ({
253
+ head: `${k}: `,
254
+ holes: [{ read: () => obj[k], tail: "" }],
255
+ })));
256
+ }
257
+ /** The laid-out form of a value, expanded across lines wherever one line will not do. */
258
+ _format(value, at) {
259
+ const scalar = this._scalar(value);
260
+ if (scalar !== null)
261
+ return scalar;
262
+ const object = value;
263
+ if (at.open.has(object))
264
+ return "[Circular]";
265
+ at.open.add(object);
266
+ try {
267
+ return this._formatObject(object, at);
268
+ }
269
+ catch (error) {
270
+ // The container's *shape* would not be read — `Object.keys`, an iterator,
271
+ // `toString`. Nothing can be enumerated, so the whole container degrades;
272
+ // a value that merely would not be read degrades alone, in its own slot.
273
+ return threw(error);
274
+ }
275
+ finally {
276
+ at.open.delete(object);
277
+ }
278
+ }
279
+ /** The arms for a non-null object, with `value` already on the open path. */
280
+ _formatObject(value, at) {
281
+ const shape = this._shape(value, at.level, Infinity);
282
+ if (shape.kind === "text")
283
+ return shape.text;
284
+ const indentStr = " ".repeat(this.indent * at.inset);
285
+ if (!this.expandAll) {
286
+ const compact = this._joinOneLine(shape, {
287
+ level: at.level + 1,
288
+ budget: at.maxWidth - cellLen(indentStr),
289
+ open: at.open,
290
+ });
291
+ if (compact !== null)
292
+ return compact;
293
+ }
294
+ const innerIndent = " ".repeat(this.indent * (at.inset + 1));
295
+ const deeper = { inset: at.inset + 1, level: at.level + 1, maxWidth: at.maxWidth, open: at.open };
296
+ const parts = shape.slots.map((slot) => innerIndent + this._expandSlot(slot, deeper));
297
+ return shape.open + "\n" + parts.join(",\n") + "\n" + indentStr + shape.close;
298
+ }
299
+ /** One position, with every value in it laid out. */
300
+ _expandSlot(slot, at) {
301
+ let out = slot.head;
302
+ for (const hole of slot.holes) {
303
+ // This is the read that costs the least when it fails: neighbours are
304
+ // unaffected, so `{ a: 1, b: [Threw: …], c: 3 }` still shows everything
305
+ // that could be read.
306
+ try {
307
+ out += this._format(hole.read(), at);
308
+ }
309
+ catch (error) {
310
+ out += threw(error);
311
+ }
312
+ out += hole.tail;
313
+ }
314
+ return out;
315
+ }
316
+ /** The one-line form of a value, or `null` when it will not fit `at.budget`. */
317
+ _oneLine(value, at) {
318
+ const scalar = this._scalar(value);
319
+ if (scalar !== null)
320
+ return fitOneLine(scalar, at.budget);
321
+ const object = value;
322
+ if (at.open.has(object))
323
+ return fitOneLine("[Circular]", at.budget);
324
+ at.open.add(object);
325
+ try {
326
+ const shape = this._shape(object, at.level, at.budget);
327
+ if (shape.kind === "text")
328
+ return fitOneLine(shape.text, at.budget);
329
+ return this._joinOneLine(shape, { level: at.level + 1, budget: at.budget, open: at.open });
330
+ }
331
+ catch (error) {
332
+ return fitOneLine(threw(error), at.budget);
333
+ }
334
+ finally {
335
+ at.open.delete(object);
336
+ }
337
+ }
338
+ /**
339
+ * A container's positions on one line, or `null` as soon as they overrun.
340
+ *
341
+ * The budget is spent as it goes and each position is asked for only what is
342
+ * left, so a subtree that has already outgrown the line is abandoned where it
343
+ * outgrew it rather than formatted in full and then measured.
344
+ *
345
+ * The brackets are charged before anything is read, and that ordering is what
346
+ * bounds the traversal: a budget checked only against the finished text still
347
+ * reads the whole subtree to produce text it then throws away. Charged first,
348
+ * every level costs at least the two cells of its own brackets, so a probe
349
+ * descends at most `budget / 2` levels however deep the data goes.
350
+ */
351
+ _joinOneLine(shape, at) {
352
+ let used = cellLen(shape.open) + cellLen(shape.close) + 2 * cellLen(shape.pad);
353
+ if (used > at.budget)
354
+ return null;
355
+ const pieces = [];
356
+ for (const slot of shape.slots) {
357
+ used += pieces.length > 0 ? cellLen(SEPARATOR) : 0;
358
+ const piece = this._slotOneLine(slot, { ...at, budget: at.budget - used });
359
+ if (piece === null)
360
+ return null;
361
+ used += cellLen(piece);
362
+ pieces.push(piece);
363
+ }
364
+ return shape.open + shape.pad + pieces.join(SEPARATOR) + shape.pad + shape.close;
365
+ }
366
+ /** One position on one line, or `null` when any value in it will not fit. */
367
+ _slotOneLine(slot, at) {
368
+ let out = slot.head;
369
+ for (const hole of slot.holes) {
370
+ const left = at.budget - cellLen(out);
371
+ let text;
372
+ try {
373
+ text = this._oneLine(hole.read(), { ...at, budget: left });
374
+ }
375
+ catch (error) {
376
+ text = fitOneLine(threw(error), left);
377
+ }
378
+ if (text === null)
379
+ return null;
380
+ out += text + hole.tail;
381
+ }
382
+ return fitOneLine(out, at.budget);
383
+ }
384
+ _addIndentGuides(text) {
385
+ const lines = text.plain.split("\n");
386
+ let offset = 0;
387
+ for (const line of lines) {
388
+ const leadingSpaces = line.length - line.trimStart().length;
389
+ for (let i = 0; i < leadingSpaces; i += this.indent) {
390
+ if (i + offset < text.length) {
391
+ text.stylize("repr.indent", offset + i, offset + i + 1);
392
+ }
393
+ }
394
+ offset += line.length + 1; // +1 for newline
395
+ }
396
+ }
397
+ }
398
+ //# sourceMappingURL=pretty.js.map