|
@@ -2,7 +2,9 @@ import { ModuleControl } from "queenjs";
|
|
|
import { reactive } from "vue";
|
|
|
import { EditorModule } from "../../module";
|
|
|
import { DesignComp } from "../../objects/DesignTemp/DesignComp";
|
|
|
+import { Matrix } from "./Matrix";
|
|
|
import * as transforms from "./transforms";
|
|
|
+import { GroupActionCtrl } from "./GroupCtrl";
|
|
|
|
|
|
type TransHandle = (this: TransferCtrl, e: MouseEvent) => void;
|
|
|
|
|
@@ -20,6 +22,8 @@ export class TransferCtrl extends ModuleControl<EditorModule> {
|
|
|
currObserver?: MutationObserver;
|
|
|
transforms = transforms;
|
|
|
|
|
|
+ groupCtrl = new GroupActionCtrl(this.module);
|
|
|
+
|
|
|
transEvent = {
|
|
|
startX: 0,
|
|
|
startY: 0,
|
|
@@ -47,6 +51,8 @@ export class TransferCtrl extends ModuleControl<EditorModule> {
|
|
|
};
|
|
|
|
|
|
init(pageEl: HTMLElement) {
|
|
|
+ this.groupCtrl.init();
|
|
|
+
|
|
|
this.currComp = this.module.store.currComp;
|
|
|
this.compEl = this.currComp.$el;
|
|
|
this.pageEl = pageEl;
|
|
@@ -114,10 +120,11 @@ export class TransferCtrl extends ModuleControl<EditorModule> {
|
|
|
const rect = this.compEl.getBoundingClientRect();
|
|
|
const pageRect = this.pageEl.getBoundingClientRect();
|
|
|
|
|
|
- const transform = getTransform(this.compEl);
|
|
|
+ const matrix = new Matrix();
|
|
|
+ matrix.setFormDiv(this.compEl);
|
|
|
|
|
|
- const width = this.compEl.clientWidth * transform.scale;
|
|
|
- const height = this.compEl.clientHeight * transform.scale;
|
|
|
+ const width = this.compEl.clientWidth * matrix.getScale();
|
|
|
+ const height = this.compEl.clientHeight * matrix.getScale();
|
|
|
|
|
|
this.transferStyle.width = width + "px";
|
|
|
this.transferStyle.height = height + "px";
|
|
@@ -131,8 +138,8 @@ export class TransferCtrl extends ModuleControl<EditorModule> {
|
|
|
translateY: "-50%",
|
|
|
};
|
|
|
}
|
|
|
- this.transferStyle.transform.scale = transform.scale;
|
|
|
- this.transferStyle.transform.rotate = transform.rotate;
|
|
|
+ this.transferStyle.transform.scale = matrix.getScale();
|
|
|
+ this.transferStyle.transform.rotate = matrix.getRotate() + "deg";
|
|
|
this.transferStyle.transform.translateY = "-" + height / 2 + "px";
|
|
|
|
|
|
this.originPiont.x = rect.left + rect.width / 2;
|
|
@@ -146,41 +153,8 @@ export class TransferCtrl extends ModuleControl<EditorModule> {
|
|
|
}
|
|
|
|
|
|
destroy() {
|
|
|
+ this.groupCtrl.destroy();
|
|
|
this.currObserver?.disconnect();
|
|
|
this.resetStyle();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-export function getTransform(el: HTMLElement) {
|
|
|
- const st = getComputedStyle(el, null);
|
|
|
- const tr =
|
|
|
- st.getPropertyValue("-webkit-transform") ||
|
|
|
- st.getPropertyValue("-moz-transform") ||
|
|
|
- st.getPropertyValue("-ms-transform") ||
|
|
|
- st.getPropertyValue("-o-transform") ||
|
|
|
- st.getPropertyValue("transform") ||
|
|
|
- "FAIL";
|
|
|
-
|
|
|
- // console.error("Matrix: " + tr);
|
|
|
-
|
|
|
- if (tr == "none")
|
|
|
- return {
|
|
|
- rotate: "0deg",
|
|
|
- scale: 1,
|
|
|
- };
|
|
|
-
|
|
|
- // rotation matrix - http://en.wikipedia.org/wiki/Rotation_matrix
|
|
|
-
|
|
|
- const values = tr.split("(")[1].split(")")[0].split(",");
|
|
|
- // console.error("values: ", values);
|
|
|
- const a: any = values[0];
|
|
|
- const b: any = values[1];
|
|
|
-
|
|
|
- const angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
|
|
|
- const scale = Math.sqrt(a * a + b * b);
|
|
|
-
|
|
|
- return {
|
|
|
- rotate: `${angle}deg`,
|
|
|
- scale,
|
|
|
- };
|
|
|
-}
|