PromoCursed/node_modules/.cache/babel-loader/2a644614e5470a2a71edf983a6db931ad085bc8ca5216eaebd5a7847b62b562b.json

1 line
46 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nconst round = Math.round;\n\n/**\n * Support format, alpha unit will check the % mark:\n * - rgba(102, 204, 255, .5) -> [102, 204, 255, 0.5]\n * - rgb(102 204 255 / .5) -> [102, 204, 255, 0.5]\n * - rgb(100%, 50%, 0% / 50%) -> [255, 128, 0, 0.5]\n * - hsl(270, 60, 40, .5) -> [270, 60, 40, 0.5]\n * - hsl(270deg 60% 40% / 50%) -> [270, 60, 40, 0.5]\n *\n * When `base` is provided, the percentage value will be divided by `base`.\n */\nfunction splitColorStr(str, parseNum) {\n const match = str\n // Remove str before `(`\n .replace(/^[^(]*\\((.*)/, '$1')\n // Remove str after `)`\n .replace(/\\).*/, '').match(/\\d*\\.?\\d+%?/g) || [];\n const numList = match.map(item => parseFloat(item));\n for (let i = 0; i < 3; i += 1) {\n numList[i] = parseNum(numList[i] || 0, match[i] || '', i);\n }\n\n // For alpha. 50% should be 0.5\n if (match[3]) {\n numList[3] = match[3].includes('%') ? numList[3] / 100 : numList[3];\n } else {\n // By default, alpha is 1\n numList[3] = 1;\n }\n return numList;\n}\nconst parseHSVorHSL = (num, _, index) => index === 0 ? num : num / 100;\n\n/** round and limit number to integer between 0-255 */\nfunction limitRange(value, max) {\n const mergedMax = max || 255;\n if (value > mergedMax) {\n return mergedMax;\n }\n if (value < 0) {\n return 0;\n }\n return value;\n}\nexport class FastColor {\n constructor(input) {\n /**\n * All FastColor objects are valid. So isValid is always true. This property is kept to be compatible with TinyColor.\n */\n _defineProperty(this, \"isValid\", true);\n /**\n * Red, R in RGB\n */\n _defineProperty(this, \"r\", 0);\n /**\n * Green, G in RGB\n */\n _defineProperty(this, \"g\", 0);\n /**\n * Blue, B in RGB\n */\n _defineProperty(this, \"b\", 0);\n /**\n * Alpha/Opacity, A in RGBA/HSLA\n */\n _defineProperty(this, \"a\", 1);\n // HSV privates\n _defineProperty(this, \"_h\", void 0);\n _defineProperty(this, \"_s\", void 0);\n _defineProperty(this, \"_l\", void 0);\n _defineProperty(this, \"_v\", void 0);\n // intermediate variables to calculate HSL/HSV\n _defineProperty(this, \"_max\", void 0);\n _defineProperty(this, \"_min\", void 0);\n _defineProperty(this, \"_brightness\", void 0);\n /**\n * Always check 3 char in the object to determine the format.\n * We not use function in check to save bundle size.\n * e.g. 'rgb' -> { r: 0, g: 0, b: 0 }.\n */\n function matchFormat(str) {\n return str[0] in input && str[1] in input && str[2] in input;\n }\n if (!input) {\n // Do nothing since already initialized\n } else if (typeof input === 'string') {\n const trimStr = input.trim();\n function matchPrefix(prefix) {\n return trimStr.startsWith(prefix);\n }\n if (/^#?[A-F\\d]{3,8}$/i.test(trimStr)) {\n this.fromHexString(trimStr);\n } else if (matchPrefix('rgb')) {\n this.fromRgbString(trimStr);\n } else if (matchPrefix('hsl')) {\n this.fromHslString(trimStr);\n } else if (matchPrefix('hsv') || matchPrefix('hsb')) {\n this.fromHsvString(trimStr);\n }\n } else if (input instanceof FastColor) {\n this.r = input.r;\n this.g = input.g;\n this.b = input.b;\n this.a = input.a;\n this._h = input._h;\n this._s = input._s;\n this._l = input._l;\n this._v = input._v;\n } else if (matchFormat('rgb')) {\n this.r = limitRange(input.r);\n this.g = limitRange(input.g);\n this.b = limitRange(input.b);\n this.a = typeof input.a === 'number' ? limitRange(input.a, 1) : 1;\n } else if (matchFormat('hsl')) {\n this.fromHsl(input);\n } else if (matchFormat('hsv')) {\n this.fromHsv(input);\n } else {\n throw new Error('@ant-design/fast-color: unsupported input ' + JSON.stringify(input));\n }\n }\n\n // ======================= Setter ==============