Ignore:
Timestamp:
12/12/24 17:06:06 (5 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
d565449
Message:

Pred finalna verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/node_modules/postcss/lib/node.js

    rd565449 r0c6b92a  
    11'use strict'
    22
    3 let { isClean, my } = require('./symbols')
    43let CssSyntaxError = require('./css-syntax-error')
    54let Stringifier = require('./stringifier')
    65let stringify = require('./stringify')
     6let { isClean, my } = require('./symbols')
    77
    88function cloneNode(obj, parent) {
     
    3131
    3232  return cloned
     33}
     34
     35function sourceOffset(inputCSS, position) {
     36  // Not all custom syntaxes support `offset` in `source.start` and `source.end`
     37  if (
     38    position &&
     39    typeof position.offset !== 'undefined'
     40  ) {
     41    return position.offset;
     42  }
     43
     44  let column = 1
     45  let line = 1
     46  let offset = 0
     47
     48  for (let i = 0; i < inputCSS.length; i++) {
     49    if (line === position.line && column === position.column) {
     50      offset = i
     51      break
     52    }
     53
     54    if (inputCSS[i] === '\n') {
     55      column = 1
     56      line += 1
     57    } else {
     58      column += 1
     59    }
     60  }
     61
     62  return offset
    3363}
    3464
     
    154184  }
    155185
     186  /* c8 ignore next 3 */
     187  markClean() {
     188    this[isClean] = true
     189  }
     190
    156191  markDirty() {
    157192    if (this[isClean]) {
     
    170205  }
    171206
    172   positionBy(opts, stringRepresentation) {
     207  positionBy(opts) {
    173208    let pos = this.source.start
    174209    if (opts.index) {
    175       pos = this.positionInside(opts.index, stringRepresentation)
     210      pos = this.positionInside(opts.index)
    176211    } else if (opts.word) {
    177       stringRepresentation = this.toString()
     212      let stringRepresentation = this.source.input.css.slice(
     213        sourceOffset(this.source.input.css, this.source.start),
     214        sourceOffset(this.source.input.css, this.source.end)
     215      )
    178216      let index = stringRepresentation.indexOf(opts.word)
    179       if (index !== -1) pos = this.positionInside(index, stringRepresentation)
     217      if (index !== -1) pos = this.positionInside(index)
    180218    }
    181219    return pos
    182220  }
    183221
    184   positionInside(index, stringRepresentation) {
    185     let string = stringRepresentation || this.toString()
     222  positionInside(index) {
    186223    let column = this.source.start.column
    187224    let line = this.source.start.line
    188 
    189     for (let i = 0; i < index; i++) {
    190       if (string[i] === '\n') {
     225    let offset = sourceOffset(this.source.input.css, this.source.start)
     226    let end = offset + index
     227
     228    for (let i = offset; i < end; i++) {
     229      if (this.source.input.css[i] === '\n') {
    191230        column = 1
    192231        line += 1
     
    212251    let end = this.source.end
    213252      ? {
    214         column: this.source.end.column + 1,
    215         line: this.source.end.line
    216       }
     253          column: this.source.end.column + 1,
     254          line: this.source.end.line
     255        }
    217256      : {
    218         column: start.column + 1,
    219         line: start.line
    220       }
     257          column: start.column + 1,
     258          line: start.line
     259        }
    221260
    222261    if (opts.word) {
    223       let stringRepresentation = this.toString()
     262      let stringRepresentation = this.source.input.css.slice(
     263        sourceOffset(this.source.input.css, this.source.start),
     264        sourceOffset(this.source.input.css, this.source.end)
     265      )
    224266      let index = stringRepresentation.indexOf(opts.word)
    225267      if (index !== -1) {
    226         start = this.positionInside(index, stringRepresentation)
    227         end = this.positionInside(index + opts.word.length, stringRepresentation)
     268        start = this.positionInside(index)
     269        end = this.positionInside(
     270          index + opts.word.length,
     271        )
    228272      }
    229273    } else {
Note: See TracChangeset for help on using the changeset viewer.