colorino 0.10.1 → 0.11.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.
package/dist/browser.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const determineBaseTheme = require('./shared/colorino.B4p-EEl9.cjs');
3
+ const inputValidator = require('./shared/colorino.D9xuyiJg.cjs');
4
4
 
5
5
  class BrowserColorSupportDetector {
6
6
  constructor(_window, _navigator, _overrideTheme) {
@@ -13,12 +13,12 @@ class BrowserColorSupportDetector {
13
13
  }
14
14
  getColorLevel() {
15
15
  if (!this.isBrowserEnv()) {
16
- return determineBaseTheme.ColorLevel.NO_COLOR;
16
+ return inputValidator.ColorLevel.NO_COLOR;
17
17
  }
18
18
  const userAgent = this._navigator.userAgent.toLowerCase();
19
- if (userAgent.includes("chrome")) return determineBaseTheme.ColorLevel.ANSI256;
20
- if (userAgent.includes("firefox")) return determineBaseTheme.ColorLevel.ANSI256;
21
- return determineBaseTheme.ColorLevel.ANSI256;
19
+ if (userAgent.includes("chrome")) return inputValidator.ColorLevel.ANSI256;
20
+ if (userAgent.includes("firefox")) return inputValidator.ColorLevel.ANSI256;
21
+ return inputValidator.ColorLevel.ANSI256;
22
22
  }
23
23
  getTheme() {
24
24
  if (this._overrideTheme) {
@@ -37,8 +37,8 @@ class BrowserColorSupportDetector {
37
37
  }
38
38
  }
39
39
 
40
- function createColorino(palette = {}, options = {}) {
41
- const validator = new determineBaseTheme.InputValidator();
40
+ function createColorino(userPalette = {}, options = {}) {
41
+ const validator = new inputValidator.InputValidator();
42
42
  let detectorThemeOverride;
43
43
  if (options.theme === "dark" || options.theme === "light") {
44
44
  detectorThemeOverride = options.theme;
@@ -50,14 +50,15 @@ function createColorino(palette = {}, options = {}) {
50
50
  );
51
51
  const detectedBrowserTheme = browserDetector.getTheme();
52
52
  const themeOpt = options.theme ?? "auto";
53
- const baseThemeName = determineBaseTheme.determineBaseTheme(
53
+ const baseThemeName = inputValidator.determineBaseTheme(
54
54
  themeOpt,
55
55
  detectedBrowserTheme
56
56
  );
57
- const basePalette = determineBaseTheme.themePalettes[baseThemeName];
58
- const finalPalette = { ...basePalette, ...palette };
59
- return new determineBaseTheme.MyColorino(
57
+ const basePalette = inputValidator.themePalettes[baseThemeName];
58
+ const finalPalette = { ...basePalette, ...userPalette };
59
+ return new inputValidator.MyColorino(
60
60
  finalPalette,
61
+ userPalette,
61
62
  validator,
62
63
  browserDetector,
63
64
  // Always use browser detector
@@ -66,8 +67,6 @@ function createColorino(palette = {}, options = {}) {
66
67
  options
67
68
  );
68
69
  }
69
- const colorino = createColorino();
70
70
 
71
- exports.themePalettes = determineBaseTheme.themePalettes;
72
- exports.colorino = colorino;
71
+ exports.themePalettes = inputValidator.themePalettes;
73
72
  exports.createColorino = createColorino;
@@ -1,8 +1,8 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DjY5jpGa.cjs';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DjY5jpGa.cjs';
1
+ import { T as ThemeName, P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.bX_hrCT6.cjs';
2
+ export { L as LogLevel } from './shared/colorino.bX_hrCT6.cjs';
3
3
 
4
- declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
4
+ declare const themePalettes: Record<ThemeName, Palette>;
5
5
 
6
- declare const colorino: Colorino;
6
+ declare function createColorino(userPalette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
7
7
 
8
- export { Colorino, ColorinoOptions, Palette, colorino, createColorino };
8
+ export { Colorino, ColorinoOptions, Palette, ThemeName, createColorino, themePalettes };
@@ -1,8 +1,8 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DjY5jpGa.mjs';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DjY5jpGa.mjs';
1
+ import { T as ThemeName, P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.bX_hrCT6.mjs';
2
+ export { L as LogLevel } from './shared/colorino.bX_hrCT6.mjs';
3
3
 
4
- declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
4
+ declare const themePalettes: Record<ThemeName, Palette>;
5
5
 
6
- declare const colorino: Colorino;
6
+ declare function createColorino(userPalette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
7
7
 
8
- export { Colorino, ColorinoOptions, Palette, colorino, createColorino };
8
+ export { Colorino, ColorinoOptions, Palette, ThemeName, createColorino, themePalettes };
package/dist/browser.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DjY5jpGa.js';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DjY5jpGa.js';
1
+ import { T as ThemeName, P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.bX_hrCT6.js';
2
+ export { L as LogLevel } from './shared/colorino.bX_hrCT6.js';
3
3
 
4
- declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
4
+ declare const themePalettes: Record<ThemeName, Palette>;
5
5
 
6
- declare const colorino: Colorino;
6
+ declare function createColorino(userPalette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
7
7
 
8
- export { Colorino, ColorinoOptions, Palette, colorino, createColorino };
8
+ export { Colorino, ColorinoOptions, Palette, ThemeName, createColorino, themePalettes };
package/dist/browser.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as ColorLevel, t as themePalettes, M as MyColorino, I as InputValidator, d as determineBaseTheme } from './shared/colorino.BnDovC2X.mjs';
1
+ import { C as ColorLevel, t as themePalettes, M as MyColorino, I as InputValidator, d as determineBaseTheme } from './shared/colorino.BPD_4Zhq.mjs';
2
2
 
3
3
  class BrowserColorSupportDetector {
4
4
  constructor(_window, _navigator, _overrideTheme) {
@@ -35,7 +35,7 @@ class BrowserColorSupportDetector {
35
35
  }
36
36
  }
37
37
 
38
- function createColorino(palette = {}, options = {}) {
38
+ function createColorino(userPalette = {}, options = {}) {
39
39
  const validator = new InputValidator();
40
40
  let detectorThemeOverride;
41
41
  if (options.theme === "dark" || options.theme === "light") {
@@ -53,9 +53,10 @@ function createColorino(palette = {}, options = {}) {
53
53
  detectedBrowserTheme
54
54
  );
55
55
  const basePalette = themePalettes[baseThemeName];
56
- const finalPalette = { ...basePalette, ...palette };
56
+ const finalPalette = { ...basePalette, ...userPalette };
57
57
  return new MyColorino(
58
58
  finalPalette,
59
+ userPalette,
59
60
  validator,
60
61
  browserDetector,
61
62
  // Always use browser detector
@@ -64,6 +65,5 @@ function createColorino(palette = {}, options = {}) {
64
65
  options
65
66
  );
66
67
  }
67
- const colorino = createColorino();
68
68
 
69
- export { colorino, createColorino, themePalettes };
69
+ export { createColorino, themePalettes };
package/dist/node.cjs CHANGED
@@ -1,98 +1,39 @@
1
1
  'use strict';
2
2
 
3
- const determineBaseTheme = require('./shared/colorino.B4p-EEl9.cjs');
3
+ const inputValidator = require('./shared/colorino.D9xuyiJg.cjs');
4
4
  const node_child_process = require('node:child_process');
5
+ const node_url = require('node:url');
6
+ const node_path = require('node:path');
5
7
 
6
- class OscThemeQuerier {
7
- constructor(_stdin, _stdout, _timeout = 300, _cacheTtl = 36e5) {
8
- this._stdin = _stdin;
9
- this._stdout = _stdout;
10
- this._timeout = _timeout;
11
- this._cacheTtl = _cacheTtl;
8
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
+ const __dirname$1 = node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('node.cjs', document.baseURI).href))));
10
+ function getTerminalThemeSync() {
11
+ const scriptPath = node_path.join(__dirname$1, "osc-child-probe.js");
12
+ const result = node_child_process.spawnSync(process.execPath, [scriptPath], {
13
+ stdio: ["inherit", "pipe", "inherit"],
14
+ encoding: "utf8",
15
+ timeout: 1500
16
+ });
17
+ if (result.error || result.status !== 0) {
18
+ return "unknown";
12
19
  }
13
- _cachedResult;
14
- _cacheTimestamp;
15
- query() {
16
- if (!this._stdout.isTTY || typeof this._stdin.setRawMode !== "function") {
17
- return determineBaseTheme.err(new determineBaseTheme.OscQueryError("Not a TTY environment"));
18
- }
19
- const now = Date.now();
20
- if (this._cachedResult !== void 0 && this._cacheTimestamp !== void 0 && now - this._cacheTimestamp < this._cacheTtl) {
21
- return this._cachedResult;
22
- }
23
- const result = this._performQuery();
24
- this._cachedResult = result;
25
- this._cacheTimestamp = now;
26
- return result;
27
- }
28
- _performQuery() {
29
- const originalRawMode = this._stdin.isRaw;
30
- let buffer = "";
31
- this._stdin.setRawMode(true);
32
- this._stdin.resume();
33
- this._stdout.write("\x1B]11;?\x1B\\");
34
- const startTime = Date.now();
35
- const pollInterval = 10;
36
- while (Date.now() - startTime < this._timeout) {
37
- const chunk = this._stdin.read();
38
- if (chunk !== null) {
39
- buffer += chunk.toString();
40
- const parseResult = this._parseResponse(buffer);
41
- if (parseResult.isOk()) {
42
- this._cleanup(originalRawMode);
43
- return parseResult;
44
- }
45
- }
46
- this._sleepSync(pollInterval);
47
- }
48
- this._cleanup(originalRawMode);
49
- return determineBaseTheme.err(
50
- new determineBaseTheme.OscQueryError("OSC query timeout - terminal did not respond")
51
- );
52
- }
53
- _cleanup(originalRawMode) {
54
- this._stdin.setRawMode(originalRawMode);
55
- this._stdin.pause();
56
- }
57
- _sleepSync(ms) {
58
- if (process.platform === "win32") {
59
- node_child_process.spawnSync("timeout", ["/T", String(Math.ceil(ms / 1e3)), "/NOBREAK"], {
60
- stdio: "ignore",
61
- shell: true
62
- });
63
- } else {
64
- node_child_process.spawnSync("sleep", [String(ms / 1e3)], { stdio: "ignore" });
65
- }
66
- }
67
- _parseResponse(response) {
68
- const rgbMatch = response.match(
69
- /rgb:([0-9a-f]{2,4})\/([0-9a-f]{2,4})\/([0-9a-f]{2,4})/i
70
- );
71
- if (!rgbMatch) {
72
- return determineBaseTheme.err(new determineBaseTheme.OscQueryError("No valid OSC response found in buffer"));
73
- }
74
- const red = this._normalizeHex(rgbMatch[1]);
75
- const green = this._normalizeHex(rgbMatch[2]);
76
- const blue = this._normalizeHex(rgbMatch[3]);
77
- const luminance = this._calculateLuminance(red, green, blue);
78
- return determineBaseTheme.ok(luminance < 0.5 ? "dark" : "light");
79
- }
80
- _normalizeHex(hexValue) {
81
- const normalized = hexValue.padEnd(4, "0").slice(0, 2);
82
- return parseInt(normalized, 16);
83
- }
84
- _calculateLuminance(red, green, blue) {
85
- return (0.299 * red + 0.587 * green + 0.114 * blue) / 255;
20
+ const output = result.stdout.trim();
21
+ if (output === "dark" || output === "light") {
22
+ return output;
86
23
  }
24
+ return "unknown";
87
25
  }
88
26
 
89
27
  class NodeColorSupportDetector {
90
- constructor(_process, overrideTheme) {
28
+ constructor(_process, _overrideTheme, _disableOscProbe = false) {
91
29
  this._process = _process;
92
- if (!this.isNodeEnv()) {
93
- this._theme = "unknown";
30
+ this._overrideTheme = _overrideTheme;
31
+ this._disableOscProbe = _disableOscProbe;
32
+ if (this._overrideTheme !== void 0) {
33
+ this._theme = this._overrideTheme;
94
34
  return;
95
35
  }
36
+ this._isTTY = !!_process.stdout.isTTY;
96
37
  const processEnv = _process.env;
97
38
  this._envForceColor = processEnv["FORCE_COLOR"];
98
39
  this._envNoColor = processEnv["NO_COLOR"];
@@ -101,21 +42,11 @@ class NodeColorSupportDetector {
101
42
  this._envCliColor = processEnv["CLICOLOR"];
102
43
  this._envCliColorForce = processEnv["CLICOLOR_FORCE"];
103
44
  this._envWtSession = processEnv["WT_SESSION"];
104
- this._isTTY = !!_process.stdout.isTTY;
105
- if (overrideTheme !== void 0) {
106
- this._theme = overrideTheme;
107
- return;
108
- }
109
- if (!this._isTTY) {
45
+ if (!this._isTTY || this._disableOscProbe || !this.isNodeEnv) {
110
46
  this._theme = "unknown";
111
47
  return;
112
48
  }
113
- const querier = new OscThemeQuerier(
114
- _process.stdin,
115
- _process.stdout
116
- );
117
- const result = querier.query();
118
- this._theme = result.isOk() ? result.value : "unknown";
49
+ this._theme = getTerminalThemeSync();
119
50
  }
120
51
  _envForceColor;
121
52
  _envTerm;
@@ -129,89 +60,91 @@ class NodeColorSupportDetector {
129
60
  isNodeEnv() {
130
61
  return typeof this._process !== "undefined";
131
62
  }
63
+ onTheme(listener) {
64
+ listener(this._theme);
65
+ }
132
66
  getTheme() {
133
67
  return this._theme;
134
68
  }
135
69
  getColorLevel() {
136
70
  if (this._envNoColor !== void 0 && this._envNoColor !== "") {
137
- return determineBaseTheme.ColorLevel.NO_COLOR;
71
+ return inputValidator.ColorLevel.NO_COLOR;
138
72
  }
139
73
  if (this._envForceColor !== void 0) {
140
74
  if (this._envForceColor === "0" || this._envForceColor === "false") {
141
- return determineBaseTheme.ColorLevel.NO_COLOR;
75
+ return inputValidator.ColorLevel.NO_COLOR;
142
76
  }
143
77
  if (this._envForceColor === "1" || this._envForceColor === "true") {
144
- return determineBaseTheme.ColorLevel.ANSI;
78
+ return inputValidator.ColorLevel.ANSI;
145
79
  }
146
80
  const level = parseInt(this._envForceColor, 10);
147
81
  if (level >= 0 && level <= 3) {
148
82
  return level;
149
83
  }
150
- return determineBaseTheme.ColorLevel.ANSI;
84
+ return inputValidator.ColorLevel.ANSI;
151
85
  }
152
86
  const isForced = this._envCliColorForce !== void 0 && this._envCliColorForce !== "0";
153
87
  if (!this._isTTY && !isForced) {
154
- return determineBaseTheme.ColorLevel.NO_COLOR;
88
+ return inputValidator.ColorLevel.NO_COLOR;
155
89
  }
156
90
  if (this._envTerm === "dumb") {
157
- return determineBaseTheme.ColorLevel.NO_COLOR;
91
+ return inputValidator.ColorLevel.NO_COLOR;
158
92
  }
159
93
  if (this._envColorTerm === "truecolor" || this._envColorTerm === "24bit") {
160
- return determineBaseTheme.ColorLevel.TRUECOLOR;
94
+ return inputValidator.ColorLevel.TRUECOLOR;
161
95
  }
162
96
  if (this._envWtSession !== void 0) {
163
- return determineBaseTheme.ColorLevel.TRUECOLOR;
97
+ return inputValidator.ColorLevel.TRUECOLOR;
164
98
  }
165
99
  if (this._envTerm) {
166
100
  if (/^xterm-kitty$/.test(this._envTerm) || /^xterm-ghostty$/.test(this._envTerm) || /^wezterm$/.test(this._envTerm) || this._envTerm.endsWith("-truecolor")) {
167
- return determineBaseTheme.ColorLevel.TRUECOLOR;
101
+ return inputValidator.ColorLevel.TRUECOLOR;
168
102
  }
169
103
  if (/-256(color)?$/i.test(this._envTerm)) {
170
- return determineBaseTheme.ColorLevel.ANSI256;
104
+ return inputValidator.ColorLevel.ANSI256;
171
105
  }
172
106
  if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(
173
107
  this._envTerm
174
108
  )) {
175
- return determineBaseTheme.ColorLevel.ANSI;
109
+ return inputValidator.ColorLevel.ANSI;
176
110
  }
177
111
  }
178
112
  if (this._envColorTerm) {
179
- return determineBaseTheme.ColorLevel.ANSI;
113
+ return inputValidator.ColorLevel.ANSI;
180
114
  }
181
115
  if (this._envCliColor !== void 0 && this._envCliColor !== "0") {
182
- return determineBaseTheme.ColorLevel.ANSI;
116
+ return inputValidator.ColorLevel.ANSI;
183
117
  }
184
- return this._isTTY || isForced ? determineBaseTheme.ColorLevel.ANSI : determineBaseTheme.ColorLevel.NO_COLOR;
118
+ return this._isTTY || isForced ? inputValidator.ColorLevel.ANSI : inputValidator.ColorLevel.NO_COLOR;
185
119
  }
186
120
  }
187
121
 
188
- function createColorino(palette = {}, options = {}) {
189
- const validator = new determineBaseTheme.InputValidator();
122
+ function createColorino(userPalette = {}, options = {}) {
123
+ const validator = new inputValidator.InputValidator();
124
+ const themeOpt = options.theme ?? "auto";
190
125
  let detectorThemeOverride;
191
- if (options.theme === "dark" || options.theme === "light") {
192
- detectorThemeOverride = options.theme;
126
+ if (themeOpt === "dark" || themeOpt === "light") {
127
+ detectorThemeOverride = themeOpt;
128
+ } else if (themeOpt !== "auto") {
129
+ detectorThemeOverride = "unknown";
193
130
  }
194
131
  const nodeDetector = new NodeColorSupportDetector(
195
132
  process,
196
- detectorThemeOverride
133
+ detectorThemeOverride,
134
+ options.disableOscProbe ?? false
197
135
  );
198
- const detectedTerminalTheme = nodeDetector.getTheme();
199
- const themeOpt = options.theme ?? "auto";
200
- const baseThemeName = determineBaseTheme.determineBaseTheme(themeOpt, detectedTerminalTheme);
201
- const basePalette = determineBaseTheme.themePalettes[baseThemeName];
202
- const finalPalette = { ...basePalette, ...palette };
203
- return new determineBaseTheme.MyColorino(
136
+ const detectedTerminalTheme = themeOpt === "auto" && !options.disableOscProbe ? nodeDetector.getTheme() : "unknown";
137
+ const baseThemeName = inputValidator.determineBaseTheme(themeOpt, detectedTerminalTheme);
138
+ const basePalette = inputValidator.themePalettes[baseThemeName];
139
+ const finalPalette = { ...basePalette, ...userPalette };
140
+ return new inputValidator.MyColorino(
204
141
  finalPalette,
142
+ userPalette,
205
143
  validator,
206
144
  void 0,
207
- // Browser detector is never available
208
145
  nodeDetector,
209
- // Always use node detector
210
146
  options
211
147
  );
212
148
  }
213
- const colorino = createColorino();
214
149
 
215
- exports.themePalettes = determineBaseTheme.themePalettes;
216
- exports.colorino = colorino;
217
150
  exports.createColorino = createColorino;
package/dist/node.d.cts CHANGED
@@ -1,8 +1,5 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DjY5jpGa.cjs';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DjY5jpGa.cjs';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.bX_hrCT6.cjs';
3
2
 
4
- declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
3
+ declare function createColorino(userPalette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
5
4
 
6
- declare const colorino: Colorino;
7
-
8
- export { Colorino, ColorinoOptions, Palette, colorino, createColorino };
5
+ export { createColorino };
package/dist/node.d.mts CHANGED
@@ -1,8 +1,5 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DjY5jpGa.mjs';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DjY5jpGa.mjs';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.bX_hrCT6.mjs';
3
2
 
4
- declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
3
+ declare function createColorino(userPalette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
5
4
 
6
- declare const colorino: Colorino;
7
-
8
- export { Colorino, ColorinoOptions, Palette, colorino, createColorino };
5
+ export { createColorino };
package/dist/node.d.ts CHANGED
@@ -1,8 +1,5 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DjY5jpGa.js';
2
- export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DjY5jpGa.js';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.bX_hrCT6.js';
3
2
 
4
- declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
3
+ declare function createColorino(userPalette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
5
4
 
6
- declare const colorino: Colorino;
7
-
8
- export { Colorino, ColorinoOptions, Palette, colorino, createColorino };
5
+ export { createColorino };
package/dist/node.mjs CHANGED
@@ -1,96 +1,36 @@
1
- import { e as err, O as OscQueryError, o as ok, C as ColorLevel, d as determineBaseTheme, t as themePalettes, M as MyColorino, I as InputValidator } from './shared/colorino.BnDovC2X.mjs';
1
+ import { C as ColorLevel, t as themePalettes, M as MyColorino, I as InputValidator, d as determineBaseTheme } from './shared/colorino.BPD_4Zhq.mjs';
2
2
  import { spawnSync } from 'node:child_process';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { dirname, join } from 'node:path';
3
5
 
4
- class OscThemeQuerier {
5
- constructor(_stdin, _stdout, _timeout = 300, _cacheTtl = 36e5) {
6
- this._stdin = _stdin;
7
- this._stdout = _stdout;
8
- this._timeout = _timeout;
9
- this._cacheTtl = _cacheTtl;
6
+ const __dirname$1 = dirname(fileURLToPath(import.meta.url));
7
+ function getTerminalThemeSync() {
8
+ const scriptPath = join(__dirname$1, "osc-child-probe.js");
9
+ const result = spawnSync(process.execPath, [scriptPath], {
10
+ stdio: ["inherit", "pipe", "inherit"],
11
+ encoding: "utf8",
12
+ timeout: 1500
13
+ });
14
+ if (result.error || result.status !== 0) {
15
+ return "unknown";
10
16
  }
11
- _cachedResult;
12
- _cacheTimestamp;
13
- query() {
14
- if (!this._stdout.isTTY || typeof this._stdin.setRawMode !== "function") {
15
- return err(new OscQueryError("Not a TTY environment"));
16
- }
17
- const now = Date.now();
18
- if (this._cachedResult !== void 0 && this._cacheTimestamp !== void 0 && now - this._cacheTimestamp < this._cacheTtl) {
19
- return this._cachedResult;
20
- }
21
- const result = this._performQuery();
22
- this._cachedResult = result;
23
- this._cacheTimestamp = now;
24
- return result;
25
- }
26
- _performQuery() {
27
- const originalRawMode = this._stdin.isRaw;
28
- let buffer = "";
29
- this._stdin.setRawMode(true);
30
- this._stdin.resume();
31
- this._stdout.write("\x1B]11;?\x1B\\");
32
- const startTime = Date.now();
33
- const pollInterval = 10;
34
- while (Date.now() - startTime < this._timeout) {
35
- const chunk = this._stdin.read();
36
- if (chunk !== null) {
37
- buffer += chunk.toString();
38
- const parseResult = this._parseResponse(buffer);
39
- if (parseResult.isOk()) {
40
- this._cleanup(originalRawMode);
41
- return parseResult;
42
- }
43
- }
44
- this._sleepSync(pollInterval);
45
- }
46
- this._cleanup(originalRawMode);
47
- return err(
48
- new OscQueryError("OSC query timeout - terminal did not respond")
49
- );
50
- }
51
- _cleanup(originalRawMode) {
52
- this._stdin.setRawMode(originalRawMode);
53
- this._stdin.pause();
54
- }
55
- _sleepSync(ms) {
56
- if (process.platform === "win32") {
57
- spawnSync("timeout", ["/T", String(Math.ceil(ms / 1e3)), "/NOBREAK"], {
58
- stdio: "ignore",
59
- shell: true
60
- });
61
- } else {
62
- spawnSync("sleep", [String(ms / 1e3)], { stdio: "ignore" });
63
- }
64
- }
65
- _parseResponse(response) {
66
- const rgbMatch = response.match(
67
- /rgb:([0-9a-f]{2,4})\/([0-9a-f]{2,4})\/([0-9a-f]{2,4})/i
68
- );
69
- if (!rgbMatch) {
70
- return err(new OscQueryError("No valid OSC response found in buffer"));
71
- }
72
- const red = this._normalizeHex(rgbMatch[1]);
73
- const green = this._normalizeHex(rgbMatch[2]);
74
- const blue = this._normalizeHex(rgbMatch[3]);
75
- const luminance = this._calculateLuminance(red, green, blue);
76
- return ok(luminance < 0.5 ? "dark" : "light");
77
- }
78
- _normalizeHex(hexValue) {
79
- const normalized = hexValue.padEnd(4, "0").slice(0, 2);
80
- return parseInt(normalized, 16);
81
- }
82
- _calculateLuminance(red, green, blue) {
83
- return (0.299 * red + 0.587 * green + 0.114 * blue) / 255;
17
+ const output = result.stdout.trim();
18
+ if (output === "dark" || output === "light") {
19
+ return output;
84
20
  }
21
+ return "unknown";
85
22
  }
86
23
 
87
24
  class NodeColorSupportDetector {
88
- constructor(_process, overrideTheme) {
25
+ constructor(_process, _overrideTheme, _disableOscProbe = false) {
89
26
  this._process = _process;
90
- if (!this.isNodeEnv()) {
91
- this._theme = "unknown";
27
+ this._overrideTheme = _overrideTheme;
28
+ this._disableOscProbe = _disableOscProbe;
29
+ if (this._overrideTheme !== void 0) {
30
+ this._theme = this._overrideTheme;
92
31
  return;
93
32
  }
33
+ this._isTTY = !!_process.stdout.isTTY;
94
34
  const processEnv = _process.env;
95
35
  this._envForceColor = processEnv["FORCE_COLOR"];
96
36
  this._envNoColor = processEnv["NO_COLOR"];
@@ -99,21 +39,11 @@ class NodeColorSupportDetector {
99
39
  this._envCliColor = processEnv["CLICOLOR"];
100
40
  this._envCliColorForce = processEnv["CLICOLOR_FORCE"];
101
41
  this._envWtSession = processEnv["WT_SESSION"];
102
- this._isTTY = !!_process.stdout.isTTY;
103
- if (overrideTheme !== void 0) {
104
- this._theme = overrideTheme;
105
- return;
106
- }
107
- if (!this._isTTY) {
42
+ if (!this._isTTY || this._disableOscProbe || !this.isNodeEnv) {
108
43
  this._theme = "unknown";
109
44
  return;
110
45
  }
111
- const querier = new OscThemeQuerier(
112
- _process.stdin,
113
- _process.stdout
114
- );
115
- const result = querier.query();
116
- this._theme = result.isOk() ? result.value : "unknown";
46
+ this._theme = getTerminalThemeSync();
117
47
  }
118
48
  _envForceColor;
119
49
  _envTerm;
@@ -127,6 +57,9 @@ class NodeColorSupportDetector {
127
57
  isNodeEnv() {
128
58
  return typeof this._process !== "undefined";
129
59
  }
60
+ onTheme(listener) {
61
+ listener(this._theme);
62
+ }
130
63
  getTheme() {
131
64
  return this._theme;
132
65
  }
@@ -183,31 +116,32 @@ class NodeColorSupportDetector {
183
116
  }
184
117
  }
185
118
 
186
- function createColorino(palette = {}, options = {}) {
119
+ function createColorino(userPalette = {}, options = {}) {
187
120
  const validator = new InputValidator();
121
+ const themeOpt = options.theme ?? "auto";
188
122
  let detectorThemeOverride;
189
- if (options.theme === "dark" || options.theme === "light") {
190
- detectorThemeOverride = options.theme;
123
+ if (themeOpt === "dark" || themeOpt === "light") {
124
+ detectorThemeOverride = themeOpt;
125
+ } else if (themeOpt !== "auto") {
126
+ detectorThemeOverride = "unknown";
191
127
  }
192
128
  const nodeDetector = new NodeColorSupportDetector(
193
129
  process,
194
- detectorThemeOverride
130
+ detectorThemeOverride,
131
+ options.disableOscProbe ?? false
195
132
  );
196
- const detectedTerminalTheme = nodeDetector.getTheme();
197
- const themeOpt = options.theme ?? "auto";
133
+ const detectedTerminalTheme = themeOpt === "auto" && !options.disableOscProbe ? nodeDetector.getTheme() : "unknown";
198
134
  const baseThemeName = determineBaseTheme(themeOpt, detectedTerminalTheme);
199
135
  const basePalette = themePalettes[baseThemeName];
200
- const finalPalette = { ...basePalette, ...palette };
136
+ const finalPalette = { ...basePalette, ...userPalette };
201
137
  return new MyColorino(
202
138
  finalPalette,
139
+ userPalette,
203
140
  validator,
204
141
  void 0,
205
- // Browser detector is never available
206
142
  nodeDetector,
207
- // Always use node detector
208
143
  options
209
144
  );
210
145
  }
211
- const colorino = createColorino();
212
146
 
213
- export { colorino, createColorino, themePalettes };
147
+ export { createColorino };