@promptctl/rich-js 0.19.0 → 0.20.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 (53) hide show
  1. package/README.md +3 -2
  2. package/dist/core/color.d.ts +1 -0
  3. package/dist/core/color.js +3 -2
  4. package/dist/core/noise.d.ts +31 -0
  5. package/dist/core/noise.js +94 -0
  6. package/dist/core/paint.js +13 -2
  7. package/dist/core/pretty.d.ts +23 -2
  8. package/dist/core/pretty.js +54 -18
  9. package/dist/core/protocol.d.ts +2 -0
  10. package/dist/core/protocol.js +3 -2
  11. package/dist/core/selection.d.ts +12 -0
  12. package/dist/core/selection.js +14 -0
  13. package/dist/core/strip.d.ts +103 -72
  14. package/dist/core/strip.js +240 -212
  15. package/dist/core/style.js +9 -7
  16. package/dist/host/app.d.ts +68 -2
  17. package/dist/host/app.js +125 -15
  18. package/dist/host/index.d.ts +3 -1
  19. package/dist/host/index.js +1 -0
  20. package/dist/host/input.d.ts +84 -0
  21. package/dist/host/input.js +498 -0
  22. package/dist/host/terminal-host.d.ts +12 -0
  23. package/dist/host/terminal-host.js +2 -0
  24. package/dist/index.d.ts +9 -4
  25. package/dist/index.js +6 -3
  26. package/dist/node/terminal-host.d.ts +7 -0
  27. package/dist/node/terminal-host.js +7 -0
  28. package/dist/renderables/effect.d.ts +23 -8
  29. package/dist/renderables/effect.js +48 -26
  30. package/dist/renderables/effects.d.ts +252 -0
  31. package/dist/renderables/effects.js +565 -0
  32. package/dist/renderables/embed.d.ts +11 -5
  33. package/dist/renderables/embed.js +13 -6
  34. package/dist/renderables/list-view.d.ts +42 -0
  35. package/dist/renderables/list-view.js +78 -0
  36. package/dist/renderables/progress.d.ts +6 -0
  37. package/dist/renderables/progress.js +11 -4
  38. package/dist/renderables/progressBar.d.ts +22 -2
  39. package/dist/renderables/progressBar.js +51 -7
  40. package/dist/renderables/rule.d.ts +2 -2
  41. package/dist/renderables/rule.js +12 -10
  42. package/dist/renderables/table.js +5 -7
  43. package/dist/renderables/viewport.d.ts +30 -0
  44. package/dist/renderables/viewport.js +59 -3
  45. package/dist/widgets/dropdown.js +3 -3
  46. package/dist/widgets/event-router.d.ts +31 -40
  47. package/dist/widgets/event-router.js +52 -483
  48. package/dist/widgets/index.d.ts +2 -1
  49. package/dist/widgets/types.d.ts +8 -25
  50. package/dist/widgets/types.js +8 -0
  51. package/dist/widgets/widget-app.d.ts +22 -7
  52. package/dist/widgets/widget-app.js +22 -12
  53. package/package.json +22 -18
@@ -1,49 +1,38 @@
1
1
  /**
2
- * EventRouter — parses raw stdin into KeyEvent / ScreenMouseEvent values
3
- * and dispatches them to widgets via a FocusManager and the frame on screen.
2
+ * EventRouter — dispatches the keys and pointer events an `App` hears to
3
+ * widgets, via a FocusManager and the frame on screen.
4
4
  *
5
- * It reads the terminal and never sets it up: raw mode and mouse tracking are
6
- * the runtime's (`App`), which undoes them on every path out.
7
- *
8
- * [LAW:single-enforcer] ANSI escape parsing lives only here — widgets never
9
- * see raw bytes. One parser, one dispatch surface.
10
- *
11
- * [LAW:dataflow-not-control-flow] The same parse pipeline runs for every
12
- * input chunk: append → consume one event at a time until the buffer can't
13
- * yield more. The byte's value, not a side-mode, decides which event is
14
- * emitted. There is no "are we mid-sequence" mode flag — the buffer head
15
- * carries all the state we need.
16
- *
17
- * Lone-ESC handling: a bare `\x1b` is ambiguous (escape key vs. start of a
18
- * CSI sequence). When the buffer is drained but ends with a lone ESC, the
19
- * router defers emission via setTimeout(0). The next chunk cancels the timer
20
- * if it extends the sequence. Tests can call `flush()` to drain synchronously.
5
+ * It parses nothing and reads no terminal: `App` owns the one parser over its
6
+ * host's input (`host/input`), and `WidgetApp` hands this what the app hears.
21
7
  */
