@wistia/kaleidoscope 0.0.8 → 0.0.9-beta.1a75b2cd.e9b254b
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/{color-BuPhQjcd.js → color-D2ukUyQ4.js} +3 -3
- package/dist/{color-BuPhQjcd.js.map → color-D2ukUyQ4.js.map} +1 -1
- package/dist/{engine-6ocr431e.js → engine-BkcGT3zW.js} +739 -443
- package/dist/engine-BkcGT3zW.js.map +1 -0
- package/dist/{engine-CcU0Q8Jg.d.ts → engine-DI3tsQ5q.d.ts} +2 -2
- package/dist/{engine-CcU0Q8Jg.d.ts.map → engine-DI3tsQ5q.d.ts.map} +1 -1
- package/dist/entries/color.js +3 -3
- package/dist/entries/engine.d.ts +1 -1
- package/dist/entries/engine.js +2 -2
- package/dist/entries/styleRegistry.d.ts +1 -1
- package/dist/entries/styleRegistry.js +2 -2
- package/dist/entries/validate.d.ts +1 -1
- package/dist/entries/validate.js +2 -2
- package/dist/entries/vocabulary.d.ts +2 -2
- package/dist/entries/vocabulary.js +3 -3
- package/dist/{getColorLightnessClassification-Dgr8qirZ.js → getColorLightnessClassification-DeMTfiRQ.js} +3 -3
- package/dist/getColorLightnessClassification-DeMTfiRQ.js.map +1 -0
- package/dist/{guards-BPewjm9T.js → guards-COR3JnSB.js} +2 -2
- package/dist/{guards-BPewjm9T.js.map → guards-COR3JnSB.js.map} +1 -1
- package/dist/{index-BTumAeju.d.ts → index-L5x6rNF_.d.ts} +13 -9
- package/dist/{index-BTumAeju.d.ts.map → index-L5x6rNF_.d.ts.map} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +8 -8
- package/dist/{styleRegistry-BsMmbH_0.d.ts → styleRegistry-C7HARIpw.d.ts} +2 -2
- package/dist/{styleRegistry-BsMmbH_0.d.ts.map → styleRegistry-C7HARIpw.d.ts.map} +1 -1
- package/dist/{styleRegistry-BqGmp-3z.js → styleRegistry-DbYq1tOv.js} +74 -74
- package/dist/styleRegistry-DbYq1tOv.js.map +1 -0
- package/dist/{styleVocabulary-CDTPCMhZ.js → styleVocabulary-Ci1NPdH5.js} +2 -2
- package/dist/{styleVocabulary-CDTPCMhZ.js.map → styleVocabulary-Ci1NPdH5.js.map} +1 -1
- package/dist/{typography-BCKqcNDx.js → typography-Bzx3_PhF.js} +8 -3
- package/dist/typography-Bzx3_PhF.js.map +1 -0
- package/dist/{validate-8Ow1tYvz.d.ts → validate-BzIATwDA.d.ts} +2 -2
- package/dist/{validate-8Ow1tYvz.d.ts.map → validate-BzIATwDA.d.ts.map} +1 -1
- package/dist/{validate-D_VsJM1q.js → validate-DXYu6I7I.js} +75 -37
- package/dist/validate-DXYu6I7I.js.map +1 -0
- package/package.json +4 -4
- package/schema/style-v1.json +70 -21
- package/styles/aurora-dark.json +8 -8
- package/styles/aurora-light.json +8 -8
- package/styles/glass-dark.json +8 -8
- package/styles/glass-light.json +8 -8
- package/styles/opaque-bright.json +8 -8
- package/styles/opaque-heavy.json +8 -8
- package/styles/opaque-light.json +8 -8
- package/styles/opaque-medium.json +8 -8
- package/styles/opaque-minimal.json +8 -8
- package/CHANGELOG.md +0 -77
- package/dist/engine-6ocr431e.js.map +0 -1
- package/dist/getColorLightnessClassification-Dgr8qirZ.js.map +0 -1
- package/dist/styleRegistry-BqGmp-3z.js.map +0 -1
- package/dist/typography-BCKqcNDx.js.map +0 -1
- package/dist/validate-D_VsJM1q.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
/*
|
|
3
|
-
* @license @wistia/kaleidoscope v0.0.
|
|
3
|
+
* @license @wistia/kaleidoscope v0.0.9-beta.1a75b2cd.e9b254b
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) 2026, Wistia, Inc. and its affiliates.
|
|
6
6
|
*
|
|
7
7
|
* This source code is unlicensed, all rights reserved.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { a as maxChroma, f as Color,
|
|
10
|
+
import { a as maxChroma, f as Color, g as clamp, h as rgbToOklch, m as oklchToRgb, n as buildBrandedColorScale, r as perceivedLightness, t as getColorLightnessClassification } from "./getColorLightnessClassification-DeMTfiRQ.js";
|
|
11
11
|
// src/getBrandedColorScale.ts
|
|
12
12
|
/**
|
|
13
13
|
* Builds a color scale using the derived light/dark background colors based on the given primary color,
|
|
@@ -145,4 +145,4 @@ const getSlightAccentedBackgroundColor = (_backgroundColor, { shouldReturnWhiteF
|
|
|
145
145
|
};
|
|
146
146
|
export { getHeavyAccentedBackgroundColor as n, getBrandedColorScale as r, getSlightAccentedBackgroundColor as t };
|
|
147
147
|
|
|
148
|
-
//# sourceMappingURL=color-
|
|
148
|
+
//# sourceMappingURL=color-D2ukUyQ4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-BuPhQjcd.js","names":[],"sources":["../src/getBrandedColorScale.ts","../src/private/getAccentedBackgroundByLightness.ts","../src/private/getBackgroundAccentFromPrimaryColor.ts","../src/private/getAccentedBackground.ts","../src/getHeavyAccentedBackgroundColor.ts","../src/getSlightAccentedBackgroundColor.ts"],"sourcesContent":["import type { ColorInput } from './types';\nimport { Color } from './Color';\nimport {\n buildBrandedColorScale,\n DEFAULT_COLOR_SCALE_STEPS,\n} from './private/buildBrandedColorScale';\n\nexport type BrandColorScaleOptions = {\n /** How many steps the scale is divided into. */\n readonly steps?: number;\n};\n\n/**\n * Builds a color scale using the derived light/dark background colors based on the given primary color,\n * with the primary color slotted into the scale wherever it fits based on lightness.\n *\n * It's important to include the primary color in the scale because the light/dark derived background colors\n * do not have the same saturation as the primary color, and we want the scale to reflect the vibrancy\n * of the primary color.\n *\n * @example\n * ```ts\n * getBrandedColorScale('#2949e5').map((color) => color.toHex());\n * // ['#ebeefd', '#d4dbfa', '#bdc8f7', '#a5b5f4', '#8da2f1', '#748eef',\n * // '#5b7aec', '#4263e8', '#2949e5', '#2539ba', '#213080', '#171f45']\n * // ^ the primary, at its own lightness\n * ```\n */\nexport const getBrandedColorScale = (\n primaryColor: ColorInput,\n { steps = DEFAULT_COLOR_SCALE_STEPS }: BrandColorScaleOptions = {},\n): Color[] => {\n const scale = buildBrandedColorScale(new Color(primaryColor), { steps });\n\n return Array.from({ length: steps }, (_, index) => scale.atStep(index));\n};\n","import type { getBackgroundAccentFromPrimaryColor } from './getBackgroundAccentFromPrimaryColor';\nimport { Color } from '../Color';\nimport { getColorLightnessClassification } from '../getColorLightnessClassification';\nimport { DEFAULT_COLOR_SCALE_STEPS } from './buildBrandedColorScale';\nimport { clamp } from './clamp';\nimport { oklchToRgb, rgbToOklch } from './colorSpace';\nimport { ACHROMATIC_CHROMA, maxChroma } from './maxChroma';\nimport { perceivedLightness } from './perceivedLightness';\n\n/**\n * Get the total distance between the lightest and darkest page background colors, measured in lightness.\n * This determines the actual step size we'll use, which correlates to the size of the step between colors\n * in a branded color scale.\n */\nconst MAX_BACKGROUND_LIGHTNESS = 0.95;\nconst MIN_BACKGROUND_LIGHTNESS = 0.09;\nconst STEP_SIZE_IN_LIGHTNESS =\n (MAX_BACKGROUND_LIGHTNESS - MIN_BACKGROUND_LIGHTNESS) / (DEFAULT_COLOR_SCALE_STEPS - 1);\n\n/**\n * Move the background color by the given distance to generate an accented background color.\n * This is used when no primary color has been provided, meaning the background color was not derived from the primary color.\n * The size of the steps used by this utility should match the size of the steps used in the\n * corresponding {@link getBackgroundAccentFromPrimaryColor} utility.\n */\nexport const getAccentedBackgroundByLightness = (\n backgroundColor: Color,\n distanceInSteps: number,\n): Color => {\n const { chroma, hue, lightness } = rgbToOklch(\n backgroundColor.r,\n backgroundColor.g,\n backgroundColor.b,\n );\n const maxPossibleChroma = maxChroma(lightness, hue);\n\n // If there is no perceptible chroma for this color or for the max possible chroma for this hue/lightness,\n // don't try to add any chroma into the result.\n const share =\n chroma < ACHROMATIC_CHROMA || maxPossibleChroma < ACHROMATIC_CHROMA\n ? 0\n : Math.min(1, chroma / maxPossibleChroma);\n\n const atLightness = (candidate: number): Color => {\n const [red, green, blue] = oklchToRgb({\n chroma: share * maxChroma(candidate, hue),\n hue,\n lightness: candidate,\n });\n\n return new Color([red, green, blue, backgroundColor.a]);\n };\n\n const band = getColorLightnessClassification(backgroundColor);\n const towards = band === 'dark' || band === 'veryDark' ? 1 : -1;\n const target = clamp(\n perceivedLightness(backgroundColor) + towards * distanceInSteps * STEP_SIZE_IN_LIGHTNESS,\n 0,\n 1,\n );\n\n let low = 0;\n let high = 1;\n for (let iteration = 0; iteration < 30; iteration += 1) {\n const middle = (low + high) / 2;\n if (perceivedLightness(atLightness(middle)) < target) {\n low = middle;\n } else {\n high = middle;\n }\n }\n\n return atLightness((low + high) / 2);\n};\n","import type { Color } from '../Color';\nimport { getColorLightnessClassification } from '../getColorLightnessClassification';\nimport { buildBrandedColorScale } from './buildBrandedColorScale';\nimport { clamp } from './clamp';\n\n/**\n * Using a branded color scale based on the primary color,\n * move the given background color by the given distance along the scale\n * to generate an accented version of the background color.\n */\nexport const getBackgroundAccentFromPrimaryColor = (\n backgroundColor: Color,\n stepDistance: number,\n primaryColor: Color,\n): Color => {\n const scale = buildBrandedColorScale(primaryColor);\n const last = scale.steps - 1;\n const colorLightnessClass = getColorLightnessClassification(backgroundColor);\n const towards =\n colorLightnessClass === 'dark' || colorLightnessClass === 'veryDark'\n ? -stepDistance\n : stepDistance;\n const from = clamp(Math.round(scale.stepOf(backgroundColor)), 0, last);\n\n return scale.atStep(clamp(from + towards, 0, last));\n};\n","import type { Color } from '../Color';\nimport { getAccentedBackgroundByLightness } from './getAccentedBackgroundByLightness';\nimport { getBackgroundAccentFromPrimaryColor } from './getBackgroundAccentFromPrimaryColor';\n\nexport type AccentedBackgroundOptions = {\n readonly backgroundColor: Color;\n readonly primaryColor?: Color | undefined;\n readonly stepDistance: number;\n};\n\n/**\n * A background `distance` steps off `background`, always in the direction away from it:\n * darker when the background is light, lighter when it is dark.\n *\n * Gets a an accented color spaced apart from the given background color by the given distance.\n * If a primary color is included, we will derive the accent color using a color scale.\n */\nexport const getAccentedBackground = ({\n backgroundColor,\n stepDistance,\n primaryColor,\n}: AccentedBackgroundOptions): Color =>\n primaryColor === undefined\n ? getAccentedBackgroundByLightness(backgroundColor, stepDistance)\n : getBackgroundAccentFromPrimaryColor(backgroundColor, stepDistance, primaryColor);\n","import type { getBrandedColorScale } from './getBrandedColorScale';\nimport type { getSlightAccentedBackgroundColor } from './getSlightAccentedBackgroundColor';\nimport type { ColorInput } from './types';\nimport { Color } from './Color';\nimport { getAccentedBackground } from './private/getAccentedBackground';\n\nexport type HeavyAccentedBackgroundColorOptions = {\n readonly primaryColor?: ColorInput;\n};\n\n/**\n * Get an accented version of a background color that is a two steps lighter/darker.\n * Use this when the color contrast of the accented background color is not significant,\n * such as for card/panel background colors.\n * \n * Accepts an optional primary color, used when the background color has been derived from the primary color,\n * and we want the accented versions of the background color to come from the color scale, see {@link getBrandedColorScale}\n\n * See {@link getSlightAccentedBackgroundColor} for a single step away from the background color instead of two.\n\n *\n * @example\n * ```ts\n * getHeavyAccentedBackgroundColor('#f5f5f5').toHex(); // '#cbcbcb'\n * getHeavyAccentedBackgroundColor('#f5f5f5', { primaryColor: '#2949e5' }).toHex(); // '#adbbf5'\n * ```\n */\nexport const getHeavyAccentedBackgroundColor = (\n _backgroundColor: ColorInput,\n { primaryColor }: HeavyAccentedBackgroundColorOptions = {},\n): Color => {\n const backgroundColor = new Color(_backgroundColor);\n\n return getAccentedBackground({\n backgroundColor,\n stepDistance: 2,\n primaryColor: primaryColor === undefined ? undefined : new Color(primaryColor),\n });\n};\n","import type { getBrandedColorScale } from './getBrandedColorScale';\nimport type { getHeavyAccentedBackgroundColor } from './getHeavyAccentedBackgroundColor';\nimport type { ColorInput } from './types';\nimport { Color } from './Color';\nimport { getAccentedBackground } from './private/getAccentedBackground';\n\nconst WHITE = '#ffffff';\n\nexport type SlightAccentedBackgroundColorOptions = {\n readonly shouldReturnWhiteForWhiteBackground?: boolean;\n /**\n * Optional primary color, which is used when the background color is derived from the primary color,\n * so we'll calculate the accented background color using a color scale.\n */\n readonly primaryColor?: ColorInput;\n};\n\n/**\n * Get an accented version of a background color that is a single step lighter/darker.\n * Use this when the color contrast of the accented background color is not significant,\n * such as for card/panel background colors.\n * \n * Accepts an optional primary color, used when the background color has been derived from the primary color,\n * and we want the accented versions of the background color to come from the color scale, see {@link getBrandedColorScale}\n\n * See {@link getHeavyAccentedBackgroundColor} for two steps away from the background color instead of one.\n *\n * @example\n * ```ts\n * getSlightAccentedBackgroundColor('#f5f5f5').toHex(); // '#e0e0e0'\n * getSlightAccentedBackgroundColor('#f5f5f5', { primaryColor: '#2949e5' }).toHex(); // '#cdd5f9'\n * getSlightAccentedBackgroundColor('#ffffff', { shouldReturnWhiteForWhiteBackground: true }).toHex(); // '#ffffff'\n * ```\n */\nexport const getSlightAccentedBackgroundColor = (\n _backgroundColor: ColorInput,\n {\n shouldReturnWhiteForWhiteBackground = false,\n primaryColor,\n }: SlightAccentedBackgroundColorOptions = {},\n): Color => {\n const backgroundColor = new Color(_backgroundColor);\n\n if (shouldReturnWhiteForWhiteBackground && backgroundColor.toHex() === WHITE) {\n return backgroundColor;\n }\n\n return getAccentedBackground({\n backgroundColor,\n stepDistance: 1,\n primaryColor: primaryColor === undefined ? undefined : new Color(primaryColor),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,wBACX,cACA,EAAE,QAAA,OAA8D,CAAC,MACrD;CACZ,MAAM,QAAQ,uBAAuB,IAAI,MAAM,YAAY,GAAG,EAAE,MAAM,CAAC;CAEvE,OAAO,MAAM,KAAK,EAAE,QAAQ,MAAM,IAAI,GAAG,UAAU,MAAM,OAAO,KAAK,CAAC;AACxE;;ACnBA,MAAM,yBACH,MAAA;;;;;;;AAQH,MAAa,oCACX,iBACA,oBACU;CACV,MAAM,EAAE,QAAQ,KAAK,cAAc,WACjC,gBAAgB,GAChB,gBAAgB,GAChB,gBAAgB,CAClB;CACA,MAAM,oBAAoB,UAAU,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,iBAAsD,CAAC,MAC/C;CACV,MAAM,kBAAkB,IAAI,MAAM,gBAAgB;CAElD,OAAO,sBAAsB;EAC3B;EACA,cAAc;EACd,cAAc,iBAAiB,KAAA,IAAY,KAAA,IAAY,IAAI,MAAM,YAAY;CAC/E,CAAC;AACH;;AChCA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;AA4Bd,MAAa,oCACX,kBACA,EACE,sCAAsC,OACtC,iBACwC,CAAC,MACjC;CACV,MAAM,kBAAkB,IAAI,MAAM,gBAAgB;CAElD,IAAI,uCAAuC,gBAAgB,MAAM,MAAM,OACrE,OAAO;CAGT,OAAO,sBAAsB;EAC3B;EACA,cAAc;EACd,cAAc,iBAAiB,KAAA,IAAY,KAAA,IAAY,IAAI,MAAM,YAAY;CAC/E,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"color-D2ukUyQ4.js","names":[],"sources":["../src/getBrandedColorScale.ts","../src/private/getAccentedBackgroundByLightness.ts","../src/private/getBackgroundAccentFromPrimaryColor.ts","../src/private/getAccentedBackground.ts","../src/getHeavyAccentedBackgroundColor.ts","../src/getSlightAccentedBackgroundColor.ts"],"sourcesContent":["import type { ColorInput } from './types';\nimport { Color } from './Color';\nimport {\n buildBrandedColorScale,\n DEFAULT_COLOR_SCALE_STEPS,\n} from './private/buildBrandedColorScale';\n\nexport type BrandColorScaleOptions = {\n /** How many steps the scale is divided into. */\n readonly steps?: number;\n};\n\n/**\n * Builds a color scale using the derived light/dark background colors based on the given primary color,\n * with the primary color slotted into the scale wherever it fits based on lightness.\n *\n * It's important to include the primary color in the scale because the light/dark derived background colors\n * do not have the same saturation as the primary color, and we want the scale to reflect the vibrancy\n * of the primary color.\n *\n * @example\n * ```ts\n * getBrandedColorScale('#2949e5').map((color) => color.toHex());\n * // ['#ebeefd', '#d4dbfa', '#bdc8f7', '#a5b5f4', '#8da2f1', '#748eef',\n * // '#5b7aec', '#4263e8', '#2949e5', '#2539ba', '#213080', '#171f45']\n * // ^ the primary, at its own lightness\n * ```\n */\nexport const getBrandedColorScale = (\n primaryColor: ColorInput,\n { steps = DEFAULT_COLOR_SCALE_STEPS }: BrandColorScaleOptions = {},\n): Color[] => {\n const scale = buildBrandedColorScale(new Color(primaryColor), { steps });\n\n return Array.from({ length: steps }, (_, index) => scale.atStep(index));\n};\n","import type { getBackgroundAccentFromPrimaryColor } from './getBackgroundAccentFromPrimaryColor';\nimport { Color } from '../Color';\nimport { getColorLightnessClassification } from '../getColorLightnessClassification';\nimport { DEFAULT_COLOR_SCALE_STEPS } from './buildBrandedColorScale';\nimport { clamp } from './clamp';\nimport { oklchToRgb, rgbToOklch } from './colorSpace';\nimport { ACHROMATIC_CHROMA, maxChroma } from './maxChroma';\nimport { perceivedLightness } from './perceivedLightness';\n\n/**\n * Get the total distance between the lightest and darkest page background colors, measured in lightness.\n * This determines the actual step size we'll use, which correlates to the size of the step between colors\n * in a branded color scale.\n */\nconst MAX_BACKGROUND_LIGHTNESS = 0.95;\nconst MIN_BACKGROUND_LIGHTNESS = 0.09;\nconst STEP_SIZE_IN_LIGHTNESS =\n (MAX_BACKGROUND_LIGHTNESS - MIN_BACKGROUND_LIGHTNESS) / (DEFAULT_COLOR_SCALE_STEPS - 1);\n\n/**\n * Move the background color by the given distance to generate an accented background color.\n * This is used when no primary color has been provided, meaning the background color was not derived from the primary color.\n * The size of the steps used by this utility should match the size of the steps used in the\n * corresponding {@link getBackgroundAccentFromPrimaryColor} utility.\n */\nexport const getAccentedBackgroundByLightness = (\n backgroundColor: Color,\n distanceInSteps: number,\n): Color => {\n const { chroma, hue, lightness } = rgbToOklch(\n backgroundColor.r,\n backgroundColor.g,\n backgroundColor.b,\n );\n const maxPossibleChroma = maxChroma(lightness, hue);\n\n // If there is no perceptible chroma for this color or for the max possible chroma for this hue/lightness,\n // don't try to add any chroma into the result.\n const share =\n chroma < ACHROMATIC_CHROMA || maxPossibleChroma < ACHROMATIC_CHROMA\n ? 0\n : Math.min(1, chroma / maxPossibleChroma);\n\n const atLightness = (candidate: number): Color => {\n const [red, green, blue] = oklchToRgb({\n chroma: share * maxChroma(candidate, hue),\n hue,\n lightness: candidate,\n });\n\n return new Color([red, green, blue, backgroundColor.a]);\n };\n\n const band = getColorLightnessClassification(backgroundColor);\n const towards = band === 'dark' || band === 'veryDark' ? 1 : -1;\n const target = clamp(\n perceivedLightness(backgroundColor) + towards * distanceInSteps * STEP_SIZE_IN_LIGHTNESS,\n 0,\n 1,\n );\n\n let low = 0;\n let high = 1;\n for (let iteration = 0; iteration < 30; iteration += 1) {\n const middle = (low + high) / 2;\n if (perceivedLightness(atLightness(middle)) < target) {\n low = middle;\n } else {\n high = middle;\n }\n }\n\n return atLightness((low + high) / 2);\n};\n","import type { Color } from '../Color';\nimport { getColorLightnessClassification } from '../getColorLightnessClassification';\nimport { buildBrandedColorScale } from './buildBrandedColorScale';\nimport { clamp } from './clamp';\n\n/**\n * Using a branded color scale based on the primary color,\n * move the given background color by the given distance along the scale\n * to generate an accented version of the background color.\n */\nexport const getBackgroundAccentFromPrimaryColor = (\n backgroundColor: Color,\n stepDistance: number,\n primaryColor: Color,\n): Color => {\n const scale = buildBrandedColorScale(primaryColor);\n const last = scale.steps - 1;\n const colorLightnessClass = getColorLightnessClassification(backgroundColor);\n const towards =\n colorLightnessClass === 'dark' || colorLightnessClass === 'veryDark'\n ? -stepDistance\n : stepDistance;\n const from = clamp(Math.round(scale.stepOf(backgroundColor)), 0, last);\n\n return scale.atStep(clamp(from + towards, 0, last));\n};\n","import type { Color } from '../Color';\nimport { getAccentedBackgroundByLightness } from './getAccentedBackgroundByLightness';\nimport { getBackgroundAccentFromPrimaryColor } from './getBackgroundAccentFromPrimaryColor';\n\nexport type AccentedBackgroundOptions = {\n readonly backgroundColor: Color;\n readonly primaryColor?: Color | undefined;\n readonly stepDistance: number;\n};\n\n/**\n * A background `distance` steps off `background`, always in the direction away from it:\n * darker when the background is light, lighter when it is dark.\n *\n * Gets a an accented color spaced apart from the given background color by the given distance.\n * If a primary color is included, we will derive the accent color using a color scale.\n */\nexport const getAccentedBackground = ({\n backgroundColor,\n stepDistance,\n primaryColor,\n}: AccentedBackgroundOptions): Color =>\n primaryColor === undefined\n ? getAccentedBackgroundByLightness(backgroundColor, stepDistance)\n : getBackgroundAccentFromPrimaryColor(backgroundColor, stepDistance, primaryColor);\n","import type { getBrandedColorScale } from './getBrandedColorScale';\nimport type { getSlightAccentedBackgroundColor } from './getSlightAccentedBackgroundColor';\nimport type { ColorInput } from './types';\nimport { Color } from './Color';\nimport { getAccentedBackground } from './private/getAccentedBackground';\n\nexport type HeavyAccentedBackgroundColorOptions = {\n readonly primaryColor?: ColorInput;\n};\n\n/**\n * Get an accented version of a background color that is a two steps lighter/darker.\n * Use this when the color contrast of the accented background color is not significant,\n * such as for card/panel background colors.\n * \n * Accepts an optional primary color, used when the background color has been derived from the primary color,\n * and we want the accented versions of the background color to come from the color scale, see {@link getBrandedColorScale}\n\n * See {@link getSlightAccentedBackgroundColor} for a single step away from the background color instead of two.\n\n *\n * @example\n * ```ts\n * getHeavyAccentedBackgroundColor('#f5f5f5').toHex(); // '#cbcbcb'\n * getHeavyAccentedBackgroundColor('#f5f5f5', { primaryColor: '#2949e5' }).toHex(); // '#adbbf5'\n * ```\n */\nexport const getHeavyAccentedBackgroundColor = (\n _backgroundColor: ColorInput,\n { primaryColor }: HeavyAccentedBackgroundColorOptions = {},\n): Color => {\n const backgroundColor = new Color(_backgroundColor);\n\n return getAccentedBackground({\n backgroundColor,\n stepDistance: 2,\n primaryColor: primaryColor === undefined ? undefined : new Color(primaryColor),\n });\n};\n","import type { getBrandedColorScale } from './getBrandedColorScale';\nimport type { getHeavyAccentedBackgroundColor } from './getHeavyAccentedBackgroundColor';\nimport type { ColorInput } from './types';\nimport { Color } from './Color';\nimport { getAccentedBackground } from './private/getAccentedBackground';\n\nconst WHITE = '#ffffff';\n\nexport type SlightAccentedBackgroundColorOptions = {\n readonly shouldReturnWhiteForWhiteBackground?: boolean;\n /**\n * Optional primary color, which is used when the background color is derived from the primary color,\n * so we'll calculate the accented background color using a color scale.\n */\n readonly primaryColor?: ColorInput;\n};\n\n/**\n * Get an accented version of a background color that is a single step lighter/darker.\n * Use this when the color contrast of the accented background color is not significant,\n * such as for card/panel background colors.\n * \n * Accepts an optional primary color, used when the background color has been derived from the primary color,\n * and we want the accented versions of the background color to come from the color scale, see {@link getBrandedColorScale}\n\n * See {@link getHeavyAccentedBackgroundColor} for two steps away from the background color instead of one.\n *\n * @example\n * ```ts\n * getSlightAccentedBackgroundColor('#f5f5f5').toHex(); // '#e0e0e0'\n * getSlightAccentedBackgroundColor('#f5f5f5', { primaryColor: '#2949e5' }).toHex(); // '#cdd5f9'\n * getSlightAccentedBackgroundColor('#ffffff', { shouldReturnWhiteForWhiteBackground: true }).toHex(); // '#ffffff'\n * ```\n */\nexport const getSlightAccentedBackgroundColor = (\n _backgroundColor: ColorInput,\n {\n shouldReturnWhiteForWhiteBackground = false,\n primaryColor,\n }: SlightAccentedBackgroundColorOptions = {},\n): Color => {\n const backgroundColor = new Color(_backgroundColor);\n\n if (shouldReturnWhiteForWhiteBackground && backgroundColor.toHex() === WHITE) {\n return backgroundColor;\n }\n\n return getAccentedBackground({\n backgroundColor,\n stepDistance: 1,\n primaryColor: primaryColor === undefined ? undefined : new Color(primaryColor),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,wBACX,cACA,EAAE,QAAA,OAA8D,CAAC,MACrD;CACZ,MAAM,QAAQ,uBAAuB,IAAI,MAAM,YAAY,GAAG,EAAE,MAAM,CAAC;CAEvE,OAAO,MAAM,KAAK,EAAE,QAAQ,MAAM,IAAI,GAAG,UAAU,MAAM,OAAO,KAAK,CAAC;AACxE;;ACnBA,MAAM,yBACH,MAAA;;;;;;;AAQH,MAAa,oCACX,iBACA,oBACU;CACV,MAAM,EAAE,QAAQ,KAAK,cAAc,WACjC,gBAAgB,GAChB,gBAAgB,GAChB,gBAAgB,CAClB;CACA,MAAM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