From 9757a2c663ebaa96c5ae27ebe47db20852abeeca Mon Sep 17 00:00:00 2001 From: Claas Date: Sun, 16 Feb 2025 22:34:03 +0100 Subject: [PATCH] Fix overwriting light-dark colors that also have a palette --- index.js | 17 ++- theme test.snapshot.json | 232 +++++++++++++++++++-------------------- 2 files changed, 120 insertions(+), 129 deletions(-) diff --git a/index.js b/index.js index b3e9115..9e49d5d 100644 --- a/index.js +++ b/index.js @@ -29,8 +29,9 @@ function camelToKebabCase(value) { /** * * @param {TonalPalette} palette + * @returns {Generator<[number, string]>} */ -function generatePaletteSteps(palette) { +function* generatePaletteSteps(palette) { // Supported color steps // Material Design goes from 0 to 100 for lightness (like percent) // whereas Tailwind goes from 50 to 950 @@ -44,13 +45,9 @@ function generatePaletteSteps(palette) { 0, 5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 95, 98, 99, 100, ]; - /** @type {Record} */ - const result = {}; for (const step of materialPalletteSteps) { - result[step] = hexFromArgb(palette.tone(step)); + yield [step, hexFromArgb(palette.tone(step))]; } - - return result; } /** @typedef {[name: string, palette: TonalPalette][]} PaletteArray */ @@ -59,12 +56,14 @@ function generatePaletteSteps(palette) { * @param {PaletteArray} materialPalettes */ function createPalettes(materialPalettes) { - /** @type {Record>} */ + /** @type {Record} */ const palettes = {}; for (let [name, palette] of materialPalettes) { - const paletteSteps = generatePaletteSteps(palette); name = camelToKebabCase(name); - palettes[name] = paletteSteps; + + for (const [step, color] of generatePaletteSteps(palette)) { + palettes[`${name}-${step}`] = color; + } } return palettes; diff --git a/theme test.snapshot.json b/theme test.snapshot.json index d6126eb..d239d45 100644 --- a/theme test.snapshot.json +++ b/theme test.snapshot.json @@ -746,26 +746,7 @@ "reduced-contrast-surface-tint": "light-dark(#525a92, #bbc3ff)", "medium-contrast-surface-tint": "light-dark(#525a92, #bbc3ff)", "high-contrast-surface-tint": "light-dark(#525a92, #bbc3ff)", - "primary": { - "0": "#000000", - "5": "#010841", - "10": "#0c154b", - "15": "#182055", - "20": "#232c61", - "25": "#2f376c", - "30": "#3a4279", - "35": "#464e85", - "40": "#525a92", - "50": "#6b73ad", - "60": "#858dc8", - "70": "#9fa7e5", - "80": "#bbc3ff", - "90": "#dfe0ff", - "95": "#f0efff", - "98": "#fbf8ff", - "99": "#fffbff", - "100": "#ffffff" - }, + "primary": "light-dark(#525a92, #bbc3ff)", "reduced-contrast-primary": "light-dark(#6971aa, #858dc8)", "medium-contrast-primary": "light-dark(#293267, #d7daff)", "high-contrast-primary": "light-dark(#1f275c, #efeeff)", @@ -785,26 +766,7 @@ "reduced-contrast-inverse-primary": "light-dark(#6e76b0, #757db7)", "medium-contrast-inverse-primary": "light-dark(#bbc3ff, #3c447a)", "high-contrast-inverse-primary": "light-dark(#bbc3ff, #3c447a)", - "secondary": { - "0": "#000000", - "5": "#0d1021", - "10": "#181a2c", - "15": "#222537", - "20": "#2d2f42", - "25": "#383a4d", - "30": "#434559", - "35": "#4f5165", - "40": "#5b5d72", - "50": "#74768b", - "60": "#8e8fa6", - "70": "#a8a9c1", - "80": "#c4c5dd", - "90": "#e0e1f9", - "95": "#f0efff", - "98": "#fbf8ff", - "99": "#fffbff", - "100": "#ffffff" - }, + "secondary": "light-dark(#5b5d72, #c4c5dd)", "reduced-contrast-secondary": "light-dark(#717389, #8e8fa6)", "medium-contrast-secondary": "light-dark(#333548, #dadaf3)", "high-contrast-secondary": "light-dark(#292b3d, #efeeff)", @@ -820,26 +782,7 @@ "reduced-contrast-on-secondary-container": "light-dark(#77788e, #818399)", "medium-contrast-on-secondary-container": "light-dark(#ffffff, #000000)", "high-contrast-on-secondary-container": "light-dark(#ffffff, #070a1b)", - "tertiary": { - "0": "#000000", - "5": "#21071c", - "10": "#2d1227", - "15": "#391c32", - "20": "#45263d", - "25": "#513148", - "30": "#5d3c54", - "35": "#6a4860", - "40": "#77536c", - "50": "#916c86", - "60": "#ad85a0", - "70": "#c99fbb", - "80": "#e6bad7", - "90": "#ffd7f0", - "95": "#ffecf6", - "98": "#fff7f9", - "99": "#fffbff", - "100": "#ffffff" - }, + "tertiary": "light-dark(#77536c, #e6bad7)", "reduced-contrast-tertiary": "light-dark(#8f6983, #ad85a0)", "medium-contrast-tertiary": "light-dark(#4b2c43, #fdcfed)", "high-contrast-tertiary": "light-dark(#402239, #ffebf5)", @@ -855,26 +798,7 @@ "reduced-contrast-on-tertiary-container": "light-dark(#956e89, #9f7893)", "medium-contrast-on-tertiary-container": "light-dark(#ffffff, #000000)", "high-contrast-on-tertiary-container": "light-dark(#ffffff, #1a0316)", - "error": { - "0": "#000000", - "5": "#2d0001", - "10": "#410002", - "15": "#540003", - "20": "#690005", - "25": "#7e0007", - "30": "#93000a", - "35": "#a80710", - "40": "#ba1a1a", - "50": "#de3730", - "60": "#ff5449", - "70": "#ff897d", - "80": "#ffb4ab", - "90": "#ffdad6", - "95": "#ffedea", - "98": "#fff8f7", - "99": "#fffbff", - "100": "#ffffff" - }, + "error": "light-dark(#ba1a1a, #ffb4ab)", "reduced-contrast-error": "light-dark(#da342e, #ff5449)", "medium-contrast-error": "light-dark(#740006, #ffd2cc)", "high-contrast-error": "light-dark(#600004, #ffece9)", @@ -938,46 +862,114 @@ "reduced-contrast-on-tertiary-fixed-variant": "light-dark(#805b75, #bd94b0)", "medium-contrast-on-tertiary-fixed-variant": "light-dark(#ffffff, #4b2c43)", "high-contrast-on-tertiary-fixed-variant": "light-dark(#ffffff, #21071c)", - "neutral": { - "0": "#000000", - "5": "#101116", - "10": "#1b1b21", - "15": "#25252b", - "20": "#303036", - "25": "#3b3b41", - "30": "#46464c", - "35": "#525258", - "40": "#5e5e64", - "50": "#77767d", - "60": "#919097", - "70": "#acaab1", - "80": "#c7c5cd", - "90": "#e4e1e9", - "95": "#f2eff7", - "98": "#fbf8ff", - "99": "#fffbff", - "100": "#ffffff" - }, - "neutral-variant": { - "0": "#000000", - "5": "#101018", - "10": "#1a1b23", - "15": "#25252d", - "20": "#2f3038", - "25": "#3a3b43", - "30": "#46464f", - "35": "#52525b", - "40": "#5e5e67", - "50": "#767680", - "60": "#90909a", - "70": "#abaab4", - "80": "#c7c5d0", - "90": "#e3e1ec", - "95": "#f1effa", - "98": "#fbf8ff", - "99": "#fffbff", - "100": "#ffffff" - } + "primary-0": "#000000", + "primary-5": "#010841", + "primary-10": "#0c154b", + "primary-15": "#182055", + "primary-20": "#232c61", + "primary-25": "#2f376c", + "primary-30": "#3a4279", + "primary-35": "#464e85", + "primary-40": "#525a92", + "primary-50": "#6b73ad", + "primary-60": "#858dc8", + "primary-70": "#9fa7e5", + "primary-80": "#bbc3ff", + "primary-90": "#dfe0ff", + "primary-95": "#f0efff", + "primary-98": "#fbf8ff", + "primary-99": "#fffbff", + "primary-100": "#ffffff", + "secondary-0": "#000000", + "secondary-5": "#0d1021", + "secondary-10": "#181a2c", + "secondary-15": "#222537", + "secondary-20": "#2d2f42", + "secondary-25": "#383a4d", + "secondary-30": "#434559", + "secondary-35": "#4f5165", + "secondary-40": "#5b5d72", + "secondary-50": "#74768b", + "secondary-60": "#8e8fa6", + "secondary-70": "#a8a9c1", + "secondary-80": "#c4c5dd", + "secondary-90": "#e0e1f9", + "secondary-95": "#f0efff", + "secondary-98": "#fbf8ff", + "secondary-99": "#fffbff", + "secondary-100": "#ffffff", + "tertiary-0": "#000000", + "tertiary-5": "#21071c", + "tertiary-10": "#2d1227", + "tertiary-15": "#391c32", + "tertiary-20": "#45263d", + "tertiary-25": "#513148", + "tertiary-30": "#5d3c54", + "tertiary-35": "#6a4860", + "tertiary-40": "#77536c", + "tertiary-50": "#916c86", + "tertiary-60": "#ad85a0", + "tertiary-70": "#c99fbb", + "tertiary-80": "#e6bad7", + "tertiary-90": "#ffd7f0", + "tertiary-95": "#ffecf6", + "tertiary-98": "#fff7f9", + "tertiary-99": "#fffbff", + "tertiary-100": "#ffffff", + "neutral-0": "#000000", + "neutral-5": "#101116", + "neutral-10": "#1b1b21", + "neutral-15": "#25252b", + "neutral-20": "#303036", + "neutral-25": "#3b3b41", + "neutral-30": "#46464c", + "neutral-35": "#525258", + "neutral-40": "#5e5e64", + "neutral-50": "#77767d", + "neutral-60": "#919097", + "neutral-70": "#acaab1", + "neutral-80": "#c7c5cd", + "neutral-90": "#e4e1e9", + "neutral-95": "#f2eff7", + "neutral-98": "#fbf8ff", + "neutral-99": "#fffbff", + "neutral-100": "#ffffff", + "neutral-variant-0": "#000000", + "neutral-variant-5": "#101018", + "neutral-variant-10": "#1a1b23", + "neutral-variant-15": "#25252d", + "neutral-variant-20": "#2f3038", + "neutral-variant-25": "#3a3b43", + "neutral-variant-30": "#46464f", + "neutral-variant-35": "#52525b", + "neutral-variant-40": "#5e5e67", + "neutral-variant-50": "#767680", + "neutral-variant-60": "#90909a", + "neutral-variant-70": "#abaab4", + "neutral-variant-80": "#c7c5d0", + "neutral-variant-90": "#e3e1ec", + "neutral-variant-95": "#f1effa", + "neutral-variant-98": "#fbf8ff", + "neutral-variant-99": "#fffbff", + "neutral-variant-100": "#ffffff", + "error-0": "#000000", + "error-5": "#2d0001", + "error-10": "#410002", + "error-15": "#540003", + "error-20": "#690005", + "error-25": "#7e0007", + "error-30": "#93000a", + "error-35": "#a80710", + "error-40": "#ba1a1a", + "error-50": "#de3730", + "error-60": "#ff5449", + "error-70": "#ff897d", + "error-80": "#ffb4ab", + "error-90": "#ffdad6", + "error-95": "#ffedea", + "error-98": "#fff8f7", + "error-99": "#fffbff", + "error-100": "#ffffff" } } } \ No newline at end of file -- knotmirror 0.0.1