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
  1c8e1044_08e4_f6ad_7550_c4fa3667fbf3["createLineTable()"]
  c078df4e_9ae3_a02e_4feb_6380507fddd9["line-table.ts"]
  1c8e1044_08e4_f6ad_7550_c4fa3667fbf3 -->|defined in| c078df4e_9ae3_a02e_4feb_6380507fddd9
  8f3d660c_68fa_523a_8143_e7bfeb96a4a2["parseSourceMap()"]
  8f3d660c_68fa_523a_8143_e7bfeb96a4a2 -->|calls| 1c8e1044_08e4_f6ad_7550_c4fa3667fbf3
  dea2012d_fe14_a673_2ce4_701a84a75cdb["cssAstToPostCssAst()"]
  dea2012d_fe14_a673_2ce4_701a84a75cdb -->|calls| 1c8e1044_08e4_f6ad_7550_c4fa3667fbf3
  06bbe705_93d4_b06f_973a_f7b9b75ffb1d["constructor()"]
  06bbe705_93d4_b06f_973a_f7b9b75ffb1d -->|calls| 1c8e1044_08e4_f6ad_7550_c4fa3667fbf3
  e55a3745_8aee_a25b_5e76_52ab134693bc["createSourceMap()"]
  e55a3745_8aee_a25b_5e76_52ab134693bc -->|calls| 1c8e1044_08e4_f6ad_7550_c4fa3667fbf3
  0799cdd2_4b0e_a38a_f2e3_313f628e1d75["createTranslationMap()"]
  0799cdd2_4b0e_a38a_f2e3_313f628e1d75 -->|calls| 1c8e1044_08e4_f6ad_7550_c4fa3667fbf3
  style 1c8e1044_08e4_f6ad_7550_c4fa3667fbf3 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