@effect-tui/core 0.1.1 → 0.1.5
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 +31 -11
- package/dist/ansi.d.ts +127 -32
- package/dist/ansi.d.ts.map +1 -1
- package/dist/ansi.js +159 -37
- package/dist/ansi.js.map +1 -1
- package/dist/colors.d.ts +139 -0
- package/dist/colors.d.ts.map +1 -0
- package/dist/colors.js +339 -0
- package/dist/colors.js.map +1 -0
- package/dist/index.d.ts +6 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -11
- package/dist/index.js.map +1 -1
- package/dist/keys.d.ts +21 -0
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +199 -58
- package/dist/keys.js.map +1 -1
- package/dist/layout/axis-helpers.d.ts +19 -0
- package/dist/layout/axis-helpers.d.ts.map +1 -0
- package/dist/layout/axis-helpers.js +19 -0
- package/dist/layout/axis-helpers.js.map +1 -0
- package/dist/output.d.ts +59 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +142 -0
- package/dist/output.js.map +1 -0
- package/dist/render/buffer.d.ts.map +1 -1
- package/dist/render/buffer.js +6 -25
- package/dist/render/buffer.js.map +1 -1
- package/dist/render/graphemes.d.ts +15 -0
- package/dist/render/graphemes.d.ts.map +1 -0
- package/dist/render/graphemes.js +28 -0
- package/dist/render/graphemes.js.map +1 -0
- package/dist/render/measure.d.ts +1 -0
- package/dist/render/measure.d.ts.map +1 -1
- package/dist/render/measure.js +14 -36
- package/dist/render/measure.js.map +1 -1
- package/dist/render/palette.d.ts.map +1 -1
- package/dist/render/palette.js +26 -1
- package/dist/render/palette.js.map +1 -1
- package/dist/render/segmenter.d.ts +8 -0
- package/dist/render/segmenter.d.ts.map +1 -0
- package/dist/render/segmenter.js +23 -0
- package/dist/render/segmenter.js.map +1 -0
- package/dist/render/surface.d.ts +6 -32
- package/dist/render/surface.d.ts.map +1 -1
- package/dist/render/surface.js +11 -80
- package/dist/render/surface.js.map +1 -1
- package/dist/runtime/backend_node.d.ts.map +1 -1
- package/dist/runtime/backend_node.js.map +1 -1
- package/dist/tailwind-colors.d.ts +291 -0
- package/dist/tailwind-colors.d.ts.map +1 -0
- package/dist/tailwind-colors.js +291 -0
- package/dist/tailwind-colors.js.map +1 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +55 -55
- package/src/ansi.ts +201 -73
- package/src/colors.ts +468 -0
- package/src/index.ts +28 -14
- package/src/keys.ts +467 -287
- package/src/layout/axis-helpers.ts +33 -0
- package/src/output.ts +175 -0
- package/src/render/buffer.ts +161 -184
- package/src/render/graphemes.ts +34 -0
- package/src/render/measure.ts +15 -38
- package/src/render/palette.ts +98 -77
- package/src/render/segmenter.ts +27 -0
- package/src/render/surface.ts +139 -225
- package/src/runtime/backend_node.ts +71 -71
- package/src/tailwind-colors.ts +295 -0
- package/src/types.ts +18 -0
- package/dist/anim.d.ts +0 -4
- package/dist/anim.d.ts.map +0 -1
- package/dist/anim.js +0 -5
- package/dist/anim.js.map +0 -1
- package/dist/layout/linearStack.d.ts +0 -17
- package/dist/layout/linearStack.d.ts.map +0 -1
- package/dist/layout/linearStack.js +0 -86
- package/dist/layout/linearStack.js.map +0 -1
- package/dist/motion-value.d.ts +0 -58
- package/dist/motion-value.d.ts.map +0 -1
- package/dist/motion-value.js +0 -250
- package/dist/motion-value.js.map +0 -1
- package/dist/present/display.d.ts +0 -58
- package/dist/present/display.d.ts.map +0 -1
- package/dist/present/display.js +0 -168
- package/dist/present/display.js.map +0 -1
- package/dist/present/writers/fullscreen.d.ts +0 -19
- package/dist/present/writers/fullscreen.d.ts.map +0 -1
- package/dist/present/writers/fullscreen.js +0 -55
- package/dist/present/writers/fullscreen.js.map +0 -1
- package/dist/present/writers/inline.d.ts +0 -20
- package/dist/present/writers/inline.d.ts.map +0 -1
- package/dist/present/writers/inline.js +0 -92
- package/dist/present/writers/inline.js.map +0 -1
- package/dist/render/color-utils.d.ts +0 -18
- package/dist/render/color-utils.d.ts.map +0 -1
- package/dist/render/color-utils.js +0 -58
- package/dist/render/color-utils.js.map +0 -1
- package/dist/render/diff.d.ts +0 -30
- package/dist/render/diff.d.ts.map +0 -1
- package/dist/render/diff.js +0 -83
- package/dist/render/diff.js.map +0 -1
- package/dist/spring-physics.d.ts +0 -36
- package/dist/spring-physics.d.ts.map +0 -1
- package/dist/spring-physics.js +0 -113
- package/dist/spring-physics.js.map +0 -1
- package/dist/spring.d.ts +0 -73
- package/dist/spring.d.ts.map +0 -1
- package/dist/spring.js +0 -136
- package/dist/spring.js.map +0 -1
- package/dist/ui/containers/canvas.d.ts +0 -13
- package/dist/ui/containers/canvas.d.ts.map +0 -1
- package/dist/ui/containers/canvas.js +0 -16
- package/dist/ui/containers/canvas.js.map +0 -1
- package/dist/ui/containers/geometry-reader.d.ts +0 -17
- package/dist/ui/containers/geometry-reader.d.ts.map +0 -1
- package/dist/ui/containers/geometry-reader.js +0 -24
- package/dist/ui/containers/geometry-reader.js.map +0 -1
- package/dist/ui/containers/hstack.d.ts +0 -12
- package/dist/ui/containers/hstack.d.ts.map +0 -1
- package/dist/ui/containers/hstack.js +0 -28
- package/dist/ui/containers/hstack.js.map +0 -1
- package/dist/ui/containers/scroll.d.ts +0 -28
- package/dist/ui/containers/scroll.d.ts.map +0 -1
- package/dist/ui/containers/scroll.js +0 -97
- package/dist/ui/containers/scroll.js.map +0 -1
- package/dist/ui/containers/shared.d.ts +0 -12
- package/dist/ui/containers/shared.d.ts.map +0 -1
- package/dist/ui/containers/shared.js +0 -19
- package/dist/ui/containers/shared.js.map +0 -1
- package/dist/ui/containers/vstack.d.ts +0 -12
- package/dist/ui/containers/vstack.d.ts.map +0 -1
- package/dist/ui/containers/vstack.js +0 -28
- package/dist/ui/containers/vstack.js.map +0 -1
- package/dist/ui/containers/zstack.d.ts +0 -14
- package/dist/ui/containers/zstack.d.ts.map +0 -1
- package/dist/ui/containers/zstack.js +0 -36
- package/dist/ui/containers/zstack.js.map +0 -1
- package/dist/ui/core/geometry-store.d.ts +0 -22
- package/dist/ui/core/geometry-store.d.ts.map +0 -1
- package/dist/ui/core/geometry-store.js +0 -29
- package/dist/ui/core/geometry-store.js.map +0 -1
- package/dist/ui/core/geometry.d.ts +0 -34
- package/dist/ui/core/geometry.d.ts.map +0 -1
- package/dist/ui/core/geometry.js +0 -14
- package/dist/ui/core/geometry.js.map +0 -1
- package/dist/ui/core/view.d.ts +0 -25
- package/dist/ui/core/view.d.ts.map +0 -1
- package/dist/ui/core/view.js +0 -34
- package/dist/ui/core/view.js.map +0 -1
- package/dist/ui/index.d.ts +0 -44
- package/dist/ui/index.d.ts.map +0 -1
- package/dist/ui/index.js +0 -39
- package/dist/ui/index.js.map +0 -1
- package/dist/ui/inlinetext.d.ts +0 -24
- package/dist/ui/inlinetext.d.ts.map +0 -1
- package/dist/ui/inlinetext.js +0 -131
- package/dist/ui/inlinetext.js.map +0 -1
- package/dist/ui/install.d.ts +0 -22
- package/dist/ui/install.d.ts.map +0 -1
- package/dist/ui/install.js +0 -66
- package/dist/ui/install.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -40
- package/dist/ui/markdown.d.ts.map +0 -1
- package/dist/ui/markdown.js +0 -351
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/modifiers/border.d.ts +0 -33
- package/dist/ui/modifiers/border.d.ts.map +0 -1
- package/dist/ui/modifiers/border.js +0 -82
- package/dist/ui/modifiers/border.js.map +0 -1
- package/dist/ui/modifiers/fill.d.ts +0 -14
- package/dist/ui/modifiers/fill.d.ts.map +0 -1
- package/dist/ui/modifiers/fill.js +0 -25
- package/dist/ui/modifiers/fill.js.map +0 -1
- package/dist/ui/modifiers/frame.d.ts +0 -23
- package/dist/ui/modifiers/frame.d.ts.map +0 -1
- package/dist/ui/modifiers/frame.js +0 -54
- package/dist/ui/modifiers/frame.js.map +0 -1
- package/dist/ui/modifiers/offset.d.ts +0 -15
- package/dist/ui/modifiers/offset.d.ts.map +0 -1
- package/dist/ui/modifiers/offset.js +0 -21
- package/dist/ui/modifiers/offset.js.map +0 -1
- package/dist/ui/modifiers/opacity.d.ts +0 -15
- package/dist/ui/modifiers/opacity.d.ts.map +0 -1
- package/dist/ui/modifiers/opacity.js +0 -95
- package/dist/ui/modifiers/opacity.js.map +0 -1
- package/dist/ui/modifiers/padding.d.ts +0 -20
- package/dist/ui/modifiers/padding.d.ts.map +0 -1
- package/dist/ui/modifiers/padding.js +0 -36
- package/dist/ui/modifiers/padding.js.map +0 -1
- package/dist/ui/modifiers/styled.d.ts +0 -14
- package/dist/ui/modifiers/styled.d.ts.map +0 -1
- package/dist/ui/modifiers/styled.js +0 -26
- package/dist/ui/modifiers/styled.js.map +0 -1
- package/dist/ui/primitives/rectangle.d.ts +0 -15
- package/dist/ui/primitives/rectangle.d.ts.map +0 -1
- package/dist/ui/primitives/rectangle.js +0 -23
- package/dist/ui/primitives/rectangle.js.map +0 -1
- package/dist/ui/primitives/spacer.d.ts +0 -13
- package/dist/ui/primitives/spacer.d.ts.map +0 -1
- package/dist/ui/primitives/spacer.js +0 -16
- package/dist/ui/primitives/spacer.js.map +0 -1
- package/dist/ui/primitives/text.d.ts +0 -15
- package/dist/ui/primitives/text.d.ts.map +0 -1
- package/dist/ui/primitives/text.js +0 -79
- package/dist/ui/primitives/text.js.map +0 -1
- package/dist/ui/primitives/wrapped-text.d.ts +0 -30
- package/dist/ui/primitives/wrapped-text.d.ts.map +0 -1
- package/dist/ui/primitives/wrapped-text.js +0 -117
- package/dist/ui/primitives/wrapped-text.js.map +0 -1
- package/dist/ui/shinytext.d.ts +0 -66
- package/dist/ui/shinytext.d.ts.map +0 -1
- package/dist/ui/shinytext.js +0 -99
- package/dist/ui/shinytext.js.map +0 -1
- package/dist/ui/text/layout.d.ts +0 -35
- package/dist/ui/text/layout.d.ts.map +0 -1
- package/dist/ui/text/layout.js +0 -102
- package/dist/ui/text/layout.js.map +0 -1
- package/dist/ui/textinput.d.ts +0 -140
- package/dist/ui/textinput.d.ts.map +0 -1
- package/dist/ui/textinput.js +0 -402
- package/dist/ui/textinput.js.map +0 -1
- package/dist/ui/view-constructors.d.ts +0 -72
- package/dist/ui/view-constructors.d.ts.map +0 -1
- package/dist/ui/view-constructors.js +0 -74
- package/dist/ui/view-constructors.js.map +0 -1
- package/src/anim.ts +0 -5
- package/src/layout/linearStack.ts +0 -115
- package/src/motion-value.ts +0 -335
- package/src/present/display.ts +0 -206
- package/src/present/writers/fullscreen.ts +0 -58
- package/src/present/writers/inline.ts +0 -101
- package/src/render/color-utils.ts +0 -60
- package/src/render/diff.ts +0 -95
- package/src/spring-physics.ts +0 -151
- package/src/spring.ts +0 -234
- package/src/ui/__snapshots__/wrappedtext.test.ts.snap +0 -57
- package/src/ui/containers/canvas.ts +0 -18
- package/src/ui/containers/geometry-reader.ts +0 -32
- package/src/ui/containers/hstack.ts +0 -33
- package/src/ui/containers/scroll.ts +0 -106
- package/src/ui/containers/shared.ts +0 -27
- package/src/ui/containers/vstack.ts +0 -34
- package/src/ui/containers/zstack.ts +0 -37
- package/src/ui/core/geometry-store.ts +0 -42
- package/src/ui/core/geometry.ts +0 -30
- package/src/ui/core/view.ts +0 -49
- package/src/ui/index.ts +0 -84
- package/src/ui/inlinetext.ts +0 -135
- package/src/ui/install.ts +0 -110
- package/src/ui/markdown.test.ts +0 -74
- package/src/ui/markdown.ts +0 -388
- package/src/ui/modifiers/border.ts +0 -100
- package/src/ui/modifiers/fill.ts +0 -28
- package/src/ui/modifiers/frame.ts +0 -74
- package/src/ui/modifiers/offset.ts +0 -23
- package/src/ui/modifiers/opacity.ts +0 -93
- package/src/ui/modifiers/padding.ts +0 -53
- package/src/ui/modifiers/styled.ts +0 -31
- package/src/ui/primitives/rectangle.ts +0 -25
- package/src/ui/primitives/spacer.ts +0 -18
- package/src/ui/primitives/text.ts +0 -85
- package/src/ui/primitives/wrapped-text.ts +0 -131
- package/src/ui/shinytext.ts +0 -159
- package/src/ui/text/layout.ts +0 -119
- package/src/ui/textinput.ts +0 -496
- package/src/ui/view-constructors.ts +0 -96
- package/src/ui/wrappedtext.test.ts +0 -138
package/README.md
CHANGED
|
@@ -63,27 +63,47 @@ const surface = new Surface(process.stdout)
|
|
|
63
63
|
surface.render(buffer)
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
##
|
|
66
|
+
## Animation
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
### MotionValue
|
|
69
|
+
|
|
70
|
+
Observable values with spring physics (matches framer-motion):
|
|
69
71
|
|
|
70
72
|
```typescript
|
|
71
|
-
import {
|
|
73
|
+
import { motionValue } from "@effect-tui/core"
|
|
74
|
+
|
|
75
|
+
// Create motion value
|
|
76
|
+
const mv = motionValue(0)
|
|
77
|
+
|
|
78
|
+
// Subscribe to changes
|
|
79
|
+
mv.onChange((value) => console.log(value))
|
|
72
80
|
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
const animated = Spring.to(spring, 100, { visualDuration: 0.35, bounce: 0.2 })
|
|
81
|
+
// Animate to target with spring physics
|
|
82
|
+
mv.animate(100, { duration: 0.35, bounce: 0.2 })
|
|
76
83
|
|
|
77
|
-
//
|
|
78
|
-
const
|
|
79
|
-
const value = Spring.value(next) // Current position
|
|
80
|
-
const done = Spring.settled(next) // Animation complete?
|
|
84
|
+
// Read current value
|
|
85
|
+
const value = mv.get()
|
|
81
86
|
```
|
|
82
87
|
|
|
83
88
|
**Parameters:**
|
|
84
|
-
- `
|
|
89
|
+
- `duration` - Time to reach ~99% of target (seconds)
|
|
85
90
|
- `bounce` - Overshoot amount (0 = no bounce, 0.5 = bouncy)
|
|
86
91
|
|
|
92
|
+
### Step
|
|
93
|
+
|
|
94
|
+
Frame-based discrete animation (used by ShinyText):
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { Step } from "@effect-tui/core"
|
|
98
|
+
|
|
99
|
+
// Create stepper cycling through 10 frames at 80ms/frame
|
|
100
|
+
let stepper = Step.init(10, 80)
|
|
101
|
+
|
|
102
|
+
// Tick with current timestamp
|
|
103
|
+
stepper = Step.tick(stepper, Date.now())
|
|
104
|
+
console.log(stepper.index) // Current frame index
|
|
105
|
+
```
|
|
106
|
+
|
|
87
107
|
## Related
|
|
88
108
|
|
|
89
109
|
- [@effect-tui/react](https://github.com/kitlangton/effect-tui/tree/main/packages/effect-tui-react) - React renderer for terminal UIs
|
package/dist/ansi.d.ts
CHANGED
|
@@ -1,69 +1,164 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** ANSI escape sequence primitives */
|
|
2
2
|
export declare const ANSI: {
|
|
3
|
-
/** Reset all attributes */
|
|
4
|
-
readonly reset: "\u001B[0m";
|
|
5
3
|
/** Cursor control */
|
|
6
4
|
readonly cursor: {
|
|
5
|
+
/** Move cursor to 1-based row/column position */
|
|
6
|
+
readonly to: (x: number, y: number) => string;
|
|
7
|
+
/** Move cursor to 1-based column on current row */
|
|
8
|
+
readonly toCol: (col: number) => string;
|
|
9
|
+
/** Move cursor up by n rows */
|
|
10
|
+
readonly up: (n: number) => string;
|
|
11
|
+
/** Move cursor down by n rows */
|
|
12
|
+
readonly down: (n: number) => string;
|
|
7
13
|
/** Hide cursor */
|
|
8
14
|
readonly hide: "\u001B[?25l";
|
|
9
15
|
/** Show cursor */
|
|
10
16
|
readonly show: "\u001B[?25h";
|
|
17
|
+
/** Move cursor to start of current line */
|
|
18
|
+
readonly startOfLine: "\r";
|
|
11
19
|
/** Move cursor to home position (1,1) */
|
|
12
20
|
readonly home: "\u001B[H";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
};
|
|
22
|
+
/** Line control */
|
|
23
|
+
readonly line: {
|
|
24
|
+
/** Clear entire line */
|
|
25
|
+
readonly clear: "\u001B[2K";
|
|
26
|
+
/** Clear from cursor to end of line */
|
|
27
|
+
readonly clearToEnd: "\u001B[0K";
|
|
17
28
|
};
|
|
18
29
|
/** Screen control */
|
|
19
30
|
readonly screen: {
|
|
20
31
|
/** Enter alternate screen buffer */
|
|
21
|
-
readonly
|
|
32
|
+
readonly enterAlt: "\u001B[?1049h";
|
|
22
33
|
/** Exit alternate screen buffer */
|
|
23
|
-
readonly
|
|
24
|
-
/** Clear entire
|
|
34
|
+
readonly exitAlt: "\u001B[?1049l";
|
|
35
|
+
/** Clear entire screen */
|
|
25
36
|
readonly clear: "\u001B[2J";
|
|
37
|
+
/** Clear from cursor to end of screen */
|
|
38
|
+
readonly clearToEnd: "\u001B[J";
|
|
26
39
|
/** Clear scrollback buffer */
|
|
27
40
|
readonly clearScrollback: "\u001B[3J";
|
|
28
41
|
};
|
|
42
|
+
/** Mouse reporting */
|
|
43
|
+
readonly mouse: {
|
|
44
|
+
/** Enable SGR extended mouse mode with any-event tracking (scroll wheel support) */
|
|
45
|
+
readonly enable: "\u001B[?1003h\u001B[?1006h";
|
|
46
|
+
/** Disable mouse tracking */
|
|
47
|
+
readonly disable: "\u001B[?1006l\u001B[?1003l";
|
|
48
|
+
};
|
|
49
|
+
/** Bracketed paste mode */
|
|
50
|
+
readonly paste: {
|
|
51
|
+
/** Enable bracketed paste */
|
|
52
|
+
readonly enable: "\u001B[?2004h";
|
|
53
|
+
/** Disable bracketed paste */
|
|
54
|
+
readonly disable: "\u001B[?2004l";
|
|
55
|
+
/** Paste start marker */
|
|
56
|
+
readonly startMarker: "\u001B[200~";
|
|
57
|
+
/** Paste end marker */
|
|
58
|
+
readonly endMarker: "\u001B[201~";
|
|
59
|
+
};
|
|
60
|
+
/** Line reflow control (DEC mode 2028 - limited terminal support) */
|
|
61
|
+
readonly reflow: {
|
|
62
|
+
/** Disable line reflow on resize (Contour, some others) */
|
|
63
|
+
readonly disable: "\u001B[?2028l";
|
|
64
|
+
/** Enable line reflow on resize (default) */
|
|
65
|
+
readonly enable: "\u001B[?2028h";
|
|
66
|
+
};
|
|
67
|
+
/** Scroll region control (DECSTBM) */
|
|
68
|
+
readonly scrollRegion: {
|
|
69
|
+
/** Set scroll region to rows [top, bottom] (1-indexed, inclusive) */
|
|
70
|
+
readonly set: (top: number, bottom: number) => string;
|
|
71
|
+
/** Reset scroll region to full screen */
|
|
72
|
+
readonly reset: "\u001B[r";
|
|
73
|
+
};
|
|
74
|
+
/** Line insertion/deletion */
|
|
75
|
+
readonly lines: {
|
|
76
|
+
/** Insert n blank lines at cursor, pushing content down (IL) */
|
|
77
|
+
readonly insert: (n: number) => string;
|
|
78
|
+
/** Delete n lines at cursor, pulling content up (DL) */
|
|
79
|
+
readonly delete: (n: number) => string;
|
|
80
|
+
};
|
|
81
|
+
/** Cursor save/restore (DECSC/DECRC) */
|
|
82
|
+
readonly cursorState: {
|
|
83
|
+
/** Save cursor position and attributes */
|
|
84
|
+
readonly save: "\u001B7";
|
|
85
|
+
/** Restore cursor position and attributes */
|
|
86
|
+
readonly restore: "\u001B8";
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Kitty keyboard protocol
|
|
90
|
+
* @see https://sw.kovidgoyal.net/kitty/keyboard-protocol/
|
|
91
|
+
* Enables enhanced key reporting with modifier detection for Ctrl+Shift+key combos
|
|
92
|
+
*/
|
|
93
|
+
readonly keyboard: {
|
|
94
|
+
/**
|
|
95
|
+
* Enable Kitty keyboard protocol with flags.
|
|
96
|
+
* Flag 1 (disambiguate): Reports Ctrl+C as CSI sequence instead of raw ETX,
|
|
97
|
+
* allowing detection of Ctrl+Shift+C vs Ctrl+C.
|
|
98
|
+
* Supported by: Kitty, iTerm2 3.5+, WezTerm, Ghostty, foot, Contour, rio
|
|
99
|
+
* NOTE: Many terminals intercept Ctrl+Shift+C for their own copy - may need
|
|
100
|
+
* to configure terminal or use different keybinding.
|
|
101
|
+
*/
|
|
102
|
+
readonly enable: (flags?: number) => string;
|
|
103
|
+
/** Disable/pop Kitty keyboard protocol */
|
|
104
|
+
readonly disable: "\u001B[<u";
|
|
105
|
+
/** Query current keyboard mode (response: CSI ? flags u) */
|
|
106
|
+
readonly query: "\u001B[?u";
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* xterm modifyOtherKeys mode
|
|
110
|
+
* @see https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
|
|
111
|
+
* Alternative to Kitty protocol, supported by xterm and some other terminals.
|
|
112
|
+
*/
|
|
113
|
+
readonly modifyOtherKeys: {
|
|
114
|
+
/** Enable mode 2 (full modifier reporting) */
|
|
115
|
+
readonly enable: "\u001B[>4;2m";
|
|
116
|
+
/** Disable modifyOtherKeys */
|
|
117
|
+
readonly disable: "\u001B[>4;0m";
|
|
118
|
+
};
|
|
119
|
+
/** Style/SGR reset */
|
|
120
|
+
readonly resetStyle: "\u001B[0m";
|
|
121
|
+
/** Build style SGR sequence */
|
|
122
|
+
readonly style: (s: {
|
|
123
|
+
fg?: number;
|
|
124
|
+
bg?: number;
|
|
125
|
+
bold?: boolean;
|
|
126
|
+
italic?: boolean;
|
|
127
|
+
underline?: boolean;
|
|
128
|
+
inverse?: boolean;
|
|
129
|
+
}) => string;
|
|
29
130
|
/** Scrolling */
|
|
30
131
|
readonly scroll: {
|
|
31
132
|
/** Scroll up by n lines */
|
|
32
133
|
readonly up: (n: number) => string;
|
|
33
134
|
};
|
|
34
|
-
/** Device Status Reports
|
|
135
|
+
/** Device Status Reports */
|
|
35
136
|
readonly report: {
|
|
36
|
-
/**
|
|
137
|
+
/** Request cursor position (response: ESC [ row ; col R) */
|
|
37
138
|
readonly cursorPosition: "\u001B[6n";
|
|
38
139
|
};
|
|
39
|
-
/** Bracketed paste mode */
|
|
40
|
-
readonly paste: {
|
|
41
|
-
readonly bracketed: {
|
|
42
|
-
readonly on: "\u001B[?2004h";
|
|
43
|
-
readonly off: "\u001B[?2004l";
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
/** Mouse reporting toggles */
|
|
47
|
-
readonly mouse: {
|
|
48
|
-
/** Enable button tracking and SGR coordinates */
|
|
49
|
-
readonly on: "\u001B[?1002h\u001B[?1006h";
|
|
50
|
-
/** Disable SGR coords and button tracking */
|
|
51
|
-
readonly off: "\u001B[?1006l\u001B[?1002l";
|
|
52
|
-
};
|
|
53
140
|
};
|
|
54
|
-
/**
|
|
141
|
+
/** High-level terminal control utilities (compositions of ANSI primitives) */
|
|
55
142
|
export declare const Terminal: {
|
|
56
|
-
/** Enter full-screen mode: alternate screen + hide cursor */
|
|
143
|
+
/** Enter full-screen mode: alternate screen + clear + hide cursor */
|
|
57
144
|
readonly enterFullscreen: string;
|
|
58
|
-
/** Exit full-screen mode:
|
|
145
|
+
/** Exit full-screen mode: show cursor + exit alternate screen */
|
|
59
146
|
readonly exitFullscreen: string;
|
|
147
|
+
/** Hide cursor */
|
|
148
|
+
readonly hideCursor: "\u001B[?25l";
|
|
149
|
+
/** Show cursor */
|
|
150
|
+
readonly showCursor: "\u001B[?25h";
|
|
60
151
|
/** Clear screen and move cursor to home */
|
|
61
152
|
readonly clearAndHome: string;
|
|
62
|
-
/**
|
|
153
|
+
/** Enable bracketed paste mode */
|
|
63
154
|
readonly bracketedPasteOn: "\u001B[?2004h";
|
|
155
|
+
/** Disable bracketed paste mode */
|
|
64
156
|
readonly bracketedPasteOff: "\u001B[?2004l";
|
|
65
|
-
|
|
66
|
-
readonly
|
|
157
|
+
/** Enable mouse tracking */
|
|
158
|
+
readonly mouseOn: "\u001B[?1003h\u001B[?1006h";
|
|
159
|
+
/** Disable mouse tracking */
|
|
160
|
+
readonly mouseOff: "\u001B[?1006l\u001B[?1003l";
|
|
161
|
+
/** Request cursor position report */
|
|
67
162
|
readonly reportCursorPosition: "\u001B[6n";
|
|
68
163
|
};
|
|
69
164
|
//# sourceMappingURL=ansi.d.ts.map
|
package/dist/ansi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ansi.d.ts","sourceRoot":"","sources":["../src/ansi.ts"],"names":[],"mappings":"AAKA,
|
|
1
|
+
{"version":3,"file":"ansi.d.ts","sourceRoot":"","sources":["../src/ans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AGf,4BAA4B;;QAE3B,4DAA4D;;;CAGpD,CAAA;AAEV,8EAA8E;AAC9E,eAAO,MAAM,QAAQ;IACpB,qEAAqE;;IAErE,iEAAiE;;IAEjE,kBAAkB;;IAElB,kBAAkB;;IAElB,2CAA2C;;IAE3C,kCAAkC;;IAElC,mCAAmC;;IAEnC,4BAA4B;;IAE5B,6BAA6B;;IAE7B,qCAAqC;;CAE5B,CAAA"}
|
package/dist/ansi.js
CHANGED
|
@@ -1,72 +1,194 @@
|
|
|
1
|
-
// ANSI escape sequences
|
|
1
|
+
// ansi.ts — ANSI escape sequences for terminal control
|
|
2
2
|
/** CSI prefix (ESC [) */
|
|
3
3
|
const CSI = "\x1b[";
|
|
4
|
-
/**
|
|
4
|
+
/** ANSI escape sequence primitives */
|
|
5
5
|
export const ANSI = {
|
|
6
|
-
/** Reset all attributes */
|
|
7
|
-
reset: `${CSI}0m`,
|
|
8
6
|
/** Cursor control */
|
|
9
7
|
cursor: {
|
|
8
|
+
/** Move cursor to 1-based row/column position */
|
|
9
|
+
to: (x, y) => `${CSI}${y};${x}H`,
|
|
10
|
+
/** Move cursor to 1-based column on current row */
|
|
11
|
+
toCol: (col) => `${CSI}${col}G`,
|
|
12
|
+
/** Move cursor up by n rows */
|
|
13
|
+
up: (n) => (n > 0 ? `${CSI}${n}A` : ""),
|
|
14
|
+
/** Move cursor down by n rows */
|
|
15
|
+
down: (n) => (n > 0 ? `${CSI}${n}B` : ""),
|
|
10
16
|
/** Hide cursor */
|
|
11
17
|
hide: `${CSI}?25l`,
|
|
12
18
|
/** Show cursor */
|
|
13
19
|
show: `${CSI}?25h`,
|
|
20
|
+
/** Move cursor to start of current line */
|
|
21
|
+
startOfLine: "\r",
|
|
14
22
|
/** Move cursor to home position (1,1) */
|
|
15
23
|
home: `${CSI}H`,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
},
|
|
25
|
+
/** Line control */
|
|
26
|
+
line: {
|
|
27
|
+
/** Clear entire line */
|
|
28
|
+
clear: `${CSI}2K`,
|
|
29
|
+
/** Clear from cursor to end of line */
|
|
30
|
+
clearToEnd: `${CSI}0K`,
|
|
20
31
|
},
|
|
21
32
|
/** Screen control */
|
|
22
33
|
screen: {
|
|
23
34
|
/** Enter alternate screen buffer */
|
|
24
|
-
|
|
35
|
+
enterAlt: `${CSI}?1049h`,
|
|
25
36
|
/** Exit alternate screen buffer */
|
|
26
|
-
|
|
27
|
-
/** Clear entire
|
|
37
|
+
exitAlt: `${CSI}?1049l`,
|
|
38
|
+
/** Clear entire screen */
|
|
28
39
|
clear: `${CSI}2J`,
|
|
40
|
+
/** Clear from cursor to end of screen */
|
|
41
|
+
clearToEnd: `${CSI}J`,
|
|
29
42
|
/** Clear scrollback buffer */
|
|
30
43
|
clearScrollback: `${CSI}3J`,
|
|
31
44
|
},
|
|
45
|
+
/** Mouse reporting */
|
|
46
|
+
mouse: {
|
|
47
|
+
/** Enable SGR extended mouse mode with any-event tracking (scroll wheel support) */
|
|
48
|
+
enable: `${CSI}?1003h${CSI}?1006h`,
|
|
49
|
+
/** Disable mouse tracking */
|
|
50
|
+
disable: `${CSI}?1006l${CSI}?1003l`,
|
|
51
|
+
},
|
|
52
|
+
/** Bracketed paste mode */
|
|
53
|
+
paste: {
|
|
54
|
+
/** Enable bracketed paste */
|
|
55
|
+
enable: `${CSI}?2004h`,
|
|
56
|
+
/** Disable bracketed paste */
|
|
57
|
+
disable: `${CSI}?2004l`,
|
|
58
|
+
/** Paste start marker */
|
|
59
|
+
startMarker: `${CSI}200~`,
|
|
60
|
+
/** Paste end marker */
|
|
61
|
+
endMarker: `${CSI}201~`,
|
|
62
|
+
},
|
|
63
|
+
/** Line reflow control (DEC mode 2028 - limited terminal support) */
|
|
64
|
+
reflow: {
|
|
65
|
+
/** Disable line reflow on resize (Contour, some others) */
|
|
66
|
+
disable: `${CSI}?2028l`,
|
|
67
|
+
/** Enable line reflow on resize (default) */
|
|
68
|
+
enable: `${CSI}?2028h`,
|
|
69
|
+
},
|
|
70
|
+
/** Scroll region control (DECSTBM) */
|
|
71
|
+
scrollRegion: {
|
|
72
|
+
/** Set scroll region to rows [top, bottom] (1-indexed, inclusive) */
|
|
73
|
+
set: (top, bottom) => `${CSI}${top};${bottom}r`,
|
|
74
|
+
/** Reset scroll region to full screen */
|
|
75
|
+
reset: `${CSI}r`,
|
|
76
|
+
},
|
|
77
|
+
/** Line insertion/deletion */
|
|
78
|
+
lines: {
|
|
79
|
+
/** Insert n blank lines at cursor, pushing content down (IL) */
|
|
80
|
+
insert: (n) => (n > 0 ? `${CSI}${n}L` : ""),
|
|
81
|
+
/** Delete n lines at cursor, pulling content up (DL) */
|
|
82
|
+
delete: (n) => (n > 0 ? `${CSI}${n}M` : ""),
|
|
83
|
+
},
|
|
84
|
+
/** Cursor save/restore (DECSC/DECRC) */
|
|
85
|
+
cursorState: {
|
|
86
|
+
/** Save cursor position and attributes */
|
|
87
|
+
save: "\x1b7",
|
|
88
|
+
/** Restore cursor position and attributes */
|
|
89
|
+
restore: "\x1b8",
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Kitty keyboard protocol
|
|
93
|
+
* @see https://sw.kovidgoyal.net/kitty/keyboard-protocol/
|
|
94
|
+
* Enables enhanced key reporting with modifier detection for Ctrl+Shift+key combos
|
|
95
|
+
*/
|
|
96
|
+
keyboard: {
|
|
97
|
+
/**
|
|
98
|
+
* Enable Kitty keyboard protocol with flags.
|
|
99
|
+
* Flag 1 (disambiguate): Reports Ctrl+C as CSI sequence instead of raw ETX,
|
|
100
|
+
* allowing detection of Ctrl+Shift+C vs Ctrl+C.
|
|
101
|
+
* Supported by: Kitty, iTerm2 3.5+, WezTerm, Ghostty, foot, Contour, rio
|
|
102
|
+
* NOTE: Many terminals intercept Ctrl+Shift+C for their own copy - may need
|
|
103
|
+
* to configure terminal or use different keybinding.
|
|
104
|
+
*/
|
|
105
|
+
enable: (flags = 1) => `${CSI}>${flags}u`,
|
|
106
|
+
/** Disable/pop Kitty keyboard protocol */
|
|
107
|
+
disable: `${CSI}<u`,
|
|
108
|
+
/** Query current keyboard mode (response: CSI ? flags u) */
|
|
109
|
+
query: `${CSI}?u`,
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* xterm modifyOtherKeys mode
|
|
113
|
+
* @see https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
|
|
114
|
+
* Alternative to Kitty protocol, supported by xterm and some other terminals.
|
|
115
|
+
*/
|
|
116
|
+
modifyOtherKeys: {
|
|
117
|
+
/** Enable mode 2 (full modifier reporting) */
|
|
118
|
+
enable: `${CSI}>4;2m`,
|
|
119
|
+
/** Disable modifyOtherKeys */
|
|
120
|
+
disable: `${CSI}>4;0m`,
|
|
121
|
+
},
|
|
122
|
+
/** Style/SGR reset */
|
|
123
|
+
resetStyle: `${CSI}0m`,
|
|
124
|
+
/** Build style SGR sequence */
|
|
125
|
+
style: (s) => {
|
|
126
|
+
const codes = [];
|
|
127
|
+
if (s.bold)
|
|
128
|
+
codes.push(1);
|
|
129
|
+
if (s.italic)
|
|
130
|
+
codes.push(3);
|
|
131
|
+
if (s.underline)
|
|
132
|
+
codes.push(4);
|
|
133
|
+
if (s.inverse)
|
|
134
|
+
codes.push(7);
|
|
135
|
+
if (s.fg !== undefined) {
|
|
136
|
+
if (s.fg < 256) {
|
|
137
|
+
codes.push(38, 5, s.fg);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// Truecolor: decode from packed RGB
|
|
141
|
+
const r = (s.fg >> 16) & 0xff;
|
|
142
|
+
const g = (s.fg >> 8) & 0xff;
|
|
143
|
+
const b = s.fg & 0xff;
|
|
144
|
+
codes.push(38, 2, r, g, b);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (s.bg !== undefined) {
|
|
148
|
+
if (s.bg < 256) {
|
|
149
|
+
codes.push(48, 5, s.bg);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
const r = (s.bg >> 16) & 0xff;
|
|
153
|
+
const g = (s.bg >> 8) & 0xff;
|
|
154
|
+
const b = s.bg & 0xff;
|
|
155
|
+
codes.push(48, 2, r, g, b);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return codes.length > 0 ? `${CSI}${codes.join(";")}m` : "";
|
|
159
|
+
},
|
|
32
160
|
/** Scrolling */
|
|
33
161
|
scroll: {
|
|
34
162
|
/** Scroll up by n lines */
|
|
35
163
|
up: (n) => `${CSI}${n}S`,
|
|
36
164
|
},
|
|
37
|
-
/** Device Status Reports
|
|
165
|
+
/** Device Status Reports */
|
|
38
166
|
report: {
|
|
39
|
-
/**
|
|
167
|
+
/** Request cursor position (response: ESC [ row ; col R) */
|
|
40
168
|
cursorPosition: `${CSI}6n`,
|
|
41
169
|
},
|
|
42
|
-
/** Bracketed paste mode */
|
|
43
|
-
paste: {
|
|
44
|
-
bracketed: {
|
|
45
|
-
on: `${CSI}?2004h`,
|
|
46
|
-
off: `${CSI}?2004l`,
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
/** Mouse reporting toggles */
|
|
50
|
-
mouse: {
|
|
51
|
-
/** Enable button tracking and SGR coordinates */
|
|
52
|
-
on: `${CSI}?1002h${CSI}?1006h`,
|
|
53
|
-
/** Disable SGR coords and button tracking */
|
|
54
|
-
off: `${CSI}?1006l${CSI}?1002l`,
|
|
55
|
-
},
|
|
56
170
|
};
|
|
57
|
-
/**
|
|
171
|
+
/** High-level terminal control utilities (compositions of ANSI primitives) */
|
|
58
172
|
export const Terminal = {
|
|
59
|
-
/** Enter full-screen mode: alternate screen + hide cursor */
|
|
60
|
-
enterFullscreen: ANSI.screen.
|
|
61
|
-
/** Exit full-screen mode:
|
|
62
|
-
exitFullscreen: ANSI.
|
|
173
|
+
/** Enter full-screen mode: alternate screen + clear + hide cursor */
|
|
174
|
+
enterFullscreen: ANSI.screen.enterAlt + ANSI.screen.clear + ANSI.cursor.hide,
|
|
175
|
+
/** Exit full-screen mode: show cursor + exit alternate screen */
|
|
176
|
+
exitFullscreen: ANSI.screen.exitAlt + ANSI.cursor.show,
|
|
177
|
+
/** Hide cursor */
|
|
178
|
+
hideCursor: ANSI.cursor.hide,
|
|
179
|
+
/** Show cursor */
|
|
180
|
+
showCursor: ANSI.cursor.show,
|
|
63
181
|
/** Clear screen and move cursor to home */
|
|
64
182
|
clearAndHome: ANSI.screen.clear + ANSI.cursor.home,
|
|
65
|
-
/**
|
|
66
|
-
bracketedPasteOn: ANSI.paste.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
183
|
+
/** Enable bracketed paste mode */
|
|
184
|
+
bracketedPasteOn: ANSI.paste.enable,
|
|
185
|
+
/** Disable bracketed paste mode */
|
|
186
|
+
bracketedPasteOff: ANSI.paste.disable,
|
|
187
|
+
/** Enable mouse tracking */
|
|
188
|
+
mouseOn: ANSI.mouse.enable,
|
|
189
|
+
/** Disable mouse tracking */
|
|
190
|
+
mouseOff: ANSI.mouse.disable,
|
|
191
|
+
/** Request cursor position report */
|
|
70
192
|
reportCursorPosition: ANSI.report.cursorPosition,
|
|
71
193
|
};
|
|
72
194
|
//# sourceMappingURL=ansi.js.map
|
package/dist/ansi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ansi.js","sourceRoot":"","sources":["../src/ansi.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,yBAAyB;AACzB,MAAM,GAAG,GAAG,OAAO,CAAA;AAEnB,
|
|
1
|
+
{"version":3,"file":"ansi.js","sourceRoot":"","sources":["../src/ansi.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,yBAAyB;AACzB,MAAM,GAAG,GAAG,OAAO,CAAA;AAEnB,sCAAsC;AACtC,MAAM,CAAC,MAAM,IAAI,GAAG;IACnB,qBAAqB;IACrB,MAAM,EAAE;QACP,iDAAiD;QACjD,EAAE,EAAE,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CA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ACjE,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI;IACtD,kBAAkB;IAClB,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;IAC5B,kBAAkB;IAClB,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;IAC5B,2CAA2C;IAC3C,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI;IAClD,kCAAkC;IAClC,gBAAgB,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;IACnC,mCAAmC;IACnC,iBAAiB,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;IACrC,4BAA4B;IAC5B,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;IAC1B,6BAA6B;IAC7B,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;IAC5B,qCAAqC;IACrC,oBAAoB,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc;CACvC,CAAA"}
|
package/dist/colors.d.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { type TailwindShade } from "./tailwind-colors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Hex color string: #rgb, #rrggbb, #rgba, or #rrggbbaa
|
|
4
|
+
*
|
|
5
|
+
* Note: We use `#${string}` because enumerating all valid hex digit combinations
|
|
6
|
+
* (22^6 = 113M for 6-char hex) exceeds TypeScript's union type limits.
|
|
7
|
+
* The # prefix is validated at compile time; hex digits are validated at runtime.
|
|
8
|
+
*/
|
|
9
|
+
export type HexColor = `#${string}`;
|
|
10
|
+
/** Base ANSI terminal color names */
|
|
11
|
+
export type BaseColorName = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "brightBlack" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite";
|
|
12
|
+
/**
|
|
13
|
+
* Color input type - the main public type for color props.
|
|
14
|
+
*
|
|
15
|
+
* Accepts:
|
|
16
|
+
* - Palette index: 0-255
|
|
17
|
+
* - RGB object: { r, g, b }
|
|
18
|
+
* - Named color: "red", "brightBlue", etc. (type-checked)
|
|
19
|
+
* - Hex color: "#f00", "#ff0000" (# prefix required)
|
|
20
|
+
*/
|
|
21
|
+
export type Color = number | {
|
|
22
|
+
r: number;
|
|
23
|
+
g: number;
|
|
24
|
+
b: number;
|
|
25
|
+
} | BaseColorName | HexColor;
|
|
26
|
+
/** RGBA color with alpha channel - used for color springs/interpolation */
|
|
27
|
+
export type RGBA = {
|
|
28
|
+
r: number;
|
|
29
|
+
g: number;
|
|
30
|
+
b: number;
|
|
31
|
+
a: number;
|
|
32
|
+
};
|
|
33
|
+
/** Color input for springs (includes alpha variants) */
|
|
34
|
+
export type ColorInput = string | RGBA | {
|
|
35
|
+
r: number;
|
|
36
|
+
g: number;
|
|
37
|
+
b: number;
|
|
38
|
+
};
|
|
39
|
+
/** Standard ANSI color names mapped to 256-color indices */
|
|
40
|
+
export declare const BASE_NAMES: {
|
|
41
|
+
readonly black: 0;
|
|
42
|
+
readonly red: 1;
|
|
43
|
+
readonly green: 2;
|
|
44
|
+
readonly yellow: 3;
|
|
45
|
+
readonly blue: 4;
|
|
46
|
+
readonly magenta: 5;
|
|
47
|
+
readonly cyan: 6;
|
|
48
|
+
readonly white: 7;
|
|
49
|
+
readonly brightBlack: 8;
|
|
50
|
+
readonly brightRed: 9;
|
|
51
|
+
readonly brightGreen: 10;
|
|
52
|
+
readonly brightYellow: 11;
|
|
53
|
+
readonly brightBlue: 12;
|
|
54
|
+
readonly brightMagenta: 13;
|
|
55
|
+
readonly brightCyan: 14;
|
|
56
|
+
readonly brightWhite: 15;
|
|
57
|
+
};
|
|
58
|
+
/** Clamp a number to 0-255 range */
|
|
59
|
+
export declare function clamp255(n: number): number;
|
|
60
|
+
/** Clamp a number to 0-1 range */
|
|
61
|
+
export declare function clamp1(n: number): number;
|
|
62
|
+
/** Internal type for resolved colors (palette index or RGB) */
|
|
63
|
+
type ColorValue = number | {
|
|
64
|
+
r: number;
|
|
65
|
+
g: number;
|
|
66
|
+
b: number;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Parse flexible color inputs into a resolved color value.
|
|
70
|
+
* Supports: number (0-255), {r,g,b}, "#rgb", "#rrggbb", base names, gray0-23.
|
|
71
|
+
* Used by Palette and style systems.
|
|
72
|
+
*/
|
|
73
|
+
export declare function parseColor(c: Color): ColorValue;
|
|
74
|
+
/**
|
|
75
|
+
* Parse any supported color format to RGBA (with alpha).
|
|
76
|
+
* Supports: hex (#rgb, #rrggbb, #rgba, #rrggbbaa), rgb(), rgba(), hsl(), hsla(), {r,g,b,a}.
|
|
77
|
+
* Used by color springs for interpolation.
|
|
78
|
+
*/
|
|
79
|
+
export declare function parseColorRGBA(input: ColorInput): RGBA;
|
|
80
|
+
/**
|
|
81
|
+
* Convert HSL to RGBA.
|
|
82
|
+
* h: 0-360, s: 0-100, l: 0-100, a: 0-1
|
|
83
|
+
*/
|
|
84
|
+
export declare function hslToRgba(h: number, s: number, l: number, a: number): RGBA;
|
|
85
|
+
/**
|
|
86
|
+
* Convert a 256-color index to RGB values (approximate xterm palette).
|
|
87
|
+
* 0-15: Standard ANSI, 16-231: 6x6x6 RGB cube, 232-255: Grayscale ramp
|
|
88
|
+
*/
|
|
89
|
+
export declare function idxToRGB(idx: number): {
|
|
90
|
+
r: number;
|
|
91
|
+
g: number;
|
|
92
|
+
b: number;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Check if a value looks like a color input.
|
|
96
|
+
*/
|
|
97
|
+
export declare function isColorInput(value: unknown): value is ColorInput;
|
|
98
|
+
type RGB = {
|
|
99
|
+
r: number;
|
|
100
|
+
g: number;
|
|
101
|
+
b: number;
|
|
102
|
+
};
|
|
103
|
+
type TailwindColorFn = (shade: TailwindShade) => RGB;
|
|
104
|
+
type TailwindColors = {
|
|
105
|
+
slate: TailwindColorFn;
|
|
106
|
+
gray: TailwindColorFn;
|
|
107
|
+
zinc: TailwindColorFn;
|
|
108
|
+
neutral: TailwindColorFn;
|
|
109
|
+
stone: TailwindColorFn;
|
|
110
|
+
red: TailwindColorFn;
|
|
111
|
+
orange: TailwindColorFn;
|
|
112
|
+
amber: TailwindColorFn;
|
|
113
|
+
yellow: TailwindColorFn;
|
|
114
|
+
lime: TailwindColorFn;
|
|
115
|
+
green: TailwindColorFn;
|
|
116
|
+
emerald: TailwindColorFn;
|
|
117
|
+
teal: TailwindColorFn;
|
|
118
|
+
cyan: TailwindColorFn;
|
|
119
|
+
sky: TailwindColorFn;
|
|
120
|
+
blue: TailwindColorFn;
|
|
121
|
+
indigo: TailwindColorFn;
|
|
122
|
+
violet: TailwindColorFn;
|
|
123
|
+
purple: TailwindColorFn;
|
|
124
|
+
fuchsia: TailwindColorFn;
|
|
125
|
+
pink: TailwindColorFn;
|
|
126
|
+
rose: TailwindColorFn;
|
|
127
|
+
};
|
|
128
|
+
type ColorsApi = typeof BASE_NAMES & {
|
|
129
|
+
rgb(r: number, g: number, b: number): RGB;
|
|
130
|
+
hex(hex: HexColor): RGB;
|
|
131
|
+
/** Gray - 24-level grayscale palette (0-23) */
|
|
132
|
+
gray(level: number): number;
|
|
133
|
+
/** Tailwind color palette */
|
|
134
|
+
tw: TailwindColors;
|
|
135
|
+
};
|
|
136
|
+
/** Convenience API for creating color values */
|
|
137
|
+
export declare const Colors: ColorsApi;
|
|
138
|
+
export {};
|
|
139
|
+
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,aAAa,EAA4B,MAAM,sBAAsB,CAAA;AAMnG;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,IAAI,MAAM,EAAE,CAAA;AAEnC,qCAAqC;AACrC,MAAM,MAAM,aAAa,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