UNPKG

3.89 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at
5 * http://polymer.github.io/LICENSE.txt The complete set of authors may be found
6 * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
7 * be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
8 * Google as part of the polymer project is also subject to an additional IP
9 * rights grant found at http://polymer.github.io/PATENTS.txt
10 */
11/**
12 * A set of common RegExp matchers for tokenizing CSS.
13 */
14declare const matcher: {
15 whitespace: RegExp;
16 whitespaceGreedy: RegExp;
17 commentGreedy: RegExp;
18 boundary: RegExp;
19 stringBoundary: RegExp;
20};
21/**
22 * An enumeration of Node types.
23 */
24export declare enum nodeType {
25 stylesheet = "stylesheet",
26 comment = "comment",
27 atRule = "atRule",
28 ruleset = "ruleset",
29 expression = "expression",
30 declaration = "declaration",
31 rulelist = "rulelist",
32 discarded = "discarded",
33}
34export declare type Node = Stylesheet | AtRule | Comment | Rulelist | Ruleset | Expression | Declaration | Discarded;
35export declare type Rule = Ruleset | Declaration | AtRule | Discarded | Comment;
36/** A Stylesheet node. */
37export interface Stylesheet {
38 type: nodeType.stylesheet;
39 /**
40 * The list of rules that appear at the top level of the stylesheet.
41 */
42 rules: Rule[];
43 range: Range;
44}
45export interface AtRule {
46 type: nodeType.atRule;
47 /** The "name" of the At Rule (e.g., `charset`) */
48 name: string;
49 nameRange: Range;
50 /** The "parameters" of the At Rule (e.g., `utf8`) */
51 parameters: string;
52 parametersRange: Range | undefined;
53 /** The Rulelist node (if any) of the At Rule. */
54 rulelist: Rulelist | undefined;
55 range: Range;
56}
57/**
58 * A Comment node.
59 */
60export interface Comment {
61 type: nodeType.comment;
62 /**
63 * The full text content of the comment, including opening and closing
64 * comment signature.
65 */
66 value: string;
67 range: Range;
68}
69/**
70 * A Rulelist node.
71 */
72export interface Rulelist {
73 type: nodeType.rulelist;
74 /** An array of the Rule nodes found within the Ruleset. */
75 rules: Rule[];
76 range: Range;
77}
78/**
79 * A Ruleset node.
80 */
81export interface Ruleset {
82 type: nodeType.ruleset;
83 /** The selector that corresponds to the Ruleset (e.g., `#foo > .bar`). */
84 selector: string;
85 selectorRange: Range;
86 /** The Rulelist node that corresponds to the Selector. */
87 rulelist: Rulelist;
88 range: Range;
89}
90/**
91 * A Declaration node.
92 */
93export interface Declaration {
94 type: nodeType.declaration;
95 /** The property name of the Declaration (e.g., `color`). */
96 name: string;
97 /** The range in the original sourcetext where the name can be found. */
98 nameRange: Range;
99 /**
100 * Either an Expression node, or a Rulelist node, that
101 * corresponds to the value of the Declaration.
102 */
103 value: Expression | Rulelist | undefined;
104 range: Range;
105}
106/**
107 * An Expression node.
108 */
109export interface Expression {
110 type: nodeType.expression;
111 /** The full text content of the expression (e.g., `url(img.jpg)`) */
112 text: string;
113 range: Range;
114}
115/**
116 * A Discarded node. Discarded nodes contain content that was not
117 * parseable (usually due to typos, or otherwise unrecognized syntax).
118 */
119export interface Discarded {
120 type: nodeType.discarded;
121 /** The text content that is discarded. */
122 text: string;
123 range: Range;
124}
125export interface Range {
126 start: number;
127 end: number;
128}
129export interface NodeTypeMap {
130 'stylesheet': Stylesheet;
131 'atRule': AtRule;
132 'comment': Comment;
133 'rulelist': Rulelist;
134 'ruleset': Ruleset;
135 'declaration': Declaration;
136 'expression': Expression;
137 'discarded': Discarded;
138}
139export { matcher };