-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
70 lines (58 loc) · 1.85 KB
/
Copy pathindex.ts
File metadata and controls
70 lines (58 loc) · 1.85 KB
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
// import Parser from './src/Parser';
// import Padding from './src/Padding';
// import Margin from './src/Margin';
// import Background from './src/Background';
import Fruit, { decl } from './src/Fruit';
import Color from './src/dataTypes/Color';
import Image from './src/dataTypes/Image';
import Length from './src/dataTypes/Length';
import Number from './src/dataTypes/Number';
import Percentage from './src/dataTypes/Percentage';
import URL from './src/dataTypes/URL';
import Background from './src/properties/Background';
import BackgroundPosition from './src/properties/BackgroundPosition';
import BackgroundRepeat from './src/properties/BackgroundRepeat';
import BackgroundSize from './src/properties/BackgroundSize';
import Margin from './src/properties/Margin';
import Padding from './src/properties/Padding';
const Kinds: { [prop: string]: any } = {
background: Background,
};
Fruit.absorb = function absorb(prop: string | decl | Array<decl>, value?: string): Fruit {
if (this.name !== 'Fruit') {
const fruit = new this();
return fruit.absorb.apply(fruit, arguments);
} else {
if (Array.isArray(prop)) {
if (!prop.length)
return undefined;
const first = prop[0];
const rest = prop.slice(1) || [];
return this.absorb(first).absorb(rest);
}
if (typeof prop === 'object') {
value = prop.value;
prop = prop.prop;
}
const shorthand = prop.split('-')[0];
const Kind = Kinds[shorthand];
if (!Kind)
throw new Error('Unsupported property');
return Kind.absorb(prop, value);
}
};
export default Fruit;
export {
Color,
Image,
Length,
Number,
Percentage,
URL,
Background,
BackgroundPosition,
BackgroundRepeat,
BackgroundSize,
Margin,
Padding,
}