mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 18:12:09 +08:00
38 lines
951 B
TypeScript
38 lines
951 B
TypeScript
import { Color } from '../../color';
|
|
import { CoreTypes } from '../../core-types';
|
|
import { parseCSSShorthand } from './css-utils';
|
|
|
|
export interface ShadowCSSValues {
|
|
inset: boolean;
|
|
offsetX: CoreTypes.LengthType;
|
|
offsetY: CoreTypes.LengthType;
|
|
blurRadius?: CoreTypes.LengthType;
|
|
spreadRadius?: CoreTypes.LengthType;
|
|
color: Color;
|
|
}
|
|
|
|
/**
|
|
* Parse a string into ShadowCSSValues
|
|
* Supports any valid css box/text shadow combination.
|
|
*
|
|
* inspired by https://github.com/jxnblk/css-box-shadow/blob/master/index.js (MIT License)
|
|
*
|
|
* @param value
|
|
*/
|
|
export function parseCSSShadow(value: string): ShadowCSSValues {
|
|
const data = parseCSSShorthand(value);
|
|
if (!data) {
|
|
return null;
|
|
}
|
|
const [offsetX, offsetY, blurRadius, spreadRadius] = data.values;
|
|
|
|
return {
|
|
inset: data.inset,
|
|
offsetX: offsetX,
|
|
offsetY: offsetY,
|
|
blurRadius: blurRadius,
|
|
spreadRadius: spreadRadius,
|
|
color: data.color ? new Color(data.color) : undefined,
|
|
};
|
|
}
|