Home / File/ replace-shadow-colors.ts — tailwindcss Source File

replace-shadow-colors.ts — tailwindcss Source File

Architecture documentation for replace-shadow-colors.ts, a typescript file in the tailwindcss codebase. 2 imports, 2 dependents.

File typescript OxideEngine Extractor 2 imports 2 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  fa53b0d6_dd5c_93d6_d0a9_732da934552f["replace-shadow-colors.ts"]
  ef204000_8998_5a6c_5455_324b37624713["segment.ts"]
  fa53b0d6_dd5c_93d6_d0a9_732da934552f --> ef204000_8998_5a6c_5455_324b37624713
  f712ed47_45d4_4e5a_dd73_fdefa1da71da["segment"]
  fa53b0d6_dd5c_93d6_d0a9_732da934552f --> f712ed47_45d4_4e5a_dd73_fdefa1da71da
  2bc6f8eb_6339_d09c_79df_e9025a479c97["utilities.ts"]
  2bc6f8eb_6339_d09c_79df_e9025a479c97 --> fa53b0d6_dd5c_93d6_d0a9_732da934552f
  3aa2bab7_9691_50d5_6634_fb0c58dcd427["replace-shadow-colors.test.ts"]
  3aa2bab7_9691_50d5_6634_fb0c58dcd427 --> fa53b0d6_dd5c_93d6_d0a9_732da934552f
  style fa53b0d6_dd5c_93d6_d0a9_732da934552f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { segment } from './segment'

const KEYWORDS = new Set(['inset', 'inherit', 'initial', 'revert', 'unset'])
const LENGTH = /^-?(\d+|\.\d+)(.*?)$/g

export function replaceShadowColors(input: string, replacement: (color: string) => string) {
  let shadows = segment(input, ',').map((shadow) => {
    shadow = shadow.trim()
    let parts = segment(shadow, ' ').filter((part) => part.trim() !== '')
    let color = null
    let offsetX = null
    let offsetY = null

    for (let part of parts) {
      if (KEYWORDS.has(part)) {
        continue
      } else if (LENGTH.test(part)) {
        if (offsetX === null) {
          offsetX = part
        } else if (offsetY === null) {
          offsetY = part
        }

        // Reset index, since the regex is stateful.
        LENGTH.lastIndex = 0
      } else if (color === null) {
        color = part
      }
    }

    // If the x and y offsets were not detected, the shadow is either invalid or
    // using a variable to represent more than one field in the shadow value, so
    // we can't know what to replace.
    if (offsetX === null || offsetY === null) return shadow

    let replacementColor = replacement(color ?? 'currentcolor')

    if (color !== null) {
      // If a color was found, replace the color.
      return shadow.replace(color, replacementColor)
    }
    // If no color was found, assume the shadow is relying on the browser
    // default shadow color and append the replacement color.
    return `${shadow} ${replacementColor}`
  })

  return shadows.join(', ')
}

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does replace-shadow-colors.ts do?
replace-shadow-colors.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the OxideEngine domain, Extractor subdomain.
What functions are defined in replace-shadow-colors.ts?
replace-shadow-colors.ts defines 1 function(s): replaceShadowColors.
What does replace-shadow-colors.ts depend on?
replace-shadow-colors.ts imports 2 module(s): segment, segment.ts.
What files import replace-shadow-colors.ts?
replace-shadow-colors.ts is imported by 2 file(s): replace-shadow-colors.test.ts, utilities.ts.
Where is replace-shadow-colors.ts in the architecture?
replace-shadow-colors.ts is located at packages/tailwindcss/src/utils/replace-shadow-colors.ts (domain: OxideEngine, subdomain: Extractor, directory: packages/tailwindcss/src/utils).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free