|
@@ -34,12 +34,18 @@ export class TransferCtrl extends ModuleControl<EditorModule> {
|
|
|
width: "",
|
|
|
height: "",
|
|
|
transform: {
|
|
|
+ scale: 1,
|
|
|
rotate: "0deg",
|
|
|
translateX: "-50%",
|
|
|
translateY: "-50%",
|
|
|
},
|
|
|
});
|
|
|
|
|
|
+ originPiont = {
|
|
|
+ x: 0,
|
|
|
+ y: 0,
|
|
|
+ };
|
|
|
+
|
|
|
init(pageEl: HTMLElement) {
|
|
|
this.currComp = this.module.store.currComp;
|
|
|
this.compEl = this.currComp.$el;
|
|
@@ -104,26 +110,33 @@ export class TransferCtrl extends ModuleControl<EditorModule> {
|
|
|
|
|
|
initStyle() {
|
|
|
if (!this.compEl) return;
|
|
|
-
|
|
|
+
|
|
|
const rect = this.compEl.getBoundingClientRect();
|
|
|
const pageRect = this.pageEl.getBoundingClientRect();
|
|
|
|
|
|
const transform = getTransform(this.compEl);
|
|
|
|
|
|
- this.transferStyle.width = this.compEl.clientWidth + "px";
|
|
|
- this.transferStyle.height = this.compEl.clientHeight + "px";
|
|
|
+ const width = this.compEl.clientWidth * transform.scale;
|
|
|
+ const height = this.compEl.clientHeight * transform.scale;
|
|
|
+
|
|
|
+ this.transferStyle.width = width + "px";
|
|
|
+ this.transferStyle.height = height + "px";
|
|
|
this.transferStyle.top = rect.top + rect.height / 2 - pageRect.top + "px";
|
|
|
this.transferStyle.left = rect.left + rect.width / 2 - pageRect.left + "px";
|
|
|
if (!this.transferStyle.transform) {
|
|
|
this.transferStyle.transform = {
|
|
|
+ scale: 1,
|
|
|
rotate: "0deg",
|
|
|
translateX: "-50%",
|
|
|
translateY: "-50%",
|
|
|
};
|
|
|
}
|
|
|
+ this.transferStyle.transform.scale = transform.scale;
|
|
|
this.transferStyle.transform.rotate = transform.rotate;
|
|
|
- this.transferStyle.transform.translateY =
|
|
|
- "-" + this.compEl.clientHeight / 2 + "px";
|
|
|
+ this.transferStyle.transform.translateY = "-" + height / 2 + "px";
|
|
|
+
|
|
|
+ this.originPiont.x = rect.left + rect.width / 2;
|
|
|
+ this.originPiont.y = rect.top + rect.height / 2;
|
|
|
}
|
|
|
|
|
|
resetStyle() {
|
|
@@ -153,6 +166,7 @@ export function getTransform(el: HTMLElement) {
|
|
|
if (tr == "none")
|
|
|
return {
|
|
|
rotate: "0deg",
|
|
|
+ scale: 1,
|
|
|
};
|
|
|
|
|
|
// rotation matrix - http://en.wikipedia.org/wiki/Rotation_matrix
|
|
@@ -161,11 +175,12 @@ export function getTransform(el: HTMLElement) {
|
|
|
// console.error("values: ", values);
|
|
|
const a: any = values[0];
|
|
|
const b: any = values[1];
|
|
|
- const c: any = values[2];
|
|
|
- const d: any = values[3];
|
|
|
|
|
|
const angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
|
|
|
+ const scale = Math.sqrt(a * a + b * b);
|
|
|
+
|
|
|
return {
|
|
|
rotate: `${angle}deg`,
|
|
|
+ scale,
|
|
|
};
|
|
|
}
|