import { Stylesheet } from 'vscode-css-languageservice' ; import { Position } from 'vscode-languageserver' ; import { getLanguageService } from './service' ; import { Document , DocumentMapper , ReadableDocument } from '../../lib/documents' ; const PREFIX = '__ {' ; const SUFFIX = '}' ; export class StyleAttributeDocument extends ReadableDocument implements DocumentMapper { readonly version = this . parent . version ; public stylesheet : Stylesheet ; public languageId = 'css' ; constructor ( private readonly parent , private readonly attrStart , private readonly attrEnd ) { super ( ) ; this . stylesheet = getLanguageService ( this . languageId ) . parseStylesheet ( this ) ; } param pos getOriginalPosition ( pos ) { const parentOffset = this . attrStart + this . offsetAt ( pos ) - PREFIX . length ; return this . parent . positionAt ( parentOffset ) ; } param pos getGeneratedPosition ( pos ) { const fragmentOffset = this . parent . offsetAt ( pos ) - this . attrStart + PREFIX . length ; return this . positionAt ( fragmentOffset ) ; } param pos isInGenerated ( pos ) { const offset = this . parent . offsetAt ( pos ) ; return offset >= this . attrStart && offset <= this . attrEnd ; } /**
     * Get the fragment text from the parent
     */ getText ( ) { return PREFIX + this . parent . getText ( ) . slice ( this . attrStart , this . attrEnd ) + SUFFIX ; } /**
     * Returns the length of the fragment as calculated from the start and end position
     */ getTextLength ( ) { return PREFIX . length + this . attrEnd - this . attrStart + SUFFIX . length ; } /**
     * Return the parent file path
     */ getFilePath ( ) { return this . parent . getFilePath ( ) ; } getURL ( ) { return this . parent . getURL ( ) ; } }