Home / Function/ createLineTable() — tailwindcss Function Reference

createLineTable() — tailwindcss Function Reference

Architecture documentation for the createLineTable() function in line-table.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  0204f9b9_80aa_c3e8_eb61_22170d608d65["createLineTable()"]
  ac7e86e1_459b_f374_4516_afecc84f2a17["line-table.ts"]
  0204f9b9_80aa_c3e8_eb61_22170d608d65 -->|defined in| ac7e86e1_459b_f374_4516_afecc84f2a17
  062dc08d_4708_183b_67ab_c1a5231c576a["parseSourceMap()"]
  062dc08d_4708_183b_67ab_c1a5231c576a -->|calls| 0204f9b9_80aa_c3e8_eb61_22170d608d65
  2b13c224_9fb8_311a_1669_17e838226ea5["cssAstToPostCssAst()"]
  2b13c224_9fb8_311a_1669_17e838226ea5 -->|calls| 0204f9b9_80aa_c3e8_eb61_22170d608d65
  78de071a_f799_6ab3_0591_47a529ff04e2["constructor()"]
  78de071a_f799_6ab3_0591_47a529ff04e2 -->|calls| 0204f9b9_80aa_c3e8_eb61_22170d608d65
  ce95eae1_6998_4776_5146_d52bb0aefb63["createSourceMap()"]
  ce95eae1_6998_4776_5146_d52bb0aefb63 -->|calls| 0204f9b9_80aa_c3e8_eb61_22170d608d65
  b8973deb_e07f_d1e1_e7f9_7a680d9120d4["createTranslationMap()"]
  b8973deb_e07f_d1e1_e7f9_7a680d9120d4 -->|calls| 0204f9b9_80aa_c3e8_eb61_22170d608d65
  style 0204f9b9_80aa_c3e8_eb61_22170d608d65 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/source-maps/line-table.ts lines 50–100

export function createLineTable(source: string): LineTable {
  let table: number[] = [0]

  // Compute the offsets for the start of each line
  for (let i = 0; i < source.length; i++) {
    if (source.charCodeAt(i) === LINE_BREAK) {
      table.push(i + 1)
    }
  }

  function find(offset: number) {
    // Based on esbuild's binary search for line numbers
    let line = 0
    let count = table.length
    while (count > 0) {
      // `| 0` improves performance (in V8 at least)
      let mid = (count | 0) >> 1
      let i = line + mid
      if (table[i] <= offset) {
        line = i + 1
        count = count - mid - 1
      } else {
        count = mid
      }
    }

    line -= 1

    let column = offset - table[line]

    return {
      line: line + 1,
      column: column,
    }
  }

  function findOffset({ line, column }: Position) {
    line -= 1
    line = Math.min(Math.max(line, 0), table.length - 1)

    let offsetA = table[line]
    let offsetB = table[line + 1] ?? offsetA

    return Math.min(Math.max(offsetA + column, 0), offsetB)
  }

  return {
    find,
    findOffset,
  }
}

Domain

Subdomains

Frequently Asked Questions

What does createLineTable() do?
createLineTable() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/source-maps/line-table.ts.
Where is createLineTable() defined?
createLineTable() is defined in packages/tailwindcss/src/source-maps/line-table.ts at line 50.
What calls createLineTable()?
createLineTable() is called by 5 function(s): constructor, createSourceMap, createTranslationMap, cssAstToPostCssAst, parseSourceMap.

Analyze Your Own Codebase

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

Try Supermodel Free