@tmagic/stage 1.0.0-beta.12 → 1.0.0-beta.13

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.
@@ -170,21 +170,14 @@
170
170
  };
171
171
 
172
172
  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
173
  constructor(config) {
187
174
  super();
175
+ this.horizontalGuidelines = [];
176
+ this.verticalGuidelines = [];
177
+ this.elementGuidelines = [];
178
+ this.moveableOptions = {};
179
+ this.dragStatus = "end" /* END */;
180
+ this.mode = Mode.ABSOLUTE;
188
181
  this.core = config.core;
189
182
  this.container = config.container;
190
183
  this.dragEl = globalThis.document.createElement("div");
@@ -521,10 +514,6 @@
521
514
  };
522
515
 
523
516
  class StageHighlight extends EventEmitter.EventEmitter {
524
- core;
525
- container;
526
- target;
527
- moveable;
528
517
  constructor(config) {
529
518
  super();
530
519
  this.core = config.core;
@@ -554,14 +543,41 @@
554
543
  }
555
544
 
556
545
  class Rule extends EventEmitter__default["default"] {
557
- hGuides;
558
- vGuides;
559
- horizontalGuidelines = [];
560
- verticalGuidelines = [];
561
- container;
562
- containerResizeObserver;
563
546
  constructor(container) {
564
547
  super();
548
+ this.horizontalGuidelines = [];
549
+ this.verticalGuidelines = [];
550
+ this.getGuidesStyle = (type) => ({
551
+ position: "fixed",
552
+ zIndex: 1,
553
+ left: type === GuidesType.HORIZONTAL ? 0 : "-30px",
554
+ top: type === GuidesType.HORIZONTAL ? "-30px" : 0,
555
+ width: type === GuidesType.HORIZONTAL ? "100%" : "30px",
556
+ height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
557
+ });
558
+ this.createGuides = (type, defaultGuides = []) => new Guides__default["default"](this.container, {
559
+ type,
560
+ defaultGuides,
561
+ displayDragPos: true,
562
+ backgroundColor: "#fff",
563
+ lineColor: "#000",
564
+ textColor: "#000",
565
+ style: this.getGuidesStyle(type)
566
+ });
567
+ this.hGuidesChangeGuidesHandler = (e) => {
568
+ this.horizontalGuidelines = e.guides;
569
+ this.emit("changeGuides", {
570
+ type: GuidesType.HORIZONTAL,
571
+ guides: this.horizontalGuidelines
572
+ });
573
+ };
574
+ this.vGuidesChangeGuidesHandler = (e) => {
575
+ this.verticalGuidelines = e.guides;
576
+ this.emit("changeGuides", {
577
+ type: GuidesType.VERTICAL,
578
+ guides: this.verticalGuidelines
579
+ });
580
+ };
565
581
  this.container = container;
566
582
  this.hGuides = this.createGuides(GuidesType.HORIZONTAL);
567
583
  this.vGuides = this.createGuides(GuidesType.VERTICAL);
@@ -630,37 +646,6 @@
630
646
  this.containerResizeObserver.disconnect();
631
647
  this.removeAllListeners();
632
648
  }
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
649
  }
665
650
 
666
651
  const wrapperClassName = "editor-mask-wrapper";
@@ -698,28 +683,66 @@
698
683
  return el;
699
684
  };
700
685
  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
686
  constructor(config) {
721
687
  const wrapper = createWrapper();
722
688
  super(wrapper);
689
+ this.content = createContent();
690
+ this.page = null;
691
+ this.pageScrollParent = null;
692
+ this.scrollTop = 0;
693
+ this.scrollLeft = 0;
694
+ this.width = 0;
695
+ this.height = 0;
696
+ this.wrapperHeight = 0;
697
+ this.wrapperWidth = 0;
698
+ this.maxScrollTop = 0;
699
+ this.maxScrollLeft = 0;
700
+ this.mode = Mode.ABSOLUTE;
701
+ this.pageResizeObserver = null;
702
+ this.wrapperResizeObserver = null;
703
+ this.highlightHandler = lodashEs.throttle((event) => {
704
+ this.emit("highlight", event);
705
+ }, throttleTime);
706
+ this.mouseDownHandler = (event) => {
707
+ this.emit("clearHighlight");
708
+ event.stopImmediatePropagation();
709
+ event.stopPropagation();
710
+ if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
711
+ return;
712
+ if (event.target.className.indexOf("moveable-control") !== -1) {
713
+ return;
714
+ }
715
+ this.content.removeEventListener("mousemove", this.highlightHandler);
716
+ this.emit("beforeSelect", event);
717
+ globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
718
+ };
719
+ this.mouseUpHandler = () => {
720
+ globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
721
+ this.content.addEventListener("mousemove", this.highlightHandler);
722
+ this.emit("select");
723
+ };
724
+ this.mouseWheelHandler = (event) => {
725
+ this.emit("clearHighlight");
726
+ if (!this.page)
727
+ throw new Error("page \u672A\u521D\u59CB\u5316");
728
+ const { deltaY, deltaX } = event;
729
+ if (this.page.clientHeight < this.wrapperHeight && deltaY)
730
+ return;
731
+ if (this.page.clientWidth < this.wrapperWidth && deltaX)
732
+ return;
733
+ if (this.maxScrollTop > 0) {
734
+ this.scrollTop = this.scrollTop + deltaY;
735
+ }
736
+ if (this.maxScrollLeft > 0) {
737
+ this.scrollLeft = this.scrollLeft + deltaX;
738
+ }
739
+ this.fixScrollValue();
740
+ this.scroll();
741
+ this.emit("scroll", event);
742
+ };
743
+ this.mouseLeaveHandler = () => {
744
+ setTimeout(() => this.emit("clearHighlight"), throttleTime);
745
+ };
723
746
  this.wrapper = wrapper;
724
747
  this.core = config.core;
725
748
  this.content.addEventListener("mousedown", this.mouseDownHandler);
@@ -828,53 +851,51 @@
828
851
  if (this.maxScrollLeft < this.scrollLeft)
829
852
  this.scrollLeft = this.maxScrollLeft;
830
853
  }
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
854
  }
