Home / File/ urls.ts — tailwindcss Source File

urls.ts — tailwindcss Source File

Architecture documentation for urls.ts, a typescript file in the tailwindcss codebase. 9 imports, 2 dependents.

File typescript NodeServer Compiler 9 imports 2 dependents 12 functions

Entity Profile

Dependency Diagram

graph LR
  95a806ab_8556_4112_9786_fda4ff23eeca["urls.ts"]
  b9cbffa4_c352_cf3c_268f_cbb174fb3a47["ast.ts"]
  95a806ab_8556_4112_9786_fda4ff23eeca --> b9cbffa4_c352_cf3c_268f_cbb174fb3a47
  9b49f3c6_0c8d_5c62_965c_30a1db6499f8["toCss"]
  95a806ab_8556_4112_9786_fda4ff23eeca --> 9b49f3c6_0c8d_5c62_965c_30a1db6499f8
  8be42ab2_7e92_957a_da93_ffe4c7d161fe["css-parser.ts"]
  95a806ab_8556_4112_9786_fda4ff23eeca --> 8be42ab2_7e92_957a_da93_ffe4c7d161fe
  9d7d664d_b6fd_88fd_8800_4b530c33a95b["parse"]
  95a806ab_8556_4112_9786_fda4ff23eeca --> 9d7d664d_b6fd_88fd_8800_4b530c33a95b
  1b8f1c54_b1e9_e18d_0719_b7ad92808185["walk.ts"]
  95a806ab_8556_4112_9786_fda4ff23eeca --> 1b8f1c54_b1e9_e18d_0719_b7ad92808185
  4982d9ce_98d4_85d9_44af_7cc47b93c482["walk"]
  95a806ab_8556_4112_9786_fda4ff23eeca --> 4982d9ce_98d4_85d9_44af_7cc47b93c482
  57241391_a529_5dd8_8832_b09118cb2fae["normalize-path.ts"]
  95a806ab_8556_4112_9786_fda4ff23eeca --> 57241391_a529_5dd8_8832_b09118cb2fae
  1814a389_cfe2_00cf_bd4d_7fa2fc24143c["normalizePath"]
  95a806ab_8556_4112_9786_fda4ff23eeca --> 1814a389_cfe2_00cf_bd4d_7fa2fc24143c
  89aef3dd_1eed_c141_d425_b8949215a653["node:path"]
  95a806ab_8556_4112_9786_fda4ff23eeca --> 89aef3dd_1eed_c141_d425_b8949215a653
  86cbca6b_bfa0_804c_ee2e_2cc7a7aef7fe["compile.ts"]
  86cbca6b_bfa0_804c_ee2e_2cc7a7aef7fe --> 95a806ab_8556_4112_9786_fda4ff23eeca
  4209a852_d05f_56e9_0381_957b4155b649["urls.test.ts"]
  4209a852_d05f_56e9_0381_957b4155b649 --> 95a806ab_8556_4112_9786_fda4ff23eeca
  style 95a806ab_8556_4112_9786_fda4ff23eeca fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// Inlined version of code from Vite <https://github.com/vitejs/vite>
// Copyright (c) 2019-present, VoidZero Inc. and Vite contributors
// Released under the MIT License.
//
// Minor modifications have been made to work with the Tailwind CSS codebase

import * as path from 'node:path'
import { toCss } from '../../tailwindcss/src/ast'
import { parse } from '../../tailwindcss/src/css-parser'
import { walk } from '../../tailwindcss/src/walk'
import { normalizePath } from './normalize-path'

const cssUrlRE =
  /(?<!@import\s+)(?<=^|[^\w\-\u0080-\uffff])url\((\s*('[^']+'|"[^"]+")\s*|[^'")]+)\)/
const cssImageSetRE = /(?<=image-set\()((?:[\w-]{1,256}\([^)]*\)|[^)])*)(?=\))/
const cssNotProcessedRE = /(?:gradient|element|cross-fade|image)\(/

const dataUrlRE = /^\s*data:/i
const externalRE = /^([a-z]+:)?\/\//
const functionCallRE = /^[A-Z_][.\w-]*\(/i

const imageCandidateRE =
  /(?:^|\s)(?<url>[\w-]+\([^)]*\)|"[^"]*"|'[^']*'|[^,]\S*[^,])\s*(?:\s(?<descriptor>\w[^,]+))?(?:,|$)/g
const nonEscapedDoubleQuoteRE = /(?<!\\)"/g
const escapedSpaceCharactersRE = /(?: |\\t|\\n|\\f|\\r)+/g

const isDataUrl = (url: string): boolean => dataUrlRE.test(url)
const isExternalUrl = (url: string): boolean => externalRE.test(url)

type CssUrlReplacer = (url: string, importer?: string) => string | Promise<string>

interface ImageCandidate {
  url: string
  descriptor: string
}

export async function rewriteUrls({
  css,
  base,
  root,
}: {
  css: string
  base: string
  root: string
}) {
  if (!css.includes('url(') && !css.includes('image-set(')) {
    return css
  }

  let ast = parse(css)

  let promises: Promise<void>[] = []

  function replacerForDeclaration(url: string) {
    if (url[0] === '/') return url

    let absoluteUrl = path.posix.join(normalizePath(base), url)
    let relativeUrl = path.posix.relative(normalizePath(root), absoluteUrl)

    // If the path points to a file in the same directory, `path.relative` will
// ... (148 more lines)

Domain

Subdomains

Frequently Asked Questions

What does urls.ts do?
urls.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the NodeServer domain, Compiler subdomain.
What functions are defined in urls.ts?
urls.ts defines 12 function(s): asyncReplace, doUrlReplace, isDataUrl, isExternalUrl, joinSrcset, parseSrcset, processSrcSet, rewriteCssImageSet, rewriteCssUrls, rewriteUrls, and 2 more.
What does urls.ts depend on?
urls.ts imports 9 module(s): ast.ts, css-parser.ts, node:path, normalize-path.ts, normalizePath, parse, toCss, walk, and 1 more.
What files import urls.ts?
urls.ts is imported by 2 file(s): compile.ts, urls.test.ts.
Where is urls.ts in the architecture?
urls.ts is located at packages/@tailwindcss-node/src/urls.ts (domain: NodeServer, subdomain: Compiler, directory: packages/@tailwindcss-node/src).

Analyze Your Own Codebase

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

Try Supermodel Free