-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLiveTranslateTransform.index.js
60 lines (51 loc) · 1.82 KB
/
LiveTranslateTransform.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
import { defaultTo } from "fxjs/es";
import { $$appendTranslateTransform } from "../appendTranslateTransform/appendTranslateTransform.index.js";
import { $$getSVG } from "../getSetSVG/getSetSVG.index.js";
import { $$initTranslateTransform } from "../initTranslateTransform/initTranslateTransform.index.js";
import { $$LiveTransform } from "../LiveTransform/LiveTransform.index.js";
import { $$mergeTranslateTransform } from "../mergeTranslateTransform/mergeTranslateTransform.index.js";
import { $$updateTranslateTransform } from "../updateTranslateTransform/updateTranslateTransform.index.js";
export class $$LiveTranslateTransform extends $$LiveTransform {
constructor(
{ index = 0, tx = 0, ty = 0, x_name, y_name } = {},
$el,
$svg = $$getSVG()
) {
super();
this.is_done = false;
this.transform = $$initTranslateTransform({ tx, ty, index })($el, $svg);
this.x_name = x_name;
this.y_name = y_name;
this.index = index;
this.$el = $el;
this.$svg = $svg;
}
static $$create({ index = 0, tx = 0, ty = 0, x_name, y_name } = {}) {
return ($el, $svg = $$getSVG()) =>
new $$LiveTranslateTransform(
{ index, tx, ty, x_name, y_name },
$el,
$svg
);
}
$$getIsDone() {
return this.is_done;
}
$$done() {
this.is_done = true;
}
$$update({ tx, ty } = {}) {
$$updateTranslateTransform({ tx, ty })(this.transform);
}
$$append({ tx = 0, ty = 0 } = {}) {
$$appendTranslateTransform({ tx, ty })(this.transform);
}
$$merge({ x_name: x_name1, y_name: y_name1 } = {}) {
const { x_name: x_name2, y_name: y_name2, index, $el, $svg } = this;
const x_name = defaultTo(x_name2, x_name1);
const y_name = defaultTo(y_name2, y_name1);
if (x_name && y_name) {
$$mergeTranslateTransform({ index, x_name, y_name })($el, $svg);
}
}
}