@pega/cosmos-react-core 7.0.0-build.8.0 → 7.0.0-build.9.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.
Files changed (62) hide show
  1. package/lib/components/AppShell/AppHeader.styles.js +2 -2
  2. package/lib/components/AppShell/AppHeader.styles.js.map +1 -1
  3. package/lib/components/AppShell/AppShell.styles.js +2 -2
  4. package/lib/components/AppShell/AppShell.styles.js.map +1 -1
  5. package/lib/components/AppShell/style-utils.js +2 -2
  6. package/lib/components/AppShell/style-utils.js.map +1 -1
  7. package/lib/components/Avatar/Avatar.d.ts.map +1 -1
  8. package/lib/components/Avatar/Avatar.js +2 -1
  9. package/lib/components/Avatar/Avatar.js.map +1 -1
  10. package/lib/components/Banner/Banner.d.ts.map +1 -1
  11. package/lib/components/Banner/Banner.js +2 -1
  12. package/lib/components/Banner/Banner.js.map +1 -1
  13. package/lib/components/Button/Button.d.ts.map +1 -1
  14. package/lib/components/Button/Button.js +2 -2
  15. package/lib/components/Button/Button.js.map +1 -1
  16. package/lib/components/DateTime/Picker/Calendar.styles.d.ts.map +1 -1
  17. package/lib/components/DateTime/Picker/Calendar.styles.js +2 -1
  18. package/lib/components/DateTime/Picker/Calendar.styles.js.map +1 -1
  19. package/lib/components/File/FileInput.d.ts.map +1 -1
  20. package/lib/components/File/FileInput.js +15 -12
  21. package/lib/components/File/FileInput.js.map +1 -1
  22. package/lib/components/File/FileList.d.ts.map +1 -1
  23. package/lib/components/File/FileList.js +2 -2
  24. package/lib/components/File/FileList.js.map +1 -1
  25. package/lib/components/FormField/FormField.js +2 -2
  26. package/lib/components/FormField/FormField.js.map +1 -1
  27. package/lib/components/Icon/Icon.d.ts.map +1 -1
  28. package/lib/components/Icon/Icon.js +1 -1
  29. package/lib/components/Icon/Icon.js.map +1 -1
  30. package/lib/components/Label/Label.js +2 -2
  31. package/lib/components/Label/Label.js.map +1 -1
  32. package/lib/components/Link/Link.d.ts.map +1 -1
  33. package/lib/components/Link/Link.js +1 -2
  34. package/lib/components/Link/Link.js.map +1 -1
  35. package/lib/components/Menu/Menu.styles.d.ts.map +1 -1
  36. package/lib/components/Menu/Menu.styles.js +2 -1
  37. package/lib/components/Menu/Menu.styles.js.map +1 -1
  38. package/lib/components/PageTemplates/CategorySubPage.styles.d.ts.map +1 -1
  39. package/lib/components/PageTemplates/CategorySubPage.styles.js +1 -2
  40. package/lib/components/PageTemplates/CategorySubPage.styles.js.map +1 -1
  41. package/lib/components/PageTemplates/PageTemplates.d.ts.map +1 -1
  42. package/lib/components/PageTemplates/PageTemplates.js +1 -1
  43. package/lib/components/PageTemplates/PageTemplates.js.map +1 -1
  44. package/lib/components/Progress/Progress.styles.js +2 -2
  45. package/lib/components/Progress/Progress.styles.js.map +1 -1
  46. package/lib/components/RadioCheck/RadioCheck.js +2 -2
  47. package/lib/components/RadioCheck/RadioCheck.js.map +1 -1
  48. package/lib/components/Switch/Switch.js +2 -2
  49. package/lib/components/Switch/Switch.js.map +1 -1
  50. package/lib/hooks/useI18n.d.ts +3 -0
  51. package/lib/hooks/useI18n.d.ts.map +1 -1
  52. package/lib/i18n/default.d.ts +3 -0
  53. package/lib/i18n/default.d.ts.map +1 -1
  54. package/lib/i18n/default.js +3 -0
  55. package/lib/i18n/default.js.map +1 -1
  56. package/lib/i18n/i18n.d.ts +3 -0
  57. package/lib/i18n/i18n.d.ts.map +1 -1
  58. package/lib/styles/utils.d.ts +7 -5
  59. package/lib/styles/utils.d.ts.map +1 -1
  60. package/lib/styles/utils.js +22 -12
  61. package/lib/styles/utils.js.map +1 -1
  62. package/package.json +1 -1
