({ negative }: { negative: boolean })
| 362 | } |
| 363 | |
| 364 | function compileFn({ negative }: { negative: boolean }) { |
| 365 | return (candidate: Extract<Candidate, { kind: 'functional' }>) => { |
| 366 | // Throw out any candidate whose value is not a supported type |
| 367 | if ( |
| 368 | candidate.value?.kind === 'arbitrary' && |
| 369 | types.length > 0 && |
| 370 | !types.includes('any') |
| 371 | ) { |
| 372 | // The candidate has an explicit data type but it's not in the list |
| 373 | // of supported types by this utility. For example, a `scrollbar` |
| 374 | // utility that is only used to change the scrollbar color but is |
| 375 | // used with a `length` value: `scrollbar-[length:var(--whatever)]` |
| 376 | if (candidate.value.dataType && !types.includes(candidate.value.dataType)) { |
| 377 | return |
| 378 | } |
| 379 | |
| 380 | // The candidate does not have an explicit data type and the value |
| 381 | // cannot be inferred as one of the supported types. For example, a |
| 382 | // `scrollbar` utility that is only used to change the scrollbar |
| 383 | // color but is used with a `length` value: `scrollbar-[33px]` |
| 384 | if ( |
| 385 | !candidate.value.dataType && |
| 386 | !inferDataType(candidate.value.value, types as any[]) |
| 387 | ) { |
| 388 | return |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | let isColor = types.includes('color') |
| 393 | |
| 394 | // Resolve the candidate value |
| 395 | let value: string | null = null |
| 396 | let ignoreModifier = false |
| 397 | |
| 398 | { |
| 399 | let values = options?.values ?? {} |
| 400 | |
| 401 | if (isColor) { |
| 402 | // Color utilities implicitly support `inherit`, `transparent`, and `currentcolor` |
| 403 | // for backwards compatibility but still allow them to be overridden |
| 404 | values = Object.assign( |
| 405 | { |
| 406 | inherit: 'inherit', |
| 407 | transparent: 'transparent', |
| 408 | current: 'currentcolor', |
| 409 | }, |
| 410 | values, |
| 411 | ) |
| 412 | } |
| 413 | |
| 414 | if (!candidate.value) { |
| 415 | value = values.DEFAULT ?? null |
| 416 | } else if (candidate.value.kind === 'arbitrary') { |
| 417 | value = candidate.value.value |
| 418 | } else if ( |
| 419 | candidate.value.fraction && |
| 420 | Object.hasOwn(values, candidate.value.fraction) |
| 421 | ) { |
no test coverage detected