/
getShadow.ts
23 lines (17 loc) · 845 Bytes
/
getShadow.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { FRAME as Frame } from '../../../../contracts/Figma';
import { roundColorValue } from '../../../../frameworks/string/roundColorValue';
import { ErrorGetShadow } from '../../../../frameworks/errors/errors';
export function getShadow(element: Frame): string | null {
if (!element) throw Error(ErrorGetShadow);
if (!(element.effects && element.effects[0] && element.effects[0].type === 'DROP_SHADOW'))
return null;
const dropShadow = element.effects[0];
const X = dropShadow.offset.x;
const Y = dropShadow.offset.y;
const radius = dropShadow.radius;
const R = roundColorValue(dropShadow.color.r);
const G = roundColorValue(dropShadow.color.g);
const B = roundColorValue(dropShadow.color.b);
const A = roundColorValue(dropShadow.color.a, 1);
return `${X}px ${Y}px ${radius}px rgba(${R}, ${G}, ${B}, ${A})`;
}