868
855
 
869
856
  class StageRender extends EventEmitter.EventEmitter {
870
- contentWindow = null;
871
- runtime = null;
872
- iframe;
873
- runtimeUrl;
874
- core;
875
- render;
876
857
  constructor({ core }) {
877
858
  super();
859
+ this.contentWindow = null;
860
+ this.runtime = null;
861
+ this.getMagicApi = () => ({
862
+ onPageElUpdate: (el) => this.emit("page-el-update", el),
863
+ onRuntimeReady: (runtime) => {
864
+ this.runtime = runtime;
865
+ globalThis.runtime = runtime;
866
+ this.emit("runtime-ready", runtime);
867
+ }
868
+ });
869
+ this.getRuntime = () => {
870
+ if (this.runtime)
871
+ return Promise.resolve(this.runtime);
872
+ return new Promise((resolve) => {
873
+ const listener = (runtime) => {
874
+ this.off("runtime-ready", listener);
875
+ resolve(runtime);
876
+ };
877
+ this.on("runtime-ready", listener);
878
+ });
879
+ };
880
+ this.loadHandler = async () => {
881
+ this.emit("onload");
882
+ if (this.render) {
883
+ const el = await this.render(this.core);
884
+ if (el) {
885
+ this.iframe?.contentDocument?.body?.appendChild(el);
886
+ }
887
+ }
888
+ if (this.contentWindow) {
889
+ const style = this.contentWindow.document.createElement("style");
890
+ style.id = "tmagic-stage-render";
891
+ style.innerHTML = `
892
+ .${SELECTED_CLASS}, .${SELECTED_CLASS}-parent {
893
+ z-index: ${ZIndex.SELECTED_EL};
894
+ }
895
+ `;
896
+ this.contentWindow.document.head.appendChild(style);
897
+ }
898
+ };
878
899
  this.core = core;
879
900
  this.runtimeUrl = core.config.runtimeUrl || "";
880
901
  this.render = core.config.render;
@@ -887,14 +908,6 @@
887
908
  `;
888
909
  this.iframe.addEventListener("load", this.loadHandler);
889
910
  }
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
911
  async mount(el) {
899
912
  if (this.iframe) {
900
913
  if (!isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
@@ -911,17 +924,6 @@
911
924
  throw Error("mount \u5931\u8D25");
912
925
  }
913
926
  }
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
927
  destroy() {
926
928
  this.iframe?.removeEventListener("load", this.loadHandler);
927
929
  this.contentWindow = null;
@@ -929,40 +931,12 @@
929
931
  this.iframe = void 0;
930
932
  this.removeAllListeners();
931
933
  }
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
934
  }
952
935
 
953
936
  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
937
  constructor(config) {
965
938
  super();
939
+ this.zoom = DEFAULT_ZOOM;
966
940
  this.config = config;
967
941
  this.setZoom(config.zoom);
968
942
  this.canSelect = config.canSelect || ((el) => !!el.id);
@@ -1122,8 +1096,7 @@
1122
1096
  exports.StageRender = StageRender;
1123
1097
  exports["default"] = StageCore;
1124
1098
 
1125
- Object.defineProperty(exports, '__esModule', { value: true });
1126
- exports[Symbol.toStringTag] = 'Module';
1099
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
1127
1100
 
1128
1101
  }));
1129
1102
  //# sourceMappingURL=tmagic-stage.umd.js.map