forked from mahirshah/css-property-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss-property-parser.d.ts
147 lines (138 loc) · 5.89 KB
/
css-property-parser.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
export = CssPropertyParser;
declare namespace CssPropertyParser {
class ParseError extends Error {
}
class UnsupportedPropertyError extends Error {
readonly property: string;
constructor(property: string);
}
class UnknownPropertyError extends Error {
readonly property: string;
constructor(property: string);
}
interface Declarations {
[property: string]: string;
}
/**
* Given a property and value attempts to expand the value into its longhand
* equivalents. Returns an object mapping the property longhand names to the
* longhand values. If the property cannot be expanded (i.e. the property is
* not a shorthand property) simply returns an object mapping the original
* property to the original value.
*
* @param {string} propertyName - the property name for the given value
* @param {string} propertyValue - the value of the property
* @param {boolean} [recursivelyResolve=true] - recursively resolve additional
* longhand properties if the shorthands expand to additional shorthands. For
* example, the border property expands to border-width, which expands
* further to border-left-width, border-right-width, etc.
* @param {boolean} [includeInitialValues=false] - when expanding the shorthand
* property, fill in any missing longhand values with their initial value.
* For example, the property declaration "border: 1px" only explicitly sets the
* "border-width" longhand property. If this param is true, the returned object
* will fill in the initial values for "border-style" and "border-color". By
* default, the returned object will only contain the "border-width".
*/
function expandShorthandProperty(
propertyName: string,
propertyValue: string,
recursivelyResolve?: boolean,
includeInitialValues?: boolean,
): Declarations;
/**
* Given a shorthand property, returns an array of the computed properties for
* that shorthand property. If given a known property that is not a shorthand,
* simply returns the given property. If given an unknown property, returns an
* empty array.
*
* @param {string} shorthandProperty - the shorthand property name. For
* example, "background" or "border".
* @param {boolean} recursivelyResolve - recursively resolve additional
* longhand properties if the shorthands expand to additional shorthands. For
* example, the border property expands to border-width, which expands further
* to border-left-width, border-right-width, etc. Defaults to false.
* @returns {Array} - an array containing the computed properties for the given
* shorthand property. Returns an empty array if the given property is not a
* valid property.
*/
function getShorthandComputedProperties(
shorthandProperty: string,
recursivelyResolve?: boolean
): Array<string>;
/**
* Checks if a given property is a shorthand property
* @param {String} property - the property name
* @returns {boolean} - true if property is a shorthand, false otherwise
*/
function isShorthandProperty(
shorthandProperty: string
): boolean;
/**
* Return a list of all properties that set the given property.
* Includes at least the value provided, plus any other shorthands that can
* set it.
*/
function getShorthandsForProperty(
longhandProperty: string
): Array<string>;
/**
* Checks if the given property, value pair is valid.
*
* @param {String} property - the property name. For example, 'border' or 'color'.
* @param {String} value - the property value. For example, '1px solid black'.
* @return {boolean} - true if the given value is valid for the property. Else, false.
*/
function isValidDeclaration(
property: string,
value: string
): boolean;
/**
* Because of the `initial` keyword and shorthand expansion,
* there are many possible values that are equivalently identical
* with the initial value of a css property. This function
* returns true for all possible values that have the effect of
* setting a property to its initial value.
*
* @param property the property to which the value is assigned
* @param value the value to check
* @return whether the value is equivalent to the initial value.
*/
function isInitialValue(
property: string,
value: string
): boolean;
/**
* Warms up the initial value cache for all known css properties.
* It is not usually necessary to call this function but
* may be useful in some performance testing scenarios.
*/
function computeInitialValues(): void;
/**
* Get the initial values for a property.
* @param property - the property name
* @param recursivelyResolve - Defaults to false. when given a shorthand property,
* causes the result to include long hand values.
* @param includeShorthands - Defaults to false. when resolving recursively, causes the
* the result to include the specified shorthand property as well as any
* intermediate shorthands of this property to to the initial value.
* @return the initial value or values a property has by
* default according the CSS specification. If the property's initial
* value(s) is/are unknown, the global keyword `initial` is returned.
*/
function initialValues(
property: string,
recursivelyResolve?: boolean,
includeShorthands?: boolean
): Declarations;
/**
* Get the initial value for a property. the property can be a shorthand or a
* longhand.
* @param property - the property name
* @return {string} the initial value has by default according the CSS
* specification. If the property's initial value is unknown, the global
* keyword `initial` is returned. There's no spec value for shorthands
* so in those cases, the value returned is not the only legal value that can be returned,
* instead, it is a value that developers is commonly in practice.
*/
function initialValue(property: string): string;
}