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 NodeBridge NapiBinding 9 imports 2 dependents 12 functions

Entity Profile

Dependency Diagram

graph LR
  5e3855e0_f04e_28ee_98ea_8502e6531bc8["urls.ts"]
  42640952_ea63_55f1_1ff1_00816e2980ae["ast.ts"]
  5e3855e0_f04e_28ee_98ea_8502e6531bc8 --> 42640952_ea63_55f1_1ff1_00816e2980ae
  2da63033_d079_7b37_5cfb_3877674a70b9["toCss"]
  5e3855e0_f04e_28ee_98ea_8502e6531bc8 --> 2da63033_d079_7b37_5cfb_3877674a70b9
  54851997_7544_bab2_96ab_548e5f5df205["css-parser.ts"]
  5e3855e0_f04e_28ee_98ea_8502e6531bc8 --> 54851997_7544_bab2_96ab_548e5f5df205
  b8a15b09_3dfb_7181_b1f8_368422e178e4["parse"]
  5e3855e0_f04e_28ee_98ea_8502e6531bc8 --> b8a15b09_3dfb_7181_b1f8_368422e178e4
  d1b39b63_c9d5_6c28_0206_0ddc8b895876["walk.ts"]
  5e3855e0_f04e_28ee_98ea_8502e6531bc8 --> d1b39b63_c9d5_6c28_0206_0ddc8b895876
  ed78da58_8727_ad98_120c_61f35cea357a["walk"]
  5e3855e0_f04e_28ee_98ea_8502e6531bc8 --> ed78da58_8727_ad98_120c_61f35cea357a
  342c0afc_3173_535b_9e25_ef41f6768585["normalize-path.ts"]
  5e3855e0_f04e_28ee_98ea_8502e6531bc8 --> 342c0afc_3173_535b_9e25_ef41f6768585
  df397cc3_5766_b5b5_66f1_04e0e5873574["normalizePath"]
  5e3855e0_f04e_28ee_98ea_8502e6531bc8 --> df397cc3_5766_b5b5_66f1_04e0e5873574
  2a7660a5_3e09_bd74_37f0_e4e54bc64ce5["node:path"]
  5e3855e0_f04e_28ee_98ea_8502e6531bc8 --> 2a7660a5_3e09_bd74_37f0_e4e54bc64ce5
  69d3ce9e_56db_8f40_5261_64f91b0dee31["compile.ts"]
  69d3ce9e_56db_8f40_5261_64f91b0dee31 --> 5e3855e0_f04e_28ee_98ea_8502e6531bc8
  0595d463_c492_bf18_2219_7aebf4857c89["urls.test.ts"]
  0595d463_c492_bf18_2219_7aebf4857c89 --> 5e3855e0_f04e_28ee_98ea_8502e6531bc8
  style 5e3855e0_f04e_28ee_98ea_8502e6531bc8 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 NodeBridge domain, NapiBinding 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: NodeBridge, subdomain: NapiBinding, 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