Skip to content

Commit

Permalink
Use prefixed transform values
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasvh committed Aug 30, 2017
1 parent badbf52 commit 6d9639d
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/parsing/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,44 @@ export type Transform = {
const MATRIX = /(matrix|matrix3d)\((.+)\)/;

export const parseTransform = (style: CSSStyleDeclaration): Transform => {
// TODO get prefixed values
const transform = parseTransformMatrix(style.transform);
const transform = parseTransformMatrix(
style.transform ||
style.webkitTransform ||
style.mozTransform ||
// $FlowFixMe
style.msTransform ||
// $FlowFixMe
style.oTransform
);
if (transform === null) {
return null;
}

return {
transform,
transformOrigin: parseTransformOrigin(style.transformOrigin)
transformOrigin: parseTransformOrigin(
style.transformOrigin ||
style.webkitTransformOrigin ||
style.mozTransformOrigin ||
// $FlowFixMe
style.msTransformOrigin ||
// $FlowFixMe
style.oTransformOrigin
)
};
};

const parseTransformOrigin = (origin: string): TransformOrigin => {
// $FlowFixMe
const parseTransformOrigin = (origin: ?string): TransformOrigin => {
if (typeof origin !== 'string') {
const v = new Length('0');
return [v, v];
}
const values = origin.split(' ').map(Length.create);
return [values[0], values[1]];
};

// $FlowFixMe
const parseTransformMatrix = (transform: ?string): Matrix | null => {
if (transform === 'none' || typeof transform !== 'string') {
return null;
Expand Down

0 comments on commit 6d9639d

Please sign in to comment.