@@ -1,5 +1,11 @@
1
1
  import type { StyledConfig } from 'styled-components';
2
2
  import type { ContrastScores } from 'polished/lib/types/color';
3
+ declare const wcagContrast: Record<keyof ContrastScores | 'AANonText', number>;
4
+ interface ContrastOptions {
5
+ mode?: 'light' | 'dark' | 'both';
6
+ level?: keyof typeof wcagContrast | number;
7
+ }
8
+ export declare const readableColor: (color: string, { mode, level }?: ContrastOptions) => string;
3
9
  export declare const getHoverColors: (color: string) => {
4
10
  background: string | undefined;
5
11
  foreground: string | undefined;
@@ -8,11 +14,7 @@ export declare const getActiveColors: (color: string) => {
8
14
  background: string | undefined;
9
15
  foreground: string | undefined;
10
16
  };
11
- declare const wcagContrast: Record<keyof ContrastScores | 'AANonText', number>;
12
- export declare const readableHue: (color1: string, color2: string, { mode, level }?: {
13
- mode?: "both" | "dark" | "light" | undefined;
14
- level?: number | keyof ContrastScores | "AANonText" | undefined;
15
- }) => string;
17
+ export declare const readableHue: (color1: string, color2: string, { mode, level }?: ContrastOptions) => string;
16
18
  export declare const omitProps: <O extends object = Record<PropertyKey, unknown>>(prop: keyof O, ...props: (keyof O)[]) => StyledConfig<O>;
17
19
  export type FontSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';
18
20
  export declare const calculateFontSize: (baseFontSize: string, baseFontScale: string | number) => Record<FontSize, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/styles/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAYtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAoB/D,eAAO,MAAM,cAAc,UAAW,MAAM;;;CAE3C,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,MAAM;;;CAE5C,CAAC;AAEF,QAAA,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,EAAE,MAAM,CASpE,CAAC;AAEF,eAAO,MAAM,WAAW,WACd,MAAM,UACN,MAAM;;;MAKb,MAqDF,CAAC;AAEF,eAAO,MAAM,SAAS,4GAIpB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,KAAK,CAAC;AAWrE,eAAO,MAAM,iBAAiB,iBAAkB,MAAM,iBAAiB,MAAM,GAAG,MAAM,6BAkBrF,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/styles/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAYtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAK/D,QAAA,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,EAAE,MAAM,CASpE,CAAC;AAEF,UAAU,eAAe;IACvB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,OAAO,YAAY,GAAG,MAAM,CAAC;CAC5C;AAED,eAAO,MAAM,aAAa,UACjB,MAAM,oBACqB,eAAe,KAChD,MAYF,CAAC;AAiBF,eAAO,MAAM,cAAc,UAAW,MAAM;;;CAE3C,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,MAAM;;;CAE5C,CAAC;AAEF,eAAO,MAAM,WAAW,WACd,MAAM,UACN,MAAM,oBACmB,eAAe,KAC/C,MAqDF,CAAC;AAEF,eAAO,MAAM,SAAS,4GAIpB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,KAAK,CAAC;AAWrE,eAAO,MAAM,iBAAiB,iBAAkB,MAAM,iBAAiB,MAAM,GAAG,MAAM,6BAkBrF,CAAC"}
@@ -1,5 +1,25 @@
1
- import { parseToHsl, lighten, readableColor, darken, getContrast, hsl, modularScale, stripUnit, math } from 'polished';
1
+ import { parseToHsl, lighten, readableColor as polishedReadableColor, darken, getContrast, hsl, modularScale, stripUnit, math } from 'polished';
2
2
  import { tryCatch } from '../utils';
3
+ const wcagContrast = {
4
+ // https://www.w3.org/TR/WCAG21/#contrast-minimum
5
+ AA: 4.5,
6
+ AALarge: 3,
7
+ // https://www.w3.org/TR/WCAG21/#contrast-enhanced
8
+ AAA: 7,
9
+ AAALarge: 4.5,
10
+ // https://www.w3.org/TR/WCAG21/#non-text-contrast
11
+ AANonText: 3
12
+ };
13
+ export const readableColor = (color, { mode = 'light', level = 'AA' } = {}) => {
14
+ const minContrast = typeof level === 'string' ? wcagContrast[level] : level;
15
+ if (mode === 'light' && getContrast('#fff', color) >= minContrast) {
16
+ return '#fff';
17
+ }
18
+ if (mode === 'dark' && getContrast('#000', color) >= minContrast) {
19
+ return '#000';
20
+ }
21
+ return polishedReadableColor(color);
22
+ };
3
23
  const getBackgroundForegroundColors = (color, delta) => {
4
24
  const backgroundLightness = tryCatch(() => parseToHsl(color).lightness, () => 1);
5
25
  let background = tryCatch(() => lighten(delta, color));
@@ -16,16 +36,6 @@ export const getHoverColors = (color) => {
16
36
  export const getActiveColors = (color) => {
17
37
  return getBackgroundForegroundColors(color, 0.2);
18
38
  };
19
- const wcagContrast = {
20
- // https://www.w3.org/TR/WCAG21/#contrast-minimum
21
- AA: 4.5,
22
- AALarge: 3,
23
- // https://www.w3.org/TR/WCAG21/#contrast-enhanced
24
- AAA: 7,
25
- AAALarge: 4.5,
26
- // https://www.w3.org/TR/WCAG21/#non-text-contrast
27
- AANonText: 3
28
- };
29
39
  export const readableHue = (color1, color2, { mode = 'both', level = 'AA' } = {}) => {
30
40
  const minContrast = typeof level === 'string' ? wcagContrast[level] : level;
31
41
  if (getContrast(color1, color2) >= minContrast)
@@ -71,7 +81,7 @@ export const readableHue = (color1, color2, { mode = 'both', level = 'AA' } = {}
71
81
  return lightEnough;
72
82
  if (darkEnough)
73
83
  return darkEnough;
74
- return readableColor(color2);
84
+ return readableColor(color2, { mode, level });
75
85
  };
76
86
  export const omitProps = (...props) => ({
77
87
  shouldForwardProp: (prop, defaultValidatorFn) => !props.includes(prop) && defaultValidatorFn(prop)
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","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YAAoB,EAAE,aAA8B,EAAE,EAAE;IACxF,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE;QAC7C,MAAM,WAAW,GAAG,QAAQ,CAC1B,GAAG,EAAE,CACH,aAAa,KAAK,QAAQ;YACxB,CAAC,CAAC,IAAI,CAAC,GAAG,YAAY,OAAO,KAAK,eAAe,CAAC;YAClD,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,aAAkC,CAAC,EAC3E,GAAG,EAAE,CAAC,YAAY,CACnB,CAAC;QAEF,IAAI,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE;YAC1E,OAAO,CAAC,IAAI,EAAE,aAAa,YAAY,sBAAsB,CAAC,CAAC;SAChE;QAED,OAAO,CAAC,IAAI,EAAE,OAAO,WAAW,SAAS,CAAC,CAAC;IAC7C,CAAC,CAAC,CACyB,CAAC;AAChC,CAAC,CAAC","sourcesContent":["import type { StyledConfig } from 'styled-components';\nimport {\n parseToHsl,\n lighten,\n readableColor,\n darken,\n getContrast,\n hsl,\n modularScale,\n stripUnit,\n math\n} from 'polished';\nimport type { ContrastScores } from 'polished/lib/types/color';\nimport type { ModularScaleRatio } from 'polished/lib/types/modularScaleRatio';\n\nimport { tryCatch } from '../utils';\n\nconst getBackgroundForegroundColors = (color: string, delta: number) => {\n const backgroundLightness = tryCatch(\n () => parseToHsl(color).lightness,\n () => 1\n );\n let background = tryCatch(() => lighten(delta, color));\n let foreground = tryCatch(() => readableColor(lighten(delta, color)));\n if (backgroundLightness > 0.35) {\n background = tryCatch(() => darken(delta, color));\n foreground = tryCatch(() => readableColor(darken(delta, color)));\n }\n\n return { background, foreground };\n};\n\nexport const getHoverColors = (color: string) => {\n return getBackgroundForegroundColors(color, 0.1);\n};\n\nexport const getActiveColors = (color: string) => {\n return getBackgroundForegroundColors(color, 0.2);\n};\n\nconst wcagContrast: Record<keyof ContrastScores | 'AANonText', number> = {\n // https://www.w3.org/TR/WCAG21/#contrast-minimum\n AA: 4.5,\n AALarge: 3,\n // https://www.w3.org/TR/WCAG21/#contrast-enhanced\n AAA: 7,\n AAALarge: 4.5,\n // https://www.w3.org/TR/WCAG21/#non-text-contrast\n AANonText: 3\n};\n\nexport const readableHue = (\n color1: string,\n color2: string,\n {\n mode = 'both',\n level = 'AA'\n }: { mode?: 'light' | 'dark' | 'both'; level?: keyof typeof wcagContrast | number } = {}\n): string => {\n const minContrast = typeof level === 'string' ? wcagContrast[level] : level;\n\n if (getContrast(color1, color2) >= minContrast) return color1;\n\n const { lightness, ...hueSaturation } = parseToHsl(color1);\n\n let shouldLighten = true;\n let shouldDarken = true;\n\n let lightEnough = '';\n let darkEnough = '';\n\n for (let i = 0; i <= 1; i += 0.01) {\n if (shouldLighten) {\n const lightented = hsl({\n ...hueSaturation,\n lightness: Math.min(lightness + i, 1)\n });\n\n if (getContrast(lightented, color2) >= minContrast) {\n if (mode !== 'dark') return lightented;\n\n shouldLighten = false;\n lightEnough = lightented;\n }\n\n if (lightness + i >= 1) shouldLighten = false;\n }\n\n if (shouldDarken) {\n const darkened = hsl({\n ...hueSaturation,\n lightness: Math.max(lightness - i, 0)\n });\n\n if (getContrast(darkened, color2) >= minContrast) {\n if (mode !== 'light') return darkened;\n\n shouldDarken = false;\n darkEnough = darkened;\n }\n\n if (lightness - i <= 0) shouldDarken = false;\n }\n\n if (!shouldLighten && !shouldDarken) break;\n }\n\n if (lightEnough) return lightEnough;\n if (darkEnough) return darkEnough;\n\n return readableColor(color2);\n};\n\nexport const omitProps = <O extends object = Record<PropertyKey, unknown>>(\n ...props: [prop: keyof O, ...props: (keyof O)[]]\n): StyledConfig<O> => ({\n shouldForwardProp: (prop, defaultValidatorFn) => !props.includes(prop) && defaultValidatorFn(prop)\n});\n\nexport type FontSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';\nconst stepsMap = {\n xxs: -2,\n xs: -1,\n s: 0,\n m: 1,\n l: 2,\n xl: 3,\n xxl: 4\n};\n\nexport const calculateFontSize = (baseFontSize: string, baseFontScale: string | number) => {\n return Object.fromEntries(\n Object.entries(stepsMap).map(([size, steps]) => {\n const calculation = tryCatch(\n () =>\n baseFontScale === 'linear'\n ? math(`${baseFontSize} + (${steps} * 0.0625rem)`)\n : modularScale(steps, baseFontSize, baseFontScale as ModularScaleRatio),\n () => baseFontSize\n );\n\n if (size === 'xs' && Number.parseFloat(`${stripUnit(calculation)}`) < 0.75) {\n return [size, `max(calc((${baseFontSize} + 12px) / 2), 12px)`];\n }\n\n return [size, `max(${calculation}, 12px)`];\n })\n ) as Record<FontSize, string>;\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/styles/utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,OAAO,EACP,aAAa,IAAI,qBAAqB,EACtC,MAAM,EACN,WAAW,EACX,GAAG,EACH,YAAY,EACZ,SAAS,EACT,IAAI,EACL,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,YAAY,GAAuD;IACvE,iDAAiD;IACjD,EAAE,EAAE,GAAG;IACP,OAAO,EAAE,CAAC;IACV,kDAAkD;IAClD,GAAG,EAAE,CAAC;IACN,QAAQ,EAAE,GAAG;IACb,kDAAkD;IAClD,SAAS,EAAE,CAAC;CACb,CAAC;AAOF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,KAAa,EACb,EAAE,IAAI,GAAG,OAAO,EAAE,KAAK,GAAG,IAAI,KAAsB,EAAE,EAC9C,EAAE;IACV,MAAM,WAAW,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAA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,CACvB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE;QAC7C,MAAM,WAAW,GAAG,QAAQ,CAC1B,GAAG,EAAE,CACH,aAAa,KAAK,QAAQ;YACxB,CAAC,CAAC,IAAI,CAAC,GAAG,YAAY,OAAO,KAAK,eAAe,CAAC;YAClD,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,aAAkC,CAAC,EAC3E,GAAG,EAAE,CAAC,YAAY,CACnB,CAAC;QAEF,IAAI,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE;YAC1E,OAAO,CAAC,IAAI,EAAE,aAAa,YAAY,sBAAsB,CAAC,CAAC;SAChE;QAED,OAAO,CAAC,IAAI,EAAE,OAAO,WAAW,SAAS,CAAC,CAAC;IAC7C,CAAC,CAAC,CACyB,CAAC;AAChC,CAAC,CAAC","sourcesContent":["import type { StyledConfig } from 'styled-components';\nimport {\n parseToHsl,\n lighten,\n readableColor as polishedReadableColor,\n darken,\n getContrast,\n hsl,\n modularScale,\n stripUnit,\n math\n} from 'polished';\nimport type { ContrastScores } from 'polished/lib/types/color';\nimport type { ModularScaleRatio } from 'polished/lib/types/modularScaleRatio';\n\nimport { tryCatch } from '../utils';\n\nconst wcagContrast: Record<keyof ContrastScores | 'AANonText', number> = {\n // https://www.w3.org/TR/WCAG21/#contrast-minimum\n AA: 4.5,\n AALarge: 3,\n // https://www.w3.org/TR/WCAG21/#contrast-enhanced\n AAA: 7,\n AAALarge: 4.5,\n // https://www.w3.org/TR/WCAG21/#non-text-contrast\n AANonText: 3\n};\n\ninterface ContrastOptions {\n mode?: 'light' | 'dark' | 'both';\n level?: keyof typeof wcagContrast | number;\n}\n\nexport const readableColor = (\n color: string,\n { mode = 'light', level = 'AA' }: ContrastOptions = {}\n): string => {\n const minContrast = typeof level === 'string' ? wcagContrast[level] : level;\n\n if (mode === 'light' && getContrast('#fff', color) >= minContrast) {\n return '#fff';\n }\n\n if (mode === 'dark' && getContrast('#000', color) >= minContrast) {\n return '#000';\n }\n\n return polishedReadableColor(color);\n};\n\nconst getBackgroundForegroundColors = (color: string, delta: number) => {\n const backgroundLightness = tryCatch(\n () => parseToHsl(color).lightness,\n () => 1\n );\n let background = tryCatch(() => lighten(delta, color));\n let foreground = tryCatch(() => readableColor(lighten(delta, color)));\n if (backgroundLightness > 0.35) {\n background = tryCatch(() => darken(delta, color));\n foreground = tryCatch(() => readableColor(darken(delta, color)));\n }\n\n return { background, foreground };\n};\n\nexport const getHoverColors = (color: string) => {\n return getBackgroundForegroundColors(color, 0.1);\n};\n\nexport const getActiveColors = (color: string) => {\n return getBackgroundForegroundColors(color, 0.2);\n};\n\nexport const readableHue = (\n color1: string,\n color2: string,\n { mode = 'both', level = 'AA' }: ContrastOptions = {}\n): string => {\n const minContrast = typeof level === 'string' ? wcagContrast[level] : level;\n\n if (getContrast(color1, color2) >= minContrast) return color1;\n\n const { lightness, ...hueSaturation } = parseToHsl(color1);\n\n let shouldLighten = true;\n let shouldDarken = true;\n\n let lightEnough = '';\n let darkEnough = '';\n\n for (let i = 0; i <= 1; i += 0.01) {\n if (shouldLighten) {\n const lightented = hsl({\n ...hueSaturation,\n lightness: Math.min(lightness + i, 1)\n });\n\n if (getContrast(lightented, color2) >= minContrast) {\n if (mode !== 'dark') return lightented;\n\n shouldLighten = false;\n lightEnough = lightented;\n }\n\n if (lightness + i >= 1) shouldLighten = false;\n }\n\n if (shouldDarken) {\n const darkened = hsl({\n ...hueSaturation,\n lightness: Math.max(lightness - i, 0)\n });\n\n if (getContrast(darkened, color2) >= minContrast) {\n if (mode !== 'light') return darkened;\n\n shouldDarken = false;\n darkEnough = darkened;\n }\n\n if (lightness - i <= 0) shouldDarken = false;\n }\n\n if (!shouldLighten && !shouldDarken) break;\n }\n\n if (lightEnough) return lightEnough;\n if (darkEnough) return darkEnough;\n\n return readableColor(color2, { mode, level });\n};\n\nexport const omitProps = <O extends object = Record<PropertyKey, unknown>>(\n ...props: [prop: keyof O, ...props: (keyof O)[]]\n): StyledConfig<O> => ({\n shouldForwardProp: (prop, defaultValidatorFn) => !props.includes(prop) && defaultValidatorFn(prop)\n});\n\nexport type FontSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';\nconst stepsMap = {\n xxs: -2,\n xs: -1,\n s: 0,\n m: 1,\n l: 2,\n xl: 3,\n xxl: 4\n};\n\nexport const calculateFontSize = (baseFontSize: string, baseFontScale: string | number) => {\n return Object.fromEntries(\n Object.entries(stepsMap).map(([size, steps]) => {\n const calculation = tryCatch(\n () =>\n baseFontScale === 'linear'\n ? math(`${baseFontSize} + (${steps} * 0.0625rem)`)\n : modularScale(steps, baseFontSize, baseFontScale as ModularScaleRatio),\n () => baseFontSize\n );\n\n if (size === 'xs' && Number.parseFloat(`${stripUnit(calculation)}`) < 0.75) {\n return [size, `max(calc((${baseFontSize} + 12px) / 2), 12px)`];\n }\n\n return [size, `max(${calculation}, 12px)`];\n })\n ) as Record<FontSize, string>;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/cosmos-react-core",
3
- "version": "7.0.0-build.8.0",
3
+ "version": "7.0.0-build.9.0",
4
4
  "description": "Cosmos is a visual design system and UI component collection. Its goal is to empower application developers in their pursuit to create engaging and rewarding user experiences.",
5
5
  "repository": {
6
6
  "type": "git",