{"version":3,"file":"migrate_colors.mjs","names":[],"sources":["../../src/migrate/migrate_colors.ts"],"sourcesContent":["/**\n * Migrate color style values to supported format.\n *\n * @param colorToMigrate Color value to migrate, could be a string or an expression.\n * @returns Color style value in supported format.\n */\nexport function migrateColors<T>(colorToMigrate: T): T {\n    return JSON.parse(migrateHslColors(JSON.stringify(colorToMigrate)));\n}\n\n/**\n * Created to migrate from colors supported by the former CSS color parsing\n * library `csscolorparser` but not compliant with the CSS Color specification,\n * like `hsl(900, 0.15, 90%)`.\n *\n * @param colorToMigrate Serialized color style value.\n * @returns A serialized color style value in which all non-standard hsl color values\n * have been converted to a format that complies with the CSS Color specification.\n *\n * @example\n * migrateHslColors('\"hsl(900, 0.15, 90%)\"'); // returns '\"hsl(900, 15%, 90%)\"'\n * migrateHslColors('\"hsla(900, .15, .9)\"'); // returns '\"hsl(900, 15%, 90%)\"'\n * migrateHslColors('\"hsl(900, 15%, 90%)\"'); // returns '\"hsl(900, 15%, 90%)\"' - no changes\n */\nfunction migrateHslColors(colorToMigrate: string): string {\n    return colorToMigrate.replace(/\"hsla?\\((.+?)\\)\"/gi, (match, hslArgs) => {\n        const argsMatch = hslArgs.match(/^(.+?)\\s*,\\s*(.+?)\\s*,\\s*(.+?)(?:\\s*,\\s*(.+))?$/i);\n        if (argsMatch) {\n            let [h, s, l, a] = argsMatch.slice(1);\n            [s, l] = [s, l].map((v) => (v.endsWith('%') ? v : `${parseFloat(v) * 100}%`));\n            return `\"hsl${typeof a === 'string' ? 'a' : ''}(${[h, s, l, a].filter(Boolean).join(',')})\"`;\n        }\n        return match;\n    });\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,cAAiB,gBAAsB;CACnD,OAAO,KAAK,MAAM,iBAAiB,KAAK,UAAU,cAAc,CAAC,CAAC;AACtE;;;;;;;;;;;;;;;AAgBA,SAAS,iBAAiB,gBAAgC;CACtD,OAAO,eAAe,QAAQ,uBAAuB,OAAO,YAAY;EACpE,MAAM,YAAY,QAAQ,MAAM,kDAAkD;EAClF,IAAI,WAAW;GACX,IAAI,CAAC,GAAG,GAAG,GAAG,KAAK,UAAU,MAAM,CAAC;GACpC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,MAAO,EAAE,SAAS,GAAG,IAAI,IAAI,GAAG,WAAW,CAAC,IAAI,IAAI,EAAG;GAC5E,OAAO,OAAO,OAAO,MAAM,WAAW,MAAM,GAAG,GAAG;IAAC;IAAG;IAAG;IAAG;GAAC,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,EAAE;EAC7F;EACA,OAAO;CACX,CAAC;AACL"}