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

Function collapseComposite

packages/extension/utils/tailwind.ts:1071–1106  ·  view source on GitHub ↗
(
  config: CompositeFamily,
  familyKey: string,
  buffer: Record<string, string>
)

Source from the content-addressed store, hash-verified

1069}
1070
1071function collapseComposite(
1072 config: CompositeFamily,
1073 familyKey: string,
1074 buffer: Record<string, string>
1075): string[] {
1076 const out: string[] = []
1077 const matchedComposite = config.composites.find((comp) => {
1078 return Object.entries(comp.match).every(([k, v]) => buffer[k] === v)
1079 })
1080
1081 if (matchedComposite) {
1082 out.push(
1083 buildClass(config, '', {
1084 text: matchedComposite.suffix,
1085 isNegative: false,
1086 isKeyword: true
1087 })
1088 )
1089 return out
1090 }
1091
1092 Object.keys(config.props).forEach((field) => {
1093 const val = buffer[field]
1094 if (!val) return
1095
1096 // Composite props and atomics are defined in lockstep in TAILWIND_CONFIG.
1097 const atomicConfig = config.atomics[field] as AtomicFallback
1098 const formatted = extractValuePart(val, config, familyKey, atomicConfig.valueKind)
1099 const tempConfig: FamilyConfig = {
1100 ...config,
1101 prefix: atomicConfig.prefix
1102 }
1103 out.push(buildClass(tempConfig, '', formatted))
1104 })
1105 return out
1106}
1107
1108export function cssToTailwind(rawStyle: Record<string, string>): string {
1109 if (!rawStyle || Object.keys(rawStyle).length === 0) return ''

Callers 1

cssToTailwindFunction · 0.85

Calls 2

buildClassFunction · 0.85
extractValuePartFunction · 0.85

Tested by

no test coverage detected