|
|
|
@ -6,7 +6,12 @@ import { ParsedCssRule } from '../types'; |
|
|
|
import BrowserCssParser, { parseSelector, createNode } from './BrowserParserCss'; |
|
|
|
import { ParserEvents } from '../types'; |
|
|
|
|
|
|
|
const ParserCss = (em?: EditorModel, config: ParserConfig = {}) => ({ |
|
|
|
export default class ParserCss { |
|
|
|
constructor( |
|
|
|
private em?: EditorModel, |
|
|
|
private config: ParserConfig = {}, |
|
|
|
) {} |
|
|
|
|
|
|
|
/** |
|
|
|
* Parse CSS string to a desired model object |
|
|
|
* @param {String} str CSS string |
|
|
|
@ -14,11 +19,11 @@ const ParserCss = (em?: EditorModel, config: ParserConfig = {}) => ({ |
|
|
|
*/ |
|
|
|
parse(str: string, opts: { throwOnError?: boolean } = {}) { |
|
|
|
let output: CssRuleJSON[] = []; |
|
|
|
const { parserCss } = config; |
|
|
|
const editor = em?.Editor; |
|
|
|
const { parserCss } = this.config; |
|
|
|
const editor = this.em?.Editor; |
|
|
|
let nodes: CssRuleJSON[] | ParsedCssRule[] = []; |
|
|
|
let error: unknown; |
|
|
|
const Parser = em?.Parser; |
|
|
|
const Parser = this.em?.Parser; |
|
|
|
const inputOptions = { input: str }; |
|
|
|
Parser?.__emitEvent(ParserEvents.cssBefore, inputOptions); |
|
|
|
const { input } = inputOptions; |
|
|
|
@ -34,7 +39,7 @@ const ParserCss = (em?: EditorModel, config: ParserConfig = {}) => ({ |
|
|
|
Parser?.__emitEvent(ParserEvents.css, { input, output, nodes, error }); |
|
|
|
|
|
|
|
return output; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Check the returned node from a custom parser and transforms it to |
|
|
|
@ -70,7 +75,5 @@ const ParserCss = (em?: EditorModel, config: ParserConfig = {}) => ({ |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
export default ParserCss; |
|
|
|
} |
|
|
|
} |
|
|
|
|