@tmagic/stage 1.0.0-rc.12 → 1.0.0-rc.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.
- package/dist/tmagic-stage.es.js +32 -61
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +40 -60
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/Rule.d.ts +1 -0
- package/dist/types/src/const.d.ts +0 -2
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/util.d.ts +5 -6
- package/package.json +5 -5
- package/src/Rule.ts +22 -25
- package/src/StageDragResize.ts +8 -5
- package/src/const.ts +0 -3
- package/src/index.ts +1 -0
- package/src/util.ts +10 -42
package/dist/tmagic-stage.es.js
CHANGED
|
@@ -33,8 +33,6 @@ var Mode = /* @__PURE__ */ ((Mode2) => {
|
|
|
33
33
|
return Mode2;
|
|
34
34
|
})(Mode || {});
|
|
35
35
|
const SELECTED_CLASS = "tmagic-stage-selected-area";
|
|
36
|
-
const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
|
|
37
|
-
const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
|
|
38
36
|
|
|
39
37
|
const getParents = (el, relative) => {
|
|
40
38
|
let cur = el.parentElement;
|
|
@@ -79,26 +77,15 @@ const isSameDomain = (targetUrl = "", source = globalThis.location.host) => {
|
|
|
79
77
|
return true;
|
|
80
78
|
return getHost(targetUrl) === source;
|
|
81
79
|
};
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
};
|
|
87
|
-
const isStatic = (el) => {
|
|
88
|
-
if (!el)
|
|
89
|
-
return false;
|
|
90
|
-
return getComputedStyle(el).position === "static";
|
|
91
|
-
};
|
|
92
|
-
const isFixed = (el) => {
|
|
93
|
-
if (!el)
|
|
94
|
-
return false;
|
|
95
|
-
return getComputedStyle(el).position === "fixed";
|
|
96
|
-
};
|
|
80
|
+
const isAbsolute = (style) => style.position === "absolute";
|
|
81
|
+
const isRelative = (style) => style.position === "relative";
|
|
82
|
+
const isStatic = (style) => style.position === "static";
|
|
83
|
+
const isFixed = (style) => style.position === "fixed";
|
|
97
84
|
const isFixedParent = (el) => {
|
|
98
85
|
let fixed = false;
|
|
99
86
|
let dom = el;
|
|
100
87
|
while (dom) {
|
|
101
|
-
fixed = isFixed(dom);
|
|
88
|
+
fixed = isFixed(getComputedStyle(dom));
|
|
102
89
|
if (fixed) {
|
|
103
90
|
break;
|
|
104
91
|
}
|
|
@@ -113,20 +100,20 @@ const isFixedParent = (el) => {
|
|
|
113
100
|
const getMode = (el) => {
|
|
114
101
|
if (isFixedParent(el))
|
|
115
102
|
return Mode.FIXED;
|
|
116
|
-
|
|
103
|
+
const style = getComputedStyle(el);
|
|
104
|
+
if (isStatic(style) || isRelative(style))
|
|
117
105
|
return Mode.SORTABLE;
|
|
118
106
|
return Mode.ABSOLUTE;
|
|
119
107
|
};
|
|
120
108
|
const getScrollParent = (element, includeHidden = false) => {
|
|
121
109
|
let style = getComputedStyle(element);
|
|
122
|
-
const excludeStaticParent = style.position === "absolute";
|
|
123
110
|
const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
|
|
124
|
-
if (style
|
|
111
|
+
if (isFixed(style))
|
|
125
112
|
return null;
|
|
126
113
|
for (let parent = element; parent.parentElement; ) {
|
|
127
114
|
parent = parent.parentElement;
|
|
128
115
|
style = getComputedStyle(parent);
|
|
129
|
-
if (
|
|
116
|
+
if (isAbsolute(style) && isStatic(style))
|
|
130
117
|
continue;
|
|
131
118
|
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX))
|
|
132
119
|
return parent;
|
|
@@ -156,29 +143,12 @@ const addSelectedClassName = (el, doc) => {
|
|
|
156
143
|
item.classList.add(`${SELECTED_CLASS}-parents`);
|
|
157
144
|
});
|
|
158
145
|
};
|
|
159
|
-
const getGuideLineFromCache = (type) => {
|
|
160
|
-
const key = {
|
|
161
|
-
[GuidesType.HORIZONTAL]: H_GUIDE_LINE_STORAGE_KEY,
|
|
162
|
-
[GuidesType.VERTICAL]: V_GUIDE_LINE_STORAGE_KEY
|
|
163
|
-
}[type];
|
|
164
|
-
if (!key)
|
|
165
|
-
return [];
|
|
166
|
-
const guideLineCacheData = globalThis.localStorage.getItem(key);
|
|
167
|
-
if (guideLineCacheData) {
|
|
168
|
-
try {
|
|
169
|
-
return JSON.parse(guideLineCacheData) || [];
|
|
170
|
-
} catch (e) {
|
|
171
|
-
console.error(e);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return [];
|
|
175
|
-
};
|
|
176
146
|
|
|
177
147
|
class StageDragResize extends EventEmitter {
|
|
178
148
|
constructor(config) {
|
|
179
149
|
super();
|
|
180
|
-
this.horizontalGuidelines =
|
|
181
|
-
this.verticalGuidelines =
|
|
150
|
+
this.horizontalGuidelines = [];
|
|
151
|
+
this.verticalGuidelines = [];
|
|
182
152
|
this.elementGuidelines = [];
|
|
183
153
|
this.mode = Mode.ABSOLUTE;
|
|
184
154
|
this.moveableOptions = {};
|
|
@@ -226,7 +196,9 @@ class StageDragResize extends EventEmitter {
|
|
|
226
196
|
this.verticalGuidelines = guidelines;
|
|
227
197
|
this.moveableOptions.verticalGuidelines = guidelines;
|
|
228
198
|
}
|
|
229
|
-
this.
|
|
199
|
+
if (this.moveable) {
|
|
200
|
+
this.updateMoveable();
|
|
201
|
+
}
|
|
230
202
|
}
|
|
231
203
|
clearGuides() {
|
|
232
204
|
this.horizontalGuidelines = [];
|
|
@@ -527,7 +499,7 @@ class StageDragResize extends EventEmitter {
|
|
|
527
499
|
elementGuidelines: this.elementGuidelines,
|
|
528
500
|
bounds: {
|
|
529
501
|
top: 0,
|
|
530
|
-
left:
|
|
502
|
+
left: -1,
|
|
531
503
|
right: this.container.clientWidth,
|
|
532
504
|
bottom: this.container.clientHeight,
|
|
533
505
|
...moveableOptions.bounds || {}
|
|
@@ -699,8 +671,8 @@ class StageHighlight extends EventEmitter {
|
|
|
699
671
|
class Rule extends EventEmitter$1 {
|
|
700
672
|
constructor(container) {
|
|
701
673
|
super();
|
|
702
|
-
this.horizontalGuidelines =
|
|
703
|
-
this.verticalGuidelines =
|
|
674
|
+
this.horizontalGuidelines = [];
|
|
675
|
+
this.verticalGuidelines = [];
|
|
704
676
|
this.getGuidesStyle = (type) => ({
|
|
705
677
|
position: "fixed",
|
|
706
678
|
zIndex: 1,
|
|
@@ -724,7 +696,6 @@ class Rule extends EventEmitter$1 {
|
|
|
724
696
|
type: GuidesType.HORIZONTAL,
|
|
725
697
|
guides: this.horizontalGuidelines
|
|
726
698
|
});
|
|
727
|
-
globalThis.localStorage.setItem(H_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
728
699
|
};
|
|
729
700
|
this.vGuidesChangeGuidesHandler = (e) => {
|
|
730
701
|
this.verticalGuidelines = e.guides;
|
|
@@ -732,7 +703,6 @@ class Rule extends EventEmitter$1 {
|
|
|
732
703
|
type: GuidesType.VERTICAL,
|
|
733
704
|
guides: this.verticalGuidelines
|
|
734
705
|
});
|
|
735
|
-
globalThis.localStorage.setItem(V_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
736
706
|
};
|
|
737
707
|
this.container = container;
|
|
738
708
|
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
|
|
@@ -753,25 +723,26 @@ class Rule extends EventEmitter$1 {
|
|
|
753
723
|
showGuides: show
|
|
754
724
|
});
|
|
755
725
|
}
|
|
756
|
-
|
|
757
|
-
this.horizontalGuidelines =
|
|
758
|
-
this.verticalGuidelines =
|
|
759
|
-
this.vGuides.setState({
|
|
760
|
-
defaultGuides: []
|
|
761
|
-
});
|
|
726
|
+
setGuides([hLines, vLines]) {
|
|
727
|
+
this.horizontalGuidelines = hLines;
|
|
728
|
+
this.verticalGuidelines = vLines;
|
|
762
729
|
this.hGuides.setState({
|
|
763
|
-
defaultGuides:
|
|
730
|
+
defaultGuides: hLines
|
|
764
731
|
});
|
|
765
|
-
this.
|
|
766
|
-
|
|
767
|
-
guides: []
|
|
732
|
+
this.vGuides.setState({
|
|
733
|
+
defaultGuides: vLines
|
|
768
734
|
});
|
|
769
735
|
this.emit("changeGuides", {
|
|
770
736
|
type: GuidesType.HORIZONTAL,
|
|
771
|
-
guides:
|
|
737
|
+
guides: hLines
|
|
738
|
+
});
|
|
739
|
+
this.emit("changeGuides", {
|
|
740
|
+
type: GuidesType.VERTICAL,
|
|
741
|
+
guides: vLines
|
|
772
742
|
});
|
|
773
|
-
|
|
774
|
-
|
|
743
|
+
}
|
|
744
|
+
clearGuides() {
|
|
745
|
+
this.setGuides([[], []]);
|
|
775
746
|
}
|
|
776
747
|
showRule(show = true) {
|
|
777
748
|
if (show) {
|
|
@@ -1272,5 +1243,5 @@ class StageCore extends EventEmitter {
|
|
|
1272
1243
|
}
|
|
1273
1244
|
}
|
|
1274
1245
|
|
|
1275
|
-
export { StageDragResize, StageMask, StageRender, StageCore as default };
|
|
1246
|
+
export { DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, SELECTED_CLASS, StageDragResize, StageMask, StageRender, ZIndex, StageCore as default };
|
|
1276
1247
|
//# sourceMappingURL=tmagic-stage.es.js.map
|