MCPcopy Create free account
hub / github.com/ecomfe/tempad-dev / simplifyColorMixToRgba

Function simplifyColorMixToRgba

packages/extension/utils/css.ts:348–362  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

346}
347
348export function simplifyColorMixToRgba(input: string): string {
349 if (!input || !input.includes('color-mix(')) return input
350
351 return input.replace(
352 /color-mix\(\s*in\s+srgb\s*,\s*(#[0-9a-fA-F]{3,8})\s+([0-9.]+)%\s*,\s*transparent\s*\)/g,
353 (_match, hex: string, pct: string) => {
354 const parsed = parseHexColor(hex)
355 if (!parsed) return _match
356 const weight = Number(pct) / 100
357 if (!Number.isFinite(weight)) return _match
358 const alpha = toDecimalPlace(Math.min(1, Math.max(0, parsed.a * weight)), 2)
359 return `rgba(${parsed.r}, ${parsed.g}, ${parsed.b}, ${alpha})`
360 }
361 )
362}
363
364export function simplifyHexAlphaToRgba(input: string): string {
365 if (!input || !input.includes('#')) return input

Callers 2

css.test.tsFile · 0.90
processValueFunction · 0.85

Calls 2

toDecimalPlaceFunction · 0.90
parseHexColorFunction · 0.85

Tested by

no test coverage detected