@mudah-cli/ui 0.2.0 → 0.3.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/index.d.ts CHANGED
@@ -3,4 +3,4 @@ export { Output, type OutputEvent, type OutputMode, type OutputOptions } from '.
3
3
  export { renderMarkdown, type RenderMarkdownOptions } from './markdown.js';
4
4
  export { renderPanel, type RenderPanelOptions } from './panel.js';
5
5
  export { renderTable, type RenderTableOptions, type TableColumn } from './table.js';
6
- export { resolveTheme, sleekDark, sleekLight, themes, type Theme, type ThemeColors } from './theme.js';
6
+ export { detectTheme, resolveTheme, sleekDark, sleekLight, themes, type DetectThemeOptions, type Theme, type ThemeColors, } from './theme.js';
package/dist/index.js CHANGED
@@ -3,5 +3,5 @@ export { Output } from './output.js';
3
3
  export { renderMarkdown } from './markdown.js';
4
4
  export { renderPanel } from './panel.js';
5
5
  export { renderTable } from './table.js';
6
- export { resolveTheme, sleekDark, sleekLight, themes } from './theme.js';
6
+ export { detectTheme, resolveTheme, sleekDark, sleekLight, themes, } from './theme.js';
7
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,GAAG,EACH,MAAM,EACN,KAAK,EACL,OAAO,EACP,SAAS,EACT,SAAS,EACT,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAyD,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,cAAc,EAA8B,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,WAAW,EAA2B,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,WAAW,EAA6C,MAAM,YAAY,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAgC,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,GAAG,EACH,MAAM,EACN,KAAK,EACL,OAAO,EACP,SAAS,EACT,SAAS,EACT,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAyD,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,cAAc,EAA8B,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,WAAW,EAA2B,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,WAAW,EAA6C,MAAM,YAAY,CAAC;AACpF,OAAO,EACL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,UAAU,EACV,MAAM,GAIP,MAAM,YAAY,CAAC"}
package/dist/theme.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type OscWriter, type ThemeQueryInput } from '@mudah-cli/terminal';
1
2
  export interface ThemeColors {
2
3
  /** Primary brand accent (headings, highlights). */
3
4
  accent: string;
@@ -20,6 +21,32 @@ export declare const sleekLight: Theme;
20
21
  export declare const themes: Record<string, Theme>;
21
22
  /**
22
23
  * Resolve a theme by name. `'auto'` falls back to dark mode (the safe
23
- * default for CLI tools); a runtime OSC 10 query can refine this in v0.2.
24
+ * default for CLI tools) — use `detectTheme()` when you want the terminal's
25
+ * real colors to decide.
24
26
  */
25
27
  export declare function resolveTheme(name: string | undefined): Theme;
28
+ export interface DetectThemeOptions {
29
+ /**
30
+ * Theme name. Only `'auto'` triggers a terminal query — an explicit name
31
+ * (and `undefined`) resolve synchronously, keeping cold start untouched.
32
+ */
33
+ name?: string;
34
+ /**
35
+ * Skip the query entirely (non-interactive runs, tests). Defaults to
36
+ * `process.stdin.isTTY`.
37
+ */
38
+ allowQuery?: boolean;
39
+ /** How long to wait for the terminal's answer. */
40
+ timeoutMs?: number;
41
+ /** Stream the query is written to (default `process.stdout`). */
42
+ stdout?: OscWriter;
43
+ /** Stream the answer is read from (default `process.stdin`). */
44
+ stdin?: ThemeQueryInput;
45
+ }
46
+ /**
47
+ * Resolve the theme, asking the terminal for its colors when the manifest
48
+ * asks for `'auto'`. Every other name resolves synchronously, and any run
49
+ * that can't answer (no TTY, timeout, silent terminal) falls back to dark.
50
+ * Never throws.
51
+ */
52
+ export declare function detectTheme(options?: DetectThemeOptions): Promise<Theme>;
package/dist/theme.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { queryTerminalTheme } from '@mudah-cli/terminal';
1
2
  export const sleekDark = {
2
3
  name: 'sleek-dark',
3
4
  mode: 'dark',
@@ -35,11 +36,39 @@ export const themes = {
35
36
  };
36
37
  /**
37
38
  * Resolve a theme by name. `'auto'` falls back to dark mode (the safe
38
- * default for CLI tools); a runtime OSC 10 query can refine this in v0.2.
39
+ * default for CLI tools) — use `detectTheme()` when you want the terminal's
40
+ * real colors to decide.
39
41
  */
40
42
  export function resolveTheme(name) {
41
43
  if (name === undefined || name === 'auto')
42
44
  return sleekDark;
43
45
  return themes[name] ?? sleekDark;
44
46
  }
47
+ /**
48
+ * Resolve the theme, asking the terminal for its colors when the manifest
49
+ * asks for `'auto'`. Every other name resolves synchronously, and any run
50
+ * that can't answer (no TTY, timeout, silent terminal) falls back to dark.
51
+ * Never throws.
52
+ */
53
+ export async function detectTheme(options = {}) {
54
+ const name = options.name;
55
+ if (name !== 'auto')
56
+ return resolveTheme(name);
57
+ const allowQuery = options.allowQuery ?? process.stdin.isTTY === true;
58
+ if (!allowQuery)
59
+ return sleekDark;
60
+ try {
61
+ const result = await queryTerminalTheme({
62
+ timeoutMs: options.timeoutMs,
63
+ stdout: options.stdout,
64
+ stdin: options.stdin,
65
+ });
66
+ if (!result.ok)
67
+ return sleekDark;
68
+ return result.theme === 'light' ? sleekLight : sleekDark;
69
+ }
70
+ catch {
71
+ return sleekDark;
72
+ }
73
+ }
45
74
  //# sourceMappingURL=theme.js.map
package/dist/theme.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"theme.js","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"m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QACH,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC;YACtC,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,OAAO,SAAS,CAAC;QACjC,OAAO,MAAM,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mudah-cli/ui",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Terminal design system: tokens, themes, output primitives, tables, panels, and markdown rendering.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "sideEffects": false,
20
20
  "dependencies": {
21
- "@mudah-cli/terminal": "^0.2.0"
21
+ "@mudah-cli/terminal": "^0.3.0"
22
22
  },
23
23
  "publishConfig": {
24
24
  "access": "public"