Changeset 0c6b92a for imaps-frontend/node_modules/postcss/lib/node.js
- Timestamp:
- 12/12/24 17:06:06 (5 weeks ago)
- Branches:
- main
- Parents:
- d565449
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/postcss/lib/node.js
rd565449 r0c6b92a 1 1 'use strict' 2 2 3 let { isClean, my } = require('./symbols')4 3 let CssSyntaxError = require('./css-syntax-error') 5 4 let Stringifier = require('./stringifier') 6 5 let stringify = require('./stringify') 6 let { isClean, my } = require('./symbols') 7 7 8 8 function cloneNode(obj, parent) { … … 31 31 32 32 return cloned 33 } 34 35 function 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 33 63 } 34 64 … … 154 184 } 155 185 186 /* c8 ignore next 3 */ 187 markClean() { 188 this[isClean] = true 189 } 190 156 191 markDirty() { 157 192 if (this[isClean]) { … … 170 205 } 171 206 172 positionBy(opts , stringRepresentation) {207 positionBy(opts) { 173 208 let pos = this.source.start 174 209 if (opts.index) { 175 pos = this.positionInside(opts.index , stringRepresentation)210 pos = this.positionInside(opts.index) 176 211 } 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 ) 178 216 let index = stringRepresentation.indexOf(opts.word) 179 if (index !== -1) pos = this.positionInside(index , stringRepresentation)217 if (index !== -1) pos = this.positionInside(index) 180 218 } 181 219 return pos 182 220 } 183 221 184 positionInside(index, stringRepresentation) { 185 let string = stringRepresentation || this.toString() 222 positionInside(index) { 186 223 let column = this.source.start.column 187 224 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') { 191 230 column = 1 192 231 line += 1 … … 212 251 let end = this.source.end 213 252 ? { 214 column: this.source.end.column + 1,215 line: this.source.end.line216 }253 column: this.source.end.column + 1, 254 line: this.source.end.line 255 } 217 256 : { 218 column: start.column + 1,219 line: start.line220 }257 column: start.column + 1, 258 line: start.line 259 } 221 260 222 261 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 ) 224 266 let index = stringRepresentation.indexOf(opts.word) 225 267 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 ) 228 272 } 229 273 } else {
Note:
See TracChangeset
for help on using the changeset viewer.