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
  85813fc9_ab7d_8f75_33b7_a217e8daf5ee["createLineTable()"]
  b17889f0_63a5_81d9_9305_7d7b699c9b32["parseSourceMap()"]
  b17889f0_63a5_81d9_9305_7d7b699c9b32 -->|calls| 85813fc9_ab7d_8f75_33b7_a217e8daf5ee
  81a639ec_bc2c_cf5e_48e3_3ae33426ae0a["cssAstToPostCssAst()"]
  81a639ec_bc2c_cf5e_48e3_3ae33426ae0a -->|calls| 85813fc9_ab7d_8f75_33b7_a217e8daf5ee
  16b9e300_563f_af90_e6f8_aea6ea1ebc4a["constructor()"]
  16b9e300_563f_af90_e6f8_aea6ea1ebc4a -->|calls| 85813fc9_ab7d_8f75_33b7_a217e8daf5ee
  5ab956da_909b_1c7e_21c8_9cf5b074e2ba["createSourceMap()"]
  5ab956da_909b_1c7e_21c8_9cf5b074e2ba -->|calls| 85813fc9_ab7d_8f75_33b7_a217e8daf5ee
  bb31abbc_7fee_b057_cbe4_7ee1725378c5["createTranslationMap()"]
  bb31abbc_7fee_b057_cbe4_7ee1725378c5 -->|calls| 85813fc9_ab7d_8f75_33b7_a217e8daf5ee
  style 85813fc9_ab7d_8f75_33b7_a217e8daf5ee 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.
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