@hypersocial/cli-games 0.1.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.
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Terminal color themes
3
+ *
4
+ * Provides both CSS colors (for UI) and ANSI escape codes (for terminal).
5
+ */
6
+ /**
7
+ * Available theme identifiers
8
+ */
9
+ type PhosphorMode = 'cyan' | 'cyanLight' | 'amber' | 'green' | 'white' | 'hotpink' | 'hotpinkLight' | 'blood' | 'ice' | 'iceLight' | 'bladerunner' | 'bladerunnerLight' | 'tron' | 'tronLight' | 'daylight' | 'kawaii' | 'kawaiiLight' | 'oled' | 'solarized' | 'solarizedLight' | 'nord' | 'nordLight' | 'highcontrast' | 'highcontrastLight' | 'banana' | 'cream';
10
+ /**
11
+ * Theme color definition for CSS/UI usage
12
+ */
13
+ interface ThemeColors {
14
+ /** Display name */
15
+ name: string;
16
+ /** Emoji icon for quick switcher / UI */
17
+ icon: string;
18
+ /** Primary text/accent color (hex) */
19
+ primary: string;
20
+ /** Secondary accent color (hex) */
21
+ secondary: string;
22
+ /** Subtle glow effect (rgba) */
23
+ glow: string;
24
+ /** Intense glow effect (rgba) */
25
+ glowIntense: string;
26
+ /** Background color (hex) */
27
+ bg: string;
28
+ /** Status bar background - slightly elevated from bg */
29
+ statusBarBg: string;
30
+ /** Terminal foreground color - defaults to primary if not set */
31
+ foreground?: string;
32
+ }
33
+ /**
34
+ * All theme definitions with CSS colors
35
+ */
36
+ declare const themes: Record<PhosphorMode, ThemeColors>;
37
+ /**
38
+ * Get theme colors by mode
39
+ */
40
+ declare function getTheme(mode: PhosphorMode): ThemeColors;
41
+ /**
42
+ * Get ANSI escape code for a theme
43
+ */
44
+ declare function getAnsiColor(mode: PhosphorMode): string;
45
+ /**
46
+ * Check if a theme is light (needs dark text)
47
+ */
48
+ declare function isLightTheme(mode: PhosphorMode): boolean;
49
+ /**
50
+ * Get subtle background color for game elements
51
+ */
52
+ declare function getSubtleColor(mode: PhosphorMode): string;
53
+ /**
54
+ * Get all available theme modes
55
+ */
56
+ declare function getThemeModes(): PhosphorMode[];
57
+ /**
58
+ * Check if a string is a valid theme mode
59
+ */
60
+ declare function isValidThemeMode(value: string): value is PhosphorMode;
61
+ /**
62
+ * ANSI reset code
63
+ */
64
+ declare const ANSI_RESET = "\u001B[0m";
65
+ /**
66
+ * xterm.js ITheme-compatible color set.
67
+ * Includes the 16 ANSI colors, selection, cursor, scrollbar, and foreground/background.
68
+ */
69
+ interface ITerminalTheme {
70
+ background: string;
71
+ foreground: string;
72
+ cursor: string;
73
+ cursorAccent: string;
74
+ selectionBackground: string;
75
+ selectionForeground: string;
76
+ black: string;
77
+ red: string;
78
+ green: string;
79
+ yellow: string;
80
+ blue: string;
81
+ magenta: string;
82
+ cyan: string;
83
+ white: string;
84
+ brightBlack: string;
85
+ brightRed: string;
86
+ brightGreen: string;
87
+ brightYellow: string;
88
+ brightBlue: string;
89
+ brightMagenta: string;
90
+ brightCyan: string;
91
+ brightWhite: string;
92
+ scrollbarSliderBackground: string;
93
+ scrollbarSliderHoverBackground: string;
94
+ scrollbarSliderActiveBackground: string;
95
+ }
96
+ /**
97
+ * Generate a full xterm.js theme from a PhosphorMode.
98
+ *
99
+ * Maps theme colors to the 16 ANSI colors, selection, cursor, and scrollbar.
100
+ * Light themes get inverted black/white and muted ANSI colors for readability.
101
+ */
102
+ declare function getTerminalTheme(mode: PhosphorMode): ITerminalTheme;
103
+ /**
104
+ * Transform ANSI escape sequences for light themes.
105
+ *
106
+ * Apps like Codex use true color (24-bit) escape sequences that bypass our
107
+ * theme's ANSI color settings. This intercepts dark backgrounds/foregrounds
108
+ * and inverts them so TUI apps remain readable on light backgrounds.
109
+ *
110
+ * @param data - Raw terminal data with ANSI escape sequences
111
+ * @param themeBg - The theme's background color hex (e.g., "#F5E6D3")
112
+ * @returns Transformed data with inverted colors for light themes
113
+ */
114
+ declare function transformEscapeSequencesForLightTheme(data: string, themeBg: string): string;
115
+ /**
116
+ * Transform ANSI escape sequences for dark themes with non-black backgrounds.
117
+ *
118
+ * Apps like Claude Code use true-color (24-bit) escape sequences for dark
119
+ * backgrounds (e.g. \033[48;2;0;0;0m) which bypass the ANSI color mapping.
120
+ * On dark themes where the bg isn't pure black, these show as jarring strips.
121
+ * This remaps near-black and near-white backgrounds to the theme bg.
122
+ */
123
+ declare function transformEscapeSequencesForDarkTheme(data: string, themeBg: string): string;
124
+
125
+ export { ANSI_RESET, type ITerminalTheme, type PhosphorMode, type ThemeColors, getAnsiColor, getSubtleColor, getTerminalTheme, getTheme, getThemeModes, isLightTheme, isValidThemeMode, themes, transformEscapeSequencesForDarkTheme, transformEscapeSequencesForLightTheme };
package/dist/themes.js ADDED
@@ -0,0 +1,27 @@
1
+ import {
2
+ ANSI_RESET,
3
+ getAnsiColor,
4
+ getSubtleColor,
5
+ getTerminalTheme,
6
+ getTheme,
7
+ getThemeModes,
8
+ isLightTheme,
9
+ isValidThemeMode,
10
+ themes,
11
+ transformEscapeSequencesForDarkTheme,
12
+ transformEscapeSequencesForLightTheme
13
+ } from "./chunk-AVGB32MC.js";
14
+ export {
15
+ ANSI_RESET,
16
+ getAnsiColor,
17
+ getSubtleColor,
18
+ getTerminalTheme,
19
+ getTheme,
20
+ getThemeModes,
21
+ isLightTheme,
22
+ isValidThemeMode,
23
+ themes,
24
+ transformEscapeSequencesForDarkTheme,
25
+ transformEscapeSequencesForLightTheme
26
+ };
27
+ //# sourceMappingURL=themes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@hypersocial/cli-games",
3
+ "version": "0.1.0",
4
+ "description": "Terminal games for xterm.js and CLI — snake, 2048, pong, asteroids, tetris, and more",
5
+ "license": "AGPL-3.0",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "module": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "bin": {
11
+ "cli-games": "dist/cli.js"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ },
18
+ "./themes": {
19
+ "types": "./dist/themes.d.ts",
20
+ "import": "./dist/themes.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsup",
28
+ "dev": "tsup --watch",
29
+ "typecheck": "tsc --noEmit",
30
+ "test": "vitest run",
31
+ "test:watch": "vitest",
32
+ "prepublishOnly": "npm run build"
33
+ },
34
+ "peerDependencies": {
35
+ "@xterm/xterm": ">=5.0.0"
36
+ },
37
+ "peerDependenciesMeta": {
38
+ "@xterm/xterm": {
39
+ "optional": true
40
+ }
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^25.3.2",
44
+ "@xterm/xterm": "^6.0.0",
45
+ "tsup": "^8.5.1",
46
+ "typescript": "^5.8.3",
47
+ "vitest": "^4.0.18"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/hypersocialinc/cli-games.git"
52
+ },
53
+ "keywords": [
54
+ "terminal",
55
+ "games",
56
+ "cli",
57
+ "xterm",
58
+ "snake",
59
+ "tetris",
60
+ "2048",
61
+ "pong",
62
+ "asteroids"
63
+ ],
64
+ "author": "Hypersocial Inc."
65
+ }