@cloud-ru/ds-code-editor 1.0.3-preview-df38c64f.0 → 1.0.3-preview-fe0a44cc.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.
@@ -125,7 +125,7 @@ function CodeEditorClient({ themeName, className, theme, options, loading, backg
125
125
  }), [themeValues]);
126
126
  const dark = (0, react_2.useMemo)(() => {
127
127
  const bg = themeValues?.bg;
128
- return bg ? (0, utils_2.isDark)(bg) : false;
128
+ return bg ? !(0, utils_2.isLightBackground)(bg) : false;
129
129
  }, [themeValues?.bg]);
130
130
  // defineTheme writes to monaco's global theme registry. Run via layoutEffect
131
131
  // so the theme is registered before <Editor theme=... /> mounts (avoid FOUC),
@@ -1,7 +1,7 @@
1
1
  import { SchemasSettings } from 'monaco-yaml';
2
2
  import { JsonSchema } from './types';
3
3
  export declare function rgb2hsl(htmlColor: string): [number, number, number];
4
- export declare function isDark(color: string): boolean;
4
+ export declare function isLightBackground(color: string): boolean;
5
5
  /**
6
6
  * Monaco theme parser ест только hex; rgba(...) превращает в fail-safe red.
7
7
  * Возвращает `#RRGGBBAA` для допустимого цвета, пустую строку — иначе.
package/dist/cjs/utils.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getJsonSchema = void 0;
4
4
  exports.rgb2hsl = rgb2hsl;
5
- exports.isDark = isDark;
5
+ exports.isLightBackground = isLightBackground;
6
6
  exports.hexWithAlpha = hexWithAlpha;
7
7
  exports.uppercaseFirstLetter = uppercaseFirstLetter;
8
8
  const constants_1 = require("./constants");
@@ -61,9 +61,10 @@ function rgb2hsl(htmlColor) {
61
61
  }
62
62
  return [h, s, l];
63
63
  }
64
- // Treats colors with low hue + medium lightness OR high hue + high lightness as
65
- // 'light enough that text should be dark'. Hue thresholds use the 0–360 scale.
66
- function isDark(color) {
64
+ // Возвращает true, когда фон СВЕТЛЫЙ («достаточно светлый, чтобы текст на нём был тёмным»).
65
+ // Пороги оттенка — по шкале 0–360. Прежнее имя isDark читалось ровно наоборот и уже привело
66
+ // к тому, что на светлой теме редактор получал базовую тему vs-dark.
67
+ function isLightBackground(color) {
67
68
  const [h, , l] = rgb2hsl(color);
68
69
  return (h < 198 && l >= 0.5) || (h >= 198 && l >= 0.75);
69
70
  }
@@ -8,7 +8,7 @@ import { Editor, useMonaco } from '@monaco-editor/react';
8
8
  import cn from 'classnames';
9
9
  import { useCallback, useId, useMemo, useRef, useState } from 'react';
10
10
  import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES, TEST_IDS } from '../../constants.js';
11
- import { hexWithAlpha, isDark, uppercaseFirstLetter } from '../../utils.js';
11
+ import { hexWithAlpha, isLightBackground, uppercaseFirstLetter } from '../../utils.js';
12
12
  import { useApplyJsonSchema, useCalculatedThemeValues } from './hooks.js';
13
13
  import styles from './styles.module.css';
14
14
  // monaco theme parser принимает только hex (#RRGGBB / #RRGGBBAA);
@@ -119,7 +119,7 @@ function CodeEditorClient({ themeName, className, theme, options, loading, backg
119
119
  }), [themeValues]);
120
120
  const dark = useMemo(() => {
121
121
  const bg = themeValues?.bg;
122
- return bg ? isDark(bg) : false;
122
+ return bg ? !isLightBackground(bg) : false;
123
123
  }, [themeValues?.bg]);
124
124
  // defineTheme writes to monaco's global theme registry. Run via layoutEffect
125
125
  // so the theme is registered before <Editor theme=... /> mounts (avoid FOUC),
@@ -1,7 +1,7 @@
1
1
  import { SchemasSettings } from 'monaco-yaml';
2
2
  import { JsonSchema } from './types.js';
3
3
  export declare function rgb2hsl(htmlColor: string): [number, number, number];
4
- export declare function isDark(color: string): boolean;
4
+ export declare function isLightBackground(color: string): boolean;
5
5
  /**
6
6
  * Monaco theme parser ест только hex; rgba(...) превращает в fail-safe red.
7
7
  * Возвращает `#RRGGBBAA` для допустимого цвета, пустую строку — иначе.
package/dist/esm/utils.js CHANGED
@@ -54,9 +54,10 @@ export function rgb2hsl(htmlColor) {
54
54
  }
55
55
  return [h, s, l];
56
56
  }
57
- // Treats colors with low hue + medium lightness OR high hue + high lightness as
58
- // 'light enough that text should be dark'. Hue thresholds use the 0–360 scale.
59
- export function isDark(color) {
57
+ // Возвращает true, когда фон СВЕТЛЫЙ («достаточно светлый, чтобы текст на нём был тёмным»).
58
+ // Пороги оттенка — по шкале 0–360. Прежнее имя isDark читалось ровно наоборот и уже привело
59
+ // к тому, что на светлой теме редактор получал базовую тему vs-dark.
60
+ export function isLightBackground(color) {
60
61
  const [h, , l] = rgb2hsl(color);
61
62
  return (h < 198 && l >= 0.5) || (h >= 198 && l >= 0.75);
62
63
  }