@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
17 lines • 727 B
JavaScript
import { LabColor } from "@aurigma/design-atoms-model";
import { convertPercentToByte } from "./Utils";
export class LabColorParser {
parse(colorString) {
const labRegex = /^\s*lab\(\s*(\d{1,3})\s*,\s*(-*\d{1,3})\s*,\s*(-*\d{1,3})\s*(,\s*(\d{1,3})%)?\s*(\,\s*(.*)\s*)?\)\s*;{0,1}\s*$/;
const match = labRegex.exec(colorString);
if (match == null || match.length !== 8) {
return null;
}
let alpha = 255;
if (match[5] != null) {
alpha = convertPercentToByte(parseFloat(match[5]));
}
return new LabColor(parseInt(match[1]), parseInt(match[2]), parseInt(match[3]), alpha);
}
}
//# sourceMappingURL=LabColorParser.js.map