@oxog/pigment 1.0.1 → 1.0.2

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
@@ -1,5 +1,5 @@
1
- import { P as PigmentKernel, a as PigmentOptions, b as Pigment, C as ColorSupport, S as Styler, c as Platform } from './index-BE-MUtRO.js';
2
- export { B as BoxBorder, o as BoxChars, k as BoxPluginOptions, E as EventHandler, G as GradientPluginOptions, K as Kernel, p as KernelOptions, e as PigmentContext, f as PigmentEvents, l as PigmentPluginOptions, d as Plugin, m as SemanticPluginOptions, g as Style, h as StyleFunction, j as ThemePluginOptions, T as ThemePreset, n as ThemePresetColors, i as plugins } from './index-BE-MUtRO.js';
1
+ import { P as PigmentKernel, a as PigmentOptions, b as Pigment, C as ColorSupport, S as Styler, c as Platform } from './index-ChElNHaA.js';
2
+ export { B as BoxBorder, o as BoxChars, k as BoxPluginOptions, E as EventHandler, G as GradientPluginOptions, K as Kernel, p as KernelOptions, e as PigmentContext, f as PigmentEvents, l as PigmentPluginOptions, d as Plugin, m as SemanticPluginOptions, g as Style, h as StyleFunction, j as ThemePluginOptions, T as ThemePreset, n as ThemePresetColors, i as plugins } from './index-ChElNHaA.js';
3
3
  export { createKernel } from '@oxog/plugin';
4
4
  export { MaybePromise, Unsubscribe } from '@oxog/types';
5
5
 
@@ -213,6 +213,11 @@ declare function compose(...stylers: Styler[]): Styler;
213
213
 
214
214
  declare function detectColorSupport(overrideLevel?: 0 | 1 | 2 | 3): ColorSupport;
215
215
  declare function supportsColor(): ColorSupport;
216
+ /**
217
+ * Reset the cached color support detection.
218
+ * Useful for testing when environment variables change.
219
+ */
220
+ declare function resetColorSupportCache(): void;
216
221
 
217
222
  declare function detectPlatform(): Platform;
218
223
  declare function isNode(): boolean;
@@ -242,4 +247,4 @@ declare const pigment: Pigment & {
242
247
  supportsColor: ColorSupport;
243
248
  };
244
249
 
245
- export { BuilderPigment, ColorSupport, Pigment, PigmentKernel, PigmentOptions, Platform, Styler, bgBlack, bgBlackBright, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGreen, bgGreenBright, bgGrey, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blackBright, blue, blueBright, bold, compose, createPigment, cyan, cyanBright, chalk as default, detectColorSupport, detectPlatform, dim, gray, green, greenBright, grey, hasTTY, hexToRgb, hidden, hslToRgb, inverse, isBrowser, isCI, isNode, isWindows, italic, magenta, magentaBright, pigment, red, redBright, reset, rgbToAnsi256, strikethrough, supportsColor, underline, validateHex, white, whiteBright, yellow, yellowBright };
250
+ export { BuilderPigment, ColorSupport, Pigment, PigmentKernel, PigmentOptions, Platform, Styler, bgBlack, bgBlackBright, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGreen, bgGreenBright, bgGrey, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blackBright, blue, blueBright, bold, compose, createPigment, cyan, cyanBright, chalk as default, detectColorSupport, detectPlatform, dim, gray, green, greenBright, grey, hasTTY, hexToRgb, hidden, hslToRgb, inverse, isBrowser, isCI, isNode, isWindows, italic, magenta, magentaBright, pigment, red, redBright, reset, resetColorSupportCache, rgbToAnsi256, strikethrough, supportsColor, underline, validateHex, white, whiteBright, yellow, yellowBright };
package/dist/index.js CHANGED
@@ -383,7 +383,7 @@ function createProxyPigment(kernel, styles = []) {
383
383
  }
384
384
  if (prop === "visible") {
385
385
  const colorSupport = ctx.colorSupport;
386
- return (text) => colorSupport.level > 0 ? text : text;
386
+ return (text) => colorSupport.level > 0 ? text : "";
387
387
  }
388
388
  return target[prop];
389
389
  },
