@epilot/spark-ui 0.22.1 → 0.23.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/components/attachment.d.cts +1 -1
- package/dist/components/attachment.d.ts +1 -1
- package/dist/components/badge.cjs +1 -1
- package/dist/components/badge.cjs.map +1 -1
- package/dist/components/badge.js +1 -1
- package/dist/components/badge.js.map +1 -1
- package/dist/components/bubble.d.cts +1 -1
- package/dist/components/bubble.d.ts +1 -1
- package/dist/components/button.cjs.map +1 -1
- package/dist/components/button.js.map +1 -1
- package/dist/components/calendar.cjs +4 -3
- package/dist/components/calendar.cjs.map +1 -1
- package/dist/components/calendar.js +4 -3
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/callout.d.cts +1 -1
- package/dist/components/callout.d.ts +1 -1
- package/dist/components/checkbox.cjs.map +1 -1
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/circular-gauge.cjs +1 -1
- package/dist/components/circular-gauge.cjs.map +1 -1
- package/dist/components/circular-gauge.js +1 -1
- package/dist/components/circular-gauge.js.map +1 -1
- package/dist/components/drawer.cjs +2 -2
- package/dist/components/drawer.cjs.map +1 -1
- package/dist/components/drawer.js +2 -2
- package/dist/components/drawer.js.map +1 -1
- package/dist/components/energy-breakdown.cjs +1 -1
- package/dist/components/energy-breakdown.cjs.map +1 -1
- package/dist/components/energy-breakdown.js +1 -1
- package/dist/components/energy-breakdown.js.map +1 -1
- package/dist/components/line-chart.cjs +1 -1
- package/dist/components/line-chart.cjs.map +1 -1
- package/dist/components/line-chart.js +2 -2
- package/dist/components/line-chart.js.map +1 -1
- package/dist/components/pill.cjs +2 -2
- package/dist/components/pill.cjs.map +1 -1
- package/dist/components/pill.js +2 -2
- package/dist/components/pill.js.map +1 -1
- package/dist/components/progress.cjs +1 -1
- package/dist/components/progress.cjs.map +1 -1
- package/dist/components/progress.js +1 -1
- package/dist/components/progress.js.map +1 -1
- package/dist/components/segmented-control.cjs +4 -4
- package/dist/components/segmented-control.cjs.map +1 -1
- package/dist/components/segmented-control.d.cts +2 -16
- package/dist/components/segmented-control.d.ts +2 -16
- package/dist/components/segmented-control.js +5 -5
- package/dist/components/segmented-control.js.map +1 -1
- package/dist/components/switch.cjs +1 -1
- package/dist/components/switch.cjs.map +1 -1
- package/dist/components/switch.js +1 -1
- package/dist/components/switch.js.map +1 -1
- package/dist/components/tabs.cjs +2 -2
- package/dist/components/tabs.cjs.map +1 -1
- package/dist/components/tabs.d.cts +1 -8
- package/dist/components/tabs.d.ts +1 -8
- package/dist/components/tabs.js +2 -2
- package/dist/components/tabs.js.map +1 -1
- package/dist/components/toggle-group.cjs +40 -0
- package/dist/components/toggle-group.cjs.map +1 -0
- package/dist/components/toggle-group.d.cts +28 -0
- package/dist/components/toggle-group.d.ts +28 -0
- package/dist/components/toggle-group.js +37 -0
- package/dist/components/toggle-group.js.map +1 -0
- package/dist/components/toggle.cjs +69 -0
- package/dist/components/toggle.cjs.map +1 -0
- package/dist/components/toggle.d.cts +23 -0
- package/dist/components/toggle.d.ts +23 -0
- package/dist/components/toggle.js +66 -0
- package/dist/components/toggle.js.map +1 -0
- package/dist/components/tooltip.cjs +1 -1
- package/dist/components/tooltip.cjs.map +1 -1
- package/dist/components/tooltip.js +1 -1
- package/dist/components/tooltip.js.map +1 -1
- package/dist/lib/generate-radix-colors.cjs +1 -1
- package/dist/lib/generate-radix-colors.cjs.map +1 -1
- package/dist/lib/generate-radix-colors.js +1 -1
- package/dist/lib/generate-radix-colors.js.map +1 -1
- package/dist/lib/toggle-group-context.cjs +12 -0
- package/dist/lib/toggle-group-context.cjs.map +1 -0
- package/dist/lib/toggle-group-context.d.cts +17 -0
- package/dist/lib/toggle-group-context.d.ts +17 -0
- package/dist/lib/toggle-group-context.js +9 -0
- package/dist/lib/toggle-group-context.js.map +1 -0
- package/dist/styles/theme.css +15 -4
- package/dist/utils/format.cjs +1 -0
- package/dist/utils/format.cjs.map +1 -1
- package/dist/utils/format.d.cts +2 -1
- package/dist/utils/format.d.ts +2 -1
- package/dist/utils/format.js +1 -1
- package/dist/utils/format.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-radix-colors.cjs","names":["RadixColors","Color"],"sources":["../../src/lib/generate-radix-colors.tsx"],"sourcesContent":["/**\n * Vendored from Radix UI's website — components/generate-radix-colors.tsx\n * https://github.com/radix-ui/website\n *\n * MIT License — Copyright (c) 2024 WorkOS\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND. (Full text:\n * https://github.com/radix-ui/website/blob/main/LICENSE)\n *\n * Kept VERBATIM so it can be re-synced upstream (this file is excluded from the\n * formatter in vite.config.ts). Strict type-checking is skipped (upstream targets\n * a looser tsconfig with unchecked array indexing over fixed 12-step scales).\n *\n * Only deviation from upstream: `getAlphaColorSrgb`/`getAlphaColorP3` are `export`ed (no\n * algorithm change) so `accent-theme.ts` can re-solve alpha for its canvas-tinted steps\n * with Radix's own solver instead of duplicating its rounding-correction logic. Re-apply\n * these two keywords after a re-sync.\n */\n// @ts-nocheck\nimport * as RadixColors from \"@radix-ui/colors\";\nimport Color from \"colorjs.io\";\nimport BezierEasing from \"bezier-easing\";\n\ntype ArrayOf12<T> = [T, T, T, T, T, T, T, T, T, T, T, T];\nconst arrayOf12 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] as const;\n\n// prettier-ignore\nconst grayScaleNames = ['gray', 'mauve', 'slate', 'sage', 'olive', 'sand'] as const;\n\n// prettier-ignore\nconst scaleNames = [...grayScaleNames, 'tomato', 'red', 'ruby', 'crimson', 'pink',\n'plum', 'purple', 'violet', 'iris', 'indigo', 'blue', 'cyan', 'teal', 'jade', 'green',\n'grass', 'brown', 'orange', 'sky', 'mint', 'lime', 'yellow', 'amber'] as const;\n\nconst lightColors = Object.fromEntries(\n\tscaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}P3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof scaleNames)[number], ArrayOf12<Color>>;\n\nconst darkColors = Object.fromEntries(\n\tscaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}DarkP3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof scaleNames)[number], ArrayOf12<Color>>;\n\nconst lightGrayColors = Object.fromEntries(\n\tgrayScaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}P3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof grayScaleNames)[number], ArrayOf12<Color>>;\n\nconst darkGrayColors = Object.fromEntries(\n\tgrayScaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}DarkP3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof grayScaleNames)[number], ArrayOf12<Color>>;\n\nexport const generateRadixColors = ({\n\tappearance,\n\t...args\n}: {\n\tappearance: \"light\" | \"dark\";\n\taccent: string;\n\tgray: string;\n\tbackground: string;\n}) => {\n\tconst allScales = appearance === \"light\" ? lightColors : darkColors;\n\tconst grayScales = appearance === \"light\" ? lightGrayColors : darkGrayColors;\n\tconst backgroundColor = new Color(args.background).to(\"oklch\");\n\n\tconst grayBaseColor = new Color(args.gray).to(\"oklch\");\n\tconst grayScaleColors = getScaleFromColor(grayBaseColor, grayScales, backgroundColor);\n\n\tconst accentBaseColor = new Color(args.accent).to(\"oklch\");\n\n\tlet accentScaleColors = getScaleFromColor(accentBaseColor, allScales, backgroundColor);\n\n\t// Enforce srgb for the background color\n\tconst backgroundHex = backgroundColor.to(\"srgb\").toString({ format: \"hex\" });\n\n\t// Make sure we use the tint from the gray scale for when base is pure white or black\n\tconst accentBaseHex = accentBaseColor.to(\"srgb\").toString({ format: \"hex\" });\n\tif (accentBaseHex === \"#000\" || accentBaseHex === \"#fff\") {\n\t\taccentScaleColors = grayScaleColors.map((color) => color.clone()) as ArrayOf12<Color>;\n\t}\n\n\tconst [accent9Color, accentContrastColor] = getStep9Colors(accentScaleColors, accentBaseColor);\n\n\taccentScaleColors[8] = accent9Color;\n\taccentScaleColors[9] = getButtonHoverColor(accent9Color, [accentScaleColors]);\n\n\t// Limit saturation of the text colors\n\taccentScaleColors[10].coords[1] = Math.min(\n\t\tMath.max(accentScaleColors[8].coords[1], accentScaleColors[7].coords[1]),\n\t\taccentScaleColors[10].coords[1],\n\t);\n\taccentScaleColors[11].coords[1] = Math.min(\n\t\tMath.max(accentScaleColors[8].coords[1], accentScaleColors[7].coords[1]),\n\t\taccentScaleColors[11].coords[1],\n\t);\n\n\tconst accentScaleHex = accentScaleColors.map((color) =>\n\t\tcolor.to(\"srgb\").toString({ format: \"hex\" }),\n\t) as ArrayOf12<string>;\n\n\tconst accentScaleWideGamut = accentScaleColors.map(toOklchString) as ArrayOf12<string>;\n\n\tconst accentScaleAlphaHex = accentScaleHex.map((color) =>\n\t\tgetAlphaColorSrgb(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentScaleAlphaWideGamutString = accentScaleHex.map((color) =>\n\t\tgetAlphaColorP3(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentContrastColorHex = accentContrastColor.to(\"srgb\").toString({ format: \"hex\" });\n\n\tconst grayScaleHex = grayScaleColors.map((color) =>\n\t\tcolor.to(\"srgb\").toString({ format: \"hex\" }),\n\t) as ArrayOf12<string>;\n\n\tconst grayScaleWideGamut = grayScaleColors.map(toOklchString) as ArrayOf12<string>;\n\n\tconst grayScaleAlphaHex = grayScaleHex.map((color) =>\n\t\tgetAlphaColorSrgb(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst grayScaleAlphaWideGamutString = grayScaleHex.map((color) =>\n\t\tgetAlphaColorP3(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentSurfaceHex =\n\t\tappearance === \"light\"\n\t\t\t? getAlphaColorSrgb(accentScaleHex[1], backgroundHex, 0.8)\n\t\t\t: getAlphaColorSrgb(accentScaleHex[1], backgroundHex, 0.5);\n\n\tconst accentSurfaceWideGamutString =\n\t\tappearance === \"light\"\n\t\t\t? getAlphaColorP3(accentScaleWideGamut[1], backgroundHex, 0.8)\n\t\t\t: getAlphaColorP3(accentScaleWideGamut[1], backgroundHex, 0.5);\n\n\treturn {\n\t\taccentScale: accentScaleHex,\n\t\taccentScaleAlpha: accentScaleAlphaHex,\n\t\taccentScaleWideGamut: accentScaleWideGamut,\n\t\taccentScaleAlphaWideGamut: accentScaleAlphaWideGamutString,\n\t\taccentContrast: accentContrastColorHex,\n\n\t\tgrayScale: grayScaleHex,\n\t\tgrayScaleAlpha: grayScaleAlphaHex,\n\t\tgrayScaleWideGamut: grayScaleWideGamut,\n\t\tgrayScaleAlphaWideGamut: grayScaleAlphaWideGamutString,\n\n\t\tgraySurface: appearance === \"light\" ? \"#ffffffcc\" : \"rgba(0, 0, 0, 0.05)\",\n\t\tgraySurfaceWideGamut:\n\t\t\tappearance === \"light\" ? \"color(display-p3 1 1 1 / 80%)\" : \"color(display-p3 0 0 0 / 5%)\",\n\n\t\taccentSurface: accentSurfaceHex,\n\t\taccentSurfaceWideGamut: accentSurfaceWideGamutString,\n\n\t\tbackground: backgroundHex,\n\t};\n};\n\nfunction getStep9Colors(scale: ArrayOf12<Color>, accentBaseColor: Color): [Color, Color] {\n\tconst referenceBackgroundColor = scale[0];\n\tconst distance = accentBaseColor.deltaEOK(referenceBackgroundColor) * 100;\n\n\t// If the accent base color is close to the page background color, it's likely\n\t// white on white or black on black, so we want to return something that makes sense instead\n\tif (distance < 25) {\n\t\treturn [scale[8], getTextColor(scale[8])];\n\t}\n\n\treturn [accentBaseColor, getTextColor(accentBaseColor)];\n}\n\nfunction getButtonHoverColor(source: Color, scales: ArrayOf12<Color>[]) {\n\tconst [L, C, H] = source.coords;\n\tconst newL = L > 0.4 ? L - 0.03 / (L + 0.1) : L + 0.03 / (L + 0.1);\n\tconst newC = L > 0.4 && !isNaN(H) ? C * 0.93 + 0 : C;\n\tconst buttonHoverColor = new Color(\"oklch\", [newL, newC, H]);\n\n\t// Find closest in-scale color to donate the chroma and hue.\n\t// Especially useful when the source color is pure white or black,\n\t// but the gray scale is tinted.\n\tlet closestColor = buttonHoverColor;\n\tlet minDistance = Infinity;\n\n\tscales.forEach((scale) => {\n\t\tfor (const color of scale) {\n\t\t\tconst distance = buttonHoverColor.deltaEOK(color);\n\t\t\tif (distance < minDistance) {\n\t\t\t\tminDistance = distance;\n\t\t\t\tclosestColor = color;\n\t\t\t}\n\t\t}\n\t});\n\n\tbuttonHoverColor.coords[1] = closestColor.coords[1];\n\tbuttonHoverColor.coords[2] = closestColor.coords[2];\n\treturn buttonHoverColor;\n}\n\nfunction getScaleFromColor(\n\tsource: Color,\n\tscales: Record<string, ArrayOf12<Color>>,\n\tbackgroundColor: Color,\n) {\n\tlet allColors: { scale: string; color: Color; distance: number }[] = [];\n\n\tObject.entries(scales).forEach(([name, scale]) => {\n\t\tfor (const color of scale) {\n\t\t\tconst distance = source.deltaEOK(color);\n\t\t\tallColors.push({ scale: name, distance, color });\n\t\t}\n\t});\n\n\tallColors.sort((a, b) => a.distance - b.distance);\n\n\t// Remove non-unique scales\n\tlet closestColors = allColors.filter(\n\t\t(color, i, arr) => i === arr.findIndex((value) => value.scale === color.scale),\n\t);\n\n\t// If the next two closest colors are both grays, remove the second one until it’s not a gray anymore.\n\t// This is because up next we will be comparing how close the two closest colors are to the source color,\n\t// and since the grays are all extremely close to each other, we won’t get any useful data from the second\n\t// closest color if it’s also a gray.\n\tconst grayScaleNamesStr = grayScaleNames as readonly string[];\n\tconst allAreGrays = closestColors.every((color) => grayScaleNamesStr.includes(color.scale));\n\tif (!allAreGrays && grayScaleNamesStr.includes(closestColors[0].scale)) {\n\t\twhile (grayScaleNamesStr.includes(closestColors[1].scale)) {\n\t\t\tclosestColors.splice(1, 1);\n\t\t}\n\t}\n\n\tlet colorA = closestColors[0];\n\tlet colorB = closestColors[1];\n\n\t// Light trigonometry ahead.\n\t//\n\t// We want to determine the color that is the closest to the source color. Sometimes it makes sense\n\t// to proportionally mix the two closest colors together, but sometimes it is not useful at all.\n\t// Color coords are spatial in 3D, however we can treat the data we have as a 2D projection that is good enough.\n\t//\n\t// Case 1:\n\t// If the distances between the source color, the 1st closest color (A) and the 2nd closest color (B) form\n\t// a triangle where NEITHER angle A nor B are larger than 90 degrees, then we want to mix the 1st and the 2nd\n\t// closest colors in the same proportion as distances AD and BD are to each other. Mixing the two would result\n\t// in a color that would be closer to the source color than either of the two original closest colors.\n\t// Example: source color is a desaturated blue, which is between \"indigo\" and \"slate\" scales.\n\t//\n\t// C ← Source color\n\t// /|⟍\n\t// / | ⟍\n\t// b / | ⟍ a\n\t// / | ⟍\n\t// / | ⟍\n\t// A --- D -------- B\n\t// ↑\n\t// The color we want to use as the base, which is a mix of A and B.\n\t//\n\t// Case 2:\n\t// If the distances between the source color, the 1st closest color (A) and the 2nd closest color (B) form\n\t// a triangle where EITHER angle A or B are larger than 90 degrees, then we don’t care about point B because it’s\n\t// directionally the same as A, as mixing A and B can’t provide us with a color that is any closer to the source.\n\t// Example: source color is a saturated blue, with \"blue\" being the closest scale, and \"indigo\" just being further.\n\t//\n\t// C ← Source color\n\t// \\⟍\n\t// \\ ⟍\n\t// \\ ⟍ a\n\t// b \\ ⟍\n\t// \\ ⟍\n\t// A ------- B\n\t// ↑\n\t// The color we want to use as the base, which is not influenced by B.\n\n\t// We’ll need all the lengths of the triangle sides, named after the angles they look at:\n\tconst a = colorB.distance;\n\tconst b = colorA.distance;\n\tconst c = colorA.color.deltaEOK(colorB.color);\n\n\t// We can get the ratios of AD to BD lengths with trigonometry using tangents,\n\t// as the ratio of the tangents of the opposite angles will match.\n\tconst cosA = (b ** 2 + c ** 2 - a ** 2) / (2 * b * c);\n\tconst radA = Math.acos(cosA);\n\tconst sinA = Math.sin(radA);\n\n\tconst cosB = (a ** 2 + c ** 2 - b ** 2) / (2 * a * c);\n\tconst radB = Math.acos(cosB);\n\tconst sinB = Math.sin(radB);\n\n\t// Tangent of angle C in the ACD triangle\n\tconst tanC1 = cosA / sinA;\n\n\t// Tangent of angle C in the BCD triangle\n\tconst tanC2 = cosB / sinB;\n\n\t// The ratio of the tangents corresponds to the ratio of the distances AD to BD\n\t// In the end, it means how much of scale B we want to mix into scale A.\n\t// If it’s \"0\" or less, this is an obtuse triangle from case 2, and we use just scale A.\n\tconst ratio = Math.max(0, tanC1 / tanC2) * 0.5;\n\n\t// The base scale is going to be a mix of the two closest scales, with the mix ratio we determined before\n\tconst scaleA = scales[colorA.scale];\n\tconst scaleB = scales[colorB.scale];\n\tconst scale = arrayOf12.map((i) =>\n\t\tnew Color(Color.mix(scaleA[i], scaleB[i], ratio)).to(\"oklch\"),\n\t) as ArrayOf12<Color>;\n\n\t// Get the closest color from the pre-mixed scale we created\n\tconst baseColor = scale.slice().sort((a, b) => source.deltaEOK(a) - source.deltaEOK(b))[0];\n\n\t// Note the chroma difference between the source color and the base color\n\tconst ratioC = source.coords[1] / baseColor.coords[1];\n\n\t// Modify hue and chroma of the scale to match the source color\n\tscale.forEach((color) => {\n\t\tcolor.coords[1] = Math.min(source.coords[1] * 1.5, color.coords[1] * ratioC);\n\t\tcolor.coords[2] = source.coords[2];\n\t});\n\n\t// Light mode\n\tif (scale[0].coords[0] > 0.5) {\n\t\tconst lightnessScale = scale.map(({ coords }) => coords[0]);\n\t\tconst backgroundL = Math.max(0, Math.min(1, backgroundColor.coords[0]));\n\t\tconst newLightnessScale = transposeProgressionStart(\n\t\t\tbackgroundL,\n\t\t\t// Add white as the first \"step\" of the light scale\n\t\t\t[1, ...lightnessScale],\n\t\t\tlightModeEasing,\n\t\t);\n\n\t\t// Remove the step we added\n\t\tnewLightnessScale.shift();\n\n\t\tnewLightnessScale.forEach((lightness, i) => {\n\t\t\tscale[i].coords[0] = lightness;\n\t\t});\n\n\t\treturn scale;\n\t}\n\n\t// Dark mode\n\tlet ease: typeof darkModeEasing = [...darkModeEasing];\n\tconst referenceBackgroundColorL = scale[0].coords[0];\n\tconst backgroundColorL = Math.max(0, Math.min(1, backgroundColor.coords[0]));\n\n\t// If background is lighter than step 0, we want to gradually change the easing to linear\n\tconst ratioL = backgroundColorL / referenceBackgroundColorL;\n\n\tif (ratioL > 1) {\n\t\tconst maxRatio = 1.5;\n\n\t\tfor (let i = 0; i < ease.length; i++) {\n\t\t\tconst metaRatio = (ratioL - 1) * (maxRatio / (maxRatio - 1));\n\t\t\tease[i] = ratioL > maxRatio ? 0 : Math.max(0, ease[i] * (1 - metaRatio));\n\t\t}\n\t}\n\n\tconst lightnessScale = scale.map(({ coords }) => coords[0]);\n\tconst backgroundL = backgroundColor.coords[0];\n\tconst newLightnessScale = transposeProgressionStart(backgroundL, lightnessScale, ease);\n\n\tnewLightnessScale.forEach((lightness, i) => {\n\t\tscale[i].coords[0] = lightness;\n\t});\n\n\treturn scale;\n}\n\nfunction getTextColor(background: Color) {\n\tconst white = new Color(\"oklch\", [1, 0, 0]);\n\n\tif (Math.abs(white.contrastAPCA(background)) < 40) {\n\t\tconst [, C, H] = background.coords;\n\t\treturn new Color(\"oklch\", [0.25, Math.max(0.08 * C, 0.04), H]);\n\t}\n\n\treturn white;\n}\n\n// target = background * (1 - alpha) + foreground * alpha\n// alpha = (target - background) / (foreground - background)\n// Expects 0-1 numbers for the RGB channels\n// oxlint-disable-next-line eslint/complexity -- pre-existing; split it before adding branches\nfunction getAlphaColor(\n\ttargetRgb: number[],\n\tbackgroundRgb: number[],\n\trgbPrecision: number,\n\talphaPrecision: number,\n\ttargetAlpha?: number,\n) {\n\tconst [tr, tg, tb] = targetRgb.map((c) => Math.round(c * rgbPrecision));\n\tconst [br, bg, bb] = backgroundRgb.map((c) => Math.round(c * rgbPrecision));\n\n\tif (\n\t\ttr === undefined ||\n\t\ttg === undefined ||\n\t\ttb === undefined ||\n\t\tbr === undefined ||\n\t\tbg === undefined ||\n\t\tbb === undefined\n\t) {\n\t\tthrow Error(\"Color is undefined\");\n\t}\n\n\t// Is the background color lighter, RGB-wise, than target color?\n\t// Decide whether we want to add as little color or as much color as possible,\n\t// darkening or lightening the background respectively.\n\t// If at least one of the bits of the target RGB value\n\t// is lighter than the background, we want to lighten it.\n\tlet desiredRgb = 0;\n\tif (tr > br) {\n\t\tdesiredRgb = rgbPrecision;\n\t} else if (tg > bg) {\n\t\tdesiredRgb = rgbPrecision;\n\t} else if (tb > bb) {\n\t\tdesiredRgb = rgbPrecision;\n\t}\n\n\tconst alphaR = (tr - br) / (desiredRgb - br);\n\tconst alphaG = (tg - bg) / (desiredRgb - bg);\n\tconst alphaB = (tb - bb) / (desiredRgb - bb);\n\n\tconst isPureGray = [alphaR, alphaG, alphaB].every((alpha) => alpha === alphaR);\n\n\t// No need for precision gymnastics with pure grays, and we can get cleaner output\n\tif (!targetAlpha && isPureGray) {\n\t\t// Convert back to 0-1 values\n\t\tconst V = desiredRgb / rgbPrecision;\n\t\treturn [V, V, V, alphaR] as const;\n\t}\n\n\tconst clampRgb = (n: number) => (isNaN(n) ? 0 : Math.min(rgbPrecision, Math.max(0, n)));\n\tconst clampA = (n: number) => (isNaN(n) ? 0 : Math.min(alphaPrecision, Math.max(0, n)));\n\tconst maxAlpha = targetAlpha ?? Math.max(alphaR, alphaG, alphaB);\n\n\tconst A = clampA(Math.ceil(maxAlpha * alphaPrecision)) / alphaPrecision;\n\tlet R = clampRgb(((br * (1 - A) - tr) / A) * -1);\n\tlet G = clampRgb(((bg * (1 - A) - tg) / A) * -1);\n\tlet B = clampRgb(((bb * (1 - A) - tb) / A) * -1);\n\n\tR = Math.ceil(R);\n\tG = Math.ceil(G);\n\tB = Math.ceil(B);\n\n\tconst blendedR = blendAlpha(R, A, br);\n\tconst blendedG = blendAlpha(G, A, bg);\n\tconst blendedB = blendAlpha(B, A, bb);\n\n\t// Correct for rounding errors in light mode\n\tif (desiredRgb === 0) {\n\t\tif (tr <= br && tr !== blendedR) {\n\t\t\tR = tr > blendedR ? R + 1 : R - 1;\n\t\t}\n\n\t\tif (tg <= bg && tg !== blendedG) {\n\t\t\tG = tg > blendedG ? G + 1 : G - 1;\n\t\t}\n\n\t\tif (tb <= bb && tb !== blendedB) {\n\t\t\tB = tb > blendedB ? B + 1 : B - 1;\n\t\t}\n\t}\n\n\t// Correct for rounding errors in dark mode\n\tif (desiredRgb === rgbPrecision) {\n\t\tif (tr >= br && tr !== blendedR) {\n\t\t\tR = tr > blendedR ? R + 1 : R - 1;\n\t\t}\n\n\t\tif (tg >= bg && tg !== blendedG) {\n\t\t\tG = tg > blendedG ? G + 1 : G - 1;\n\t\t}\n\n\t\tif (tb >= bb && tb !== blendedB) {\n\t\t\tB = tb > blendedB ? B + 1 : B - 1;\n\t\t}\n\t}\n\n\t// Convert back to 0-1 values\n\tR = R / rgbPrecision;\n\tG = G / rgbPrecision;\n\tB = B / rgbPrecision;\n\n\treturn [R, G, B, A] as const;\n}\n\n// Important – I empirically discovered that this rounding is how the browser actually overlays\n// transparent RGB bits over each other. It does NOT round the whole result altogether.\nfunction blendAlpha(foreground: number, alpha: number, background: number, round = true) {\n\tif (round) {\n\t\treturn Math.round(background * (1 - alpha)) + Math.round(foreground * alpha);\n\t}\n\n\treturn background * (1 - alpha) + foreground * alpha;\n}\n\nexport function getAlphaColorSrgb(targetColor: string, backgroundColor: string, targetAlpha?: number) {\n\tconst [r, g, b, a] = getAlphaColor(\n\t\tnew Color(targetColor).to(\"srgb\").coords,\n\t\tnew Color(backgroundColor).to(\"srgb\").coords,\n\t\t255,\n\t\t255,\n\t\ttargetAlpha,\n\t);\n\n\treturn formatHex(new Color(\"srgb\", [r, g, b], a).toString({ format: \"hex\" }));\n}\n\nexport function getAlphaColorP3(targetColor: string, backgroundColor: string, targetAlpha?: number) {\n\tconst [r, g, b, a] = getAlphaColor(\n\t\tnew Color(targetColor).to(\"p3\").coords,\n\t\tnew Color(backgroundColor).to(\"p3\").coords,\n\t\t// Not sure why, but the resulting P3 alpha colors are blended in the browser most precisely when\n\t\t// rounded to 255 integers too. Is the browser using 0-255 rather than 0-1 under the hood for P3 too?\n\t\t255,\n\t\t1000,\n\t\ttargetAlpha,\n\t);\n\n\treturn (\n\t\tnew Color(\"p3\", [r, g, b], a)\n\t\t\t.toString({ precision: 4 })\n\t\t\t// Important: in non-browser environments colorjs.io outputs a different format for some reason\n\t\t\t.replace(\"color(p3 \", \"color(display-p3 \")\n\t);\n}\n\n// Format shortform hex to longform\nfunction formatHex(str: string) {\n\tif (!str.startsWith(\"#\")) {\n\t\treturn str;\n\t}\n\n\tif (str.length === 4) {\n\t\tconst hash = str.charAt(0);\n\t\tconst r = str.charAt(1);\n\t\tconst g = str.charAt(2);\n\t\tconst b = str.charAt(3);\n\t\treturn hash + r + r + g + g + b + b;\n\t}\n\n\tif (str.length === 5) {\n\t\tconst hash = str.charAt(0);\n\t\tconst r = str.charAt(1);\n\t\tconst g = str.charAt(2);\n\t\tconst b = str.charAt(3);\n\t\tconst a = str.charAt(4);\n\t\treturn hash + r + r + g + g + b + b + a + a;\n\t}\n\n\treturn str;\n}\n\nconst darkModeEasing = [1, 0, 1, 0] as [number, number, number, number];\nconst lightModeEasing = [0, 2, 0, 2] as [number, number, number, number];\n\nexport function transposeProgressionStart(\n\tto: number,\n\tarr: number[],\n\tcurve: [number, number, number, number],\n) {\n\treturn arr.map((n, i, arr) => {\n\t\tconst lastIndex = arr.length - 1;\n\t\tconst diff = arr[0] - to;\n\t\tconst fn = BezierEasing(...curve);\n\t\treturn n - diff * fn(1 - i / lastIndex);\n\t});\n}\n\nexport function transposeProgressionEnd(\n\tto: number,\n\tarr: number[],\n\tcurve: [number, number, number, number],\n) {\n\treturn arr.map((n, i, arr) => {\n\t\tconst lastIndex = arr.length - 1;\n\t\tconst diff = arr[lastIndex] - to;\n\t\tconst fn = BezierEasing(...curve);\n\t\treturn n - diff * fn(i / lastIndex);\n\t});\n}\n\n// Convert to OKLCH string with percentage for the lightness channel\n// https://github.com/radix-ui/themes/issues/420\nfunction toOklchString(color: Color) {\n\tconst L = +(color.coords[0] * 100).toFixed(1);\n\treturn color\n\t\t.to(\"oklch\")\n\t\t.toString({ precision: 4 })\n\t\t.replace(/(\\S+)(.+)/, `oklch(${L}%$2`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,YAAY;CAAC;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAI;AAAE;AAGvD,MAAM,iBAAiB;CAAC;CAAQ;CAAS;CAAS;CAAQ;CAAS;AAAM;AAGzE,MAAM,aAAa;CAAC,GAAG;CAAgB;CAAU;CAAO;CAAQ;CAAW;CAC3E;CAAQ;CAAU;CAAU;CAAQ;CAAU;CAAQ;CAAQ;CAAQ;CAAQ;CAC9E;CAAS;CAAS;CAAU;CAAO;CAAQ;CAAQ;CAAU;AAAO;AAEpE,MAAM,cAAc,OAAO,YAC1B,WAAW,KAAK,cAAc,CAC7B,WACA,OAAO,OAAOA,iBAAY,GAAG,UAAU,IAAI,EAAE,KAAK,QAAQ,IAAIC,WAAAA,QAAM,GAAG,EAAE,GAAG,OAAO,CAAC,CACrF,CAAC,CACF;AAEA,MAAM,aAAa,OAAO,YACzB,WAAW,KAAK,cAAc,CAC7B,WACA,OAAO,OAAOD,iBAAY,GAAG,UAAU,QAAQ,EAAE,KAAK,QAAQ,IAAIC,WAAAA,QAAM,GAAG,EAAE,GAAG,OAAO,CAAC,CACzF,CAAC,CACF;AAEA,MAAM,kBAAkB,OAAO,YAC9B,eAAe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AG,GAAG,QAAQ;EAC7B,MAAM,YAAY,IAAI,SAAS;EAG/B,OAAO,KAFM,IAAI,KAAK,OAAA,GAAA,cAAA,SACE,GAAG,KACR,EAAE,IAAI,IAAI,SAAS;CACvC,CAAC;AACF;AAEA,SAAgB,wBACf,IACA,KACA,OACC;CACD,OAAO,IAAI,KAAK,GAAG,GAAG,QAAQ;EAC7B,MAAM,YAAY,IAAI,SAAS;EAG/B,OAAO,KAFM,IAAI,aAAa,OAAA,GAAA,cAAA,SACN,GAAG,KACR,EAAE,IAAI,SAAS;CACnC,CAAC;AACF;AAIA,SAAS,cAAc,OAAc;CACpC,MAAM,IAAI,EAAE,MAAM,OAAO,KAAK,KAAK,QAAQ,CAAC;CAC5C,OAAO,MACL,GAAG,OAAO,EACV,SAAS,EAAE,WAAW,EAAE,CAAC,EACzB,QAAQ,aAAa,SAAS,EAAE,IAAI;AACvC"}
|
|
1
|
+
{"version":3,"file":"generate-radix-colors.cjs","names":["RadixColors","Color"],"sources":["../../src/lib/generate-radix-colors.tsx"],"sourcesContent":["/**\n * Vendored from Radix UI's website — components/generate-radix-colors.tsx\n * https://github.com/radix-ui/website\n *\n * MIT License — Copyright (c) 2024 WorkOS\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND. (Full text:\n * https://github.com/radix-ui/website/blob/main/LICENSE)\n *\n * Kept VERBATIM so it can be re-synced upstream (this file is excluded from the\n * formatter in vite.config.ts). Strict type-checking is skipped (upstream targets\n * a looser tsconfig with unchecked array indexing over fixed 12-step scales).\n *\n * Only deviation from upstream: `getAlphaColorSrgb`/`getAlphaColorP3` are `export`ed (no\n * algorithm change) so `accent-theme.ts` can re-solve alpha for its canvas-tinted steps\n * with Radix's own solver instead of duplicating its rounding-correction logic. Re-apply\n * these two keywords after a re-sync.\n */\n// @ts-nocheck\nimport * as RadixColors from \"@radix-ui/colors\";\nimport Color from \"colorjs.io\";\nimport BezierEasing from \"bezier-easing\";\n\ntype ArrayOf12<T> = [T, T, T, T, T, T, T, T, T, T, T, T];\nconst arrayOf12 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] as const;\n\n// prettier-ignore\nconst grayScaleNames = ['gray', 'mauve', 'slate', 'sage', 'olive', 'sand'] as const;\n\n// prettier-ignore\nconst scaleNames = [...grayScaleNames, 'tomato', 'red', 'ruby', 'crimson', 'pink',\n'plum', 'purple', 'violet', 'iris', 'indigo', 'blue', 'cyan', 'teal', 'jade', 'green',\n'grass', 'brown', 'orange', 'sky', 'mint', 'lime', 'yellow', 'amber'] as const;\n\nconst lightColors = Object.fromEntries(\n\tscaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}P3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof scaleNames)[number], ArrayOf12<Color>>;\n\nconst darkColors = Object.fromEntries(\n\tscaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}DarkP3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof scaleNames)[number], ArrayOf12<Color>>;\n\nconst lightGrayColors = Object.fromEntries(\n\tgrayScaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}P3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof grayScaleNames)[number], ArrayOf12<Color>>;\n\nconst darkGrayColors = Object.fromEntries(\n\tgrayScaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}DarkP3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof grayScaleNames)[number], ArrayOf12<Color>>;\n\nexport const generateRadixColors = ({\n\tappearance,\n\t...args\n}: {\n\tappearance: \"light\" | \"dark\";\n\taccent: string;\n\tgray: string;\n\tbackground: string;\n}) => {\n\tconst allScales = appearance === \"light\" ? lightColors : darkColors;\n\tconst grayScales = appearance === \"light\" ? lightGrayColors : darkGrayColors;\n\tconst backgroundColor = new Color(args.background).to(\"oklch\");\n\n\tconst grayBaseColor = new Color(args.gray).to(\"oklch\");\n\tconst grayScaleColors = getScaleFromColor(grayBaseColor, grayScales, backgroundColor);\n\n\tconst accentBaseColor = new Color(args.accent).to(\"oklch\");\n\n\tlet accentScaleColors = getScaleFromColor(accentBaseColor, allScales, backgroundColor);\n\n\t// Enforce srgb for the background color\n\tconst backgroundHex = backgroundColor.to(\"srgb\").toString({ format: \"hex\" });\n\n\t// Make sure we use the tint from the gray scale for when base is pure white or black\n\tconst accentBaseHex = accentBaseColor.to(\"srgb\").toString({ format: \"hex\" });\n\tif (accentBaseHex === \"#000\" || accentBaseHex === \"#fff\") {\n\t\taccentScaleColors = grayScaleColors.map((color) => color.clone()) as ArrayOf12<Color>;\n\t}\n\n\tconst [accent9Color, accentContrastColor] = getStep9Colors(accentScaleColors, accentBaseColor);\n\n\taccentScaleColors[8] = accent9Color;\n\taccentScaleColors[9] = getButtonHoverColor(accent9Color, [accentScaleColors]);\n\n\t// Limit saturation of the text colors\n\taccentScaleColors[10].coords[1] = Math.min(\n\t\tMath.max(accentScaleColors[8].coords[1], accentScaleColors[7].coords[1]),\n\t\taccentScaleColors[10].coords[1],\n\t);\n\taccentScaleColors[11].coords[1] = Math.min(\n\t\tMath.max(accentScaleColors[8].coords[1], accentScaleColors[7].coords[1]),\n\t\taccentScaleColors[11].coords[1],\n\t);\n\n\tconst accentScaleHex = accentScaleColors.map((color) =>\n\t\tcolor.to(\"srgb\").toString({ format: \"hex\" }),\n\t) as ArrayOf12<string>;\n\n\tconst accentScaleWideGamut = accentScaleColors.map(toOklchString) as ArrayOf12<string>;\n\n\tconst accentScaleAlphaHex = accentScaleHex.map((color) =>\n\t\tgetAlphaColorSrgb(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentScaleAlphaWideGamutString = accentScaleHex.map((color) =>\n\t\tgetAlphaColorP3(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentContrastColorHex = accentContrastColor.to(\"srgb\").toString({ format: \"hex\" });\n\n\tconst grayScaleHex = grayScaleColors.map((color) =>\n\t\tcolor.to(\"srgb\").toString({ format: \"hex\" }),\n\t) as ArrayOf12<string>;\n\n\tconst grayScaleWideGamut = grayScaleColors.map(toOklchString) as ArrayOf12<string>;\n\n\tconst grayScaleAlphaHex = grayScaleHex.map((color) =>\n\t\tgetAlphaColorSrgb(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst grayScaleAlphaWideGamutString = grayScaleHex.map((color) =>\n\t\tgetAlphaColorP3(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentSurfaceHex =\n\t\tappearance === \"light\"\n\t\t\t? getAlphaColorSrgb(accentScaleHex[1], backgroundHex, 0.8)\n\t\t\t: getAlphaColorSrgb(accentScaleHex[1], backgroundHex, 0.5);\n\n\tconst accentSurfaceWideGamutString =\n\t\tappearance === \"light\"\n\t\t\t? getAlphaColorP3(accentScaleWideGamut[1], backgroundHex, 0.8)\n\t\t\t: getAlphaColorP3(accentScaleWideGamut[1], backgroundHex, 0.5);\n\n\treturn {\n\t\taccentScale: accentScaleHex,\n\t\taccentScaleAlpha: accentScaleAlphaHex,\n\t\taccentScaleWideGamut: accentScaleWideGamut,\n\t\taccentScaleAlphaWideGamut: accentScaleAlphaWideGamutString,\n\t\taccentContrast: accentContrastColorHex,\n\n\t\tgrayScale: grayScaleHex,\n\t\tgrayScaleAlpha: grayScaleAlphaHex,\n\t\tgrayScaleWideGamut: grayScaleWideGamut,\n\t\tgrayScaleAlphaWideGamut: grayScaleAlphaWideGamutString,\n\n\t\tgraySurface: appearance === \"light\" ? \"#ffffffcc\" : \"rgba(0, 0, 0, 0.05)\",\n\t\tgraySurfaceWideGamut:\n\t\t\tappearance === \"light\" ? \"color(display-p3 1 1 1 / 80%)\" : \"color(display-p3 0 0 0 / 5%)\",\n\n\t\taccentSurface: accentSurfaceHex,\n\t\taccentSurfaceWideGamut: accentSurfaceWideGamutString,\n\n\t\tbackground: backgroundHex,\n\t};\n};\n\nfunction getStep9Colors(scale: ArrayOf12<Color>, accentBaseColor: Color): [Color, Color] {\n\tconst referenceBackgroundColor = scale[0];\n\tconst distance = accentBaseColor.deltaEOK(referenceBackgroundColor) * 100;\n\n\t// If the accent base color is close to the page background color, it's likely\n\t// white on white or black on black, so we want to return something that makes sense instead\n\tif (distance < 25) {\n\t\treturn [scale[8], getTextColor(scale[8])];\n\t}\n\n\treturn [accentBaseColor, getTextColor(accentBaseColor)];\n}\n\nfunction getButtonHoverColor(source: Color, scales: ArrayOf12<Color>[]) {\n\tconst [L, C, H] = source.coords;\n\tconst newL = L > 0.4 ? L - 0.03 / (L + 0.1) : L + 0.03 / (L + 0.1);\n\tconst newC = L > 0.4 && !isNaN(H) ? C * 0.93 + 0 : C;\n\tconst buttonHoverColor = new Color(\"oklch\", [newL, newC, H]);\n\n\t// Find closest in-scale color to donate the chroma and hue.\n\t// Especially useful when the source color is pure white or black,\n\t// but the gray scale is tinted.\n\tlet closestColor = buttonHoverColor;\n\tlet minDistance = Infinity;\n\n\tscales.forEach((scale) => {\n\t\tfor (const color of scale) {\n\t\t\tconst distance = buttonHoverColor.deltaEOK(color);\n\t\t\tif (distance < minDistance) {\n\t\t\t\tminDistance = distance;\n\t\t\t\tclosestColor = color;\n\t\t\t}\n\t\t}\n\t});\n\n\tbuttonHoverColor.coords[1] = closestColor.coords[1];\n\tbuttonHoverColor.coords[2] = closestColor.coords[2];\n\treturn buttonHoverColor;\n}\n\nfunction getScaleFromColor(\n\tsource: Color,\n\tscales: Record<string, ArrayOf12<Color>>,\n\tbackgroundColor: Color,\n) {\n\tlet allColors: { scale: string; color: Color; distance: number }[] = [];\n\n\tObject.entries(scales).forEach(([name, scale]) => {\n\t\tfor (const color of scale) {\n\t\t\tconst distance = source.deltaEOK(color);\n\t\t\tallColors.push({ scale: name, distance, color });\n\t\t}\n\t});\n\n\tallColors.sort((a, b) => a.distance - b.distance);\n\n\t// Remove non-unique scales\n\tlet closestColors = allColors.filter(\n\t\t(color, i, arr) => i === arr.findIndex((value) => value.scale === color.scale),\n\t);\n\n\t// If the next two closest colors are both grays, remove the second one until it’s not a gray anymore.\n\t// This is because up next we will be comparing how close the two closest colors are to the source color,\n\t// and since the grays are all extremely close to each other, we won’t get any useful data from the second\n\t// closest color if it’s also a gray.\n\tconst grayScaleNamesStr = grayScaleNames as readonly string[];\n\tconst allAreGrays = closestColors.every((color) => grayScaleNamesStr.includes(color.scale));\n\tif (!allAreGrays && grayScaleNamesStr.includes(closestColors[0].scale)) {\n\t\twhile (grayScaleNamesStr.includes(closestColors[1].scale)) {\n\t\t\tclosestColors.splice(1, 1);\n\t\t}\n\t}\n\n\tlet colorA = closestColors[0];\n\tlet colorB = closestColors[1];\n\n\t// Light trigonometry ahead.\n\t//\n\t// We want to determine the color that is the closest to the source color. Sometimes it makes sense\n\t// to proportionally mix the two closest colors together, but sometimes it is not useful at all.\n\t// Color coords are spatial in 3D, however we can treat the data we have as a 2D projection that is good enough.\n\t//\n\t// Case 1:\n\t// If the distances between the source color, the 1st closest color (A) and the 2nd closest color (B) form\n\t// a triangle where NEITHER angle A nor B are larger than 90 degrees, then we want to mix the 1st and the 2nd\n\t// closest colors in the same proportion as distances AD and BD are to each other. Mixing the two would result\n\t// in a color that would be closer to the source color than either of the two original closest colors.\n\t// Example: source color is a desaturated blue, which is between \"indigo\" and \"slate\" scales.\n\t//\n\t// C ← Source color\n\t// /|⟍\n\t// / | ⟍\n\t// b / | ⟍ a\n\t// / | ⟍\n\t// / | ⟍\n\t// A --- D -------- B\n\t// ↑\n\t// The color we want to use as the base, which is a mix of A and B.\n\t//\n\t// Case 2:\n\t// If the distances between the source color, the 1st closest color (A) and the 2nd closest color (B) form\n\t// a triangle where EITHER angle A or B are larger than 90 degrees, then we don’t care about point B because it’s\n\t// directionally the same as A, as mixing A and B can’t provide us with a color that is any closer to the source.\n\t// Example: source color is a saturated blue, with \"blue\" being the closest scale, and \"indigo\" just being further.\n\t//\n\t// C ← Source color\n\t// \\⟍\n\t// \\ ⟍\n\t// \\ ⟍ a\n\t// b \\ ⟍\n\t// \\ ⟍\n\t// A ------- B\n\t// ↑\n\t// The color we want to use as the base, which is not influenced by B.\n\n\t// We’ll need all the lengths of the triangle sides, named after the angles they look at:\n\tconst a = colorB.distance;\n\tconst b = colorA.distance;\n\tconst c = colorA.color.deltaEOK(colorB.color);\n\n\t// We can get the ratios of AD to BD lengths with trigonometry using tangents,\n\t// as the ratio of the tangents of the opposite angles will match.\n\tconst cosA = (b ** 2 + c ** 2 - a ** 2) / (2 * b * c);\n\tconst radA = Math.acos(cosA);\n\tconst sinA = Math.sin(radA);\n\n\tconst cosB = (a ** 2 + c ** 2 - b ** 2) / (2 * a * c);\n\tconst radB = Math.acos(cosB);\n\tconst sinB = Math.sin(radB);\n\n\t// Tangent of angle C in the ACD triangle\n\tconst tanC1 = cosA / sinA;\n\n\t// Tangent of angle C in the BCD triangle\n\tconst tanC2 = cosB / sinB;\n\n\t// The ratio of the tangents corresponds to the ratio of the distances AD to BD\n\t// In the end, it means how much of scale B we want to mix into scale A.\n\t// If it’s \"0\" or less, this is an obtuse triangle from case 2, and we use just scale A.\n\tconst ratio = Math.max(0, tanC1 / tanC2) * 0.5;\n\n\t// The base scale is going to be a mix of the two closest scales, with the mix ratio we determined before\n\tconst scaleA = scales[colorA.scale];\n\tconst scaleB = scales[colorB.scale];\n\tconst scale = arrayOf12.map((i) =>\n\t\tnew Color(Color.mix(scaleA[i], scaleB[i], ratio)).to(\"oklch\"),\n\t) as ArrayOf12<Color>;\n\n\t// Get the closest color from the pre-mixed scale we created\n\tconst baseColor = scale.toSorted((a, b) => source.deltaEOK(a) - source.deltaEOK(b))[0];\n\n\t// Note the chroma difference between the source color and the base color\n\tconst ratioC = source.coords[1] / baseColor.coords[1];\n\n\t// Modify hue and chroma of the scale to match the source color\n\tscale.forEach((color) => {\n\t\tcolor.coords[1] = Math.min(source.coords[1] * 1.5, color.coords[1] * ratioC);\n\t\tcolor.coords[2] = source.coords[2];\n\t});\n\n\t// Light mode\n\tif (scale[0].coords[0] > 0.5) {\n\t\tconst lightnessScale = scale.map(({ coords }) => coords[0]);\n\t\tconst backgroundL = Math.max(0, Math.min(1, backgroundColor.coords[0]));\n\t\tconst newLightnessScale = transposeProgressionStart(\n\t\t\tbackgroundL,\n\t\t\t// Add white as the first \"step\" of the light scale\n\t\t\t[1, ...lightnessScale],\n\t\t\tlightModeEasing,\n\t\t);\n\n\t\t// Remove the step we added\n\t\tnewLightnessScale.shift();\n\n\t\tnewLightnessScale.forEach((lightness, i) => {\n\t\t\tscale[i].coords[0] = lightness;\n\t\t});\n\n\t\treturn scale;\n\t}\n\n\t// Dark mode\n\tlet ease: typeof darkModeEasing = [...darkModeEasing];\n\tconst referenceBackgroundColorL = scale[0].coords[0];\n\tconst backgroundColorL = Math.max(0, Math.min(1, backgroundColor.coords[0]));\n\n\t// If background is lighter than step 0, we want to gradually change the easing to linear\n\tconst ratioL = backgroundColorL / referenceBackgroundColorL;\n\n\tif (ratioL > 1) {\n\t\tconst maxRatio = 1.5;\n\n\t\tfor (let i = 0; i < ease.length; i++) {\n\t\t\tconst metaRatio = (ratioL - 1) * (maxRatio / (maxRatio - 1));\n\t\t\tease[i] = ratioL > maxRatio ? 0 : Math.max(0, ease[i] * (1 - metaRatio));\n\t\t}\n\t}\n\n\tconst lightnessScale = scale.map(({ coords }) => coords[0]);\n\tconst backgroundL = backgroundColor.coords[0];\n\tconst newLightnessScale = transposeProgressionStart(backgroundL, lightnessScale, ease);\n\n\tnewLightnessScale.forEach((lightness, i) => {\n\t\tscale[i].coords[0] = lightness;\n\t});\n\n\treturn scale;\n}\n\nfunction getTextColor(background: Color) {\n\tconst white = new Color(\"oklch\", [1, 0, 0]);\n\n\tif (Math.abs(white.contrastAPCA(background)) < 40) {\n\t\tconst [, C, H] = background.coords;\n\t\treturn new Color(\"oklch\", [0.25, Math.max(0.08 * C, 0.04), H]);\n\t}\n\n\treturn white;\n}\n\n// target = background * (1 - alpha) + foreground * alpha\n// alpha = (target - background) / (foreground - background)\n// Expects 0-1 numbers for the RGB channels\n// oxlint-disable-next-line eslint/complexity -- pre-existing; split it before adding branches\nfunction getAlphaColor(\n\ttargetRgb: number[],\n\tbackgroundRgb: number[],\n\trgbPrecision: number,\n\talphaPrecision: number,\n\ttargetAlpha?: number,\n) {\n\tconst [tr, tg, tb] = targetRgb.map((c) => Math.round(c * rgbPrecision));\n\tconst [br, bg, bb] = backgroundRgb.map((c) => Math.round(c * rgbPrecision));\n\n\tif (\n\t\ttr === undefined ||\n\t\ttg === undefined ||\n\t\ttb === undefined ||\n\t\tbr === undefined ||\n\t\tbg === undefined ||\n\t\tbb === undefined\n\t) {\n\t\tthrow Error(\"Color is undefined\");\n\t}\n\n\t// Is the background color lighter, RGB-wise, than target color?\n\t// Decide whether we want to add as little color or as much color as possible,\n\t// darkening or lightening the background respectively.\n\t// If at least one of the bits of the target RGB value\n\t// is lighter than the background, we want to lighten it.\n\tlet desiredRgb = 0;\n\tif (tr > br) {\n\t\tdesiredRgb = rgbPrecision;\n\t} else if (tg > bg) {\n\t\tdesiredRgb = rgbPrecision;\n\t} else if (tb > bb) {\n\t\tdesiredRgb = rgbPrecision;\n\t}\n\n\tconst alphaR = (tr - br) / (desiredRgb - br);\n\tconst alphaG = (tg - bg) / (desiredRgb - bg);\n\tconst alphaB = (tb - bb) / (desiredRgb - bb);\n\n\tconst isPureGray = [alphaR, alphaG, alphaB].every((alpha) => alpha === alphaR);\n\n\t// No need for precision gymnastics with pure grays, and we can get cleaner output\n\tif (!targetAlpha && isPureGray) {\n\t\t// Convert back to 0-1 values\n\t\tconst V = desiredRgb / rgbPrecision;\n\t\treturn [V, V, V, alphaR] as const;\n\t}\n\n\tconst clampRgb = (n: number) => (isNaN(n) ? 0 : Math.min(rgbPrecision, Math.max(0, n)));\n\tconst clampA = (n: number) => (isNaN(n) ? 0 : Math.min(alphaPrecision, Math.max(0, n)));\n\tconst maxAlpha = targetAlpha ?? Math.max(alphaR, alphaG, alphaB);\n\n\tconst A = clampA(Math.ceil(maxAlpha * alphaPrecision)) / alphaPrecision;\n\tlet R = clampRgb(((br * (1 - A) - tr) / A) * -1);\n\tlet G = clampRgb(((bg * (1 - A) - tg) / A) * -1);\n\tlet B = clampRgb(((bb * (1 - A) - tb) / A) * -1);\n\n\tR = Math.ceil(R);\n\tG = Math.ceil(G);\n\tB = Math.ceil(B);\n\n\tconst blendedR = blendAlpha(R, A, br);\n\tconst blendedG = blendAlpha(G, A, bg);\n\tconst blendedB = blendAlpha(B, A, bb);\n\n\t// Correct for rounding errors in light mode\n\tif (desiredRgb === 0) {\n\t\tif (tr <= br && tr !== blendedR) {\n\t\t\tR = tr > blendedR ? R + 1 : R - 1;\n\t\t}\n\n\t\tif (tg <= bg && tg !== blendedG) {\n\t\t\tG = tg > blendedG ? G + 1 : G - 1;\n\t\t}\n\n\t\tif (tb <= bb && tb !== blendedB) {\n\t\t\tB = tb > blendedB ? B + 1 : B - 1;\n\t\t}\n\t}\n\n\t// Correct for rounding errors in dark mode\n\tif (desiredRgb === rgbPrecision) {\n\t\tif (tr >= br && tr !== blendedR) {\n\t\t\tR = tr > blendedR ? R + 1 : R - 1;\n\t\t}\n\n\t\tif (tg >= bg && tg !== blendedG) {\n\t\t\tG = tg > blendedG ? G + 1 : G - 1;\n\t\t}\n\n\t\tif (tb >= bb && tb !== blendedB) {\n\t\t\tB = tb > blendedB ? B + 1 : B - 1;\n\t\t}\n\t}\n\n\t// Convert back to 0-1 values\n\tR = R / rgbPrecision;\n\tG = G / rgbPrecision;\n\tB = B / rgbPrecision;\n\n\treturn [R, G, B, A] as const;\n}\n\n// Important – I empirically discovered that this rounding is how the browser actually overlays\n// transparent RGB bits over each other. It does NOT round the whole result altogether.\nfunction blendAlpha(foreground: number, alpha: number, background: number, round = true) {\n\tif (round) {\n\t\treturn Math.round(background * (1 - alpha)) + Math.round(foreground * alpha);\n\t}\n\n\treturn background * (1 - alpha) + foreground * alpha;\n}\n\nexport function getAlphaColorSrgb(targetColor: string, backgroundColor: string, targetAlpha?: number) {\n\tconst [r, g, b, a] = getAlphaColor(\n\t\tnew Color(targetColor).to(\"srgb\").coords,\n\t\tnew Color(backgroundColor).to(\"srgb\").coords,\n\t\t255,\n\t\t255,\n\t\ttargetAlpha,\n\t);\n\n\treturn formatHex(new Color(\"srgb\", [r, g, b], a).toString({ format: \"hex\" }));\n}\n\nexport function getAlphaColorP3(targetColor: string, backgroundColor: string, targetAlpha?: number) {\n\tconst [r, g, b, a] = getAlphaColor(\n\t\tnew Color(targetColor).to(\"p3\").coords,\n\t\tnew Color(backgroundColor).to(\"p3\").coords,\n\t\t// Not sure why, but the resulting P3 alpha colors are blended in the browser most precisely when\n\t\t// rounded to 255 integers too. Is the browser using 0-255 rather than 0-1 under the hood for P3 too?\n\t\t255,\n\t\t1000,\n\t\ttargetAlpha,\n\t);\n\n\treturn (\n\t\tnew Color(\"p3\", [r, g, b], a)\n\t\t\t.toString({ precision: 4 })\n\t\t\t// Important: in non-browser environments colorjs.io outputs a different format for some reason\n\t\t\t.replace(\"color(p3 \", \"color(display-p3 \")\n\t);\n}\n\n// Format shortform hex to longform\nfunction formatHex(str: string) {\n\tif (!str.startsWith(\"#\")) {\n\t\treturn str;\n\t}\n\n\tif (str.length === 4) {\n\t\tconst hash = str.charAt(0);\n\t\tconst r = str.charAt(1);\n\t\tconst g = str.charAt(2);\n\t\tconst b = str.charAt(3);\n\t\treturn hash + r + r + g + g + b + b;\n\t}\n\n\tif (str.length === 5) {\n\t\tconst hash = str.charAt(0);\n\t\tconst r = str.charAt(1);\n\t\tconst g = str.charAt(2);\n\t\tconst b = str.charAt(3);\n\t\tconst a = str.charAt(4);\n\t\treturn hash + r + r + g + g + b + b + a + a;\n\t}\n\n\treturn str;\n}\n\nconst darkModeEasing = [1, 0, 1, 0] as [number, number, number, number];\nconst lightModeEasing = [0, 2, 0, 2] as [number, number, number, number];\n\nexport function transposeProgressionStart(\n\tto: number,\n\tarr: number[],\n\tcurve: [number, number, number, number],\n) {\n\treturn arr.map((n, i, arr) => {\n\t\tconst lastIndex = arr.length - 1;\n\t\tconst diff = arr[0] - to;\n\t\tconst fn = BezierEasing(...curve);\n\t\treturn n - diff * fn(1 - i / lastIndex);\n\t});\n}\n\nexport function transposeProgressionEnd(\n\tto: number,\n\tarr: number[],\n\tcurve: [number, number, number, number],\n) {\n\treturn arr.map((n, i, arr) => {\n\t\tconst lastIndex = arr.length - 1;\n\t\tconst diff = arr[lastIndex] - to;\n\t\tconst fn = BezierEasing(...curve);\n\t\treturn n - diff * fn(i / lastIndex);\n\t});\n}\n\n// Convert to OKLCH string with percentage for the lightness channel\n// https://github.com/radix-ui/themes/issues/420\nfunction toOklchString(color: Color) {\n\tconst L = +(color.coords[0] * 100).toFixed(1);\n\treturn color\n\t\t.to(\"oklch\")\n\t\t.toString({ precision: 4 })\n\t\t.replace(/(\\S+)(.+)/, `oklch(${L}%$2`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,YAAY;CAAC;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAI;AAAE;AAGvD,MAAM,iBAAiB;CAAC;CAAQ;CAAS;CAAS;CAAQ;CAAS;AAAM;AAGzE,MAAM,aAAa;CAAC,GAAG;CAAgB;CAAU;CAAO;CAAQ;CAAW;CAC3E;CAAQ;CAAU;CAAU;CAAQ;CAAU;CAAQ;CAAQ;CAAQ;CAAQ;CAC9E;CAAS;CAAS;CAAU;C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GAAG;EACrB,MAAM,OAAO,IAAI,OAAO,CAAC;EACzB,MAAM,IAAI,IAAI,OAAO,CAAC;EACtB,MAAM,IAAI,IAAI,OAAO,CAAC;EACtB,MAAM,IAAI,IAAI,OAAO,CAAC;EACtB,MAAM,IAAI,IAAI,OAAO,CAAC;EACtB,OAAO,OAAO,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI;CAC3C;CAEA,OAAO;AACR;AAEA,MAAM,iBAAiB;CAAC;CAAG;CAAG;CAAG;AAAC;AAClC,MAAM,kBAAkB;CAAC;CAAG;CAAG;CAAG;AAAC;AAEnC,SAAgB,0BACf,IACA,KACA,OACC;CACD,OAAO,IAAI,KAAK,GAAG,GAAG,QAAQ;EAC7B,MAAM,YAAY,IAAI,SAAS;EAG/B,OAAO,KAFM,IAAI,KAAK,OAAA,GAAA,cAAA,SACE,GAAG,KACR,EAAE,IAAI,IAAI,SAAS;CACvC,CAAC;AACF;AAEA,SAAgB,wBACf,IACA,KACA,OACC;CACD,OAAO,IAAI,KAAK,GAAG,GAAG,QAAQ;EAC7B,MAAM,YAAY,IAAI,SAAS;EAG/B,OAAO,KAFM,IAAI,aAAa,OAAA,GAAA,cAAA,SACN,GAAG,KACR,EAAE,IAAI,SAAS;CACnC,CAAC;AACF;AAIA,SAAS,cAAc,OAAc;CACpC,MAAM,IAAI,EAAE,MAAM,OAAO,KAAK,KAAK,QAAQ,CAAC;CAC5C,OAAO,MACL,GAAG,OAAO,EACV,SAAS,EAAE,WAAW,EAAE,CAAC,EACzB,QAAQ,aAAa,SAAS,EAAE,IAAI;AACvC"}
|
|
@@ -184,7 +184,7 @@ function getScaleFromColor(source, scales, backgroundColor) {
|
|
|
184
184
|
const scaleA = scales[colorA.scale];
|
|
185
185
|
const scaleB = scales[colorB.scale];
|
|
186
186
|
const scale = arrayOf12.map((i) => new Color(Color.mix(scaleA[i], scaleB[i], ratio)).to("oklch"));
|
|
187
|
-
const baseColor = scale.
|
|
187
|
+
const baseColor = scale.toSorted((a, b) => source.deltaEOK(a) - source.deltaEOK(b))[0];
|
|
188
188
|
const ratioC = source.coords[1] / baseColor.coords[1];
|
|
189
189
|
scale.forEach((color) => {
|
|
190
190
|
color.coords[1] = Math.min(source.coords[1] * 1.5, color.coords[1] * ratioC);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-radix-colors.js","names":[],"sources":["../../src/lib/generate-radix-colors.tsx"],"sourcesContent":["/**\n * Vendored from Radix UI's website — components/generate-radix-colors.tsx\n * https://github.com/radix-ui/website\n *\n * MIT License — Copyright (c) 2024 WorkOS\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND. (Full text:\n * https://github.com/radix-ui/website/blob/main/LICENSE)\n *\n * Kept VERBATIM so it can be re-synced upstream (this file is excluded from the\n * formatter in vite.config.ts). Strict type-checking is skipped (upstream targets\n * a looser tsconfig with unchecked array indexing over fixed 12-step scales).\n *\n * Only deviation from upstream: `getAlphaColorSrgb`/`getAlphaColorP3` are `export`ed (no\n * algorithm change) so `accent-theme.ts` can re-solve alpha for its canvas-tinted steps\n * with Radix's own solver instead of duplicating its rounding-correction logic. Re-apply\n * these two keywords after a re-sync.\n */\n// @ts-nocheck\nimport * as RadixColors from \"@radix-ui/colors\";\nimport Color from \"colorjs.io\";\nimport BezierEasing from \"bezier-easing\";\n\ntype ArrayOf12<T> = [T, T, T, T, T, T, T, T, T, T, T, T];\nconst arrayOf12 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] as const;\n\n// prettier-ignore\nconst grayScaleNames = ['gray', 'mauve', 'slate', 'sage', 'olive', 'sand'] as const;\n\n// prettier-ignore\nconst scaleNames = [...grayScaleNames, 'tomato', 'red', 'ruby', 'crimson', 'pink',\n'plum', 'purple', 'violet', 'iris', 'indigo', 'blue', 'cyan', 'teal', 'jade', 'green',\n'grass', 'brown', 'orange', 'sky', 'mint', 'lime', 'yellow', 'amber'] as const;\n\nconst lightColors = Object.fromEntries(\n\tscaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}P3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof scaleNames)[number], ArrayOf12<Color>>;\n\nconst darkColors = Object.fromEntries(\n\tscaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}DarkP3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof scaleNames)[number], ArrayOf12<Color>>;\n\nconst lightGrayColors = Object.fromEntries(\n\tgrayScaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}P3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof grayScaleNames)[number], ArrayOf12<Color>>;\n\nconst darkGrayColors = Object.fromEntries(\n\tgrayScaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}DarkP3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof grayScaleNames)[number], ArrayOf12<Color>>;\n\nexport const generateRadixColors = ({\n\tappearance,\n\t...args\n}: {\n\tappearance: \"light\" | \"dark\";\n\taccent: string;\n\tgray: string;\n\tbackground: string;\n}) => {\n\tconst allScales = appearance === \"light\" ? lightColors : darkColors;\n\tconst grayScales = appearance === \"light\" ? lightGrayColors : darkGrayColors;\n\tconst backgroundColor = new Color(args.background).to(\"oklch\");\n\n\tconst grayBaseColor = new Color(args.gray).to(\"oklch\");\n\tconst grayScaleColors = getScaleFromColor(grayBaseColor, grayScales, backgroundColor);\n\n\tconst accentBaseColor = new Color(args.accent).to(\"oklch\");\n\n\tlet accentScaleColors = getScaleFromColor(accentBaseColor, allScales, backgroundColor);\n\n\t// Enforce srgb for the background color\n\tconst backgroundHex = backgroundColor.to(\"srgb\").toString({ format: \"hex\" });\n\n\t// Make sure we use the tint from the gray scale for when base is pure white or black\n\tconst accentBaseHex = accentBaseColor.to(\"srgb\").toString({ format: \"hex\" });\n\tif (accentBaseHex === \"#000\" || accentBaseHex === \"#fff\") {\n\t\taccentScaleColors = grayScaleColors.map((color) => color.clone()) as ArrayOf12<Color>;\n\t}\n\n\tconst [accent9Color, accentContrastColor] = getStep9Colors(accentScaleColors, accentBaseColor);\n\n\taccentScaleColors[8] = accent9Color;\n\taccentScaleColors[9] = getButtonHoverColor(accent9Color, [accentScaleColors]);\n\n\t// Limit saturation of the text colors\n\taccentScaleColors[10].coords[1] = Math.min(\n\t\tMath.max(accentScaleColors[8].coords[1], accentScaleColors[7].coords[1]),\n\t\taccentScaleColors[10].coords[1],\n\t);\n\taccentScaleColors[11].coords[1] = Math.min(\n\t\tMath.max(accentScaleColors[8].coords[1], accentScaleColors[7].coords[1]),\n\t\taccentScaleColors[11].coords[1],\n\t);\n\n\tconst accentScaleHex = accentScaleColors.map((color) =>\n\t\tcolor.to(\"srgb\").toString({ format: \"hex\" }),\n\t) as ArrayOf12<string>;\n\n\tconst accentScaleWideGamut = accentScaleColors.map(toOklchString) as ArrayOf12<string>;\n\n\tconst accentScaleAlphaHex = accentScaleHex.map((color) =>\n\t\tgetAlphaColorSrgb(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentScaleAlphaWideGamutString = accentScaleHex.map((color) =>\n\t\tgetAlphaColorP3(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentContrastColorHex = accentContrastColor.to(\"srgb\").toString({ format: \"hex\" });\n\n\tconst grayScaleHex = grayScaleColors.map((color) =>\n\t\tcolor.to(\"srgb\").toString({ format: \"hex\" }),\n\t) as ArrayOf12<string>;\n\n\tconst grayScaleWideGamut = grayScaleColors.map(toOklchString) as ArrayOf12<string>;\n\n\tconst grayScaleAlphaHex = grayScaleHex.map((color) =>\n\t\tgetAlphaColorSrgb(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst grayScaleAlphaWideGamutString = grayScaleHex.map((color) =>\n\t\tgetAlphaColorP3(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentSurfaceHex =\n\t\tappearance === \"light\"\n\t\t\t? getAlphaColorSrgb(accentScaleHex[1], backgroundHex, 0.8)\n\t\t\t: getAlphaColorSrgb(accentScaleHex[1], backgroundHex, 0.5);\n\n\tconst accentSurfaceWideGamutString =\n\t\tappearance === \"light\"\n\t\t\t? getAlphaColorP3(accentScaleWideGamut[1], backgroundHex, 0.8)\n\t\t\t: getAlphaColorP3(accentScaleWideGamut[1], backgroundHex, 0.5);\n\n\treturn {\n\t\taccentScale: accentScaleHex,\n\t\taccentScaleAlpha: accentScaleAlphaHex,\n\t\taccentScaleWideGamut: accentScaleWideGamut,\n\t\taccentScaleAlphaWideGamut: accentScaleAlphaWideGamutString,\n\t\taccentContrast: accentContrastColorHex,\n\n\t\tgrayScale: grayScaleHex,\n\t\tgrayScaleAlpha: grayScaleAlphaHex,\n\t\tgrayScaleWideGamut: grayScaleWideGamut,\n\t\tgrayScaleAlphaWideGamut: grayScaleAlphaWideGamutString,\n\n\t\tgraySurface: appearance === \"light\" ? \"#ffffffcc\" : \"rgba(0, 0, 0, 0.05)\",\n\t\tgraySurfaceWideGamut:\n\t\t\tappearance === \"light\" ? \"color(display-p3 1 1 1 / 80%)\" : \"color(display-p3 0 0 0 / 5%)\",\n\n\t\taccentSurface: accentSurfaceHex,\n\t\taccentSurfaceWideGamut: accentSurfaceWideGamutString,\n\n\t\tbackground: backgroundHex,\n\t};\n};\n\nfunction getStep9Colors(scale: ArrayOf12<Color>, accentBaseColor: Color): [Color, Color] {\n\tconst referenceBackgroundColor = scale[0];\n\tconst distance = accentBaseColor.deltaEOK(referenceBackgroundColor) * 100;\n\n\t// If the accent base color is close to the page background color, it's likely\n\t// white on white or black on black, so we want to return something that makes sense instead\n\tif (distance < 25) {\n\t\treturn [scale[8], getTextColor(scale[8])];\n\t}\n\n\treturn [accentBaseColor, getTextColor(accentBaseColor)];\n}\n\nfunction getButtonHoverColor(source: Color, scales: ArrayOf12<Color>[]) {\n\tconst [L, C, H] = source.coords;\n\tconst newL = L > 0.4 ? L - 0.03 / (L + 0.1) : L + 0.03 / (L + 0.1);\n\tconst newC = L > 0.4 && !isNaN(H) ? C * 0.93 + 0 : C;\n\tconst buttonHoverColor = new Color(\"oklch\", [newL, newC, H]);\n\n\t// Find closest in-scale color to donate the chroma and hue.\n\t// Especially useful when the source color is pure white or black,\n\t// but the gray scale is tinted.\n\tlet closestColor = buttonHoverColor;\n\tlet minDistance = Infinity;\n\n\tscales.forEach((scale) => {\n\t\tfor (const color of scale) {\n\t\t\tconst distance = buttonHoverColor.deltaEOK(color);\n\t\t\tif (distance < minDistance) {\n\t\t\t\tminDistance = distance;\n\t\t\t\tclosestColor = color;\n\t\t\t}\n\t\t}\n\t});\n\n\tbuttonHoverColor.coords[1] = closestColor.coords[1];\n\tbuttonHoverColor.coords[2] = closestColor.coords[2];\n\treturn buttonHoverColor;\n}\n\nfunction getScaleFromColor(\n\tsource: Color,\n\tscales: Record<string, ArrayOf12<Color>>,\n\tbackgroundColor: Color,\n) {\n\tlet allColors: { scale: string; color: Color; distance: number }[] = [];\n\n\tObject.entries(scales).forEach(([name, scale]) => {\n\t\tfor (const color of scale) {\n\t\t\tconst distance = source.deltaEOK(color);\n\t\t\tallColors.push({ scale: name, distance, color });\n\t\t}\n\t});\n\n\tallColors.sort((a, b) => a.distance - b.distance);\n\n\t// Remove non-unique scales\n\tlet closestColors = allColors.filter(\n\t\t(color, i, arr) => i === arr.findIndex((value) => value.scale === color.scale),\n\t);\n\n\t// If the next two closest colors are both grays, remove the second one until it’s not a gray anymore.\n\t// This is because up next we will be comparing how close the two closest colors are to the source color,\n\t// and since the grays are all extremely close to each other, we won’t get any useful data from the second\n\t// closest color if it’s also a gray.\n\tconst grayScaleNamesStr = grayScaleNames as readonly string[];\n\tconst allAreGrays = closestColors.every((color) => grayScaleNamesStr.includes(color.scale));\n\tif (!allAreGrays && grayScaleNamesStr.includes(closestColors[0].scale)) {\n\t\twhile (grayScaleNamesStr.includes(closestColors[1].scale)) {\n\t\t\tclosestColors.splice(1, 1);\n\t\t}\n\t}\n\n\tlet colorA = closestColors[0];\n\tlet colorB = closestColors[1];\n\n\t// Light trigonometry ahead.\n\t//\n\t// We want to determine the color that is the closest to the source color. Sometimes it makes sense\n\t// to proportionally mix the two closest colors together, but sometimes it is not useful at all.\n\t// Color coords are spatial in 3D, however we can treat the data we have as a 2D projection that is good enough.\n\t//\n\t// Case 1:\n\t// If the distances between the source color, the 1st closest color (A) and the 2nd closest color (B) form\n\t// a triangle where NEITHER angle A nor B are larger than 90 degrees, then we want to mix the 1st and the 2nd\n\t// closest colors in the same proportion as distances AD and BD are to each other. Mixing the two would result\n\t// in a color that would be closer to the source color than either of the two original closest colors.\n\t// Example: source color is a desaturated blue, which is between \"indigo\" and \"slate\" scales.\n\t//\n\t// C ← Source color\n\t// /|⟍\n\t// / | ⟍\n\t// b / | ⟍ a\n\t// / | ⟍\n\t// / | ⟍\n\t// A --- D -------- B\n\t// ↑\n\t// The color we want to use as the base, which is a mix of A and B.\n\t//\n\t// Case 2:\n\t// If the distances between the source color, the 1st closest color (A) and the 2nd closest color (B) form\n\t// a triangle where EITHER angle A or B are larger than 90 degrees, then we don’t care about point B because it’s\n\t// directionally the same as A, as mixing A and B can’t provide us with a color that is any closer to the source.\n\t// Example: source color is a saturated blue, with \"blue\" being the closest scale, and \"indigo\" just being further.\n\t//\n\t// C ← Source color\n\t// \\⟍\n\t// \\ ⟍\n\t// \\ ⟍ a\n\t// b \\ ⟍\n\t// \\ ⟍\n\t// A ------- B\n\t// ↑\n\t// The color we want to use as the base, which is not influenced by B.\n\n\t// We’ll need all the lengths of the triangle sides, named after the angles they look at:\n\tconst a = colorB.distance;\n\tconst b = colorA.distance;\n\tconst c = colorA.color.deltaEOK(colorB.color);\n\n\t// We can get the ratios of AD to BD lengths with trigonometry using tangents,\n\t// as the ratio of the tangents of the opposite angles will match.\n\tconst cosA = (b ** 2 + c ** 2 - a ** 2) / (2 * b * c);\n\tconst radA = Math.acos(cosA);\n\tconst sinA = Math.sin(radA);\n\n\tconst cosB = (a ** 2 + c ** 2 - b ** 2) / (2 * a * c);\n\tconst radB = Math.acos(cosB);\n\tconst sinB = Math.sin(radB);\n\n\t// Tangent of angle C in the ACD triangle\n\tconst tanC1 = cosA / sinA;\n\n\t// Tangent of angle C in the BCD triangle\n\tconst tanC2 = cosB / sinB;\n\n\t// The ratio of the tangents corresponds to the ratio of the distances AD to BD\n\t// In the end, it means how much of scale B we want to mix into scale A.\n\t// If it’s \"0\" or less, this is an obtuse triangle from case 2, and we use just scale A.\n\tconst ratio = Math.max(0, tanC1 / tanC2) * 0.5;\n\n\t// The base scale is going to be a mix of the two closest scales, with the mix ratio we determined before\n\tconst scaleA = scales[colorA.scale];\n\tconst scaleB = scales[colorB.scale];\n\tconst scale = arrayOf12.map((i) =>\n\t\tnew Color(Color.mix(scaleA[i], scaleB[i], ratio)).to(\"oklch\"),\n\t) as ArrayOf12<Color>;\n\n\t// Get the closest color from the pre-mixed scale we created\n\tconst baseColor = scale.slice().sort((a, b) => source.deltaEOK(a) - source.deltaEOK(b))[0];\n\n\t// Note the chroma difference between the source color and the base color\n\tconst ratioC = source.coords[1] / baseColor.coords[1];\n\n\t// Modify hue and chroma of the scale to match the source color\n\tscale.forEach((color) => {\n\t\tcolor.coords[1] = Math.min(source.coords[1] * 1.5, color.coords[1] * ratioC);\n\t\tcolor.coords[2] = source.coords[2];\n\t});\n\n\t// Light mode\n\tif (scale[0].coords[0] > 0.5) {\n\t\tconst lightnessScale = scale.map(({ coords }) => coords[0]);\n\t\tconst backgroundL = Math.max(0, Math.min(1, backgroundColor.coords[0]));\n\t\tconst newLightnessScale = transposeProgressionStart(\n\t\t\tbackgroundL,\n\t\t\t// Add white as the first \"step\" of the light scale\n\t\t\t[1, ...lightnessScale],\n\t\t\tlightModeEasing,\n\t\t);\n\n\t\t// Remove the step we added\n\t\tnewLightnessScale.shift();\n\n\t\tnewLightnessScale.forEach((lightness, i) => {\n\t\t\tscale[i].coords[0] = lightness;\n\t\t});\n\n\t\treturn scale;\n\t}\n\n\t// Dark mode\n\tlet ease: typeof darkModeEasing = [...darkModeEasing];\n\tconst referenceBackgroundColorL = scale[0].coords[0];\n\tconst backgroundColorL = Math.max(0, Math.min(1, backgroundColor.coords[0]));\n\n\t// If background is lighter than step 0, we want to gradually change the easing to linear\n\tconst ratioL = backgroundColorL / referenceBackgroundColorL;\n\n\tif (ratioL > 1) {\n\t\tconst maxRatio = 1.5;\n\n\t\tfor (let i = 0; i < ease.length; i++) {\n\t\t\tconst metaRatio = (ratioL - 1) * (maxRatio / (maxRatio - 1));\n\t\t\tease[i] = ratioL > maxRatio ? 0 : Math.max(0, ease[i] * (1 - metaRatio));\n\t\t}\n\t}\n\n\tconst lightnessScale = scale.map(({ coords }) => coords[0]);\n\tconst backgroundL = backgroundColor.coords[0];\n\tconst newLightnessScale = transposeProgressionStart(backgroundL, lightnessScale, ease);\n\n\tnewLightnessScale.forEach((lightness, i) => {\n\t\tscale[i].coords[0] = lightness;\n\t});\n\n\treturn scale;\n}\n\nfunction getTextColor(background: Color) {\n\tconst white = new Color(\"oklch\", [1, 0, 0]);\n\n\tif (Math.abs(white.contrastAPCA(background)) < 40) {\n\t\tconst [, C, H] = background.coords;\n\t\treturn new Color(\"oklch\", [0.25, Math.max(0.08 * C, 0.04), H]);\n\t}\n\n\treturn white;\n}\n\n// target = background * (1 - alpha) + foreground * alpha\n// alpha = (target - background) / (foreground - background)\n// Expects 0-1 numbers for the RGB channels\n// oxlint-disable-next-line eslint/complexity -- pre-existing; split it before adding branches\nfunction getAlphaColor(\n\ttargetRgb: number[],\n\tbackgroundRgb: number[],\n\trgbPrecision: number,\n\talphaPrecision: number,\n\ttargetAlpha?: number,\n) {\n\tconst [tr, tg, tb] = targetRgb.map((c) => Math.round(c * rgbPrecision));\n\tconst [br, bg, bb] = backgroundRgb.map((c) => Math.round(c * rgbPrecision));\n\n\tif (\n\t\ttr === undefined ||\n\t\ttg === undefined ||\n\t\ttb === undefined ||\n\t\tbr === undefined ||\n\t\tbg === undefined ||\n\t\tbb === undefined\n\t) {\n\t\tthrow Error(\"Color is undefined\");\n\t}\n\n\t// Is the background color lighter, RGB-wise, than target color?\n\t// Decide whether we want to add as little color or as much color as possible,\n\t// darkening or lightening the background respectively.\n\t// If at least one of the bits of the target RGB value\n\t// is lighter than the background, we want to lighten it.\n\tlet desiredRgb = 0;\n\tif (tr > br) {\n\t\tdesiredRgb = rgbPrecision;\n\t} else if (tg > bg) {\n\t\tdesiredRgb = rgbPrecision;\n\t} else if (tb > bb) {\n\t\tdesiredRgb = rgbPrecision;\n\t}\n\n\tconst alphaR = (tr - br) / (desiredRgb - br);\n\tconst alphaG = (tg - bg) / (desiredRgb - bg);\n\tconst alphaB = (tb - bb) / (desiredRgb - bb);\n\n\tconst isPureGray = [alphaR, alphaG, alphaB].every((alpha) => alpha === alphaR);\n\n\t// No need for precision gymnastics with pure grays, and we can get cleaner output\n\tif (!targetAlpha && isPureGray) {\n\t\t// Convert back to 0-1 values\n\t\tconst V = desiredRgb / rgbPrecision;\n\t\treturn [V, V, V, alphaR] as const;\n\t}\n\n\tconst clampRgb = (n: number) => (isNaN(n) ? 0 : Math.min(rgbPrecision, Math.max(0, n)));\n\tconst clampA = (n: number) => (isNaN(n) ? 0 : Math.min(alphaPrecision, Math.max(0, n)));\n\tconst maxAlpha = targetAlpha ?? Math.max(alphaR, alphaG, alphaB);\n\n\tconst A = clampA(Math.ceil(maxAlpha * alphaPrecision)) / alphaPrecision;\n\tlet R = clampRgb(((br * (1 - A) - tr) / A) * -1);\n\tlet G = clampRgb(((bg * (1 - A) - tg) / A) * -1);\n\tlet B = clampRgb(((bb * (1 - A) - tb) / A) * -1);\n\n\tR = Math.ceil(R);\n\tG = Math.ceil(G);\n\tB = Math.ceil(B);\n\n\tconst blendedR = blendAlpha(R, A, br);\n\tconst blendedG = blendAlpha(G, A, bg);\n\tconst blendedB = blendAlpha(B, A, bb);\n\n\t// Correct for rounding errors in light mode\n\tif (desiredRgb === 0) {\n\t\tif (tr <= br && tr !== blendedR) {\n\t\t\tR = tr > blendedR ? R + 1 : R - 1;\n\t\t}\n\n\t\tif (tg <= bg && tg !== blendedG) {\n\t\t\tG = tg > blendedG ? G + 1 : G - 1;\n\t\t}\n\n\t\tif (tb <= bb && tb !== blendedB) {\n\t\t\tB = tb > blendedB ? B + 1 : B - 1;\n\t\t}\n\t}\n\n\t// Correct for rounding errors in dark mode\n\tif (desiredRgb === rgbPrecision) {\n\t\tif (tr >= br && tr !== blendedR) {\n\t\t\tR = tr > blendedR ? R + 1 : R - 1;\n\t\t}\n\n\t\tif (tg >= bg && tg !== blendedG) {\n\t\t\tG = tg > blendedG ? G + 1 : G - 1;\n\t\t}\n\n\t\tif (tb >= bb && tb !== blendedB) {\n\t\t\tB = tb > blendedB ? B + 1 : B - 1;\n\t\t}\n\t}\n\n\t// Convert back to 0-1 values\n\tR = R / rgbPrecision;\n\tG = G / rgbPrecision;\n\tB = B / rgbPrecision;\n\n\treturn [R, G, B, A] as const;\n}\n\n// Important – I empirically discovered that this rounding is how the browser actually overlays\n// transparent RGB bits over each other. It does NOT round the whole result altogether.\nfunction blendAlpha(foreground: number, alpha: number, background: number, round = true) {\n\tif (round) {\n\t\treturn Math.round(background * (1 - alpha)) + Math.round(foreground * alpha);\n\t}\n\n\treturn background * (1 - alpha) + foreground * alpha;\n}\n\nexport function getAlphaColorSrgb(targetColor: string, backgroundColor: string, targetAlpha?: number) {\n\tconst [r, g, b, a] = getAlphaColor(\n\t\tnew Color(targetColor).to(\"srgb\").coords,\n\t\tnew Color(backgroundColor).to(\"srgb\").coords,\n\t\t255,\n\t\t255,\n\t\ttargetAlpha,\n\t);\n\n\treturn formatHex(new Color(\"srgb\", [r, g, b], a).toString({ format: \"hex\" }));\n}\n\nexport function getAlphaColorP3(targetColor: string, backgroundColor: string, targetAlpha?: number) {\n\tconst [r, g, b, a] = getAlphaColor(\n\t\tnew Color(targetColor).to(\"p3\").coords,\n\t\tnew Color(backgroundColor).to(\"p3\").coords,\n\t\t// Not sure why, but the resulting P3 alpha colors are blended in the browser most precisely when\n\t\t// rounded to 255 integers too. Is the browser using 0-255 rather than 0-1 under the hood for P3 too?\n\t\t255,\n\t\t1000,\n\t\ttargetAlpha,\n\t);\n\n\treturn (\n\t\tnew Color(\"p3\", [r, g, b], a)\n\t\t\t.toString({ precision: 4 })\n\t\t\t// Important: in non-browser environments colorjs.io outputs a different format for some reason\n\t\t\t.replace(\"color(p3 \", \"color(display-p3 \")\n\t);\n}\n\n// Format shortform hex to longform\nfunction formatHex(str: string) {\n\tif (!str.startsWith(\"#\")) {\n\t\treturn str;\n\t}\n\n\tif (str.length === 4) {\n\t\tconst hash = str.charAt(0);\n\t\tconst r = str.charAt(1);\n\t\tconst g = str.charAt(2);\n\t\tconst b = str.charAt(3);\n\t\treturn hash + r + r + g + g + b + b;\n\t}\n\n\tif (str.length === 5) {\n\t\tconst hash = str.charAt(0);\n\t\tconst r = str.charAt(1);\n\t\tconst g = str.charAt(2);\n\t\tconst b = str.charAt(3);\n\t\tconst a = str.charAt(4);\n\t\treturn hash + r + r + g + g + b + b + a + a;\n\t}\n\n\treturn str;\n}\n\nconst darkModeEasing = [1, 0, 1, 0] as [number, number, number, number];\nconst lightModeEasing = [0, 2, 0, 2] as [number, number, number, number];\n\nexport function transposeProgressionStart(\n\tto: number,\n\tarr: number[],\n\tcurve: [number, number, number, number],\n) {\n\treturn arr.map((n, i, arr) => {\n\t\tconst lastIndex = arr.length - 1;\n\t\tconst diff = arr[0] - to;\n\t\tconst fn = BezierEasing(...curve);\n\t\treturn n - diff * fn(1 - i / lastIndex);\n\t});\n}\n\nexport function transposeProgressionEnd(\n\tto: number,\n\tarr: number[],\n\tcurve: [number, number, number, number],\n) {\n\treturn arr.map((n, i, arr) => {\n\t\tconst lastIndex = arr.length - 1;\n\t\tconst diff = arr[lastIndex] - to;\n\t\tconst fn = BezierEasing(...curve);\n\t\treturn n - diff * fn(i / lastIndex);\n\t});\n}\n\n// Convert to OKLCH string with percentage for the lightness channel\n// https://github.com/radix-ui/themes/issues/420\nfunction toOklchString(color: Color) {\n\tconst L = +(color.coords[0] * 100).toFixed(1);\n\treturn color\n\t\t.to(\"oklch\")\n\t\t.toString({ precision: 4 })\n\t\t.replace(/(\\S+)(.+)/, `oklch(${L}%$2`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,YAAY;CAAC;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAI;AAAE;AAGvD,MAAM,iBAAiB;CAAC;CAAQ;CAAS;CAAS;CAAQ;CAAS;AAAM;AAGzE,MAAM,aAAa;CAAC,GAAG;CAAgB;CAAU;CAAO;CAAQ;CAAW;CAC3E;CAAQ;CAAU;CAAU;CAAQ;CAAU;CAAQ;CAAQ;CAAQ;CAAQ;CAC9E;CAAS;CAAS;CAAU;CAAO;CAAQ;CAAQ;CAAU;AAAO;AAEpE,MAAM,cAAc,OAAO,YAC1B,WAAW,KAAK,cAAc,CAC7B,WACA,OAAO,OAAO,YAAY,GAAG,UAAU,IAAI,EAAE,KAAK,QAAQ,IAAI,MAAM,GAAG,EAAE,GAAG,OAAO,CAAC,CACrF,CAAC,CACF;AAEA,MAAM,aAAa,OAAO,YACzB,WAAW,KAAK,cAAc,CAC7B,WACA,OAAO,OAAO,YAAY,GAAG,UAAU,QAAQ,EAAE,KAAK,QAAQ,IAAI,MAAM,GAAG,EAAE,GAAG,OAAO,CAAC,CACzF,CAAC,C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ACR,EAAE,IAAI,IAAI,SAAS;CACvC,CAAC;AACF;AAEA,SAAgB,wBACf,IACA,KACA,OACC;CACD,OAAO,IAAI,KAAK,GAAG,GAAG,QAAQ;EAC7B,MAAM,YAAY,IAAI,SAAS;EAG/B,OAAO,KAFM,IAAI,aAAa,MACnB,aAAa,GAAG,KACR,EAAE,IAAI,SAAS;CACnC,CAAC;AACF;AAIA,SAAS,cAAc,OAAc;CACpC,MAAM,IAAI,EAAE,MAAM,OAAO,KAAK,KAAK,QAAQ,CAAC;CAC5C,OAAO,MACL,GAAG,OAAO,EACV,SAAS,EAAE,WAAW,EAAE,CAAC,EACzB,QAAQ,aAAa,SAAS,EAAE,IAAI;AACvC"}
|
|
1
|
+
{"version":3,"file":"generate-radix-colors.js","names":[],"sources":["../../src/lib/generate-radix-colors.tsx"],"sourcesContent":["/**\n * Vendored from Radix UI's website — components/generate-radix-colors.tsx\n * https://github.com/radix-ui/website\n *\n * MIT License — Copyright (c) 2024 WorkOS\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND. (Full text:\n * https://github.com/radix-ui/website/blob/main/LICENSE)\n *\n * Kept VERBATIM so it can be re-synced upstream (this file is excluded from the\n * formatter in vite.config.ts). Strict type-checking is skipped (upstream targets\n * a looser tsconfig with unchecked array indexing over fixed 12-step scales).\n *\n * Only deviation from upstream: `getAlphaColorSrgb`/`getAlphaColorP3` are `export`ed (no\n * algorithm change) so `accent-theme.ts` can re-solve alpha for its canvas-tinted steps\n * with Radix's own solver instead of duplicating its rounding-correction logic. Re-apply\n * these two keywords after a re-sync.\n */\n// @ts-nocheck\nimport * as RadixColors from \"@radix-ui/colors\";\nimport Color from \"colorjs.io\";\nimport BezierEasing from \"bezier-easing\";\n\ntype ArrayOf12<T> = [T, T, T, T, T, T, T, T, T, T, T, T];\nconst arrayOf12 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] as const;\n\n// prettier-ignore\nconst grayScaleNames = ['gray', 'mauve', 'slate', 'sage', 'olive', 'sand'] as const;\n\n// prettier-ignore\nconst scaleNames = [...grayScaleNames, 'tomato', 'red', 'ruby', 'crimson', 'pink',\n'plum', 'purple', 'violet', 'iris', 'indigo', 'blue', 'cyan', 'teal', 'jade', 'green',\n'grass', 'brown', 'orange', 'sky', 'mint', 'lime', 'yellow', 'amber'] as const;\n\nconst lightColors = Object.fromEntries(\n\tscaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}P3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof scaleNames)[number], ArrayOf12<Color>>;\n\nconst darkColors = Object.fromEntries(\n\tscaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}DarkP3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof scaleNames)[number], ArrayOf12<Color>>;\n\nconst lightGrayColors = Object.fromEntries(\n\tgrayScaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}P3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof grayScaleNames)[number], ArrayOf12<Color>>;\n\nconst darkGrayColors = Object.fromEntries(\n\tgrayScaleNames.map((scaleName) => [\n\t\tscaleName,\n\t\tObject.values(RadixColors[`${scaleName}DarkP3`]).map((str) => new Color(str).to(\"oklch\")),\n\t]),\n) as Record<(typeof grayScaleNames)[number], ArrayOf12<Color>>;\n\nexport const generateRadixColors = ({\n\tappearance,\n\t...args\n}: {\n\tappearance: \"light\" | \"dark\";\n\taccent: string;\n\tgray: string;\n\tbackground: string;\n}) => {\n\tconst allScales = appearance === \"light\" ? lightColors : darkColors;\n\tconst grayScales = appearance === \"light\" ? lightGrayColors : darkGrayColors;\n\tconst backgroundColor = new Color(args.background).to(\"oklch\");\n\n\tconst grayBaseColor = new Color(args.gray).to(\"oklch\");\n\tconst grayScaleColors = getScaleFromColor(grayBaseColor, grayScales, backgroundColor);\n\n\tconst accentBaseColor = new Color(args.accent).to(\"oklch\");\n\n\tlet accentScaleColors = getScaleFromColor(accentBaseColor, allScales, backgroundColor);\n\n\t// Enforce srgb for the background color\n\tconst backgroundHex = backgroundColor.to(\"srgb\").toString({ format: \"hex\" });\n\n\t// Make sure we use the tint from the gray scale for when base is pure white or black\n\tconst accentBaseHex = accentBaseColor.to(\"srgb\").toString({ format: \"hex\" });\n\tif (accentBaseHex === \"#000\" || accentBaseHex === \"#fff\") {\n\t\taccentScaleColors = grayScaleColors.map((color) => color.clone()) as ArrayOf12<Color>;\n\t}\n\n\tconst [accent9Color, accentContrastColor] = getStep9Colors(accentScaleColors, accentBaseColor);\n\n\taccentScaleColors[8] = accent9Color;\n\taccentScaleColors[9] = getButtonHoverColor(accent9Color, [accentScaleColors]);\n\n\t// Limit saturation of the text colors\n\taccentScaleColors[10].coords[1] = Math.min(\n\t\tMath.max(accentScaleColors[8].coords[1], accentScaleColors[7].coords[1]),\n\t\taccentScaleColors[10].coords[1],\n\t);\n\taccentScaleColors[11].coords[1] = Math.min(\n\t\tMath.max(accentScaleColors[8].coords[1], accentScaleColors[7].coords[1]),\n\t\taccentScaleColors[11].coords[1],\n\t);\n\n\tconst accentScaleHex = accentScaleColors.map((color) =>\n\t\tcolor.to(\"srgb\").toString({ format: \"hex\" }),\n\t) as ArrayOf12<string>;\n\n\tconst accentScaleWideGamut = accentScaleColors.map(toOklchString) as ArrayOf12<string>;\n\n\tconst accentScaleAlphaHex = accentScaleHex.map((color) =>\n\t\tgetAlphaColorSrgb(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentScaleAlphaWideGamutString = accentScaleHex.map((color) =>\n\t\tgetAlphaColorP3(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentContrastColorHex = accentContrastColor.to(\"srgb\").toString({ format: \"hex\" });\n\n\tconst grayScaleHex = grayScaleColors.map((color) =>\n\t\tcolor.to(\"srgb\").toString({ format: \"hex\" }),\n\t) as ArrayOf12<string>;\n\n\tconst grayScaleWideGamut = grayScaleColors.map(toOklchString) as ArrayOf12<string>;\n\n\tconst grayScaleAlphaHex = grayScaleHex.map((color) =>\n\t\tgetAlphaColorSrgb(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst grayScaleAlphaWideGamutString = grayScaleHex.map((color) =>\n\t\tgetAlphaColorP3(color, backgroundHex),\n\t) as ArrayOf12<string>;\n\n\tconst accentSurfaceHex =\n\t\tappearance === \"light\"\n\t\t\t? getAlphaColorSrgb(accentScaleHex[1], backgroundHex, 0.8)\n\t\t\t: getAlphaColorSrgb(accentScaleHex[1], backgroundHex, 0.5);\n\n\tconst accentSurfaceWideGamutString =\n\t\tappearance === \"light\"\n\t\t\t? getAlphaColorP3(accentScaleWideGamut[1], backgroundHex, 0.8)\n\t\t\t: getAlphaColorP3(accentScaleWideGamut[1], backgroundHex, 0.5);\n\n\treturn {\n\t\taccentScale: accentScaleHex,\n\t\taccentScaleAlpha: accentScaleAlphaHex,\n\t\taccentScaleWideGamut: accentScaleWideGamut,\n\t\taccentScaleAlphaWideGamut: accentScaleAlphaWideGamutString,\n\t\taccentContrast: accentContrastColorHex,\n\n\t\tgrayScale: grayScaleHex,\n\t\tgrayScaleAlpha: grayScaleAlphaHex,\n\t\tgrayScaleWideGamut: grayScaleWideGamut,\n\t\tgrayScaleAlphaWideGamut: grayScaleAlphaWideGamutString,\n\n\t\tgraySurface: appearance === \"light\" ? \"#ffffffcc\" : \"rgba(0, 0, 0, 0.05)\",\n\t\tgraySurfaceWideGamut:\n\t\t\tappearance === \"light\" ? \"color(display-p3 1 1 1 / 80%)\" : \"color(display-p3 0 0 0 / 5%)\",\n\n\t\taccentSurface: accentSurfaceHex,\n\t\taccentSurfaceWideGamut: accentSurfaceWideGamutString,\n\n\t\tbackground: backgroundHex,\n\t};\n};\n\nfunction getStep9Colors(scale: ArrayOf12<Color>, accentBaseColor: Color): [Color, Color] {\n\tconst referenceBackgroundColor = scale[0];\n\tconst distance = accentBaseColor.deltaEOK(referenceBackgroundColor) * 100;\n\n\t// If the accent base color is close to the page background color, it's likely\n\t// white on white or black on black, so we want to return something that makes sense instead\n\tif (distance < 25) {\n\t\treturn [scale[8], getTextColor(scale[8])];\n\t}\n\n\treturn [accentBaseColor, getTextColor(accentBaseColor)];\n}\n\nfunction getButtonHoverColor(source: Color, scales: ArrayOf12<Color>[]) {\n\tconst [L, C, H] = source.coords;\n\tconst newL = L > 0.4 ? L - 0.03 / (L + 0.1) : L + 0.03 / (L + 0.1);\n\tconst newC = L > 0.4 && !isNaN(H) ? C * 0.93 + 0 : C;\n\tconst buttonHoverColor = new Color(\"oklch\", [newL, newC, H]);\n\n\t// Find closest in-scale color to donate the chroma and hue.\n\t// Especially useful when the source color is pure white or black,\n\t// but the gray scale is tinted.\n\tlet closestColor = buttonHoverColor;\n\tlet minDistance = Infinity;\n\n\tscales.forEach((scale) => {\n\t\tfor (const color of scale) {\n\t\t\tconst distance = buttonHoverColor.deltaEOK(color);\n\t\t\tif (distance < minDistance) {\n\t\t\t\tminDistance = distance;\n\t\t\t\tclosestColor = color;\n\t\t\t}\n\t\t}\n\t});\n\n\tbuttonHoverColor.coords[1] = closestColor.coords[1];\n\tbuttonHoverColor.coords[2] = closestColor.coords[2];\n\treturn buttonHoverColor;\n}\n\nfunction getScaleFromColor(\n\tsource: Color,\n\tscales: Record<string, ArrayOf12<Color>>,\n\tbackgroundColor: Color,\n) {\n\tlet allColors: { scale: string; color: Color; distance: number }[] = [];\n\n\tObject.entries(scales).forEach(([name, scale]) => {\n\t\tfor (const color of scale) {\n\t\t\tconst distance = source.deltaEOK(color);\n\t\t\tallColors.push({ scale: name, distance, color });\n\t\t}\n\t});\n\n\tallColors.sort((a, b) => a.distance - b.distance);\n\n\t// Remove non-unique scales\n\tlet closestColors = allColors.filter(\n\t\t(color, i, arr) => i === arr.findIndex((value) => value.scale === color.scale),\n\t);\n\n\t// If the next two closest colors are both grays, remove the second one until it’s not a gray anymore.\n\t// This is because up next we will be comparing how close the two closest colors are to the source color,\n\t// and since the grays are all extremely close to each other, we won’t get any useful data from the second\n\t// closest color if it’s also a gray.\n\tconst grayScaleNamesStr = grayScaleNames as readonly string[];\n\tconst allAreGrays = closestColors.every((color) => grayScaleNamesStr.includes(color.scale));\n\tif (!allAreGrays && grayScaleNamesStr.includes(closestColors[0].scale)) {\n\t\twhile (grayScaleNamesStr.includes(closestColors[1].scale)) {\n\t\t\tclosestColors.splice(1, 1);\n\t\t}\n\t}\n\n\tlet colorA = closestColors[0];\n\tlet colorB = closestColors[1];\n\n\t// Light trigonometry ahead.\n\t//\n\t// We want to determine the color that is the closest to the source color. Sometimes it makes sense\n\t// to proportionally mix the two closest colors together, but sometimes it is not useful at all.\n\t// Color coords are spatial in 3D, however we can treat the data we have as a 2D projection that is good enough.\n\t//\n\t// Case 1:\n\t// If the distances between the source color, the 1st closest color (A) and the 2nd closest color (B) form\n\t// a triangle where NEITHER angle A nor B are larger than 90 degrees, then we want to mix the 1st and the 2nd\n\t// closest colors in the same proportion as distances AD and BD are to each other. Mixing the two would result\n\t// in a color that would be closer to the source color than either of the two original closest colors.\n\t// Example: source color is a desaturated blue, which is between \"indigo\" and \"slate\" scales.\n\t//\n\t// C ← Source color\n\t// /|⟍\n\t// / | ⟍\n\t// b / | ⟍ a\n\t// / | ⟍\n\t// / | ⟍\n\t// A --- D -------- B\n\t// ↑\n\t// The color we want to use as the base, which is a mix of A and B.\n\t//\n\t// Case 2:\n\t// If the distances between the source color, the 1st closest color (A) and the 2nd closest color (B) form\n\t// a triangle where EITHER angle A or B are larger than 90 degrees, then we don’t care about point B because it’s\n\t// directionally the same as A, as mixing A and B can’t provide us with a color that is any closer to the source.\n\t// Example: source color is a saturated blue, with \"blue\" being the closest scale, and \"indigo\" just being further.\n\t//\n\t// C ← Source color\n\t// \\⟍\n\t// \\ ⟍\n\t// \\ ⟍ a\n\t// b \\ ⟍\n\t// \\ ⟍\n\t// A ------- B\n\t// ↑\n\t// The color we want to use as the base, which is not influenced by B.\n\n\t// We’ll need all the lengths of the triangle sides, named after the angles they look at:\n\tconst a = colorB.distance;\n\tconst b = colorA.distance;\n\tconst c = colorA.color.deltaEOK(colorB.color);\n\n\t// We can get the ratios of AD to BD lengths with trigonometry using tangents,\n\t// as the ratio of the tangents of the opposite angles will match.\n\tconst cosA = (b ** 2 + c ** 2 - a ** 2) / (2 * b * c);\n\tconst radA = Math.acos(cosA);\n\tconst sinA = Math.sin(radA);\n\n\tconst cosB = (a ** 2 + c ** 2 - b ** 2) / (2 * a * c);\n\tconst radB = Math.acos(cosB);\n\tconst sinB = Math.sin(radB);\n\n\t// Tangent of angle C in the ACD triangle\n\tconst tanC1 = cosA / sinA;\n\n\t// Tangent of angle C in the BCD triangle\n\tconst tanC2 = cosB / sinB;\n\n\t// The ratio of the tangents corresponds to the ratio of the distances AD to BD\n\t// In the end, it means how much of scale B we want to mix into scale A.\n\t// If it’s \"0\" or less, this is an obtuse triangle from case 2, and we use just scale A.\n\tconst ratio = Math.max(0, tanC1 / tanC2) * 0.5;\n\n\t// The base scale is going to be a mix of the two closest scales, with the mix ratio we determined before\n\tconst scaleA = scales[colorA.scale];\n\tconst scaleB = scales[colorB.scale];\n\tconst scale = arrayOf12.map((i) =>\n\t\tnew Color(Color.mix(scaleA[i], scaleB[i], ratio)).to(\"oklch\"),\n\t) as ArrayOf12<Color>;\n\n\t// Get the closest color from the pre-mixed scale we created\n\tconst baseColor = scale.toSorted((a, b) => source.deltaEOK(a) - source.deltaEOK(b))[0];\n\n\t// Note the chroma difference between the source color and the base color\n\tconst ratioC = source.coords[1] / baseColor.coords[1];\n\n\t// Modify hue and chroma of the scale to match the source color\n\tscale.forEach((color) => {\n\t\tcolor.coords[1] = Math.min(source.coords[1] * 1.5, color.coords[1] * ratioC);\n\t\tcolor.coords[2] = source.coords[2];\n\t});\n\n\t// Light mode\n\tif (scale[0].coords[0] > 0.5) {\n\t\tconst lightnessScale = scale.map(({ coords }) => coords[0]);\n\t\tconst backgroundL = Math.max(0, Math.min(1, backgroundColor.coords[0]));\n\t\tconst newLightnessScale = transposeProgressionStart(\n\t\t\tbackgroundL,\n\t\t\t// Add white as the first \"step\" of the light scale\n\t\t\t[1, ...lightnessScale],\n\t\t\tlightModeEasing,\n\t\t);\n\n\t\t// Remove the step we added\n\t\tnewLightnessScale.shift();\n\n\t\tnewLightnessScale.forEach((lightness, i) => {\n\t\t\tscale[i].coords[0] = lightness;\n\t\t});\n\n\t\treturn scale;\n\t}\n\n\t// Dark mode\n\tlet ease: typeof darkModeEasing = [...darkModeEasing];\n\tconst referenceBackgroundColorL = scale[0].coords[0];\n\tconst backgroundColorL = Math.max(0, Math.min(1, backgroundColor.coords[0]));\n\n\t// If background is lighter than step 0, we want to gradually change the easing to linear\n\tconst ratioL = backgroundColorL / referenceBackgroundColorL;\n\n\tif (ratioL > 1) {\n\t\tconst maxRatio = 1.5;\n\n\t\tfor (let i = 0; i < ease.length; i++) {\n\t\t\tconst metaRatio = (ratioL - 1) * (maxRatio / (maxRatio - 1));\n\t\t\tease[i] = ratioL > maxRatio ? 0 : Math.max(0, ease[i] * (1 - metaRatio));\n\t\t}\n\t}\n\n\tconst lightnessScale = scale.map(({ coords }) => coords[0]);\n\tconst backgroundL = backgroundColor.coords[0];\n\tconst newLightnessScale = transposeProgressionStart(backgroundL, lightnessScale, ease);\n\n\tnewLightnessScale.forEach((lightness, i) => {\n\t\tscale[i].coords[0] = lightness;\n\t});\n\n\treturn scale;\n}\n\nfunction getTextColor(background: Color) {\n\tconst white = new Color(\"oklch\", [1, 0, 0]);\n\n\tif (Math.abs(white.contrastAPCA(background)) < 40) {\n\t\tconst [, C, H] = background.coords;\n\t\treturn new Color(\"oklch\", [0.25, Math.max(0.08 * C, 0.04), H]);\n\t}\n\n\treturn white;\n}\n\n// target = background * (1 - alpha) + foreground * alpha\n// alpha = (target - background) / (foreground - background)\n// Expects 0-1 numbers for the RGB channels\n// oxlint-disable-next-line eslint/complexity -- pre-existing; split it before adding branches\nfunction getAlphaColor(\n\ttargetRgb: number[],\n\tbackgroundRgb: number[],\n\trgbPrecision: number,\n\talphaPrecision: number,\n\ttargetAlpha?: number,\n) {\n\tconst [tr, tg, tb] = targetRgb.map((c) => Math.round(c * rgbPrecision));\n\tconst [br, bg, bb] = backgroundRgb.map((c) => Math.round(c * rgbPrecision));\n\n\tif (\n\t\ttr === undefined ||\n\t\ttg === undefined ||\n\t\ttb === undefined ||\n\t\tbr === undefined ||\n\t\tbg === undefined ||\n\t\tbb === undefined\n\t) {\n\t\tthrow Error(\"Color is undefined\");\n\t}\n\n\t// Is the background color lighter, RGB-wise, than target color?\n\t// Decide whether we want to add as little color or as much color as possible,\n\t// darkening or lightening the background respectively.\n\t// If at least one of the bits of the target RGB value\n\t// is lighter than the background, we want to lighten it.\n\tlet desiredRgb = 0;\n\tif (tr > br) {\n\t\tdesiredRgb = rgbPrecision;\n\t} else if (tg > bg) {\n\t\tdesiredRgb = rgbPrecision;\n\t} else if (tb > bb) {\n\t\tdesiredRgb = rgbPrecision;\n\t}\n\n\tconst alphaR = (tr - br) / (desiredRgb - br);\n\tconst alphaG = (tg - bg) / (desiredRgb - bg);\n\tconst alphaB = (tb - bb) / (desiredRgb - bb);\n\n\tconst isPureGray = [alphaR, alphaG, alphaB].every((alpha) => alpha === alphaR);\n\n\t// No need for precision gymnastics with pure grays, and we can get cleaner output\n\tif (!targetAlpha && isPureGray) {\n\t\t// Convert back to 0-1 values\n\t\tconst V = desiredRgb / rgbPrecision;\n\t\treturn [V, V, V, alphaR] as const;\n\t}\n\n\tconst clampRgb = (n: number) => (isNaN(n) ? 0 : Math.min(rgbPrecision, Math.max(0, n)));\n\tconst clampA = (n: number) => (isNaN(n) ? 0 : Math.min(alphaPrecision, Math.max(0, n)));\n\tconst maxAlpha = targetAlpha ?? Math.max(alphaR, alphaG, alphaB);\n\n\tconst A = clampA(Math.ceil(maxAlpha * alphaPrecision)) / alphaPrecision;\n\tlet R = clampRgb(((br * (1 - A) - tr) / A) * -1);\n\tlet G = clampRgb(((bg * (1 - A) - tg) / A) * -1);\n\tlet B = clampRgb(((bb * (1 - A) - tb) / A) * -1);\n\n\tR = Math.ceil(R);\n\tG = Math.ceil(G);\n\tB = Math.ceil(B);\n\n\tconst blendedR = blendAlpha(R, A, br);\n\tconst blendedG = blendAlpha(G, A, bg);\n\tconst blendedB = blendAlpha(B, A, bb);\n\n\t// Correct for rounding errors in light mode\n\tif (desiredRgb === 0) {\n\t\tif (tr <= br && tr !== blendedR) {\n\t\t\tR = tr > blendedR ? R + 1 : R - 1;\n\t\t}\n\n\t\tif (tg <= bg && tg !== blendedG) {\n\t\t\tG = tg > blendedG ? G + 1 : G - 1;\n\t\t}\n\n\t\tif (tb <= bb && tb !== blendedB) {\n\t\t\tB = tb > blendedB ? B + 1 : B - 1;\n\t\t}\n\t}\n\n\t// Correct for rounding errors in dark mode\n\tif (desiredRgb === rgbPrecision) {\n\t\tif (tr >= br && tr !== blendedR) {\n\t\t\tR = tr > blendedR ? R + 1 : R - 1;\n\t\t}\n\n\t\tif (tg >= bg && tg !== blendedG) {\n\t\t\tG = tg > blendedG ? G + 1 : G - 1;\n\t\t}\n\n\t\tif (tb >= bb && tb !== blendedB) {\n\t\t\tB = tb > blendedB ? B + 1 : B - 1;\n\t\t}\n\t}\n\n\t// Convert back to 0-1 values\n\tR = R / rgbPrecision;\n\tG = G / rgbPrecision;\n\tB = B / rgbPrecision;\n\n\treturn [R, G, B, A] as const;\n}\n\n// Important – I empirically discovered that this rounding is how the browser actually overlays\n// transparent RGB bits over each other. It does NOT round the whole result altogether.\nfunction blendAlpha(foreground: number, alpha: number, background: number, round = true) {\n\tif (round) {\n\t\treturn Math.round(background * (1 - alpha)) + Math.round(foreground * alpha);\n\t}\n\n\treturn background * (1 - alpha) + foreground * alpha;\n}\n\nexport function getAlphaColorSrgb(targetColor: string, backgroundColor: string, targetAlpha?: number) {\n\tconst [r, g, b, a] = getAlphaColor(\n\t\tnew Color(targetColor).to(\"srgb\").coords,\n\t\tnew Color(backgroundColor).to(\"srgb\").coords,\n\t\t255,\n\t\t255,\n\t\ttargetAlpha,\n\t);\n\n\treturn formatHex(new Color(\"srgb\", [r, g, b], a).toString({ format: \"hex\" }));\n}\n\nexport function getAlphaColorP3(targetColor: string, backgroundColor: string, targetAlpha?: number) {\n\tconst [r, g, b, a] = getAlphaColor(\n\t\tnew Color(targetColor).to(\"p3\").coords,\n\t\tnew Color(backgroundColor).to(\"p3\").coords,\n\t\t// Not sure why, but the resulting P3 alpha colors are blended in the browser most precisely when\n\t\t// rounded to 255 integers too. Is the browser using 0-255 rather than 0-1 under the hood for P3 too?\n\t\t255,\n\t\t1000,\n\t\ttargetAlpha,\n\t);\n\n\treturn (\n\t\tnew Color(\"p3\", [r, g, b], a)\n\t\t\t.toString({ precision: 4 })\n\t\t\t// Important: in non-browser environments colorjs.io outputs a different format for some reason\n\t\t\t.replace(\"color(p3 \", \"color(display-p3 \")\n\t);\n}\n\n// Format shortform hex to longform\nfunction formatHex(str: string) {\n\tif (!str.startsWith(\"#\")) {\n\t\treturn str;\n\t}\n\n\tif (str.length === 4) {\n\t\tconst hash = str.charAt(0);\n\t\tconst r = str.charAt(1);\n\t\tconst g = str.charAt(2);\n\t\tconst b = str.charAt(3);\n\t\treturn hash + r + r + g + g + b + b;\n\t}\n\n\tif (str.length === 5) {\n\t\tconst hash = str.charAt(0);\n\t\tconst r = str.charAt(1);\n\t\tconst g = str.charAt(2);\n\t\tconst b = str.charAt(3);\n\t\tconst a = str.charAt(4);\n\t\treturn hash + r + r + g + g + b + b + a + a;\n\t}\n\n\treturn str;\n}\n\nconst darkModeEasing = [1, 0, 1, 0] as [number, number, number, number];\nconst lightModeEasing = [0, 2, 0, 2] as [number, number, number, number];\n\nexport function transposeProgressionStart(\n\tto: number,\n\tarr: number[],\n\tcurve: [number, number, number, number],\n) {\n\treturn arr.map((n, i, arr) => {\n\t\tconst lastIndex = arr.length - 1;\n\t\tconst diff = arr[0] - to;\n\t\tconst fn = BezierEasing(...curve);\n\t\treturn n - diff * fn(1 - i / lastIndex);\n\t});\n}\n\nexport function transposeProgressionEnd(\n\tto: number,\n\tarr: number[],\n\tcurve: [number, number, number, number],\n) {\n\treturn arr.map((n, i, arr) => {\n\t\tconst lastIndex = arr.length - 1;\n\t\tconst diff = arr[lastIndex] - to;\n\t\tconst fn = BezierEasing(...curve);\n\t\treturn n - diff * fn(i / lastIndex);\n\t});\n}\n\n// Convert to OKLCH string with percentage for the lightness channel\n// https://github.com/radix-ui/themes/issues/420\nfunction toOklchString(color: Color) {\n\tconst L = +(color.coords[0] * 100).toFixed(1);\n\treturn color\n\t\t.to(\"oklch\")\n\t\t.toString({ precision: 4 })\n\t\t.replace(/(\\S+)(.+)/, `oklch(${L}%$2`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,YAAY;CAAC;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAI;AAAE;AAGvD,MAAM,iBAAiB;CAAC;CAAQ;CAAS;CAAS;CAAQ;CAAS;AAAM;AAGzE,MAAM,aAAa;CAAC,GAAG;CAAgB;CAAU;CAAO;CAAQ;CAAW;CAC3E;CAAQ;CAAU;CAAU;CAAQ;CAAU;CAAQ;CAAQ;CAAQ;CAAQ;CAC9E;CAAS;CAAS;CAAU;CAAO;CAAQ;CAAQ;CAAU;AAAO;AAEpE,MAAM,cAAc,OAAO,YAC1B,WAAW,KAAK,cAAc,CAC7B,WACA,OAAO,OAAO,YAAY,GAAG,UAAU,IAAI,EAAE,KAA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G;CAAG;CAAG;AAAC;AAClC,MAAM,kBAAkB;CAAC;CAAG;CAAG;CAAG;AAAC;AAEnC,SAAgB,0BACf,IACA,KACA,OACC;CACD,OAAO,IAAI,KAAK,GAAG,GAAG,QAAQ;EAC7B,MAAM,YAAY,IAAI,SAAS;EAG/B,OAAO,KAFM,IAAI,KAAK,MACX,aAAa,GAAG,KACR,EAAE,IAAI,IAAI,SAAS;CACvC,CAAC;AACF;AAEA,SAAgB,wBACf,IACA,KACA,OACC;CACD,OAAO,IAAI,KAAK,GAAG,GAAG,QAAQ;EAC7B,MAAM,YAAY,IAAI,SAAS;EAG/B,OAAO,KAFM,IAAI,aAAa,MACnB,aAAa,GAAG,KACR,EAAE,IAAI,SAAS;CACnC,CAAC;AACF;AAIA,SAAS,cAAc,OAAc;CACpC,MAAM,IAAI,EAAE,MAAM,OAAO,KAAK,KAAK,QAAQ,CAAC;CAC5C,OAAO,MACL,GAAG,OAAO,EACV,SAAS,EAAE,WAAW,EAAE,CAAC,EACzB,QAAQ,aAAa,SAAS,EAAE,IAAI;AACvC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const require_chunk = require("../chunk-DY84GLCh.cjs");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
react = require_chunk.__toESM(react, 1);
|
|
6
|
+
//#region src/lib/toggle-group-context.ts
|
|
7
|
+
/** `ToggleGroup`'s defaults for its `Toggle`s; kept out of the public exports. */
|
|
8
|
+
const ToggleGroupContext = react.createContext({});
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.ToggleGroupContext = ToggleGroupContext;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=toggle-group-context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle-group-context.cjs","names":["React"],"sources":["../../src/lib/toggle-group-context.ts"],"sourcesContent":["import * as React from 'react'\nimport type { SparkButtonColor } from '../components/button'\nimport type { ButtonProps } from '../components/button'\nimport type { ToggleStyle } from '../components/toggle'\n\n/** `ToggleGroup`'s defaults for its `Toggle`s; kept out of the public exports. */\nexport const ToggleGroupContext = React.createContext<{\n styleVariant?: ToggleStyle\n color?: SparkButtonColor\n size?: ButtonProps['size']\n showCheck?: boolean\n}>({})\n"],"mappings":";;;;;;;AAMA,MAAa,qBAAqBA,MAAM,cAKrC,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { ButtonProps, SparkButtonColor } from "../components/button.cjs";
|
|
4
|
+
import { ToggleStyle } from "../components/toggle.cjs";
|
|
5
|
+
import * as React$1 from "react";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/toggle-group-context.d.ts
|
|
8
|
+
/** `ToggleGroup`'s defaults for its `Toggle`s; kept out of the public exports. */
|
|
9
|
+
declare const ToggleGroupContext: React$1.Context<{
|
|
10
|
+
styleVariant?: ToggleStyle;
|
|
11
|
+
color?: SparkButtonColor;
|
|
12
|
+
size?: ButtonProps["size"];
|
|
13
|
+
showCheck?: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ToggleGroupContext };
|
|
17
|
+
//# sourceMappingURL=toggle-group-context.d.cts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { ButtonProps, SparkButtonColor } from "../components/button.js";
|
|
4
|
+
import { ToggleStyle } from "../components/toggle.js";
|
|
5
|
+
import * as React$1 from "react";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/toggle-group-context.d.ts
|
|
8
|
+
/** `ToggleGroup`'s defaults for its `Toggle`s; kept out of the public exports. */
|
|
9
|
+
declare const ToggleGroupContext: React$1.Context<{
|
|
10
|
+
styleVariant?: ToggleStyle;
|
|
11
|
+
color?: SparkButtonColor;
|
|
12
|
+
size?: ButtonProps["size"];
|
|
13
|
+
showCheck?: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ToggleGroupContext };
|
|
17
|
+
//# sourceMappingURL=toggle-group-context.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React$1 from "react";
|
|
3
|
+
//#region src/lib/toggle-group-context.ts
|
|
4
|
+
/** `ToggleGroup`'s defaults for its `Toggle`s; kept out of the public exports. */
|
|
5
|
+
const ToggleGroupContext = React$1.createContext({});
|
|
6
|
+
//#endregion
|
|
7
|
+
export { ToggleGroupContext };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=toggle-group-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle-group-context.js","names":["React"],"sources":["../../src/lib/toggle-group-context.ts"],"sourcesContent":["import * as React from 'react'\nimport type { SparkButtonColor } from '../components/button'\nimport type { ButtonProps } from '../components/button'\nimport type { ToggleStyle } from '../components/toggle'\n\n/** `ToggleGroup`'s defaults for its `Toggle`s; kept out of the public exports. */\nexport const ToggleGroupContext = React.createContext<{\n styleVariant?: ToggleStyle\n color?: SparkButtonColor\n size?: ButtonProps['size']\n showCheck?: boolean\n}>({})\n"],"mappings":";;;;AAMA,MAAa,qBAAqBA,QAAM,cAKrC,CAAC,CAAC"}
|
package/dist/styles/theme.css
CHANGED
|
@@ -600,7 +600,7 @@
|
|
|
600
600
|
}
|
|
601
601
|
|
|
602
602
|
/*
|
|
603
|
-
* Overlay / focus / selection
|
|
603
|
+
* Overlay / focus / selection — Radix-parity semantic tokens, derived
|
|
604
604
|
* from existing scales (additive; the --spark-* contract is untouched). Overlay is
|
|
605
605
|
* page-level (backdrops portal to <body>); the rest follow the accent per scope.
|
|
606
606
|
*/
|
|
@@ -616,6 +616,16 @@
|
|
|
616
616
|
--color-overlay: var(--black-a8);
|
|
617
617
|
}
|
|
618
618
|
|
|
619
|
+
.light,
|
|
620
|
+
.light-theme {
|
|
621
|
+
color-scheme: light;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
.dark,
|
|
625
|
+
.dark-theme {
|
|
626
|
+
color-scheme: dark;
|
|
627
|
+
}
|
|
628
|
+
|
|
619
629
|
:root,
|
|
620
630
|
.spark-theme {
|
|
621
631
|
/*
|
|
@@ -629,7 +639,6 @@
|
|
|
629
639
|
--color-focus-root: var(--spark-11);
|
|
630
640
|
--color-primary-focus: var(--spark-11);
|
|
631
641
|
--color-selection-root: var(--spark-a5);
|
|
632
|
-
--color-autofill-root: var(--spark-a3);
|
|
633
642
|
}
|
|
634
643
|
|
|
635
644
|
.spark-theme ::selection {
|
|
@@ -638,10 +647,12 @@
|
|
|
638
647
|
|
|
639
648
|
.spark-theme :-webkit-autofill,
|
|
640
649
|
.spark-theme :-webkit-autofill:hover,
|
|
641
|
-
.spark-theme :-webkit-autofill:focus
|
|
650
|
+
.spark-theme :-webkit-autofill:focus,
|
|
651
|
+
.spark-theme :-webkit-autofill:active {
|
|
642
652
|
-webkit-text-fill-color: var(--neutral-12);
|
|
643
|
-
-webkit-box-shadow: 0 0 0 1000px var(--color-autofill-root) inset;
|
|
644
653
|
caret-color: var(--neutral-12);
|
|
654
|
+
-webkit-background-clip: text;
|
|
655
|
+
background-clip: text;
|
|
645
656
|
}
|
|
646
657
|
}
|
|
647
658
|
|
package/dist/utils/format.cjs
CHANGED
|
@@ -49,6 +49,7 @@ exports.formatPercent = formatPercent;
|
|
|
49
49
|
exports.formatPower = formatPower;
|
|
50
50
|
exports.formatRatio = formatRatio;
|
|
51
51
|
exports.formatThousands = formatThousands;
|
|
52
|
+
exports.getDocumentLang = getDocumentLang;
|
|
52
53
|
exports.integerFormat = integerFormat;
|
|
53
54
|
exports.localeNumberFormat = localeNumberFormat;
|
|
54
55
|
exports.oneDecimalFormat = oneDecimalFormat;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.cjs","names":[],"sources":["../../src/utils/format.ts"],"sourcesContent":["import { EM_DASH, NARROW_NBSP } from './chars'\n\ninterface LocaleNumberFormat {\n format: (value: number) => string\n}\n\nfunction getDocumentLang(): string | undefined {\n return typeof document === 'undefined'\n ? undefined\n : document.documentElement.lang || undefined\n}\n\nconst localeNumberFormat = (\n options?: Intl.NumberFormatOptions,\n): LocaleNumberFormat => {\n const cache = new Map<string, Intl.NumberFormat>()\n return {\n format: (value) => {\n const locale = getDocumentLang()\n const key = locale ?? ''\n let formatter = cache.get(key)\n if (!formatter) {\n formatter = new Intl.NumberFormat(locale, options)\n cache.set(key, formatter)\n }\n return formatter.format(value)\n },\n }\n}\n\nconst decimalsFormat = (decimals: number) =>\n localeNumberFormat({ maximumFractionDigits: decimals })\n\nconst integerFormat = decimalsFormat(0)\nconst oneDecimalFormat = decimalsFormat(1)\nconst twoDecimalFormat = decimalsFormat(2)\n\nconst formatThousands = (n: number) => integerFormat.format(n)\n\nconst formatEnergy = (v: number) => {\n if (v >= 1_000_000) {\n return `${twoDecimalFormat.format(v / 1000)}${NARROW_NBSP}MWh`\n }\n if (v >= 1_000) return `${integerFormat.format(v)}${NARROW_NBSP}kWh`\n if (v >= 10) return `${oneDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n return `${twoDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n}\n\nconst formatPower = (\n value: number | null,\n { signed = false }: { signed?: boolean } = {},\n): string => {\n if (value == null) return EM_DASH\n const rounded = Math.round(value)\n const sign = signed && rounded > 0 ? '+' : ''\n return `${sign}${integerFormat.format(rounded)}${NARROW_NBSP}W`\n}\n\nconst formatPercent = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value)}${NARROW_NBSP}%`\n}\n\nconst formatRatio = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value * 100)}${NARROW_NBSP}%`\n}\n\nexport {\n formatThousands,\n formatEnergy,\n formatPower,\n formatPercent,\n formatRatio,\n localeNumberFormat,\n decimalsFormat,\n integerFormat,\n oneDecimalFormat,\n twoD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AAS,MAAM,OAAA;CACnB,OAAO,GAAG,cAAc,OAAO,QAAQ,GAAG;AAC5C"}
|
|
1
|
+
{"version":3,"file":"format.cjs","names":[],"sources":["../../src/utils/format.ts"],"sourcesContent":["import { EM_DASH, NARROW_NBSP } from './chars'\n\ninterface LocaleNumberFormat {\n format: (value: number) => string\n}\n\nfunction getDocumentLang(): string | undefined {\n return typeof document === 'undefined'\n ? undefined\n : document.documentElement.lang || undefined\n}\n\nconst localeNumberFormat = (\n options?: Intl.NumberFormatOptions,\n): LocaleNumberFormat => {\n const cache = new Map<string, Intl.NumberFormat>()\n return {\n format: (value) => {\n const locale = getDocumentLang()\n const key = locale ?? ''\n let formatter = cache.get(key)\n if (!formatter) {\n formatter = new Intl.NumberFormat(locale, options)\n cache.set(key, formatter)\n }\n return formatter.format(value)\n },\n }\n}\n\nconst decimalsFormat = (decimals: number) =>\n localeNumberFormat({ maximumFractionDigits: decimals })\n\nconst integerFormat = decimalsFormat(0)\nconst oneDecimalFormat = decimalsFormat(1)\nconst twoDecimalFormat = decimalsFormat(2)\n\nconst formatThousands = (n: number) => integerFormat.format(n)\n\nconst formatEnergy = (v: number) => {\n if (v >= 1_000_000) {\n return `${twoDecimalFormat.format(v / 1000)}${NARROW_NBSP}MWh`\n }\n if (v >= 1_000) return `${integerFormat.format(v)}${NARROW_NBSP}kWh`\n if (v >= 10) return `${oneDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n return `${twoDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n}\n\nconst formatPower = (\n value: number | null,\n { signed = false }: { signed?: boolean } = {},\n): string => {\n if (value == null) return EM_DASH\n const rounded = Math.round(value)\n const sign = signed && rounded > 0 ? '+' : ''\n return `${sign}${integerFormat.format(rounded)}${NARROW_NBSP}W`\n}\n\nconst formatPercent = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value)}${NARROW_NBSP}%`\n}\n\nconst formatRatio = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value * 100)}${NARROW_NBSP}%`\n}\n\nexport {\n getDocumentLang,\n formatThousands,\n formatEnergy,\n formatPower,\n formatPercent,\n formatRatio,\n localeNumberFormat,\n decimalsFormat,\n integerFormat,\n oneDecimalFormat,\n twoDecimalFormat,\n}\n"],"mappings":";;;;AAMA,SAAS,kBAAsC;CAC7C,OAAO,OAAO,aAAa,cACvB,KAAA,IACA,SAAS,gBAAgB,QAAQ,KAAA;AACvC;AAEA,MAAM,sBACJ,YACuB;CACvB,MAAM,wBAAQ,IAAI,IAA+B;CACjD,OAAO,EACL,SAAS,UAAU;EACjB,MAAM,SAAS,gBAAgB;EAC/B,MAAM,MAAM,UAAU;EACtB,IAAI,YAAY,MAAM,IAAI,GAAG;EAC7B,IAAI,CAAC,WAAW;GACd,YAAY,IAAI,KAAK,aAAa,QAAQ,OAAO;GACjD,MAAM,IAAI,KAAK,SAAS;EAC1B;EACA,OAAO,UAAU,OAAO,KAAK;CAC/B,EACF;AACF;AAEA,MAAM,kBAAkB,aACtB,mBAAmB,EAAE,uBAAuB,SAAS,CAAC;AAExD,MAAM,gBAAgB,eAAe,CAAC;AACtC,MAAM,mBAAmB,eAAe,CAAC;AACzC,MAAM,mBAAmB,eAAe,CAAC;AAEzC,MAAM,mBAAmB,MAAc,cAAc,OAAO,CAAC;AAE7D,MAAM,gBAAgB,MAAc;CAClC,IAAI,KAAK,KACP,OAAO,GAAG,iBAAiB,OAAO,IAAI,GAAI;CAE5C,IAAI,KAAK,KAAO,OAAO,GAAG,cAAc,OAAO,CAAC;CAChD,IAAI,KAAK,IAAI,OAAO,GAAG,iBAAiB,OAAO,CAAC;CAChD,OAAO,GAAG,iBAAiB,OAAO,CAAC;AACrC;AAEA,MAAM,eACJ,OACA,EAAE,SAAS,UAAgC,CAAC,MACjC;CACX,IAAI,SAAS,MAAM,OAAA;CACnB,MAAM,UAAU,KAAK,MAAM,KAAK;CAEhC,OAAO,GADM,UAAU,UAAU,IAAI,MAAM,KAC1B,cAAc,OAAO,OAAO;AAC/C;AAEA,MAAM,iBAAiB,UAAiC;CACtD,IAAI,SAAS,MAAM,OAAA;CACnB,OAAO,GAAG,cAAc,OAAO,KAAK;AACtC;AAEA,MAAM,eAAe,UAAiC;CACpD,IAAI,SAAS,MAAM,OAAA;CACnB,OAAO,GAAG,cAAc,OAAO,QAAQ,GAAG;AAC5C"}
|
package/dist/utils/format.d.cts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
interface LocaleNumberFormat {
|
|
5
5
|
format: (value: number) => string;
|
|
6
6
|
}
|
|
7
|
+
declare function getDocumentLang(): string | undefined;
|
|
7
8
|
declare const localeNumberFormat: (options?: Intl.NumberFormatOptions) => LocaleNumberFormat;
|
|
8
9
|
declare const decimalsFormat: (decimals: number) => LocaleNumberFormat;
|
|
9
10
|
declare const integerFormat: LocaleNumberFormat;
|
|
@@ -19,5 +20,5 @@ declare const formatPower: (value: number | null, {
|
|
|
19
20
|
declare const formatPercent: (value: number | null) => string;
|
|
20
21
|
declare const formatRatio: (value: number | null) => string;
|
|
21
22
|
//#endregion
|
|
22
|
-
export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
|
|
23
|
+
export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, getDocumentLang, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
|
|
23
24
|
//# sourceMappingURL=format.d.cts.map
|
package/dist/utils/format.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
interface LocaleNumberFormat {
|
|
5
5
|
format: (value: number) => string;
|
|
6
6
|
}
|
|
7
|
+
declare function getDocumentLang(): string | undefined;
|
|
7
8
|
declare const localeNumberFormat: (options?: Intl.NumberFormatOptions) => LocaleNumberFormat;
|
|
8
9
|
declare const decimalsFormat: (decimals: number) => LocaleNumberFormat;
|
|
9
10
|
declare const integerFormat: LocaleNumberFormat;
|
|
@@ -19,5 +20,5 @@ declare const formatPower: (value: number | null, {
|
|
|
19
20
|
declare const formatPercent: (value: number | null) => string;
|
|
20
21
|
declare const formatRatio: (value: number | null) => string;
|
|
21
22
|
//#endregion
|
|
22
|
-
export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
|
|
23
|
+
export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, getDocumentLang, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
|
|
23
24
|
//# sourceMappingURL=format.d.ts.map
|
package/dist/utils/format.js
CHANGED
|
@@ -42,6 +42,6 @@ const formatRatio = (value) => {
|
|
|
42
42
|
return `${integerFormat.format(value * 100)} %`;
|
|
43
43
|
};
|
|
44
44
|
//#endregion
|
|
45
|
-
export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
|
|
45
|
+
export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, getDocumentLang, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
|
|
46
46
|
|
|
47
47
|
//# sourceMappingURL=format.js.map
|
package/dist/utils/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","names":[],"sources":["../../src/utils/format.ts"],"sourcesContent":["import { EM_DASH, NARROW_NBSP } from './chars'\n\ninterface LocaleNumberFormat {\n format: (value: number) => string\n}\n\nfunction getDocumentLang(): string | undefined {\n return typeof document === 'undefined'\n ? undefined\n : document.documentElement.lang || undefined\n}\n\nconst localeNumberFormat = (\n options?: Intl.NumberFormatOptions,\n): LocaleNumberFormat => {\n const cache = new Map<string, Intl.NumberFormat>()\n return {\n format: (value) => {\n const locale = getDocumentLang()\n const key = locale ?? ''\n let formatter = cache.get(key)\n if (!formatter) {\n formatter = new Intl.NumberFormat(locale, options)\n cache.set(key, formatter)\n }\n return formatter.format(value)\n },\n }\n}\n\nconst decimalsFormat = (decimals: number) =>\n localeNumberFormat({ maximumFractionDigits: decimals })\n\nconst integerFormat = decimalsFormat(0)\nconst oneDecimalFormat = decimalsFormat(1)\nconst twoDecimalFormat = decimalsFormat(2)\n\nconst formatThousands = (n: number) => integerFormat.format(n)\n\nconst formatEnergy = (v: number) => {\n if (v >= 1_000_000) {\n return `${twoDecimalFormat.format(v / 1000)}${NARROW_NBSP}MWh`\n }\n if (v >= 1_000) return `${integerFormat.format(v)}${NARROW_NBSP}kWh`\n if (v >= 10) return `${oneDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n return `${twoDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n}\n\nconst formatPower = (\n value: number | null,\n { signed = false }: { signed?: boolean } = {},\n): string => {\n if (value == null) return EM_DASH\n const rounded = Math.round(value)\n const sign = signed && rounded > 0 ? '+' : ''\n return `${sign}${integerFormat.format(rounded)}${NARROW_NBSP}W`\n}\n\nconst formatPercent = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value)}${NARROW_NBSP}%`\n}\n\nconst formatRatio = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value * 100)}${NARROW_NBSP}%`\n}\n\nexport {\n formatThousands,\n formatEnergy,\n formatPower,\n formatPercent,\n formatRatio,\n localeNumberFormat,\n decimalsFormat,\n integerFormat,\n oneDecimalFormat,\n twoDecimalFormat,\n}\n"],"mappings":";;;AAMA,SAAS,kBAAsC;CAC7C,OAAO,OAAO,aAAa,cACvB,KAAA,IACA,SAAS,gBAAgB,QAAQ,KAAA;AACvC;AAEA,MAAM,sBACJ,YACuB;CACvB,MAAM,wBAAQ,IAAI,IAA+B;CACjD,OAAO,EACL,SAAS,UAAU;EACjB,MAAM,SAAS,gBAAgB;EAC/B,MAAM,MAAM,UAAU;EACtB,IAAI,YAAY,MAAM,IAAI,GAAG;EAC7B,IAAI,CAAC,WAAW;GACd,YAAY,IAAI,KAAK,aAAa,QAAQ,OAAO;GACjD,MAAM,IAAI,KAAK,SAAS;EAC1B;EACA,OAAO,UAAU,OAAO,KAAK;CAC/B,EACF;AACF;AAEA,MAAM,kBAAkB,aACtB,mBAAmB,EAAE,uBAAuB,SAAS,CAAC;AAExD,MAAM,gBAAgB,eAAe,CAAC;AACtC,MAAM,mBAAmB,eAAe,CAAC;AACzC,MAAM,mBAAmB,eAAe,CAAC;AAEzC,MAAM,mBAAmB,MAAc,cAAc,OAAO,CAAC;AAE7D,MAAM,gBAAgB,MAAc;CAClC,IAAI,KAAK,KACP,OAAO,GAAG,iBAAiB,OAAO,IAAI,GAAI;CAE5C,IAAI,KAAK,KAAO,OAAO,GAAG,cAAc,OAAO,CAAC;CAChD,IAAI,KAAK,IAAI,OAAO,GAAG,iBAAiB,OAAO,CAAC;CAChD,OAAO,GAAG,iBAAiB,OAAO,CAAC;AACrC;AAEA,MAAM,eACJ,OACA,EAAE,SAAS,UAAgC,CAAC,MACjC;CACX,IAAI,SAAS,MAAM,OAAA;CACnB,MAAM,UAAU,KAAK,MAAM,KAAK;CAEhC,OAAO,GADM,UAAU,UAAU,IAAI,MAAM,KAC1B,cAAc,OAAO,OAAO;AAC/C;AAEA,MAAM,iBAAiB,UAAiC;CACtD,IAAI,SAAS,MAAM,OAAA;CACnB,OAAO,GAAG,cAAc,OAAO,KAAK;AACtC;AAEA,MAAM,eAAe,UAAiC;CACpD,IAAI,SAAS,MAAM,OAAA;CACnB,OAAO,GAAG,cAAc,OAAO,QAAQ,GAAG;AAC5C"}
|
|
1
|
+
{"version":3,"file":"format.js","names":[],"sources":["../../src/utils/format.ts"],"sourcesContent":["import { EM_DASH, NARROW_NBSP } from './chars'\n\ninterface LocaleNumberFormat {\n format: (value: number) => string\n}\n\nfunction getDocumentLang(): string | undefined {\n return typeof document === 'undefined'\n ? undefined\n : document.documentElement.lang || undefined\n}\n\nconst localeNumberFormat = (\n options?: Intl.NumberFormatOptions,\n): LocaleNumberFormat => {\n const cache = new Map<string, Intl.NumberFormat>()\n return {\n format: (value) => {\n const locale = getDocumentLang()\n const key = locale ?? ''\n let formatter = cache.get(key)\n if (!formatter) {\n formatter = new Intl.NumberFormat(locale, options)\n cache.set(key, formatter)\n }\n return formatter.format(value)\n },\n }\n}\n\nconst decimalsFormat = (decimals: number) =>\n localeNumberFormat({ maximumFractionDigits: decimals })\n\nconst integerFormat = decimalsFormat(0)\nconst oneDecimalFormat = decimalsFormat(1)\nconst twoDecimalFormat = decimalsFormat(2)\n\nconst formatThousands = (n: number) => integerFormat.format(n)\n\nconst formatEnergy = (v: number) => {\n if (v >= 1_000_000) {\n return `${twoDecimalFormat.format(v / 1000)}${NARROW_NBSP}MWh`\n }\n if (v >= 1_000) return `${integerFormat.format(v)}${NARROW_NBSP}kWh`\n if (v >= 10) return `${oneDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n return `${twoDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n}\n\nconst formatPower = (\n value: number | null,\n { signed = false }: { signed?: boolean } = {},\n): string => {\n if (value == null) return EM_DASH\n const rounded = Math.round(value)\n const sign = signed && rounded > 0 ? '+' : ''\n return `${sign}${integerFormat.format(rounded)}${NARROW_NBSP}W`\n}\n\nconst formatPercent = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value)}${NARROW_NBSP}%`\n}\n\nconst formatRatio = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value * 100)}${NARROW_NBSP}%`\n}\n\nexport {\n getDocumentLang,\n formatThousands,\n formatEnergy,\n formatPower,\n formatPercent,\n formatRatio,\n localeNumberFormat,\n decimalsFormat,\n integerFormat,\n oneDecimalFormat,\n twoDecimalFormat,\n}\n"],"mappings":";;;AAMA,SAAS,kBAAsC;CAC7C,OAAO,OAAO,aAAa,cACvB,KAAA,IACA,SAAS,gBAAgB,QAAQ,KAAA;AACvC;AAEA,MAAM,sBACJ,YACuB;CACvB,MAAM,wBAAQ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