@tmagic/stage 1.1.0-beta.4 → 1.1.0-beta.7

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.
@@ -204,14 +204,22 @@ const up = (deltaTop, target) => {
204
204
  };
205
205
 
206
206
  class StageDragResize extends EventEmitter {
207
+ core;
208
+ mask;
209
+ container;
210
+ target;
211
+ dragEl;
212
+ moveable;
213
+ horizontalGuidelines = [];
214
+ verticalGuidelines = [];
215
+ elementGuidelines = [];
216
+ mode = Mode.ABSOLUTE;
217
+ moveableOptions = {};
218
+ dragStatus = "end" /* END */;
219
+ ghostEl;
220
+ moveableHelper;
207
221
  constructor(config) {
208
222
  super();
209
- this.horizontalGuidelines = [];
210
- this.verticalGuidelines = [];
211
- this.elementGuidelines = [];
212
- this.mode = Mode.ABSOLUTE;
213
- this.moveableOptions = {};
214
- this.dragStatus = "end" /* END */;
215
223
  this.core = config.core;
216
224
  this.container = config.container;
217
225
  this.mask = config.mask;
@@ -537,7 +545,7 @@ class StageDragResize extends EventEmitter {
537
545
  return ghostEl;
538
546
  }
539
547
  setGhostElChildrenId(el) {
540
- for (const child of el.children) {
548
+ for (const child of Array.from(el.children)) {
541
549
  if (child.id) {
542
550
  child.id = `${GHOST_EL_ID_PREFIX}${child.id}`;
543
551
  }
@@ -611,6 +619,11 @@ class StageDragResize extends EventEmitter {
611
619
  }
612
620
 
613
621
  class TargetCalibrate extends EventEmitter {
622
+ parent;
623
+ mask;
624
+ dr;
625
+ core;
626
+ operationEl;
614
627
  constructor(config) {
615
628
  super();
616
629
  this.parent = config.parent;
@@ -630,6 +643,7 @@ class TargetCalibrate extends EventEmitter {
630
643
  top: ${top}px;
631
644
  width: ${el.clientWidth}px;
632
645
  height: ${el.clientHeight}px;
646
+ z-index: ${ZIndex.DRAG_EL};
633
647
  `;
634
648
  this.operationEl.id = `${prefix}${el.id}`;
635
649
  if (typeof this.core.config.updateDragEl === "function") {
@@ -677,6 +691,11 @@ class TargetCalibrate extends EventEmitter {
677
691
  }
678
692
 
679
693
  class StageHighlight extends EventEmitter {
694
+ core;
695
+ container;
696
+ target;
697
+ moveable;
698
+ calibrationTarget;
680
699
  constructor(config) {
681
700
  super();
682
701
  this.core = config.core;
@@ -697,7 +716,7 @@ class StageHighlight extends EventEmitter {
697
716
  target: this.calibrationTarget.update(el, HIGHLIGHT_EL_ID_PREFIX),
698
717
  origin: false,
699
718
  rootContainer: this.core.container,
700
- zoom: 1
719
+ zoom: 2
701
720
  });
702
721
  }
703
722
  clearHighlight() {
@@ -714,41 +733,14 @@ class StageHighlight extends EventEmitter {
714
733
  }
715
734
 
716
735
  class Rule extends EventEmitter$1 {
736
+ hGuides;
737
+ vGuides;
738
+ horizontalGuidelines = [];
739
+ verticalGuidelines = [];
740
+ container;
741
+ containerResizeObserver;
717
742
  constructor(container) {
718
743
  super();
719
- this.horizontalGuidelines = [];
720
- this.verticalGuidelines = [];
721
- this.getGuidesStyle = (type) => ({
722
- position: "fixed",
723
- zIndex: 1,
724
- left: type === GuidesType.HORIZONTAL ? 0 : "-30px",
725
- top: type === GuidesType.HORIZONTAL ? "-30px" : 0,
726
- width: type === GuidesType.HORIZONTAL ? "100%" : "30px",
727
- height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
728
- });
729
- this.createGuides = (type, defaultGuides = []) => new Guides(this.container, {
730
- type,
731
- defaultGuides,
732
- displayDragPos: true,
733
- backgroundColor: "#fff",
734
- lineColor: "#000",
735
- textColor: "#000",
736
- style: this.getGuidesStyle(type)
737
- });
738
- this.hGuidesChangeGuidesHandler = (e) => {
739
- this.horizontalGuidelines = e.guides;
740
- this.emit("changeGuides", {
741
- type: GuidesType.HORIZONTAL,
742
- guides: this.horizontalGuidelines
743
- });
744
- };
745
- this.vGuidesChangeGuidesHandler = (e) => {
746
- this.verticalGuidelines = e.guides;
747
- this.emit("changeGuides", {
748
- type: GuidesType.VERTICAL,
749
- guides: this.verticalGuidelines
750
- });
751
- };
752
744
  this.container = container;
753
745
  this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
754
746
  this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
@@ -820,6 +812,37 @@ class Rule extends EventEmitter$1 {
820
812
  this.containerResizeObserver.disconnect();
821
813
  this.removeAllListeners();
822
814
  }
815
+ getGuidesStyle = (type) => ({
816
+ position: "fixed",
817
+ zIndex: 1,
818
+ left: type === GuidesType.HORIZONTAL ? 0 : "-30px",
819
+ top: type === GuidesType.HORIZONTAL ? "-30px" : 0,
820
+ width: type === GuidesType.HORIZONTAL ? "100%" : "30px",
821
+ height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
822
+ });
823
+ createGuides = (type, defaultGuides = []) => new Guides(this.container, {
824
+ type,
825
+ defaultGuides,
826
+ displayDragPos: true,
827
+ backgroundColor: "#fff",
828
+ lineColor: "#000",
829
+ textColor: "#000",
830
+ style: this.getGuidesStyle(type)
831
+ });
832
+ hGuidesChangeGuidesHandler = (e) => {
833
+ this.horizontalGuidelines = e.guides;
834
+ this.emit("changeGuides", {
835
+ type: GuidesType.HORIZONTAL,
836
+ guides: this.horizontalGuidelines
837
+ });
838
+ };
839
+ vGuidesChangeGuidesHandler = (e) => {
840
+ this.verticalGuidelines = e.guides;
841
+ this.emit("changeGuides", {
842
+ type: GuidesType.VERTICAL,
843
+ guides: this.verticalGuidelines
844
+ });
845
+ };
823
846
  }
824
847
 
825
848
  const wrapperClassName = "editor-mask-wrapper";
@@ -853,74 +876,30 @@ const createWrapper = () => {
853
876
  return el;
854
877
  };
855
878
  class StageMask extends Rule {
879
+ content = createContent();
880
+ wrapper;
881
+ core;
882
+ page = null;
883
+ pageScrollParent = null;
884
+ scrollTop = 0;
885
+ scrollLeft = 0;
886
+ width = 0;
887
+ height = 0;
888
+ wrapperHeight = 0;
889
+ wrapperWidth = 0;
890
+ maxScrollTop = 0;
891
+ maxScrollLeft = 0;
892
+ intersectionObserver = null;
893
+ isMultiSelectStatus = false;
894
+ mode = Mode.ABSOLUTE;
895
+ pageResizeObserver = null;
896
+ wrapperResizeObserver = null;
897
+ highlightHandler = throttle((event) => {
898
+ this.emit("highlight", event);
899
+ }, throttleTime);
856
900
  constructor(config) {
857
901
  const wrapper = createWrapper();
858
902
  super(wrapper);
859
- this.content = createContent();
860
- this.page = null;
861
- this.pageScrollParent = null;
862
- this.scrollTop = 0;
863
- this.scrollLeft = 0;
864
- this.width = 0;
865
- this.height = 0;
866
- this.wrapperHeight = 0;
867
- this.wrapperWidth = 0;
868
- this.maxScrollTop = 0;
869
- this.maxScrollLeft = 0;
870
- this.intersectionObserver = null;
871
- this.shiftKeyDown = false;
872
- this.mode = Mode.ABSOLUTE;
873
- this.pageResizeObserver = null;
874
- this.wrapperResizeObserver = null;
875
- this.highlightHandler = throttle((event) => {
876
- this.emit("highlight", event);
877
- }, throttleTime);
878
- this.mouseDownHandler = (event) => {
879
- this.emit("clearHighlight");
880
- event.stopImmediatePropagation();
881
- event.stopPropagation();
882
- if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
883
- return;
884
- if (!this.shiftKeyDown && event.target.className.indexOf("moveable-area") !== -1) {
885
- return;
886
- }
887
- if (event.target.className.indexOf("moveable-control") !== -1) {
888
- return;
889
- }
890
- this.content.removeEventListener("mousemove", this.highlightHandler);
891
- if (this.shiftKeyDown) {
892
- this.emit("beforeMultiSelect", event);
893
- } else {
894
- this.emit("beforeSelect", event);
895
- globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
896
- }
897
- };
898
- this.mouseUpHandler = () => {
899
- globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
900
- this.content.addEventListener("mousemove", this.highlightHandler);
901
- this.emit("select");
902
- };
903
- this.mouseWheelHandler = (event) => {
904
- this.emit("clearHighlight");
905
- if (!this.page)
906
- throw new Error("page \u672A\u521D\u59CB\u5316");
907
- const { deltaY, deltaX } = event;
908
- if (this.page.clientHeight < this.wrapperHeight && deltaY)
909
- return;
910
- if (this.page.clientWidth < this.wrapperWidth && deltaX)
911
- return;
912
- if (this.maxScrollTop > 0) {
913
- this.scrollTop = this.scrollTop + deltaY;
914
- }
915
- if (this.maxScrollLeft > 0) {
916
- this.scrollLeft = this.scrollLeft + deltaX;
917
- }
918
- this.scroll();
919
- this.emit("scroll", event);
920
- };
921
- this.mouseLeaveHandler = () => {
922
- setTimeout(() => this.emit("clearHighlight"), throttleTime);
923
- };
924
903
  this.wrapper = wrapper;
925
904
  this.core = config.core;
926
905
  this.content.addEventListener("mousedown", this.mouseDownHandler);
@@ -928,13 +907,15 @@ class StageMask extends Rule {
928
907
  this.content.addEventListener("wheel", this.mouseWheelHandler);
929
908
  this.content.addEventListener("mousemove", this.highlightHandler);
930
909
  this.content.addEventListener("mouseleave", this.mouseLeaveHandler);
931
- KeyController.global.keydown("shift", (e) => {
910
+ const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
911
+ const ctrl = isMac ? "meta" : "ctrl";
912
+ KeyController.global.keydown(ctrl, (e) => {
932
913
  e.inputEvent.preventDefault();
933
- this.shiftKeyDown = true;
914
+ this.isMultiSelectStatus = true;
934
915
  });
935
- KeyController.global.keyup("shift", (e) => {
916
+ KeyController.global.keyup(ctrl, (e) => {
936
917
  e.inputEvent.preventDefault();
937
- this.shiftKeyDown = false;
918
+ this.isMultiSelectStatus = false;
938
919
  });
939
920
  }
940
921
  setMode(mode) {
@@ -1064,13 +1045,66 @@ class StageMask extends Rule {
1064
1045
  if (this.maxScrollLeft < this.scrollLeft)
1065
1046
  this.scrollLeft = this.maxScrollLeft;
1066
1047
  }
1048
+ mouseDownHandler = (event) => {
1049
+ this.emit("clearHighlight");
1050
+ event.stopImmediatePropagation();
1051
+ event.stopPropagation();
1052
+ if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
1053
+ return;
1054
+ if (!this.isMultiSelectStatus && event.target.className.indexOf("moveable-area") !== -1) {
1055
+ return;
1056
+ }
1057
+ if (event.target.className.indexOf("moveable-control") !== -1) {
1058
+ return;
1059
+ }
1060
+ this.content.removeEventListener("mousemove", this.highlightHandler);
1061
+ if (this.isMultiSelectStatus) {
1062
+ this.emit("beforeMultiSelect", event);
1063
+ } else {
1064
+ this.emit("beforeSelect", event);
1065
+ }
1066
+ globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
1067
+ };
1068
+ mouseUpHandler = () => {
1069
+ globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
1070
+ this.content.addEventListener("mousemove", this.highlightHandler);
1071
+ if (!this.isMultiSelectStatus) {
1072
+ this.emit("select");
1073
+ }
1074
+ };
1075
+ mouseWheelHandler = (event) => {
1076
+ this.emit("clearHighlight");
1077
+ if (!this.page)
1078
+ throw new Error("page \u672A\u521D\u59CB\u5316");
1079
+ const { deltaY, deltaX } = event;
1080
+ if (this.page.clientHeight < this.wrapperHeight && deltaY)
1081
+ return;
1082
+ if (this.page.clientWidth < this.wrapperWidth && deltaX)
1083
+ return;
1084
+ if (this.maxScrollTop > 0) {
1085
+ this.scrollTop = this.scrollTop + deltaY;
1086
+ }
1087
+ if (this.maxScrollLeft > 0) {
1088
+ this.scrollLeft = this.scrollLeft + deltaX;
1089
+ }
1090
+ this.scroll();
1091
+ this.emit("scroll", event);
1092
+ };
1093
+ mouseLeaveHandler = () => {
1094
+ setTimeout(() => this.emit("clearHighlight"), throttleTime);
1095
+ };
1067
1096
  }
1068
1097
 
1069
1098
  class StageMultiDragResize extends EventEmitter {
1099
+ core;
1100
+ mask;
1101
+ container;
1102
+ targetList = [];
1103
+ dragElList = [];
1104
+ moveableForMulti;
1105
+ multiMoveableHelper;
1070
1106
  constructor(config) {
1071
1107
  super();
1072
- this.targetList = [];
1073
- this.dragElList = [];
1074
1108
  this.core = config.core;
1075
1109
  this.container = config.container;
1076
1110
  this.mask = config.mask;
@@ -1091,19 +1125,9 @@ class StageMultiDragResize extends EventEmitter {
1091
1125
  });
1092
1126
  this.moveableForMulti?.destroy();
1093
1127
  this.multiMoveableHelper?.clear();
1094
- this.moveableForMulti = new Moveable(this.container, {
1095
- target: this.dragElList,
1096
- defaultGroupRotate: 0,
1097
- defaultGroupOrigin: "50% 50%",
1098
- draggable: true,
1099
- resizable: true,
1100
- throttleDrag: 0,
1101
- startDragRotate: 0,
1102
- throttleDragRotate: 0,
1103
- zoom: 1,
1104
- origin: true,
1105
- padding: { left: 0, top: 0, right: 0, bottom: 0 }
1106
- });
1128
+ this.moveableForMulti = new Moveable(this.container, this.getOptions({
1129
+ target: this.dragElList
1130
+ }));
1107
1131
  this.multiMoveableHelper = MoveableHelper.create({
1108
1132
  useBeforeRender: true,
1109
1133
  useRender: false,
@@ -1143,12 +1167,35 @@ class StageMultiDragResize extends EventEmitter {
1143
1167
  this.update();
1144
1168
  });
1145
1169
  }
1170
+ canSelect(el, stop) {
1171
+ if (el.className.includes(PAGE_CLASS)) {
1172
+ this.core.highlightedDom = void 0;
1173
+ this.core.highlightLayer.clearHighlight();
1174
+ stop();
1175
+ return false;
1176
+ }
1177
+ const currentTargetMode = getMode(el);
1178
+ let selectedDomMode = "";
1179
+ if (this.core.selectedDom?.className.includes(PAGE_CLASS)) {
1180
+ return true;
1181
+ }
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
+ }
1146
1192
  clearSelectStatus() {
1147
1193
  if (!this.moveableForMulti)
1148
1194
  return;
1149
1195
  this.destroyDragElList();
1150
1196
  this.moveableForMulti.target = null;
1151
1197
  this.moveableForMulti.updateTarget();
1198
+ this.targetList = [];
1152
1199
  }
1153
1200
  destroy() {
1154
1201
  this.moveableForMulti?.destroy();
@@ -1176,49 +1223,39 @@ class StageMultiDragResize extends EventEmitter {
1176
1223
  });
1177
1224
  });
1178
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
+ }
1179
1246
  }
1180
1247
 
1181
- 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";
1182
1249
 
1183
1250
  class StageRender extends EventEmitter {
1251
+ contentWindow = null;
1252
+ runtime = null;
1253
+ iframe;
1254
+ runtimeUrl;
1255
+ core;
1256
+ render;
1184
1257
  constructor({ core }) {
1185
1258
  super();
1186
- this.contentWindow = null;
1187
- this.runtime = null;
1188
- this.getMagicApi = () => ({
1189
- onPageElUpdate: (el) => this.emit("page-el-update", el),
1190
- onRuntimeReady: (runtime) => {
1191
- this.runtime = runtime;
1192
- globalThis.runtime = runtime;
1193
- this.emit("runtime-ready", runtime);
1194
- }
1195
- });
1196
- this.getRuntime = () => {
1197
- if (this.runtime)
1198
- return Promise.resolve(this.runtime);
1199
- return new Promise((resolve) => {
1200
- const listener = (runtime) => {
1201
- this.off("runtime-ready", listener);
1202
- resolve(runtime);
1203
- };
1204
- this.on("runtime-ready", listener);
1205
- });
1206
- };
1207
- this.loadHandler = async () => {
1208
- this.contentWindow = this.iframe?.contentWindow;
1209
- this.contentWindow.magic = this.getMagicApi();
1210
- if (this.render) {
1211
- const el = await this.render(this.core);
1212
- if (el) {
1213
- this.iframe?.contentDocument?.body?.appendChild(el);
1214
- }
1215
- }
1216
- this.emit("onload");
1217
- this.contentWindow.postMessage({
1218
- tmagicRuntimeReady: true
1219
- }, "*");
1220
- injectStyle(this.contentWindow.document, style);
1221
- };
1222
1259
  this.core = core;
1223
1260
  this.runtimeUrl = core.config.runtimeUrl || "";
1224
1261
  this.render = core.config.render;
@@ -1231,20 +1268,39 @@ class StageRender extends EventEmitter {
1231
1268
  `;
1232
1269
  this.iframe.addEventListener("load", this.loadHandler);
1233
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
+ });
1234
1279
  async mount(el) {
1235
- if (this.iframe) {
1236
- if (!isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
1237
- let html = await fetch(this.runtimeUrl).then((res) => res.text());
1238
- const base = `${location.protocol}//${getHost(this.runtimeUrl)}`;
1239
- html = html.replace("<head>", `<head>
1240
- <base href="${base}">`);
1241
- this.iframe.srcdoc = html;
1242
- }
1243
- el.appendChild(this.iframe);
1244
- } else {
1280
+ if (!this.iframe) {
1245
1281
  throw Error("mount \u5931\u8D25");
1246
1282
  }
1247
- }
1283
+ if (!isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
1284
+ let html = await fetch(this.runtimeUrl).then((res) => res.text());
1285
+ const base = `${location.protocol}//${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
+ };
1248
1304
  destroy() {
1249
1305
  this.iframe?.removeEventListener("load", this.loadHandler);
1250
1306
  this.contentWindow = null;
@@ -1252,13 +1308,48 @@ class StageRender extends EventEmitter {
1252
1308
  this.iframe = void 0;
1253
1309
  this.removeAllListeners();
1254
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
+ 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
+ }
1255
1333
  }
1256
1334
 
1257
1335
  class StageCore extends 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;
1258
1351
  constructor(config) {
1259
1352
  super();
1260
- this.selectedDomList = [];
1261
- this.zoom = DEFAULT_ZOOM;
1262
1353
  this.config = config;
1263
1354
  this.setZoom(config.zoom);
1264
1355
  this.canSelect = config.canSelect || ((el) => !!el.id);
@@ -1288,7 +1379,7 @@ class StageCore extends EventEmitter {
1288
1379
  this.dr.setGuidelines(data.type, data.guides);
1289
1380
  this.emit("changeGuides", data);
1290
1381
  }).on("highlight", async (event) => {
1291
- const el = await this.getElementFromPoint(event, "mousemove");
1382
+ const el = await this.getElementFromPoint(event);
1292
1383
  if (!el)
1293
1384
  return;
1294
1385
  await this.highlight(el);
@@ -1303,9 +1394,6 @@ class StageCore extends EventEmitter {
1303
1394
  const el = await this.getElementFromPoint(event);
1304
1395
  if (!el)
1305
1396
  return;
1306
- if (el.className.includes(PAGE_CLASS))
1307
- return;
1308
- this.clearSelectStatus("select");
1309
1397
  if (this.selectedDom && !this.selectedDom.className.includes(PAGE_CLASS)) {
1310
1398
  this.selectedDomList.push(this.selectedDom);
1311
1399
  this.selectedDom = void 0;
@@ -1316,8 +1404,7 @@ class StageCore extends EventEmitter {
1316
1404
  } else {
1317
1405
  this.selectedDomList.push(el);
1318
1406
  }
1319
- this.multiDr.multiSelect(this.selectedDomList);
1320
- this.emit("multiSelect", this.selectedDomList);
1407
+ this.multiSelect(this.selectedDomList);
1321
1408
  });
1322
1409
  this.dr.on("update", (data) => {
1323
1410
  setTimeout(() => this.emit("update", data));
@@ -1342,22 +1429,29 @@ class StageCore extends EventEmitter {
1342
1429
  }
1343
1430
  return doc?.elementsFromPoint(x / zoom, y / zoom);
1344
1431
  }
1345
- async getElementFromPoint(event, type) {
1432
+ async getElementFromPoint(event) {
1346
1433
  const els = this.getElementsFromPoint(event);
1347
1434
  let stopped = false;
1348
1435
  const stop = () => stopped = true;
1349
1436
  for (const el of els) {
1350
- 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)) {
1351
1438
  if (stopped)
1352
1439
  break;
1353
- if (event.type === type) {
1354
- return el;
1355
- }
1356
1440
  return el;
1357
1441
  }
1358
1442
  }
1359
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, stop);
1450
+ }
1451
+ return true;
1452
+ }
1360
1453
  async select(idOrEl, event) {
1454
+ this.clearSelectStatus("multiSelect");
1361
1455
  const el = await this.getTargetElement(idOrEl);
1362
1456
  if (el === this.selectedDom)
1363
1457
  return;
@@ -1367,7 +1461,6 @@ class StageCore extends EventEmitter {
1367
1461
  await runtime.beforeSelect(el);
1368
1462
  }
1369
1463
  this.mask.setLayout(el);
1370
- this.multiDr.destroyDragElList();
1371
1464
  this.dr.select(el, event);
1372
1465
  if (this.config.autoScrollIntoView || el.dataset.autoScrollIntoView) {
1373
1466
  this.mask.intersectionObserver?.observe(el);
@@ -1380,6 +1473,12 @@ class StageCore extends EventEmitter {
1380
1473
  }
1381
1474
  }
1382
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
+ }
1383
1482
  update(data) {
1384
1483
  const { config } = data;
1385
1484
  return this.renderer?.getRuntime().then((runtime) => {
@@ -1477,4 +1576,4 @@ class StageCore extends EventEmitter {
1477
1576
  }
1478
1577
 
1479
1578
  export { CONTAINER_HIGHLIGHT_CLASS, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, SELECTED_CLASS, StageDragResize, StageMask, StageRender, ZIndex, addSelectedClassName, calcValueByFontsize, StageCore as default, down, getAbsolutePosition, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isRelative, isStatic, removeSelectedClassName, up };
1480
- //# sourceMappingURL=tmagic-stage.es.js.map
1579
+ //# sourceMappingURL=tmagic-stage.mjs.map