@tmagic/stage 1.1.0-beta.5 → 1.1.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{tmagic-stage.es.js → tmagic-stage.mjs} +206 -154
- package/dist/tmagic-stage.mjs.map +1 -0
- package/dist/tmagic-stage.umd.js +220 -168
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/package.json +13 -11
- package/src/StageCore.ts +12 -3
- package/src/StageDragResize.ts +1 -1
- package/src/StageMask.ts +3 -1
- package/src/StageMultiDragResize.ts +5 -5
- package/src/types.ts +1 -1
- package/tsconfig.build.json +13 -0
- package/{dist/types/src → types}/Rule.d.ts +0 -0
- package/{dist/types/src → types}/StageCore.d.ts +6 -0
- package/{dist/types/src → types}/StageDragResize.d.ts +0 -0
- package/{dist/types/src → types}/StageHighlight.d.ts +0 -0
- package/{dist/types/src → types}/StageMask.d.ts +0 -0
- package/{dist/types/src → types}/StageMultiDragResize.d.ts +0 -0
- package/{dist/types/src → types}/StageRender.d.ts +0 -0
- package/{dist/types/src → types}/TargetCalibrate.d.ts +0 -0
- package/{dist/types/src → types}/const.d.ts +0 -0
- package/{dist/types/src → types}/index.d.ts +0 -0
- package/types/logger.d.ts +5 -0
- package/{dist/types/src → types}/types.d.ts +1 -1
- package/{dist/types/src → types}/util.d.ts +0 -0
- package/dist/tmagic-stage.es.js.map +0 -1
- package/dist/types/src/vite-env.d.ts +0 -1
- package/src/vite-env.d.ts +0 -1
package/dist/tmagic-stage.umd.js
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicStage = {}, global.EventEmitter, global.utils, global.Moveable, global.MoveableHelper, global.KeyController, global.lodashEs, global.Guides));
|
|
5
5
|
})(this, (function (exports, EventEmitter, utils, Moveable, MoveableHelper, KeyController, lodashEs, Guides) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
10
|
+
const Moveable__default = /*#__PURE__*/_interopDefaultLegacy(Moveable);
|
|
11
|
+
const MoveableHelper__default = /*#__PURE__*/_interopDefaultLegacy(MoveableHelper);
|
|
12
|
+
const KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
|
|
13
|
+
const Guides__default = /*#__PURE__*/_interopDefaultLegacy(Guides);
|
|
14
14
|
|
|
15
15
|
const GHOST_EL_ID_PREFIX = "ghost_el_";
|
|
16
16
|
const DRAG_EL_ID_PREFIX = "drag_el_";
|
|
@@ -210,14 +210,22 @@
|
|
|
210
210
|
};
|
|
211
211
|
|
|
212
212
|
class StageDragResize extends EventEmitter.EventEmitter {
|
|
213
|
+
core;
|
|
214
|
+
mask;
|
|
215
|
+
container;
|
|
216
|
+
target;
|
|
217
|
+
dragEl;
|
|
218
|
+
moveable;
|
|
219
|
+
horizontalGuidelines = [];
|
|
220
|
+
verticalGuidelines = [];
|
|
221
|
+
elementGuidelines = [];
|
|
222
|
+
mode = Mode.ABSOLUTE;
|
|
223
|
+
moveableOptions = {};
|
|
224
|
+
dragStatus = "end" /* END */;
|
|
225
|
+
ghostEl;
|
|
226
|
+
moveableHelper;
|
|
213
227
|
constructor(config) {
|
|
214
228
|
super();
|
|
215
|
-
this.horizontalGuidelines = [];
|
|
216
|
-
this.verticalGuidelines = [];
|
|
217
|
-
this.elementGuidelines = [];
|
|
218
|
-
this.mode = Mode.ABSOLUTE;
|
|
219
|
-
this.moveableOptions = {};
|
|
220
|
-
this.dragStatus = "end" /* END */;
|
|
221
229
|
this.core = config.core;
|
|
222
230
|
this.container = config.container;
|
|
223
231
|
this.mask = config.mask;
|
|
@@ -227,7 +235,7 @@
|
|
|
227
235
|
this.target = el;
|
|
228
236
|
if (!this.moveable || this.target !== oldTarget) {
|
|
229
237
|
this.init(el);
|
|
230
|
-
this.moveableHelper = MoveableHelper__default
|
|
238
|
+
this.moveableHelper = MoveableHelper__default.default.create({
|
|
231
239
|
useBeforeRender: true,
|
|
232
240
|
useRender: false,
|
|
233
241
|
createAuto: true
|
|
@@ -331,7 +339,7 @@
|
|
|
331
339
|
}
|
|
332
340
|
initMoveable() {
|
|
333
341
|
this.moveable?.destroy();
|
|
334
|
-
this.moveable = new Moveable__default
|
|
342
|
+
this.moveable = new Moveable__default.default(this.container, {
|
|
335
343
|
...this.moveableOptions
|
|
336
344
|
});
|
|
337
345
|
this.bindResizeEvent();
|
|
@@ -543,7 +551,7 @@
|
|
|
543
551
|
return ghostEl;
|
|
544
552
|
}
|
|
545
553
|
setGhostElChildrenId(el) {
|
|
546
|
-
for (const child of el.children) {
|
|
554
|
+
for (const child of Array.from(el.children)) {
|
|
547
555
|
if (child.id) {
|
|
548
556
|
child.id = `${GHOST_EL_ID_PREFIX}${child.id}`;
|
|
549
557
|
}
|
|
@@ -617,6 +625,11 @@
|
|
|
617
625
|
}
|
|
618
626
|
|
|
619
627
|
class TargetCalibrate extends EventEmitter.EventEmitter {
|
|
628
|
+
parent;
|
|
629
|
+
mask;
|
|
630
|
+
dr;
|
|
631
|
+
core;
|
|
632
|
+
operationEl;
|
|
620
633
|
constructor(config) {
|
|
621
634
|
super();
|
|
622
635
|
this.parent = config.parent;
|
|
@@ -684,6 +697,11 @@
|
|
|
684
697
|
}
|
|
685
698
|
|
|
686
699
|
class StageHighlight extends EventEmitter.EventEmitter {
|
|
700
|
+
core;
|
|
701
|
+
container;
|
|
702
|
+
target;
|
|
703
|
+
moveable;
|
|
704
|
+
calibrationTarget;
|
|
687
705
|
constructor(config) {
|
|
688
706
|
super();
|
|
689
707
|
this.core = config.core;
|
|
@@ -700,7 +718,7 @@
|
|
|
700
718
|
return;
|
|
701
719
|
this.target = el;
|
|
702
720
|
this.moveable?.destroy();
|
|
703
|
-
this.moveable = new Moveable__default
|
|
721
|
+
this.moveable = new Moveable__default.default(this.container, {
|
|
704
722
|
target: this.calibrationTarget.update(el, HIGHLIGHT_EL_ID_PREFIX),
|
|
705
723
|
origin: false,
|
|
706
724
|
rootContainer: this.core.container,
|
|
@@ -720,42 +738,15 @@
|
|
|
720
738
|
}
|
|
721
739
|
}
|
|
722
740
|
|
|
723
|
-
class Rule extends EventEmitter__default
|
|
741
|
+
class Rule extends EventEmitter__default.default {
|
|
742
|
+
hGuides;
|
|
743
|
+
vGuides;
|
|
744
|
+
horizontalGuidelines = [];
|
|
745
|
+
verticalGuidelines = [];
|
|
746
|
+
container;
|
|
747
|
+
containerResizeObserver;
|
|
724
748
|
constructor(container) {
|
|
725
749
|
super();
|
|
726
|
-
this.horizontalGuidelines = [];
|
|
727
|
-
this.verticalGuidelines = [];
|
|
728
|
-
this.getGuidesStyle = (type) => ({
|
|
729
|
-
position: "fixed",
|
|
730
|
-
zIndex: 1,
|
|
731
|
-
left: type === GuidesType.HORIZONTAL ? 0 : "-30px",
|
|
732
|
-
top: type === GuidesType.HORIZONTAL ? "-30px" : 0,
|
|
733
|
-
width: type === GuidesType.HORIZONTAL ? "100%" : "30px",
|
|
734
|
-
height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
|
|
735
|
-
});
|
|
736
|
-
this.createGuides = (type, defaultGuides = []) => new Guides__default["default"](this.container, {
|
|
737
|
-
type,
|
|
738
|
-
defaultGuides,
|
|
739
|
-
displayDragPos: true,
|
|
740
|
-
backgroundColor: "#fff",
|
|
741
|
-
lineColor: "#000",
|
|
742
|
-
textColor: "#000",
|
|
743
|
-
style: this.getGuidesStyle(type)
|
|
744
|
-
});
|
|
745
|
-
this.hGuidesChangeGuidesHandler = (e) => {
|
|
746
|
-
this.horizontalGuidelines = e.guides;
|
|
747
|
-
this.emit("changeGuides", {
|
|
748
|
-
type: GuidesType.HORIZONTAL,
|
|
749
|
-
guides: this.horizontalGuidelines
|
|
750
|
-
});
|
|
751
|
-
};
|
|
752
|
-
this.vGuidesChangeGuidesHandler = (e) => {
|
|
753
|
-
this.verticalGuidelines = e.guides;
|
|
754
|
-
this.emit("changeGuides", {
|
|
755
|
-
type: GuidesType.VERTICAL,
|
|
756
|
-
guides: this.verticalGuidelines
|
|
757
|
-
});
|
|
758
|
-
};
|
|
759
750
|
this.container = container;
|
|
760
751
|
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
|
|
761
752
|
this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
|
|
@@ -827,6 +818,37 @@
|
|
|
827
818
|
this.containerResizeObserver.disconnect();
|
|
828
819
|
this.removeAllListeners();
|
|
829
820
|
}
|
|
821
|
+
getGuidesStyle = (type) => ({
|
|
822
|
+
position: "fixed",
|
|
823
|
+
zIndex: 1,
|
|
824
|
+
left: type === GuidesType.HORIZONTAL ? 0 : "-30px",
|
|
825
|
+
top: type === GuidesType.HORIZONTAL ? "-30px" : 0,
|
|
826
|
+
width: type === GuidesType.HORIZONTAL ? "100%" : "30px",
|
|
827
|
+
height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
|
|
828
|
+
});
|
|
829
|
+
createGuides = (type, defaultGuides = []) => new Guides__default.default(this.container, {
|
|
830
|
+
type,
|
|
831
|
+
defaultGuides,
|
|
832
|
+
displayDragPos: true,
|
|
833
|
+
backgroundColor: "#fff",
|
|
834
|
+
lineColor: "#000",
|
|
835
|
+
textColor: "#000",
|
|
836
|
+
style: this.getGuidesStyle(type)
|
|
837
|
+
});
|
|
838
|
+
hGuidesChangeGuidesHandler = (e) => {
|
|
839
|
+
this.horizontalGuidelines = e.guides;
|
|
840
|
+
this.emit("changeGuides", {
|
|
841
|
+
type: GuidesType.HORIZONTAL,
|
|
842
|
+
guides: this.horizontalGuidelines
|
|
843
|
+
});
|
|
844
|
+
};
|
|
845
|
+
vGuidesChangeGuidesHandler = (e) => {
|
|
846
|
+
this.verticalGuidelines = e.guides;
|
|
847
|
+
this.emit("changeGuides", {
|
|
848
|
+
type: GuidesType.VERTICAL,
|
|
849
|
+
guides: this.verticalGuidelines
|
|
850
|
+
});
|
|
851
|
+
};
|
|
830
852
|
}
|
|
831
853
|
|
|
832
854
|
const wrapperClassName = "editor-mask-wrapper";
|
|
@@ -860,74 +882,30 @@
|
|
|
860
882
|
return el;
|
|
861
883
|
};
|
|
862
884
|
class StageMask extends Rule {
|
|
885
|
+
content = createContent();
|
|
886
|
+
wrapper;
|
|
887
|
+
core;
|
|
888
|
+
page = null;
|
|
889
|
+
pageScrollParent = null;
|
|
890
|
+
scrollTop = 0;
|
|
891
|
+
scrollLeft = 0;
|
|
892
|
+
width = 0;
|
|
893
|
+
height = 0;
|
|
894
|
+
wrapperHeight = 0;
|
|
895
|
+
wrapperWidth = 0;
|
|
896
|
+
maxScrollTop = 0;
|
|
897
|
+
maxScrollLeft = 0;
|
|
898
|
+
intersectionObserver = null;
|
|
899
|
+
isMultiSelectStatus = false;
|
|
900
|
+
mode = Mode.ABSOLUTE;
|
|
901
|
+
pageResizeObserver = null;
|
|
902
|
+
wrapperResizeObserver = null;
|
|
903
|
+
highlightHandler = lodashEs.throttle((event) => {
|
|
904
|
+
this.emit("highlight", event);
|
|
905
|
+
}, throttleTime);
|
|
863
906
|
constructor(config) {
|
|
864
907
|
const wrapper = createWrapper();
|
|
865
908
|
super(wrapper);
|
|
866
|
-
this.content = createContent();
|
|
867
|
-
this.page = null;
|
|
868
|
-
this.pageScrollParent = null;
|
|
869
|
-
this.scrollTop = 0;
|
|
870
|
-
this.scrollLeft = 0;
|
|
871
|
-
this.width = 0;
|
|
872
|
-
this.height = 0;
|
|
873
|
-
this.wrapperHeight = 0;
|
|
874
|
-
this.wrapperWidth = 0;
|
|
875
|
-
this.maxScrollTop = 0;
|
|
876
|
-
this.maxScrollLeft = 0;
|
|
877
|
-
this.intersectionObserver = null;
|
|
878
|
-
this.isMultiSelectStatus = false;
|
|
879
|
-
this.mode = Mode.ABSOLUTE;
|
|
880
|
-
this.pageResizeObserver = null;
|
|
881
|
-
this.wrapperResizeObserver = null;
|
|
882
|
-
this.highlightHandler = lodashEs.throttle((event) => {
|
|
883
|
-
this.emit("highlight", event);
|
|
884
|
-
}, throttleTime);
|
|
885
|
-
this.mouseDownHandler = (event) => {
|
|
886
|
-
this.emit("clearHighlight");
|
|
887
|
-
event.stopImmediatePropagation();
|
|
888
|
-
event.stopPropagation();
|
|
889
|
-
if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
|
|
890
|
-
return;
|
|
891
|
-
if (!this.isMultiSelectStatus && event.target.className.indexOf("moveable-area") !== -1) {
|
|
892
|
-
return;
|
|
893
|
-
}
|
|
894
|
-
if (event.target.className.indexOf("moveable-control") !== -1) {
|
|
895
|
-
return;
|
|
896
|
-
}
|
|
897
|
-
this.content.removeEventListener("mousemove", this.highlightHandler);
|
|
898
|
-
if (this.isMultiSelectStatus) {
|
|
899
|
-
this.emit("beforeMultiSelect", event);
|
|
900
|
-
} else {
|
|
901
|
-
this.emit("beforeSelect", event);
|
|
902
|
-
}
|
|
903
|
-
globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
|
|
904
|
-
};
|
|
905
|
-
this.mouseUpHandler = () => {
|
|
906
|
-
globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
|
|
907
|
-
this.content.addEventListener("mousemove", this.highlightHandler);
|
|
908
|
-
this.emit("select");
|
|
909
|
-
};
|
|
910
|
-
this.mouseWheelHandler = (event) => {
|
|
911
|
-
this.emit("clearHighlight");
|
|
912
|
-
if (!this.page)
|
|
913
|
-
throw new Error("page \u672A\u521D\u59CB\u5316");
|
|
914
|
-
const { deltaY, deltaX } = event;
|
|
915
|
-
if (this.page.clientHeight < this.wrapperHeight && deltaY)
|
|
916
|
-
return;
|
|
917
|
-
if (this.page.clientWidth < this.wrapperWidth && deltaX)
|
|
918
|
-
return;
|
|
919
|
-
if (this.maxScrollTop > 0) {
|
|
920
|
-
this.scrollTop = this.scrollTop + deltaY;
|
|
921
|
-
}
|
|
922
|
-
if (this.maxScrollLeft > 0) {
|
|
923
|
-
this.scrollLeft = this.scrollLeft + deltaX;
|
|
924
|
-
}
|
|
925
|
-
this.scroll();
|
|
926
|
-
this.emit("scroll", event);
|
|
927
|
-
};
|
|
928
|
-
this.mouseLeaveHandler = () => {
|
|
929
|
-
setTimeout(() => this.emit("clearHighlight"), throttleTime);
|
|
930
|
-
};
|
|
931
909
|
this.wrapper = wrapper;
|
|
932
910
|
this.core = config.core;
|
|
933
911
|
this.content.addEventListener("mousedown", this.mouseDownHandler);
|
|
@@ -935,11 +913,11 @@
|
|
|
935
913
|
this.content.addEventListener("wheel", this.mouseWheelHandler);
|
|
936
914
|
this.content.addEventListener("mousemove", this.highlightHandler);
|
|
937
915
|
this.content.addEventListener("mouseleave", this.mouseLeaveHandler);
|
|
938
|
-
KeyController__default
|
|
916
|
+
KeyController__default.default.global.keydown("shift", (e) => {
|
|
939
917
|
e.inputEvent.preventDefault();
|
|
940
918
|
this.isMultiSelectStatus = true;
|
|
941
919
|
});
|
|
942
|
-
KeyController__default
|
|
920
|
+
KeyController__default.default.global.keyup("shift", (e) => {
|
|
943
921
|
e.inputEvent.preventDefault();
|
|
944
922
|
this.isMultiSelectStatus = false;
|
|
945
923
|
});
|
|
@@ -1071,13 +1049,66 @@
|
|
|
1071
1049
|
if (this.maxScrollLeft < this.scrollLeft)
|
|
1072
1050
|
this.scrollLeft = this.maxScrollLeft;
|
|
1073
1051
|
}
|
|
1052
|
+
mouseDownHandler = (event) => {
|
|
1053
|
+
this.emit("clearHighlight");
|
|
1054
|
+
event.stopImmediatePropagation();
|
|
1055
|
+
event.stopPropagation();
|
|
1056
|
+
if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
|
|
1057
|
+
return;
|
|
1058
|
+
if (!this.isMultiSelectStatus && event.target.className.indexOf("moveable-area") !== -1) {
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
if (event.target.className.indexOf("moveable-control") !== -1) {
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
this.content.removeEventListener("mousemove", this.highlightHandler);
|
|
1065
|
+
if (this.isMultiSelectStatus) {
|
|
1066
|
+
this.emit("beforeMultiSelect", event);
|
|
1067
|
+
} else {
|
|
1068
|
+
this.emit("beforeSelect", event);
|
|
1069
|
+
}
|
|
1070
|
+
globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
|
|
1071
|
+
};
|
|
1072
|
+
mouseUpHandler = () => {
|
|
1073
|
+
globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
|
|
1074
|
+
this.content.addEventListener("mousemove", this.highlightHandler);
|
|
1075
|
+
if (!this.isMultiSelectStatus) {
|
|
1076
|
+
this.emit("select");
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
mouseWheelHandler = (event) => {
|
|
1080
|
+
this.emit("clearHighlight");
|
|
1081
|
+
if (!this.page)
|
|
1082
|
+
throw new Error("page \u672A\u521D\u59CB\u5316");
|
|
1083
|
+
const { deltaY, deltaX } = event;
|
|
1084
|
+
if (this.page.clientHeight < this.wrapperHeight && deltaY)
|
|
1085
|
+
return;
|
|
1086
|
+
if (this.page.clientWidth < this.wrapperWidth && deltaX)
|
|
1087
|
+
return;
|
|
1088
|
+
if (this.maxScrollTop > 0) {
|
|
1089
|
+
this.scrollTop = this.scrollTop + deltaY;
|
|
1090
|
+
}
|
|
1091
|
+
if (this.maxScrollLeft > 0) {
|
|
1092
|
+
this.scrollLeft = this.scrollLeft + deltaX;
|
|
1093
|
+
}
|
|
1094
|
+
this.scroll();
|
|
1095
|
+
this.emit("scroll", event);
|
|
1096
|
+
};
|
|
1097
|
+
mouseLeaveHandler = () => {
|
|
1098
|
+
setTimeout(() => this.emit("clearHighlight"), throttleTime);
|
|
1099
|
+
};
|
|
1074
1100
|
}
|
|
1075
1101
|
|
|
1076
1102
|
class StageMultiDragResize extends EventEmitter.EventEmitter {
|
|
1103
|
+
core;
|
|
1104
|
+
mask;
|
|
1105
|
+
container;
|
|
1106
|
+
targetList = [];
|
|
1107
|
+
dragElList = [];
|
|
1108
|
+
moveableForMulti;
|
|
1109
|
+
multiMoveableHelper;
|
|
1077
1110
|
constructor(config) {
|
|
1078
1111
|
super();
|
|
1079
|
-
this.targetList = [];
|
|
1080
|
-
this.dragElList = [];
|
|
1081
1112
|
this.core = config.core;
|
|
1082
1113
|
this.container = config.container;
|
|
1083
1114
|
this.mask = config.mask;
|
|
@@ -1098,10 +1129,10 @@
|
|
|
1098
1129
|
});
|
|
1099
1130
|
this.moveableForMulti?.destroy();
|
|
1100
1131
|
this.multiMoveableHelper?.clear();
|
|
1101
|
-
this.moveableForMulti = new Moveable__default
|
|
1132
|
+
this.moveableForMulti = new Moveable__default.default(this.container, this.getOptions({
|
|
1102
1133
|
target: this.dragElList
|
|
1103
1134
|
}));
|
|
1104
|
-
this.multiMoveableHelper = MoveableHelper__default
|
|
1135
|
+
this.multiMoveableHelper = MoveableHelper__default.default.create({
|
|
1105
1136
|
useBeforeRender: true,
|
|
1106
1137
|
useRender: false,
|
|
1107
1138
|
createAuto: true
|
|
@@ -1193,9 +1224,9 @@
|
|
|
1193
1224
|
});
|
|
1194
1225
|
}
|
|
1195
1226
|
getOptions(options = {}) {
|
|
1196
|
-
let {
|
|
1197
|
-
if (typeof
|
|
1198
|
-
|
|
1227
|
+
let { multiMoveableOptions = {} } = this.core.config;
|
|
1228
|
+
if (typeof multiMoveableOptions === "function") {
|
|
1229
|
+
multiMoveableOptions = multiMoveableOptions(this.core);
|
|
1199
1230
|
}
|
|
1200
1231
|
return {
|
|
1201
1232
|
defaultGroupRotate: 0,
|
|
@@ -1209,52 +1240,22 @@
|
|
|
1209
1240
|
origin: true,
|
|
1210
1241
|
padding: { left: 0, top: 0, right: 0, bottom: 0 },
|
|
1211
1242
|
...options,
|
|
1212
|
-
...
|
|
1243
|
+
...multiMoveableOptions
|
|
1213
1244
|
};
|
|
1214
1245
|
}
|
|
1215
1246
|
}
|
|
1216
1247
|
|
|
1217
|
-
|
|
1248
|
+
const style = ".tmagic-stage-container-highlight::after {\n content: '';\n position: absolute;\n width: 100%;\n height: 100%;\n top: 0;\n left: 0;\n background-color: #000;\n opacity: .1;\n pointer-events: none;\n}\n";
|
|
1218
1249
|
|
|
1219
1250
|
class StageRender extends EventEmitter.EventEmitter {
|
|
1251
|
+
contentWindow = null;
|
|
1252
|
+
runtime = null;
|
|
1253
|
+
iframe;
|
|
1254
|
+
runtimeUrl;
|
|
1255
|
+
core;
|
|
1256
|
+
render;
|
|
1220
1257
|
constructor({ core }) {
|
|
1221
1258
|
super();
|
|
1222
|
-
this.contentWindow = null;
|
|
1223
|
-
this.runtime = null;
|
|
1224
|
-
this.getMagicApi = () => ({
|
|
1225
|
-
onPageElUpdate: (el) => this.emit("page-el-update", el),
|
|
1226
|
-
onRuntimeReady: (runtime) => {
|
|
1227
|
-
this.runtime = runtime;
|
|
1228
|
-
globalThis.runtime = runtime;
|
|
1229
|
-
this.emit("runtime-ready", runtime);
|
|
1230
|
-
}
|
|
1231
|
-
});
|
|
1232
|
-
this.getRuntime = () => {
|
|
1233
|
-
if (this.runtime)
|
|
1234
|
-
return Promise.resolve(this.runtime);
|
|
1235
|
-
return new Promise((resolve) => {
|
|
1236
|
-
const listener = (runtime) => {
|
|
1237
|
-
this.off("runtime-ready", listener);
|
|
1238
|
-
resolve(runtime);
|
|
1239
|
-
};
|
|
1240
|
-
this.on("runtime-ready", listener);
|
|
1241
|
-
});
|
|
1242
|
-
};
|
|
1243
|
-
this.loadHandler = async () => {
|
|
1244
|
-
if (!this.contentWindow?.magic) {
|
|
1245
|
-
this.postTmagicRuntimeReady();
|
|
1246
|
-
}
|
|
1247
|
-
if (!this.contentWindow)
|
|
1248
|
-
return;
|
|
1249
|
-
if (this.render) {
|
|
1250
|
-
const el = await this.render(this.core);
|
|
1251
|
-
if (el) {
|
|
1252
|
-
this.contentWindow.document?.body?.appendChild(el);
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
this.emit("onload");
|
|
1256
|
-
utils.injectStyle(this.contentWindow.document, style);
|
|
1257
|
-
};
|
|
1258
1259
|
this.core = core;
|
|
1259
1260
|
this.runtimeUrl = core.config.runtimeUrl || "";
|
|
1260
1261
|
this.render = core.config.render;
|
|
@@ -1267,6 +1268,14 @@
|
|
|
1267
1268
|
`;
|
|
1268
1269
|
this.iframe.addEventListener("load", this.loadHandler);
|
|
1269
1270
|
}
|
|
1271
|
+
getMagicApi = () => ({
|
|
1272
|
+
onPageElUpdate: (el) => this.emit("page-el-update", el),
|
|
1273
|
+
onRuntimeReady: (runtime) => {
|
|
1274
|
+
this.runtime = runtime;
|
|
1275
|
+
globalThis.runtime = runtime;
|
|
1276
|
+
this.emit("runtime-ready", runtime);
|
|
1277
|
+
}
|
|
1278
|
+
});
|
|
1270
1279
|
async mount(el) {
|
|
1271
1280
|
if (!this.iframe) {
|
|
1272
1281
|
throw Error("mount \u5931\u8D25");
|
|
@@ -1281,6 +1290,17 @@
|
|
|
1281
1290
|
el.appendChild(this.iframe);
|
|
1282
1291
|
this.postTmagicRuntimeReady();
|
|
1283
1292
|
}
|
|
1293
|
+
getRuntime = () => {
|
|
1294
|
+
if (this.runtime)
|
|
1295
|
+
return Promise.resolve(this.runtime);
|
|
1296
|
+
return new Promise((resolve) => {
|
|
1297
|
+
const listener = (runtime) => {
|
|
1298
|
+
this.off("runtime-ready", listener);
|
|
1299
|
+
resolve(runtime);
|
|
1300
|
+
};
|
|
1301
|
+
this.on("runtime-ready", listener);
|
|
1302
|
+
});
|
|
1303
|
+
};
|
|
1284
1304
|
destroy() {
|
|
1285
1305
|
this.iframe?.removeEventListener("load", this.loadHandler);
|
|
1286
1306
|
this.contentWindow = null;
|
|
@@ -1288,6 +1308,21 @@
|
|
|
1288
1308
|
this.iframe = void 0;
|
|
1289
1309
|
this.removeAllListeners();
|
|
1290
1310
|
}
|
|
1311
|
+
loadHandler = async () => {
|
|
1312
|
+
if (!this.contentWindow?.magic) {
|
|
1313
|
+
this.postTmagicRuntimeReady();
|
|
1314
|
+
}
|
|
1315
|
+
if (!this.contentWindow)
|
|
1316
|
+
return;
|
|
1317
|
+
if (this.render) {
|
|
1318
|
+
const el = await this.render(this.core);
|
|
1319
|
+
if (el) {
|
|
1320
|
+
this.contentWindow.document?.body?.appendChild(el);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
this.emit("onload");
|
|
1324
|
+
utils.injectStyle(this.contentWindow.document, style);
|
|
1325
|
+
};
|
|
1291
1326
|
postTmagicRuntimeReady() {
|
|
1292
1327
|
this.contentWindow = this.iframe?.contentWindow;
|
|
1293
1328
|
this.contentWindow.magic = this.getMagicApi();
|
|
@@ -1298,10 +1333,23 @@
|
|
|
1298
1333
|
}
|
|
1299
1334
|
|
|
1300
1335
|
class StageCore extends EventEmitter.EventEmitter {
|
|
1336
|
+
container;
|
|
1337
|
+
selectedDom;
|
|
1338
|
+
selectedDomList = [];
|
|
1339
|
+
highlightedDom;
|
|
1340
|
+
renderer;
|
|
1341
|
+
mask;
|
|
1342
|
+
dr;
|
|
1343
|
+
multiDr;
|
|
1344
|
+
highlightLayer;
|
|
1345
|
+
config;
|
|
1346
|
+
zoom = DEFAULT_ZOOM;
|
|
1347
|
+
containerHighlightClassName;
|
|
1348
|
+
containerHighlightDuration;
|
|
1349
|
+
isContainer;
|
|
1350
|
+
canSelect;
|
|
1301
1351
|
constructor(config) {
|
|
1302
1352
|
super();
|
|
1303
|
-
this.selectedDomList = [];
|
|
1304
|
-
this.zoom = DEFAULT_ZOOM;
|
|
1305
1353
|
this.config = config;
|
|
1306
1354
|
this.setZoom(config.zoom);
|
|
1307
1355
|
this.canSelect = config.canSelect || ((el) => !!el.id);
|
|
@@ -1346,7 +1394,6 @@
|
|
|
1346
1394
|
const el = await this.getElementFromPoint(event);
|
|
1347
1395
|
if (!el)
|
|
1348
1396
|
return;
|
|
1349
|
-
this.clearSelectStatus("select");
|
|
1350
1397
|
if (this.selectedDom && !this.selectedDom.className.includes(PAGE_CLASS)) {
|
|
1351
1398
|
this.selectedDomList.push(this.selectedDom);
|
|
1352
1399
|
this.selectedDom = void 0;
|
|
@@ -1357,8 +1404,7 @@
|
|
|
1357
1404
|
} else {
|
|
1358
1405
|
this.selectedDomList.push(el);
|
|
1359
1406
|
}
|
|
1360
|
-
this.
|
|
1361
|
-
this.emit("multiSelect", this.selectedDomList);
|
|
1407
|
+
this.multiSelect(this.selectedDomList);
|
|
1362
1408
|
});
|
|
1363
1409
|
this.dr.on("update", (data) => {
|
|
1364
1410
|
setTimeout(() => this.emit("update", data));
|
|
@@ -1427,6 +1473,12 @@
|
|
|
1427
1473
|
}
|
|
1428
1474
|
}
|
|
1429
1475
|
}
|
|
1476
|
+
async multiSelect(idOrElList) {
|
|
1477
|
+
this.clearSelectStatus("select");
|
|
1478
|
+
const elList = await Promise.all(idOrElList.map(async (idOrEl) => await this.getTargetElement(idOrEl)));
|
|
1479
|
+
this.multiDr.multiSelect(elList);
|
|
1480
|
+
this.emit("multiSelect", elList);
|
|
1481
|
+
}
|
|
1430
1482
|
update(data) {
|
|
1431
1483
|
const { config } = data;
|
|
1432
1484
|
return this.renderer?.getRuntime().then((runtime) => {
|
|
@@ -1539,7 +1591,7 @@
|
|
|
1539
1591
|
exports.ZIndex = ZIndex;
|
|
1540
1592
|
exports.addSelectedClassName = addSelectedClassName;
|
|
1541
1593
|
exports.calcValueByFontsize = calcValueByFontsize;
|
|
1542
|
-
exports
|
|
1594
|
+
exports.default = StageCore;
|
|
1543
1595
|
exports.down = down;
|
|
1544
1596
|
exports.getAbsolutePosition = getAbsolutePosition;
|
|
1545
1597
|
exports.getMode = getMode;
|