@tmagic/stage 1.1.0-beta.3 → 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.
@@ -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
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
+ const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
8
8
 
9
- var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
10
- var Moveable__default = /*#__PURE__*/_interopDefaultLegacy(Moveable);
11
- var MoveableHelper__default = /*#__PURE__*/_interopDefaultLegacy(MoveableHelper);
12
- var KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
13
- var Guides__default = /*#__PURE__*/_interopDefaultLegacy(Guides);
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_";
@@ -162,16 +162,70 @@
162
162
  }
163
163
  return value;
164
164
  };
165
+ const down = (deltaTop, target) => {
166
+ let swapIndex = 0;
167
+ let addUpH = target.clientHeight;
168
+ const brothers = Array.from(target.parentNode?.children || []).filter((node) => !node.id.startsWith(GHOST_EL_ID_PREFIX));
169
+ const index = brothers.indexOf(target);
170
+ const downEls = brothers.slice(index + 1);
171
+ for (let i = 0; i < downEls.length; i++) {
172
+ const ele = downEls[i];
173
+ if (ele.style?.position === "fixed") {
174
+ continue;
175
+ }
176
+ addUpH += ele.clientHeight / 2;
177
+ if (deltaTop <= addUpH) {
178
+ break;
179
+ }
180
+ addUpH += ele.clientHeight / 2;
181
+ swapIndex = i;
182
+ }
183
+ return {
184
+ src: target.id,
185
+ dist: downEls.length && swapIndex > -1 ? downEls[swapIndex].id : target.id
186
+ };
187
+ };
188
+ const up = (deltaTop, target) => {
189
+ const brothers = Array.from(target.parentNode?.children || []).filter((node) => !node.id.startsWith(GHOST_EL_ID_PREFIX));
190
+ const index = brothers.indexOf(target);
191
+ const upEls = brothers.slice(0, index);
192
+ let addUpH = target.clientHeight;
193
+ let swapIndex = upEls.length - 1;
194
+ for (let i = upEls.length - 1; i >= 0; i--) {
195
+ const ele = upEls[i];
196
+ if (!ele)
197
+ continue;
198
+ if (ele.style.position === "fixed")
199
+ continue;
200
+ addUpH += ele.clientHeight / 2;
201
+ if (-deltaTop <= addUpH)
202
+ break;
203
+ addUpH += ele.clientHeight / 2;
204
+ swapIndex = i;
205
+ }
206
+ return {
207
+ src: target.id,
208
+ dist: upEls.length && swapIndex > -1 ? upEls[swapIndex].id : target.id
209
+ };
210
+ };
165
211
 
