@tmagic/stage 1.0.0-beta.12 → 1.0.0-beta.15
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 +230 -166
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +231 -168
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/StageDragResize.d.ts +2 -2
- package/dist/types/src/StageHighlight.d.ts +2 -0
- package/dist/types/src/TargetCalibrate.d.ts +18 -0
- package/dist/types/src/const.d.ts +1 -0
- package/dist/types/src/types.d.ts +7 -0
- package/package.json +11 -7
- package/src/StageDragResize.ts +2 -1
- package/src/StageHighlight.ts +13 -2
- package/src/StageMask.ts +4 -0
- package/src/TargetCalibrate.ts +135 -0
- package/src/const.ts +2 -0
- package/src/types.ts +8 -1
- package/tsconfig.json +0 -9
- package/vite.config.ts +0 -27
package/dist/tmagic-stage.umd.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
const GHOST_EL_ID_PREFIX = "ghost_el_";
|
|
15
15
|
const DRAG_EL_ID_PREFIX = "drag_el_";
|
|
16
|
+
const HIGHLIGHT_EL_ID_PREFIX = "highlight_el_";
|
|
16
17
|
const DEFAULT_ZOOM = 1;
|
|
17
18
|
var GuidesType = /* @__PURE__ */ ((GuidesType2) => {
|
|
18
19
|
GuidesType2["HORIZONTAL"] = "horizontal";
|
|
@@ -170,21 +171,14 @@
|
|
|
170
171
|
};
|
|
171
172
|
|
|
172
173
|
class StageDragResize extends EventEmitter.EventEmitter {
|
|
173
|
-
core;
|
|
174
|
-
container;
|
|
175
|
-
target;
|
|
176
|
-
dragEl;
|
|
177
|
-
moveable;
|
|
178
|
-
horizontalGuidelines = [];
|
|
179
|
-
verticalGuidelines = [];
|
|
180
|
-
elementGuidelines = [];
|
|
181
|
-
moveableOptions = {};
|
|
182
|
-
dragStatus = "end" /* END */;
|
|
183
|
-
ghostEl;
|
|
184
|
-
mode = Mode.ABSOLUTE;
|
|
185
|
-
moveableHelper;
|
|
186
174
|
constructor(config) {
|
|
187
175
|
super();
|
|
176
|
+
this.horizontalGuidelines = [];
|
|
177
|
+
this.verticalGuidelines = [];
|
|
178
|
+
this.elementGuidelines = [];
|
|
179
|
+
this.mode = Mode.ABSOLUTE;
|
|
180
|
+
this.moveableOptions = {};
|
|
181
|
+
this.dragStatus = "end" /* END */;
|
|
188
182
|
this.core = config.core;
|
|
189
183
|
this.container = config.container;
|
|
190
184
|
this.dragEl = globalThis.document.createElement("div");
|
|
@@ -406,6 +400,7 @@
|
|
|
406
400
|
top: ${offset.top}px;
|
|
407
401
|
width: ${width}px;
|
|
408
402
|
height: ${height}px;
|
|
403
|
+
z-index: 9;
|
|
409
404
|
`;
|
|
410
405
|
this.dragEl.id = `${DRAG_EL_ID_PREFIX}${el.id}`;
|
|
411
406
|
}
|
|
@@ -520,15 +515,97 @@
|
|
|
520
515
|
};
|
|
521
516
|
};
|
|
522
517
|
|
|
518
|
+
class TargetCalibrate extends EventEmitter.EventEmitter {
|
|
519
|
+
constructor(config) {
|
|
520
|
+
super();
|
|
521
|
+
this.parent = config.parent;
|
|
522
|
+
this.mask = config.mask;
|
|
523
|
+
this.dr = config.dr;
|
|
524
|
+
this.operationEl = globalThis.document.createElement("div");
|
|
525
|
+
this.parent.append(this.operationEl);
|
|
526
|
+
}
|
|
527
|
+
update(el, prefix) {
|
|
528
|
+
const { width, height } = el.getBoundingClientRect();
|
|
529
|
+
const { left, top } = this.getOffset(el);
|
|
530
|
+
this.operationEl.style.cssText = `
|
|
531
|
+
position: absolute;
|
|
532
|
+
left: ${left}px;
|
|
533
|
+
top: ${top}px;
|
|
534
|
+
width: ${width}px;
|
|
535
|
+
height: ${height}px;
|
|
536
|
+
`;
|
|
537
|
+
this.operationEl.id = `${prefix}${el.id}`;
|
|
538
|
+
return this.operationEl;
|
|
539
|
+
}
|
|
540
|
+
destroy() {
|
|
541
|
+
this.operationEl?.remove();
|
|
542
|
+
}
|
|
543
|
+
getOffset(el) {
|
|
544
|
+
const { transform } = getComputedStyle(el);
|
|
545
|
+
const { offsetParent } = el;
|
|
546
|
+
let left = el.offsetLeft;
|
|
547
|
+
let top = el.offsetTop;
|
|
548
|
+
if (transform.indexOf("matrix") > -1) {
|
|
549
|
+
let a = 1;
|
|
550
|
+
let b = 1;
|
|
551
|
+
let c = 1;
|
|
552
|
+
let d = 1;
|
|
553
|
+
let e = 0;
|
|
554
|
+
let f = 0;
|
|
555
|
+
transform.replace(/matrix\((.+), (.+), (.+), (.+), (.+), (.+)\)/, ($0, $1, $2, $3, $4, $5, $6) => {
|
|
556
|
+
a = +$1;
|
|
557
|
+
b = +$2;
|
|
558
|
+
c = +$3;
|
|
559
|
+
d = +$4;
|
|
560
|
+
e = +$5;
|
|
561
|
+
f = +$6;
|
|
562
|
+
return transform;
|
|
563
|
+
});
|
|
564
|
+
left = a * left + c * top + e;
|
|
565
|
+
top = b * left + d * top + f;
|
|
566
|
+
}
|
|
567
|
+
if (offsetParent) {
|
|
568
|
+
const parentOffset = this.getOffset(offsetParent);
|
|
569
|
+
return {
|
|
570
|
+
left: left + parentOffset.left,
|
|
571
|
+
top: top + parentOffset.top
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
if (this.dr.mode === Mode.FIXED) {
|
|
575
|
+
if (getMode(el) === Mode.FIXED) {
|
|
576
|
+
return {
|
|
577
|
+
left,
|
|
578
|
+
top
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
return {
|
|
582
|
+
left: left - this.mask.scrollLeft,
|
|
583
|
+
top: top - this.mask.scrollTop
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
if (getMode(el) === Mode.FIXED) {
|
|
587
|
+
return {
|
|
588
|
+
left: left + this.mask.scrollLeft,
|
|
589
|
+
top: top + this.mask.scrollTop
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
return {
|
|
593
|
+
left,
|
|
594
|
+
top
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
523
599
|
class StageHighlight extends EventEmitter.EventEmitter {
|
|
524
|
-
core;
|
|
525
|
-
container;
|
|
526
|
-
target;
|
|
527
|
-
moveable;
|
|
528
600
|
constructor(config) {
|
|
529
601
|
super();
|
|
530
602
|
this.core = config.core;
|
|
531
603
|
this.container = config.container;
|
|
604
|
+
this.calibrationTarget = new TargetCalibrate({
|
|
605
|
+
parent: this.core.mask.content,
|
|
606
|
+
mask: this.core.mask,
|
|
607
|
+
dr: this.core.dr
|
|
608
|
+
});
|
|
532
609
|
}
|
|
533
610
|
highlight(el) {
|
|
534
611
|
if (!el || el === this.target)
|
|
@@ -536,9 +613,10 @@
|
|
|
536
613
|
this.target = el;
|
|
537
614
|
this.moveable?.destroy();
|
|
538
615
|
this.moveable = new Moveable__default["default"](this.container, {
|
|
539
|
-
target: this.
|
|
540
|
-
|
|
541
|
-
|
|
616
|
+
target: this.calibrationTarget.update(el, HIGHLIGHT_EL_ID_PREFIX),
|
|
617
|
+
origin: false,
|
|
618
|
+
rootContainer: this.core.container,
|
|
619
|
+
zoom: 1
|
|
542
620
|
});
|
|
543
621
|
}
|
|
544
622
|
clearHighlight() {
|
|
@@ -550,18 +628,46 @@
|
|
|
550
628
|
}
|
|
551
629
|
destroy() {
|
|
552
630
|
this.moveable?.destroy();
|
|
631
|
+
this.calibrationTarget.destroy();
|
|
553
632
|
}
|
|
554
633
|
}
|
|
555
634
|
|
|
556
635
|
class Rule extends EventEmitter__default["default"] {
|
|
557
|
-
hGuides;
|
|
558
|
-
vGuides;
|
|
559
|
-
horizontalGuidelines = [];
|
|
560
|
-
verticalGuidelines = [];
|
|
561
|
-
container;
|
|
562
|
-
containerResizeObserver;
|
|
563
636
|
constructor(container) {
|
|
564
637
|
super();
|
|
638
|
+
this.horizontalGuidelines = [];
|
|
639
|
+
this.verticalGuidelines = [];
|
|
640
|
+
this.getGuidesStyle = (type) => ({
|
|
641
|
+
position: "fixed",
|
|
642
|
+
zIndex: 1,
|
|
643
|
+
left: type === GuidesType.HORIZONTAL ? 0 : "-30px",
|
|
644
|
+
top: type === GuidesType.HORIZONTAL ? "-30px" : 0,
|
|
645
|
+
width: type === GuidesType.HORIZONTAL ? "100%" : "30px",
|
|
646
|
+
height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
|
|
647
|
+
});
|
|
648
|
+
this.createGuides = (type, defaultGuides = []) => new Guides__default["default"](this.container, {
|
|
649
|
+
type,
|
|
650
|
+
defaultGuides,
|
|
651
|
+
displayDragPos: true,
|
|
652
|
+
backgroundColor: "#fff",
|
|
653
|
+
lineColor: "#000",
|
|
654
|
+
textColor: "#000",
|
|
655
|
+
style: this.getGuidesStyle(type)
|
|
656
|
+
});
|
|
657
|
+
this.hGuidesChangeGuidesHandler = (e) => {
|
|
658
|
+
this.horizontalGuidelines = e.guides;
|
|
659
|
+
this.emit("changeGuides", {
|
|
660
|
+
type: GuidesType.HORIZONTAL,
|
|
661
|
+
guides: this.horizontalGuidelines
|
|
662
|
+
});
|
|
663
|
+
};
|
|
664
|
+
this.vGuidesChangeGuidesHandler = (e) => {
|
|
665
|
+
this.verticalGuidelines = e.guides;
|
|
666
|
+
this.emit("changeGuides", {
|
|
667
|
+
type: GuidesType.VERTICAL,
|
|
668
|
+
guides: this.verticalGuidelines
|
|
669
|
+
});
|
|
670
|
+
};
|
|
565
671
|
this.container = container;
|
|
566
672
|
this.hGuides = this.createGuides(GuidesType.HORIZONTAL);
|
|
567
673
|
this.vGuides = this.createGuides(GuidesType.VERTICAL);
|
|
@@ -630,37 +736,6 @@
|
|
|
630
736
|
this.containerResizeObserver.disconnect();
|
|
631
737
|
this.removeAllListeners();
|
|
632
738
|
}
|
|
633
|
-
getGuidesStyle = (type) => ({
|
|
634
|
-
position: "fixed",
|
|
635
|
-
zIndex: 1,
|
|
636
|
-
left: type === GuidesType.HORIZONTAL ? 0 : "-30px",
|
|
637
|
-
top: type === GuidesType.HORIZONTAL ? "-30px" : 0,
|
|
638
|
-
width: type === GuidesType.HORIZONTAL ? "100%" : "30px",
|
|
639
|
-
height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
|
|
640
|
-
});
|
|
641
|
-
createGuides = (type, defaultGuides = []) => new Guides__default["default"](this.container, {
|
|
642
|
-
type,
|
|
643
|
-
defaultGuides,
|
|
644
|
-
displayDragPos: true,
|
|
645
|
-
backgroundColor: "#fff",
|
|
646
|
-
lineColor: "#000",
|
|
647
|
-
textColor: "#000",
|
|
648
|
-
style: this.getGuidesStyle(type)
|
|
649
|
-
});
|
|
650
|
-
hGuidesChangeGuidesHandler = (e) => {
|
|
651
|
-
this.horizontalGuidelines = e.guides;
|
|
652
|
-
this.emit("changeGuides", {
|
|
653
|
-
type: GuidesType.HORIZONTAL,
|
|
654
|
-
guides: this.horizontalGuidelines
|
|
655
|
-
});
|
|
656
|
-
};
|
|
657
|
-
vGuidesChangeGuidesHandler = (e) => {
|
|
658
|
-
this.verticalGuidelines = e.guides;
|
|
659
|
-
this.emit("changeGuides", {
|
|
660
|
-
type: GuidesType.VERTICAL,
|
|
661
|
-
guides: this.verticalGuidelines
|
|
662
|
-
});
|
|
663
|
-
};
|
|
664
739
|
}
|
|
665
740
|
|
|
666
741
|
const wrapperClassName = "editor-mask-wrapper";
|
|
@@ -698,28 +773,66 @@
|
|
|
698
773
|
return el;
|
|
699
774
|
};
|
|
700
775
|
class StageMask extends Rule {
|
|
701
|
-
content = createContent();
|
|
702
|
-
wrapper;
|
|
703
|
-
core;
|
|
704
|
-
page = null;
|
|
705
|
-
pageScrollParent = null;
|
|
706
|
-
scrollTop = 0;
|
|
707
|
-
scrollLeft = 0;
|
|
708
|
-
width = 0;
|
|
709
|
-
height = 0;
|
|
710
|
-
wrapperHeight = 0;
|
|
711
|
-
wrapperWidth = 0;
|
|
712
|
-
maxScrollTop = 0;
|
|
713
|
-
maxScrollLeft = 0;
|
|
714
|
-
mode = Mode.ABSOLUTE;
|
|
715
|
-
pageResizeObserver = null;
|
|
716
|
-
wrapperResizeObserver = null;
|
|
717
|
-
highlightHandler = lodashEs.throttle((event) => {
|
|
718
|
-
this.emit("highlight", event);
|
|
719
|
-
}, throttleTime);
|
|
720
776
|
constructor(config) {
|
|
721
777
|
const wrapper = createWrapper();
|
|
722
778
|
super(wrapper);
|
|
779
|
+
this.content = createContent();
|
|
780
|
+
this.page = null;
|
|
781
|
+
this.pageScrollParent = null;
|
|
782
|
+
this.scrollTop = 0;
|
|
783
|
+
this.scrollLeft = 0;
|
|
784
|
+
this.width = 0;
|
|
785
|
+
this.height = 0;
|
|
786
|
+
this.wrapperHeight = 0;
|
|
787
|
+
this.wrapperWidth = 0;
|
|
788
|
+
this.maxScrollTop = 0;
|
|
789
|
+
this.maxScrollLeft = 0;
|
|
790
|
+
this.mode = Mode.ABSOLUTE;
|
|
791
|
+
this.pageResizeObserver = null;
|
|
792
|
+
this.wrapperResizeObserver = null;
|
|
793
|
+
this.highlightHandler = lodashEs.throttle((event) => {
|
|
794
|
+
this.emit("highlight", event);
|
|
795
|
+
}, throttleTime);
|
|
796
|
+
this.mouseDownHandler = (event) => {
|
|
797
|
+
this.emit("clearHighlight");
|
|
798
|
+
event.stopImmediatePropagation();
|
|
799
|
+
event.stopPropagation();
|
|
800
|
+
if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
|
|
801
|
+
return;
|
|
802
|
+
if (event.target.className.indexOf("moveable-control") !== -1) {
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
this.content.removeEventListener("mousemove", this.highlightHandler);
|
|
806
|
+
this.emit("beforeSelect", event);
|
|
807
|
+
globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
|
|
808
|
+
};
|
|
809
|
+
this.mouseUpHandler = () => {
|
|
810
|
+
globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
|
|
811
|
+
this.content.addEventListener("mousemove", this.highlightHandler);
|
|
812
|
+
this.emit("select");
|
|
813
|
+
};
|
|
814
|
+
this.mouseWheelHandler = (event) => {
|
|
815
|
+
this.emit("clearHighlight");
|
|
816
|
+
if (!this.page)
|
|
817
|
+
throw new Error("page \u672A\u521D\u59CB\u5316");
|
|
818
|
+
const { deltaY, deltaX } = event;
|
|
819
|
+
if (this.page.clientHeight < this.wrapperHeight && deltaY)
|
|
820
|
+
return;
|
|
821
|
+
if (this.page.clientWidth < this.wrapperWidth && deltaX)
|
|
822
|
+
return;
|
|
823
|
+
if (this.maxScrollTop > 0) {
|
|
824
|
+
this.scrollTop = this.scrollTop + deltaY;
|
|
825
|
+
}
|
|
826
|
+
if (this.maxScrollLeft > 0) {
|
|
827
|
+
this.scrollLeft = this.scrollLeft + deltaX;
|
|
828
|
+
}
|
|
829
|
+
this.fixScrollValue();
|
|
830
|
+
this.scroll();
|
|
831
|
+
this.emit("scroll", event);
|
|
832
|
+
};
|
|
833
|
+
this.mouseLeaveHandler = () => {
|
|
834
|
+
setTimeout(() => this.emit("clearHighlight"), throttleTime);
|
|
835
|
+
};
|
|
723
836
|
this.wrapper = wrapper;
|
|
724
837
|
this.core = config.core;
|
|
725
838
|
this.content.addEventListener("mousedown", this.mouseDownHandler);
|
|
@@ -828,53 +941,51 @@
|
|
|
828
941
|
if (this.maxScrollLeft < this.scrollLeft)
|
|
829
942
|
this.scrollLeft = this.maxScrollLeft;
|
|
830
943
|
}
|
|
831
|
-
mouseDownHandler = (event) => {
|
|
832
|
-
this.emit("clearHighlight");
|
|
833
|
-
event.stopImmediatePropagation();
|
|
834
|
-
event.stopPropagation();
|
|
835
|
-
if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
|
|
836
|
-
return;
|
|
837
|
-
if (event.target.className.indexOf("moveable-control") !== -1) {
|
|
838
|
-
return;
|
|
839
|
-
}
|
|
840
|
-
this.content.removeEventListener("mousemove", this.highlightHandler);
|
|
841
|
-
this.emit("beforeSelect", event);
|
|
842
|
-
globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
|
|
843
|
-
};
|
|
844
|
-
mouseUpHandler = () => {
|
|
845
|
-
globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
|
|
846
|
-
this.content.addEventListener("mousemove", this.highlightHandler);
|
|
847
|
-
this.emit("select");
|
|
848
|
-
};
|
|
849
|
-
mouseWheelHandler = (event) => {
|
|
850
|
-
this.emit("clearHighlight");
|
|
851
|
-
if (!this.page)
|
|
852
|
-
throw new Error("page \u672A\u521D\u59CB\u5316");
|
|
853
|
-
const { deltaY, deltaX } = event;
|
|
854
|
-
if (this.maxScrollTop > 0) {
|
|
855
|
-
this.scrollTop = this.scrollTop + deltaY;
|
|
856
|
-
}
|
|
857
|
-
if (this.maxScrollLeft > 0) {
|
|
858
|
-
this.scrollLeft = this.scrollLeft + deltaX;
|
|
859
|
-
}
|
|
860
|
-
this.fixScrollValue();
|
|
861
|
-
this.scroll();
|
|
862
|
-
this.emit("scroll", event);
|
|
863
|
-
};
|
|
864
|
-
mouseLeaveHandler = () => {
|
|
865
|
-
setTimeout(() => this.emit("clearHighlight"), throttleTime);
|
|
866
|
-
};
|
|
867
944
|
}
|
|
868
945
|
|
|
869
946
|
class StageRender extends EventEmitter.EventEmitter {
|
|
870
|
-
contentWindow = null;
|
|
871
|
-
runtime = null;
|
|
872
|
-
iframe;
|
|
873
|
-
runtimeUrl;
|
|
874
|
-
core;
|
|
875
|
-
render;
|
|
876
947
|
constructor({ core }) {
|
|
877
948
|
super();
|
|
949
|
+
this.contentWindow = null;
|
|
950
|
+
this.runtime = null;
|
|
951
|
+
this.getMagicApi = () => ({
|
|
952
|
+
onPageElUpdate: (el) => this.emit("page-el-update", el),
|
|
953
|
+
onRuntimeReady: (runtime) => {
|
|
954
|
+
this.runtime = runtime;
|
|
955
|
+
globalThis.runtime = runtime;
|
|
956
|
+
this.emit("runtime-ready", runtime);
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
this.getRuntime = () => {
|
|
960
|
+
if (this.runtime)
|
|
961
|
+
return Promise.resolve(this.runtime);
|
|
962
|
+
return new Promise((resolve) => {
|
|
963
|
+
const listener = (runtime) => {
|
|
964
|
+
this.off("runtime-ready", listener);
|
|
965
|
+
resolve(runtime);
|
|
966
|
+
};
|
|
967
|
+
this.on("runtime-ready", listener);
|
|
968
|
+
});
|
|
969
|
+
};
|
|
970
|
+
this.loadHandler = async () => {
|
|
971
|
+
this.emit("onload");
|
|
972
|
+
if (this.render) {
|
|
973
|
+
const el = await this.render(this.core);
|
|
974
|
+
if (el) {
|
|
975
|
+
this.iframe?.contentDocument?.body?.appendChild(el);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
if (this.contentWindow) {
|
|
979
|
+
const style = this.contentWindow.document.createElement("style");
|
|
980
|
+
style.id = "tmagic-stage-render";
|
|
981
|
+
style.innerHTML = `
|
|
982
|
+
.${SELECTED_CLASS}, .${SELECTED_CLASS}-parent {
|
|
983
|
+
z-index: ${ZIndex.SELECTED_EL};
|
|
984
|
+
}
|
|
985
|
+
`;
|
|
986
|
+
this.contentWindow.document.head.appendChild(style);
|
|
987
|
+
}
|
|
988
|
+
};
|
|
878
989
|
this.core = core;
|
|
879
990
|
this.runtimeUrl = core.config.runtimeUrl || "";
|
|
880
991
|
this.render = core.config.render;
|
|
@@ -887,14 +998,6 @@
|
|
|
887
998
|
`;
|
|
888
999
|
this.iframe.addEventListener("load", this.loadHandler);
|
|
889
1000
|
}
|
|
890
|
-
getMagicApi = () => ({
|
|
891
|
-
onPageElUpdate: (el) => this.emit("page-el-update", el),
|
|
892
|
-
onRuntimeReady: (runtime) => {
|
|
893
|
-
this.runtime = runtime;
|
|
894
|
-
globalThis.runtime = runtime;
|
|
895
|
-
this.emit("runtime-ready", runtime);
|
|
896
|
-
}
|
|
897
|
-
});
|
|
898
1001
|
async mount(el) {
|
|
899
1002
|
if (this.iframe) {
|
|
900
1003
|
if (!isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
|
|
@@ -911,17 +1014,6 @@
|
|
|
911
1014
|
throw Error("mount \u5931\u8D25");
|
|
912
1015
|
}
|
|
913
1016
|
}
|
|
914
|
-
getRuntime = () => {
|
|
915
|
-
if (this.runtime)
|
|
916
|
-
return Promise.resolve(this.runtime);
|
|
917
|
-
return new Promise((resolve) => {
|
|
918
|
-
const listener = (runtime) => {
|
|
919
|
-
this.off("runtime-ready", listener);
|
|
920
|
-
resolve(runtime);
|
|
921
|
-
};
|
|
922
|
-
this.on("runtime-ready", listener);
|
|
923
|
-
});
|
|
924
|
-
};
|
|
925
1017
|
destroy() {
|
|
926
1018
|
this.iframe?.removeEventListener("load", this.loadHandler);
|
|
927
1019
|
this.contentWindow = null;
|
|
@@ -929,40 +1021,12 @@
|
|
|
929
1021
|
this.iframe = void 0;
|
|
930
1022
|
this.removeAllListeners();
|
|
931
1023
|
}
|
|
932
|
-
loadHandler = async () => {
|
|
933
|
-
this.emit("onload");
|
|
934
|
-
if (this.render) {
|
|
935
|
-
const el = await this.render(this.core);
|
|
936
|
-
if (el) {
|
|
937
|
-
this.iframe?.contentDocument?.body?.appendChild(el);
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
if (this.contentWindow) {
|
|
941
|
-
const style = this.contentWindow.document.createElement("style");
|
|
942
|
-
style.id = "tmagic-stage-render";
|
|
943
|
-
style.innerHTML = `
|
|
944
|
-
.${SELECTED_CLASS}, .${SELECTED_CLASS}-parent {
|
|
945
|
-
z-index: ${ZIndex.SELECTED_EL};
|
|
946
|
-
}
|
|
947
|
-
`;
|
|
948
|
-
this.contentWindow.document.head.appendChild(style);
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
1024
|
}
|
|
952
1025
|
|
|
953
1026
|
class StageCore extends EventEmitter.EventEmitter {
|
|
954
|
-
selectedDom;
|
|
955
|
-
highlightedDom;
|
|
956
|
-
renderer;
|
|
957
|
-
mask;
|
|
958
|
-
dr;
|
|
959
|
-
highlightLayer;
|
|
960
|
-
config;
|
|
961
|
-
zoom = DEFAULT_ZOOM;
|
|
962
|
-
container;
|
|
963
|
-
canSelect;
|
|
964
1027
|
constructor(config) {
|
|
965
1028
|
super();
|
|
1029
|
+
this.zoom = DEFAULT_ZOOM;
|
|
966
1030
|
this.config = config;
|
|
967
1031
|
this.setZoom(config.zoom);
|
|
968
1032
|
this.canSelect = config.canSelect || ((el) => !!el.id);
|
|
@@ -1122,8 +1186,7 @@
|
|
|
1122
1186
|
exports.StageRender = StageRender;
|
|
1123
1187
|
exports["default"] = StageCore;
|
|
1124
1188
|
|
|
1125
|
-
Object.
|
|
1126
|
-
exports[Symbol.toStringTag] = 'Module';
|
|
1189
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
1127
1190
|
|
|
1128
1191
|
}));
|
|
1129
1192
|
//# sourceMappingURL=tmagic-stage.umd.js.map
|