22
8
  import { KeyEvent } from "./types.js";
23
- import type { FrameSource, ScreenMouseEvent, KeyHandlerOptions } from "./types.js";
9
+ import type { FrameSource, KeyHandlerOptions } from "./types.js";
24
10
  import type { Unsubscribe } from "../core/subscription.js";
25
- import type { TerminalHost } from "../host/terminal-host.js";
11
+ import type { KeyPress } from "../host/input.js";
12
+ import type { AppMouseEvent } from "../host/app.js";
13
+ import type { Wheel } from "../host/app.js";
26
14
  type KeyHandler = (event: KeyEvent) => void;
27
15
  export interface EventRouterOptions {
28
16
  source: FrameSource;
29
- /** The I/O capability the router reads input from. */
30
- host: TerminalHost;
17
+ /** Whether a left-button press focuses the widget under it before it hears the press. */
18
+ focusOnClick: boolean;
31
19
  }
32
20
  export declare class EventRouter {
33
21
  private readonly source;
34
- private readonly host;
35
- private buffer;
36
- private running;
37
- private dataUnsubscribe;
38
- private escTimer;
22
+ private readonly focusOnClick;
39
23
  private captured;
40
24
  private pointer;
41
25
  private hoveredWidget;
42
26
  private readonly keyChain;
43
27
  private readonly mouseHandlers;
44
28
  constructor(options: EventRouterOptions);
45
- start(): void;
46
- stop(): void;
29
+ /**
30
+ * Drop what a run left behind — a captured drag, the pointer, hover — so the
31
+ * router is in the shape a fresh construction would be.
32
+ *
33
+ * [LAW:one-source-of-truth] Per-session state belongs to one session.
34
+ */
35
+ reset(): void;
47
36
  /**
48
37
  * Read hover again off the frame just painted: under a pointer that has not
49
38
  * moved, a widget may have gone, moved, or arrived.
@@ -53,17 +42,19 @@ export declare class EventRouter {
53
42
  */
54
43
  framePainted(): void;
55
44
  onKey(handler: KeyHandler, options?: KeyHandlerOptions): Unsubscribe;
56
- onMouse(handler: (event: ScreenMouseEvent) => void): Unsubscribe;
57
- /** Feed a chunk of bytes (or a string of bytes) into the parser. */
58
- feed(chunk: Uint8Array | string): void;
59
- /** Force any pending lone ESC out of the buffer. */
60
- flush(): void;
61
- private drain;
62
- private consumeOne;
63
- private consumePrintable;
64
- private consumeEscape;
65
- private consumeSS3;
66
- private consumeCSI;
45
+ onMouse(handler: (event: AppMouseEvent) => void): Unsubscribe;
46
+ /** Route a key the app heard. */
47
+ key(press: KeyPress): void;
48
+ /** Route a pointer event the app heard. */
49
+ mouse(event: AppMouseEvent): void;
50
+ /**
51
+ * Scroll the innermost viewport under the pointer that can move, a line a
52
+ * notch, past any widget it shows there and whatever a drag captured.
53
+ * Whether one moved is the answer: with none, the app passes the wheel
54
+ * outward.
55
+ */
56
+ wheel({ x, y, lines }: Wheel): boolean;
57
+ private point;
67
58
  private dispatchKey;
68
59
  private dispatchMouse;
69
60
  private hover;