166
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;
167
227
  constructor(config) {
168
228
  super();
169
- this.horizontalGuidelines = [];
170
- this.verticalGuidelines = [];
171
- this.elementGuidelines = [];
172
- this.mode = Mode.ABSOLUTE;
173
- this.moveableOptions = {};
174
- this.dragStatus = "end" /* END */;
175
229
  this.core = config.core;
176
230
  this.container = config.container;
177
231
  this.mask = config.mask;
@@ -181,7 +235,7 @@
181
235
  this.target = el;
182
236
  if (!this.moveable || this.target !== oldTarget) {
183
237
  this.init(el);
184
- this.moveableHelper = MoveableHelper__default["default"].create({
238
+ this.moveableHelper = MoveableHelper__default.default.create({
185
239
  useBeforeRender: true,
186
240
  useRender: false,
187
241
  createAuto: true
@@ -285,7 +339,7 @@
285
339
  }
286
340
  initMoveable() {
287
341
  this.moveable?.destroy();
288
- this.moveable = new Moveable__default["default"](this.container, {
342
+ this.moveable = new Moveable__default.default(this.container, {
289
343
  ...this.moveableOptions
290
344
  });
291
345
  this.bindResizeEvent();
@@ -497,7 +551,7 @@
497
551
  return ghostEl;
498
552
  }
499
553
  setGhostElChildrenId(el) {
500
- for (const child of el.children) {
554
+ for (const child of Array.from(el.children)) {
501
555
  if (child.id) {
502
556
  child.id = `${GHOST_EL_ID_PREFIX}${child.id}`;
503
557
  }
@@ -560,7 +614,7 @@
560
614
  bounds: {
561
615
  top: 0,
562
616
  left: -1,
563
- right: this.container.clientWidth,
617
+ right: this.container.clientWidth - 1,
564
618
  bottom: this.container.clientHeight,
565
619
  ...moveableOptions.bounds || {}
566
620
  },
@@ -569,54 +623,13 @@
569
623
  };
570
624
  }
571
625
  }
572
- const down = (deltaTop, target) => {
573
- let swapIndex = 0;
574
- let addUpH = target.clientHeight;
575
- const brothers = Array.from(target.parentNode?.children || []).filter((node) => !node.id.startsWith(GHOST_EL_ID_PREFIX));
576
- const index = brothers.indexOf(target);
577
- const downEls = brothers.slice(index + 1);
578
- for (let i = 0; i < downEls.length; i++) {
579
- const ele = downEls[i];
580
- if (ele.style?.position === "fixed") {
581
- continue;
582
- }
583
- addUpH += ele.clientHeight / 2;
584
- if (deltaTop <= addUpH) {
585
- break;
586
- }
587
- addUpH += ele.clientHeight / 2;
588
- swapIndex = i;
589
- }
590
- return {
591
- src: target.id,
592
- dist: downEls.length && swapIndex > -1 ? downEls[swapIndex].id : target.id
593
- };
594
- };
595
- const up = (deltaTop, target) => {
596
- const brothers = Array.from(target.parentNode?.children || []).filter((node) => !node.id.startsWith(GHOST_EL_ID_PREFIX));
597
- const index = brothers.indexOf(target);
598
- const upEls = brothers.slice(0, index);
599
- let addUpH = target.clientHeight;
600
- let swapIndex = upEls.length - 1;
601
- for (let i = upEls.length - 1; i >= 0; i--) {
602
- const ele = upEls[i];
603
- if (!ele)
604
- continue;
605
- if (ele.style.position === "fixed")
606
- continue;
607
- addUpH += ele.clientHeight / 2;
608
- if (-deltaTop <= addUpH)
609
- break;
610
- addUpH += ele.clientHeight / 2;
611
- swapIndex = i;
612
- }
613
- return {
614
- src: target.id,
615
- dist: upEls.length && swapIndex > -1 ? upEls[swapIndex].id : target.id
616
- };
617
- };
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;
@@ -636,6 +649,7 @@
636
649
  top: ${top}px;
637
650
  width: ${el.clientWidth}px;
638
651
  height: ${el.clientHeight}px;
652
+ z-index: ${ZIndex.DRAG_EL};
639
653
  `;
640
654
  this.operationEl.id = `${prefix}${el.id}`;
641
655
  if (typeof this.core.config.updateDragEl === "function") {
@@ -683,6 +697,11 @@
683
697
  }
684
698
 
685
699
  class StageHighlight extends EventEmitter.EventEmitter {
700
+ core;
701
+ container;
702
+ target;
703
+ moveable;
704
+ calibrationTarget;
686
705
  constructor(config) {
687
706
  super();
688
707
  this.core = config.core;
@@ -699,11 +718,11 @@
699
718
  return;
700
719
  this.target = el;
701
720
  this.moveable?.destroy();
702
- this.moveable = new Moveable__default["default"](this.container, {
721
+ this.moveable = new Moveable__default.default(this.container, {
703
722
  target: this.calibrationTarget.update(el, HIGHLIGHT_EL_ID_PREFIX),
704
723
  origin: false,
705
724
  rootContainer: this.core.container,
706
- zoom: 1
725
+ zoom: 2
707
726
  });
708
727
  }
709
728
  clearHighlight() {
@@ -719,42 +738,15 @@
719
738
  }
720
739
  }
721
740
 
722
- class Rule extends EventEmitter__default["default"] {
741
+ class Rule extends EventEmitter__default.default {
742
+ hGuides;
743
+ vGuides;
744
+ horizontalGuidelines = [];
745
+ verticalGuidelines = [];
746
+ container;
747
+ containerResizeObserver;
723
748
  constructor(container) {
724
749
  super();
725
- this.horizontalGuidelines = [];
726
- this.verticalGuidelines = [];
727
- this.getGuidesStyle = (type) => ({
728
- position: "fixed",
729
- zIndex: 1,
730
- left: type === GuidesType.HORIZONTAL ? 0 : "-30px",
731
- top: type === GuidesType.HORIZONTAL ? "-30px" : 0,
732
- width: type === GuidesType.HORIZONTAL ? "100%" : "30px",
733
- height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
734
- });
735
- this.createGuides = (type, defaultGuides = []) => new Guides__default["default"](this.container, {
736
- type,
737
- defaultGuides,
738
- displayDragPos: true,
739
- backgroundColor: "#fff",
740
- lineColor: "#000",
741
- textColor: "#000",
742
- style: this.getGuidesStyle(type)
743
- });
744
- this.hGuidesChangeGuidesHandler = (e) => {
745
- this.horizontalGuidelines = e.guides;
746
- this.emit("changeGuides", {
747
- type: GuidesType.HORIZONTAL,
748
- guides: this.horizontalGuidelines
749
- });
750
- };
751
- this.vGuidesChangeGuidesHandler = (e) => {
752
- this.verticalGuidelines = e.guides;
753
- this.emit("changeGuides", {
754
- type: GuidesType.VERTICAL,
755
- guides: this.verticalGuidelines
756
- });
757
- };
758
750
  this.container = container;
759
751
  this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
760
752
  this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
@@ -826,6 +818,37 @@
826
818
  this.containerResizeObserver.disconnect();
827
819
  this.removeAllListeners();
828
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
+ };
829
852
  }
830
853
 
831
854
  const wrapperClassName = "editor-mask-wrapper";
@@ -859,74 +882,30 @@
859
882
  return el;
860
883
  };
861
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);
862
906
  constructor(config) {
863
907
  const wrapper = createWrapper();
864
908
  super(wrapper);
865
- this.content = createContent();
866
- this.page = null;
867
- this.pageScrollParent = null;
868
- this.scrollTop = 0;
869
- this.scrollLeft = 0;
870
- this.width = 0;
871
- this.height = 0;
872
- this.wrapperHeight = 0;
873
- this.wrapperWidth = 0;
874
- this.maxScrollTop = 0;
875
- this.maxScrollLeft = 0;
876
- this.intersectionObserver = null;
877
- this.shiftKeyDown = false;
878
- this.mode = Mode.ABSOLUTE;
879
- this.pageResizeObserver = null;
880
- this.wrapperResizeObserver = null;
881
- this.highlightHandler = lodashEs.throttle((event) => {
882
- this.emit("highlight", event);
883
- }, throttleTime);
884
- this.mouseDownHandler = (event) => {
885
- this.emit("clearHighlight");
886
- event.stopImmediatePropagation();
887
- event.stopPropagation();
888
- if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
889
- return;
890
- if (!this.shiftKeyDown && event.target.className.indexOf("moveable-area") !== -1) {
891
- return;
892
- }
893
- if (event.target.className.indexOf("moveable-control") !== -1) {
894
- return;
895
- }
896
- this.content.removeEventListener("mousemove", this.highlightHandler);
897
- if (this.shiftKeyDown) {
898
- this.emit("beforeMultiSelect", event);
899
- } else {
900
- this.emit("beforeSelect", event);
901
- globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
902
- }
903
- };
904
- this.mouseUpHandler = () => {
905
- globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
906
- this.content.addEventListener("mousemove", this.highlightHandler);
907
- this.emit("select");
908
- };
909
- this.mouseWheelHandler = (event) => {
910
- this.emit("clearHighlight");
911
- if (!this.page)
912
- throw new Error("page \u672A\u521D\u59CB\u5316");
913
- const { deltaY, deltaX } = event;
914
- if (this.page.clientHeight < this.wrapperHeight && deltaY)
915
- return;
916
- if (this.page.clientWidth < this.wrapperWidth && deltaX)
917
- return;
918
- if (this.maxScrollTop > 0) {
919
- this.scrollTop = this.scrollTop + deltaY;
920
- }
921
- if (this.maxScrollLeft > 0) {
922
- this.scrollLeft = this.scrollLeft + deltaX;
923
- }
924
- this.scroll();
925
- this.emit("scroll", event);
926
- };
927
- this.mouseLeaveHandler = () => {
928
- setTimeout(() => this.emit("clearHighlight"), throttleTime);
929
- };
930
909
  this.wrapper = wrapper;
931
910
  this.core = config.core;
932
911
  this.content.addEventListener("mousedown", this.mouseDownHandler);
@@ -934,13 +913,13 @@
934
913
  this.content.addEventListener("wheel", this.mouseWheelHandler);
935
914
  this.content.addEventListener("mousemove", this.highlightHandler);
936
915
  this.content.addEventListener("mouseleave", this.mouseLeaveHandler);
937
- KeyController__default["default"].global.keydown("shift", (e) => {
916
+ KeyController__default.default.global.keydown("shift", (e) => {
938
917
  e.inputEvent.preventDefault();
939
- this.shiftKeyDown = true;
918
+ this.isMultiSelectStatus = true;
940
919
  });
941
- KeyController__default["default"].global.keyup("shift", (e) => {
920
+ KeyController__default.default.global.keyup("shift", (e) => {
942
921
  e.inputEvent.preventDefault();
943
- this.shiftKeyDown = false;
922
+ this.isMultiSelectStatus = false;
944
923
  });
945
924
  }
946
925
  setMode(mode) {
@@ -1070,13 +1049,66 @@
1070
1049
  if (this.maxScrollLeft < this.scrollLeft)
1071
1050
  this.scrollLeft = this.maxScrollLeft;
1072
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
+ };
1073
1100
  }
1074
1101
 
1075
1102
  class StageMultiDragResize extends EventEmitter.EventEmitter {
1103
+ core;
1104
+ mask;
1105
+ container;
1106
+ targetList = [];
1107
+ dragElList = [];
1108
+ moveableForMulti;
1109
+ multiMoveableHelper;
1076
1110
  constructor(config) {
1077
1111
  super();
1078
- this.targetList = [];
1079
- this.dragElList = [];
1080
1112
  this.core = config.core;
1081
1113
  this.container = config.container;
1082
1114
  this.mask = config.mask;
@@ -1097,20 +1129,10 @@
1097
1129
  });
1098
1130
  this.moveableForMulti?.destroy();
1099
1131
  this.multiMoveableHelper?.clear();
1100
- this.moveableForMulti = new Moveable__default["default"](this.container, {
1101
- target: this.dragElList,
1102
- defaultGroupRotate: 0,
1103
- defaultGroupOrigin: "50% 50%",
1104
- draggable: true,
1105
- resizable: true,
1106
- throttleDrag: 0,
1107
- startDragRotate: 0,
1108
- throttleDragRotate: 0,
1109
- zoom: 1,
1110
- origin: true,
1111
- padding: { left: 0, top: 0, right: 0, bottom: 0 }
1112
- });
1113
- this.multiMoveableHelper = MoveableHelper__default["default"].create({
1132
+ this.moveableForMulti = new Moveable__default.default(this.container, this.getOptions({
1133
+ target: this.dragElList
1134
+ }));
1135
+ this.multiMoveableHelper = MoveableHelper__default.default.create({
1114
1136
  useBeforeRender: true,
1115
1137
  useRender: false,
1116
1138
  createAuto: true
@@ -1149,12 +1171,31 @@
1149
1171
  this.update();
1150
1172
  });
1151
1173
  }
1174
+ canSelect(el) {
1175
+ if (el.className.includes(PAGE_CLASS)) {
1176
+ this.core.highlightedDom = void 0;
1177
+ this.core.highlightLayer.clearHighlight();
1178
+ return false;
1179
+ }
1180
+ const currentTargetMode = getMode(el);
1181
+ let selectedDomMode = "";
1182
+ if (this.targetList.length === 0 && this.core.selectedDom) {
1183
+ selectedDomMode = getMode(this.core.selectedDom);
1184
+ } else if (this.targetList.length > 0) {
1185
+ selectedDomMode = getMode(this.targetList[0]);
1186
+ }
1187
+ if (currentTargetMode !== selectedDomMode) {
1188
+ return false;
1189
+ }
1190
+ return true;
1191
+ }
1152
1192
  clearSelectStatus() {
1153
1193
  if (!this.moveableForMulti)
1154
1194
  return;
1155
1195
  this.destroyDragElList();
1156
1196
  this.moveableForMulti.target = null;
1157
1197
  this.moveableForMulti.updateTarget();
1198
+ this.targetList = [];
1158
1199
  }
1159
1200
  destroy() {
1160
1201
  this.moveableForMulti?.destroy();
@@ -1182,49 +1223,39 @@
1182
1223
  });
1183
1224
  });
1184
1225
  }
1226
+ getOptions(options = {}) {
1227
+ let { multiMoveableOptions = {} } = this.core.config;
1228
+ if (typeof multiMoveableOptions === "function") {
1229
+ multiMoveableOptions = multiMoveableOptions(this.core);
1230
+ }
1231
+ return {
1232
+ defaultGroupRotate: 0,
1233
+ defaultGroupOrigin: "50% 50%",
1234
+ draggable: true,
1235
+ resizable: true,
1236
+ throttleDrag: 0,
1237
+ startDragRotate: 0,
1238
+ throttleDragRotate: 0,
1239
+ zoom: 1,
1240
+ origin: true,
1241
+ padding: { left: 0, top: 0, right: 0, bottom: 0 },
1242
+ ...options,
1243
+ ...multiMoveableOptions
1244
+ };
1245
+ }
1185
1246
  }
1186
1247
 
1187
- var 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}\n";
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";
1188
1249
 
1189
1250
  class StageRender extends EventEmitter.EventEmitter {
1251
+ contentWindow = null;
1252
+ runtime = null;
1253
+ iframe;
1254
+ runtimeUrl;
1255
+ core;
1256
+ render;
1190
1257
  constructor({ core }) {
1191
1258
  super();
1192
- this.contentWindow = null;
1193
- this.runtime = null;
1194
- this.getMagicApi = () => ({
1195
- onPageElUpdate: (el) => this.emit("page-el-update", el),
1196
- onRuntimeReady: (runtime) => {
1197
- this.runtime = runtime;
1198
- globalThis.runtime = runtime;
1199
- this.emit("runtime-ready", runtime);
1200
- }
1201
- });
1202
- this.getRuntime = () => {
1203
- if (this.runtime)
1204
- return Promise.resolve(this.runtime);
1205
- return new Promise((resolve) => {
1206
- const listener = (runtime) => {
1207
- this.off("runtime-ready", listener);
1208
- resolve(runtime);
1209
- };
1210
- this.on("runtime-ready", listener);
1211
- });
1212
- };
1213
- this.loadHandler = async () => {
1214
- this.contentWindow = this.iframe?.contentWindow;
1215
- this.contentWindow.magic = this.getMagicApi();
1216
- if (this.render) {
1217
- const el = await this.render(this.core);
1218
- if (el) {
1219
- this.iframe?.contentDocument?.body?.appendChild(el);
1220
- }
1221
- }
1222
- this.emit("onload");
1223
- this.contentWindow.postMessage({
1224
- tmagicRuntimeReady: true
1225
- }, "*");
1226
- utils.injectStyle(this.contentWindow.document, style);
1227
- };
1228
1259
  this.core = core;
1229
1260
  this.runtimeUrl = core.config.runtimeUrl || "";
1230
1261
  this.render = core.config.render;
@@ -1237,20 +1268,39 @@
1237
1268
  `;
1238
1269
  this.iframe.addEventListener("load", this.loadHandler);
1239
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
+ });
1240
1279
  async mount(el) {
1241
- if (this.iframe) {
1242
- if (!utils.isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
1243
- let html = await fetch(this.runtimeUrl).then((res) => res.text());
1244
- const base = `${location.protocol}//${utils.getHost(this.runtimeUrl)}`;
1245
- html = html.replace("<head>", `<head>
1246
- <base href="${base}">`);
1247
- this.iframe.srcdoc = html;
1248
- }
1249
- el.appendChild(this.iframe);
1250
- } else {
1280
+ if (!this.iframe) {
1251
1281
  throw Error("mount \u5931\u8D25");
1252
1282
  }
1253
- }
1283
+ if (!utils.isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
1284
+ let html = await fetch(this.runtimeUrl).then((res) => res.text());
1285
+ const base = `${location.protocol}//${utils.getHost(this.runtimeUrl)}`;
1286
+ html = html.replace("<head>", `<head>
1287
+ <base href="${base}">`);
1288
+ this.iframe.srcdoc = html;
1289
+ }
1290
+ el.appendChild(this.iframe);
1291
+ this.postTmagicRuntimeReady();
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
+ };
1254
1304
  destroy() {
1255
1305
  this.iframe?.removeEventListener("load", this.loadHandler);
1256
1306
  this.contentWindow = null;
@@ -1258,13 +1308,48 @@
1258
1308
  this.iframe = void 0;
1259
1309
  this.removeAllListeners();
1260
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
+ };
1326
+ postTmagicRuntimeReady() {
1327
+ this.contentWindow = this.iframe?.contentWindow;
1328
+ this.contentWindow.magic = this.getMagicApi();
1329
+ this.contentWindow.postMessage({
1330
+ tmagicRuntimeReady: true
1331
+ }, "*");
1332
+ }
1261
1333
  }
1262
1334
 
1263
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;
1264
1351
  constructor(config) {
1265
1352
  super();
1266
- this.selectedDomList = [];
1267
- this.zoom = DEFAULT_ZOOM;
1268
1353
  this.config = config;
1269
1354
  this.setZoom(config.zoom);
1270
1355
  this.canSelect = config.canSelect || ((el) => !!el.id);
@@ -1294,7 +1379,7 @@
1294
1379
  this.dr.setGuidelines(data.type, data.guides);
1295
1380
  this.emit("changeGuides", data);
1296
1381
  }).on("highlight", async (event) => {
1297
- const el = await this.getElementFromPoint(event, "mousemove");
1382
+ const el = await this.getElementFromPoint(event);
1298
1383
  if (!el)
1299
1384
  return;
1300
1385
  await this.highlight(el);
@@ -1309,9 +1394,6 @@
1309
1394
  const el = await this.getElementFromPoint(event);
1310
1395
  if (!el)
1311
1396
  return;
1312
- if (el.className.includes(PAGE_CLASS))
1313
- return;
1314
- this.clearSelectStatus("select");
1315
1397
  if (this.selectedDom && !this.selectedDom.className.includes(PAGE_CLASS)) {
1316
1398
  this.selectedDomList.push(this.selectedDom);
1317
1399
  this.selectedDom = void 0;
@@ -1322,8 +1404,7 @@
1322
1404
  } else {
1323
1405
  this.selectedDomList.push(el);
1324
1406
  }
1325
- this.multiDr.multiSelect(this.selectedDomList);
1326
- this.emit("multiSelect", this.selectedDomList);
1407
+ this.multiSelect(this.selectedDomList);
1327
1408
  });
1328
1409
  this.dr.on("update", (data) => {
1329
1410
  setTimeout(() => this.emit("update", data));
@@ -1348,22 +1429,29 @@
1348
1429
  }
1349
1430
  return doc?.elementsFromPoint(x / zoom, y / zoom);
1350
1431
  }
1351
- async getElementFromPoint(event, type) {
1432
+ async getElementFromPoint(event) {
1352
1433
  const els = this.getElementsFromPoint(event);
1353
1434
  let stopped = false;
1354
1435
  const stop = () => stopped = true;
1355
1436
  for (const el of els) {
1356
- if (!el.id.startsWith(GHOST_EL_ID_PREFIX) && await this.canSelect(el, event, stop)) {
1437
+ if (!el.id.startsWith(GHOST_EL_ID_PREFIX) && await this.isElCanSelect(el, event, stop)) {
1357
1438
  if (stopped)
1358
1439
  break;
1359
- if (event.type === type) {
1360
- return el;
1361
- }
1362
1440
  return el;
1363
1441
  }
1364
1442
  }
1365
1443
  }
1444
+ async isElCanSelect(el, event, stop) {
1445
+ const canSelectByProp = await this.canSelect(el, event, stop);
1446
+ if (!canSelectByProp)
1447
+ return false;
1448
+ if (this.mask.isMultiSelectStatus) {
1449
+ return this.multiDr.canSelect(el);
1450
+ }
1451
+ return true;
1452
+ }
1366
1453
  async select(idOrEl, event) {
1454
+ this.clearSelectStatus("multiSelect");
1367
1455
  const el = await this.getTargetElement(idOrEl);
1368
1456
  if (el === this.selectedDom)
1369
1457
  return;
@@ -1373,7 +1461,6 @@
1373
1461
  await runtime.beforeSelect(el);
1374
1462
  }
1375
1463
  this.mask.setLayout(el);
1376
- this.multiDr.destroyDragElList();
1377
1464
  this.dr.select(el, event);
1378
1465
  if (this.config.autoScrollIntoView || el.dataset.autoScrollIntoView) {
1379
1466
  this.mask.intersectionObserver?.observe(el);
@@ -1386,6 +1473,12 @@
1386
1473
  }
1387
1474
  }
1388
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
+ }
1389
1482
  update(data) {
1390
1483
  const { config } = data;
1391
1484
  return this.renderer?.getRuntime().then((runtime) => {
@@ -1498,7 +1591,8 @@
1498
1591
  exports.ZIndex = ZIndex;
1499
1592
  exports.addSelectedClassName = addSelectedClassName;
1500
1593
  exports.calcValueByFontsize = calcValueByFontsize;
1501
- exports["default"] = StageCore;
1594
+ exports.default = StageCore;
1595
+ exports.down = down;
1502
1596
  exports.getAbsolutePosition = getAbsolutePosition;
1503
1597
  exports.getMode = getMode;
1504
1598
  exports.getOffset = getOffset;
@@ -1510,6 +1604,7 @@
1510
1604
  exports.isRelative = isRelative;
1511
1605
  exports.isStatic = isStatic;
1512
1606
  exports.removeSelectedClassName = removeSelectedClassName;
1607
+ exports.up = up;
1513
1608
 
1514
1609
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
1515
1610