@@ -397,12 +397,18 @@ function createProxyPigment(kernel, styles = []) {
397
397
  return pigment2;
398
398
  }
399
399
  function applyStyles(text, styles) {
400
- if (styles.length === 0) {
400
+ if (styles.length === 0 || text === "") {
401
401
  return text;
402
402
  }
403
403
  const open = styles.map((style) => style.open).join("");
404
404
  const close = [...styles].reverse().map((style) => style.close).join("");
405
- return `${open}${text}${close}`;
405
+ let result = text;
406
+ for (const style of styles) {
407
+ if (style.close) {
408
+ result = result.split(style.close).join(style.close + style.open);
409
+ }
410
+ }
411
+ return `${open}${result}${close}`;
406
412
  }
407
413
 
408
414
  // src/utils/hex-to-rgb.ts
@@ -691,12 +697,18 @@ var BuilderPigment = class {
691
697
  return this;
692
698
  }
693
699
  paint(text) {
694
- if (this.styles.length === 0) {
700
+ if (this.styles.length === 0 || text === "") {
695
701
  return text;
696
702
  }
697
703
  const open = this.styles.map((style) => style.open).join("");
698
704
  const close = [...this.styles].reverse().map((style) => style.close).join("");
699
- return `${open}${text}${close}`;
705
+ let result = text;
706
+ for (const style of this.styles) {
707
+ if (style.close) {
708
+ result = result.split(style.close).join(style.close + style.open);
709
+ }
710
+ }
711
+ return `${open}${result}${close}`;
700
712
  }
701
713
  };
702
714
 
@@ -748,10 +760,10 @@ function detectColorSupport(overrideLevel) {
748
760
  const platform = detectPlatform();
749
761
  if (platform.isBrowser) {
750
762
  cachedColorSupport = {
751
- level: 3,
763
+ level: 1,
752
764
  hasBasic: true,
753
- has256: true,
754
- has16m: true
765
+ has256: false,
766
+ has16m: false
755
767
  };
756
768
  return cachedColorSupport;
757
769
  }
@@ -832,6 +844,9 @@ function detectColorSupport(overrideLevel) {
832
844
  function supportsColor() {
833
845
  return detectColorSupport();
834
846
  }
847
+ function resetColorSupportCache() {
848
+ cachedColorSupport = void 0;
849
+ }
835
850
 
836
851
  // src/utils/rgb-to-ansi256.ts
837
852
  function rgbToAnsi256(r, g, b) {
@@ -982,12 +997,6 @@ function nestingPlugin() {
982
997
  enabled: true
983
998
  }
984
999
  });
985
- k.on("style:nest", (data) => {
986
- const { innerText, outerStyles } = data;
987
- const open = outerStyles.join("");
988
- const close = outerStyles.map(() => "\x1B[0m").join("");
989
- return `${open}${innerText}${close}`;
990
- });
991
1000
  }
992
1001
  };
993
1002
  }
@@ -1000,15 +1009,16 @@ function environmentPlugin() {
1000
1009
  install(kernel) {
1001
1010
  const k = kernel;
1002
1011
  const ci = isCI();
1003
- const colorSupport = detectColorSupport();
1012
+ const existingContext = k.getContext();
1013
+ const colorSupport = existingContext.colorSupport ?? detectColorSupport();
1004
1014
  k.updateContext({
1005
1015
  environment: {
1006
1016
  isCI: ci,
1007
1017
  noColor: process.env.NO_COLOR !== void 0,
1008
1018
  forceColor: process.env.FORCE_COLOR !== void 0,
1009
1019
  term: process.env.TERM ?? ""
1010
- },
1011
- colorSupport
1020
+ }
1021
+ // Don't overwrite colorSupport - it was already set in factory with the correct level
1012
1022
  });
1013
1023
  k.on("environment:check", () => {
1014
1024
  const ctx = k.getContext();
@@ -1789,6 +1799,7 @@ export {
1789
1799
  red,
1790
1800
  redBright,
1791
1801
  reset,
1802
+ resetColorSupportCache,
1792
1803
  rgbToAnsi256,
1793
1804
  strikethrough,
1794
1805
  supportsColor,