Home / File/ source-maps.ts — tailwindcss Source File

source-maps.ts — tailwindcss Source File

Architecture documentation for source-maps.ts, a typescript file in the tailwindcss codebase. 4 imports, 0 dependents.

File typescript NodeBridge NapiBinding 4 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  7aee1750_2c9b_68e2_d651_f79f92781488["source-maps.ts"]
  94f6a4ae_3b1f_8e71_a096_1f7d17efc49a["source-map.ts"]
  7aee1750_2c9b_68e2_d651_f79f92781488 --> 94f6a4ae_3b1f_8e71_a096_1f7d17efc49a
  c056448b_f7a2_9149_54e8_f0f8470fe3aa["default-map.ts"]
  7aee1750_2c9b_68e2_d651_f79f92781488 --> c056448b_f7a2_9149_54e8_f0f8470fe3aa
  bf2992f6_4a37_8536_70f8_94b13631027d["DefaultMap"]
  7aee1750_2c9b_68e2_d651_f79f92781488 --> bf2992f6_4a37_8536_70f8_94b13631027d
  82ad9cd3_d590_5d6c_5489_cb5e47cde1b7["source-map-js"]
  7aee1750_2c9b_68e2_d651_f79f92781488 --> 82ad9cd3_d590_5d6c_5489_cb5e47cde1b7
  style 7aee1750_2c9b_68e2_d651_f79f92781488 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { SourceMapGenerator } from 'source-map-js'
import type { DecodedSource, DecodedSourceMap } from '../../tailwindcss/src/source-maps/source-map'
import { DefaultMap } from '../../tailwindcss/src/utils/default-map'

export type { DecodedSource, DecodedSourceMap }
export interface SourceMap {
  readonly raw: string
  readonly inline: string
  comment(url: string): string
}

function serializeSourceMap(map: DecodedSourceMap): string {
  let generator = new SourceMapGenerator()

  let id = 1
  let sourceTable = new DefaultMap<
    DecodedSource | null,
    {
      url: string
      content: string
    }
  >((src) => {
    return {
      url: src?.url ?? `<unknown ${id++}>`,
      content: src?.content ?? '<none>',
    }
  })

  for (let mapping of map.mappings) {
    let original = sourceTable.get(mapping.originalPosition?.source ?? null)

    generator.addMapping({
      generated: mapping.generatedPosition,
      original: mapping.originalPosition,
      source: original.url,
      name: mapping.name,
    })

    generator.setSourceContent(original.url, original.content)
  }

  return generator.toString()
}

export function toSourceMap(map: DecodedSourceMap | string): SourceMap {
  let raw = typeof map === 'string' ? map : serializeSourceMap(map)

  function comment(url: string) {
    return `/*# sourceMappingURL=${url} */\n`
  }

  return {
    raw,
    get inline() {
      let inlined = Buffer.from(raw, 'utf-8').toString('base64')
      return comment(`data:application/json;base64,${inlined}`)
    },
    comment,
  }
}

Domain

Subdomains

Types

Dependencies

Frequently Asked Questions

What does source-maps.ts do?
source-maps.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 source-maps.ts?
source-maps.ts defines 2 function(s): serializeSourceMap, toSourceMap.
What does source-maps.ts depend on?
source-maps.ts imports 4 module(s): DefaultMap, default-map.ts, source-map-js, source-map.ts.
Where is source-maps.ts in the architecture?
source-maps.ts is located at packages/@tailwindcss-node/src/source-maps.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