-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmergeRotateTransform.index.js
64 lines (56 loc) · 2.33 KB
/
mergeRotateTransform.index.js
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
55
56
57
58
59
60
61
62
63
64
import { each, go, mapL, rangeL } from "fxjs/es";
import { $$createSVGTransformRotate } from "../createSVGTransformRotate/createSVGTransformRotate.index.js";
import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js";
import { $$getSVG } from "../getSetSVG/getSetSVG.index.js";
import { $$isRotateSVGTransform } from "../isRotateSVGTransform/isRotateSVGTransform.index.js";
import { $$isTranslateSVGTransform } from "../isTranslateSVGTransform/isTranslateSVGTransform.index.js";
const $$isValidFxRotateSVGTransformList = ({ index }) => (transform_list) => {
if (index > transform_list.numberOfItems - 2 || index < 1) {
return false;
}
const [
positive_translate_transform,
rotate_transform,
negative_translate_transform,
] = go(
rangeL(3),
mapL((i) => index - 1 + i),
mapL((i) => transform_list.getItem(i))
);
return (
$$isTranslateSVGTransform(positive_translate_transform) &&
$$isRotateSVGTransform(rotate_transform) &&
$$isTranslateSVGTransform(negative_translate_transform) &&
rotate_transform.matrix.e === 0 &&
rotate_transform.matrix.f === 0 &&
positive_translate_transform.matrix.a === 1 &&
positive_translate_transform.matrix.b === 0 &&
positive_translate_transform.matrix.c === 0 &&
positive_translate_transform.matrix.d === 1 &&
negative_translate_transform.matrix.a === 1 &&
negative_translate_transform.matrix.b === 0 &&
negative_translate_transform.matrix.c === 0 &&
negative_translate_transform.matrix.d === 1 &&
positive_translate_transform.matrix.e +
negative_translate_transform.matrix.e ===
0 &&
positive_translate_transform.matrix.f +
negative_translate_transform.matrix.f ===
0
);
};
export const $$mergeRotateTransform = ({ index = 1 } = {}) => (
$el,
$svg = $$getSVG()
) => {
const base_transform_list = $$getBaseTransformList($el);
if (!$$isValidFxRotateSVGTransformList({ index })(base_transform_list)) {
return $el;
}
const { angle } = base_transform_list.getItem(index);
const { e: cx, f: cy } = base_transform_list.getItem(index - 1).matrix;
each(() => base_transform_list.removeItem(index - 1), rangeL(3));
const rotate_transform = $$createSVGTransformRotate({ angle, cx, cy })($svg);
base_transform_list.insertItemBefore(rotate_transform, index - 1);
return $el;
};