-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathbox-shadow.ts
More file actions
54 lines (50 loc) · 1.54 KB
/
box-shadow.ts
File metadata and controls
54 lines (50 loc) · 1.54 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
import { isStyleDescriptorArray } from "../../utils";
import type { StyleFunctionResolver } from "./resolve";
import { shorthandHandler } from "./shorthand";
const color = ["color", "string"] as const;
const offsetX = ["offsetX", "number"] as const;
const offsetY = ["offsetY", "number"] as const;
const blurRadius = ["blurRadius", "number"] as const;
const spreadDistance = ["spreadDistance", "number"] as const;
// const inset = ["inset", "string"] as const;
const handler = shorthandHandler(
[
[offsetX, offsetY, blurRadius, spreadDistance, color],
[color, offsetX, offsetY],
[color, offsetX, offsetY, blurRadius],
[color, offsetX, offsetY, blurRadius, spreadDistance],
[offsetX, offsetY, color],
[offsetX, offsetY, blurRadius, color],
],
[],
"object",
);
export const boxShadow: StyleFunctionResolver = (
resolveValue,
func,
get,
options,
) => {
const args = resolveValue(func[2]);
if (!isStyleDescriptorArray(args)) {
return args;
} else {
return args.flatMap((shadows) => {
if (shadows === undefined) {
return [];
} else if (isStyleDescriptorArray(shadows)) {
if (shadows.length === 0) {
return [];
} else if (Array.isArray(shadows[0])) {
return shadows
.map((shadow) => handler(resolveValue, shadow, get, options))
.filter((v) => v !== undefined);
} else {
return handler(resolveValue, shadows, get, options);
}
} else {
return handler(resolveValue, shadows, get, options);
}
});
}
};