1 | import { isString } from '../../utils';
|
2 | import { CSSUnitValue } from '../cssom/CSSNumericValue';
|
3 | import { parseLengthOrPercentage } from './dimension';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export function parseTransformOrigin(value) {
|
10 | if (isString(value)) {
|
11 | var values = value.split(' ');
|
12 |
|
13 | if (values.length === 1) {
|
14 | if (values[0] === 'top' || values[0] === 'bottom') {
|
15 |
|
16 | values[1] = values[0];
|
17 | values[0] = 'center';
|
18 | } else {
|
19 |
|
20 | values[1] = 'center';
|
21 | }
|
22 | }
|
23 |
|
24 | if (values.length !== 2) {
|
25 | return null;
|
26 | }
|
27 |
|
28 |
|
29 | return [parseLengthOrPercentage(convertKeyword2Percent(values[0])), parseLengthOrPercentage(convertKeyword2Percent(values[1]))];
|
30 | } else {
|
31 | return [new CSSUnitValue(value[0] || 0, 'px'), new CSSUnitValue(value[1] || 0, 'px')];
|
32 | }
|
33 | }
|
34 |
|
35 | function convertKeyword2Percent(keyword) {
|
36 | if (keyword === 'center') {
|
37 | return '50%';
|
38 | } else if (keyword === 'left' || keyword === 'top') {
|
39 | return '0';
|
40 | } else if (keyword === 'right' || keyword === 'bottom') {
|
41 | return '100%';
|
42 | }
|
43 |
|
44 | return keyword;
|
45 | } |
\ | No newline at end of file |