@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.umd.js
CHANGED
|
@@ -40,8 +40,6 @@
|
|
|
40
40
|
return Mode2;
|
|
41
41
|
})(Mode || {});
|
|
42
42
|
const SELECTED_CLASS = "tmagic-stage-selected-area";
|
|
43
|
-
const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
|
|
44
|
-
const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
|
|
45
43
|
|
|
46
44
|
const getParents = (el, relative) => {
|
|
47
45
|
let cur = el.parentElement;
|
|
@@ -86,26 +84,15 @@
|
|
|
86
84
|
return true;
|
|
87
85
|
return getHost(targetUrl) === source;
|
|
88
86
|
};
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
};
|
|
94
|
-
const isStatic = (el) => {
|
|
95
|
-
if (!el)
|
|
96
|
-
return false;
|
|
97
|
-
return getComputedStyle(el).position === "static";
|
|
98
|
-
};
|
|
99
|
-
const isFixed = (el) => {
|
|
100
|
-
if (!el)
|
|
101
|
-
return false;
|
|
102
|
-
return getComputedStyle(el).position === "fixed";
|
|
103
|
-
};
|
|
87
|
+
const isAbsolute = (style) => style.position === "absolute";
|
|
88
|
+
const isRelative = (style) => style.position === "relative";
|
|
89
|
+
const isStatic = (style) => style.position === "static";
|
|
90
|
+
const isFixed = (style) => style.position === "fixed";
|
|
104
91
|
const isFixedParent = (el) => {
|
|
105
92
|
let fixed = false;
|
|
106
93
|
let dom = el;
|
|
107
94
|
while (dom) {
|
|
108
|
-
fixed = isFixed(dom);
|
|
95
|
+
fixed = isFixed(getComputedStyle(dom));
|
|
109
96
|
if (fixed) {
|
|
110
97
|
break;
|
|
111
98
|
}
|
|
@@ -120,20 +107,20 @@
|
|
|
120
107
|
const getMode = (el) => {
|
|
121
108
|
if (isFixedParent(el))
|
|
122
109
|
return Mode.FIXED;
|
|
123
|
-
|
|
110
|
+
const style = getComputedStyle(el);
|
|
111
|
+
if (isStatic(style) || isRelative(style))
|
|
124
112
|
return Mode.SORTABLE;
|
|
125
113
|
return Mode.ABSOLUTE;
|
|
126
114
|
};
|
|
127
115
|
const getScrollParent = (element, includeHidden = false) => {
|
|
128
116
|
let style = getComputedStyle(element);
|
|
129
|
-
const excludeStaticParent = style.position === "absolute";
|
|
130
117
|
const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
|
|
131
|
-
if (style
|
|
118
|
+
if (isFixed(style))
|
|
132
119
|
return null;
|
|
133
120
|
for (let parent = element; parent.parentElement; ) {
|
|
134
121
|
parent = parent.parentElement;
|
|
135
122
|
style = getComputedStyle(parent);
|
|
136
|
-
if (
|
|
123
|
+
if (isAbsolute(style) && isStatic(style))
|
|
137
124
|
continue;
|
|
138
125
|
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX))
|
|
139
126
|
return parent;
|
|
@@ -163,29 +150,12 @@
|
|
|
163
150
|
item.classList.add(`${SELECTED_CLASS}-parents`);
|
|
164
151
|
});
|
|
165
152
|
};
|
|
166
|
-
const getGuideLineFromCache = (type) => {
|
|
167
|
-
const key = {
|
|
168
|
-
[GuidesType.HORIZONTAL]: H_GUIDE_LINE_STORAGE_KEY,
|
|
169
|
-
[GuidesType.VERTICAL]: V_GUIDE_LINE_STORAGE_KEY
|
|
170
|
-
}[type];
|
|
171
|
-
if (!key)
|
|
172
|
-
return [];
|
|
173
|
-
const guideLineCacheData = globalThis.localStorage.getItem(key);
|
|
174
|
-
if (guideLineCacheData) {
|
|
175
|
-
try {
|
|
176
|
-
return JSON.parse(guideLineCacheData) || [];
|
|
177
|
-
} catch (e) {
|
|
178
|
-
console.error(e);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return [];
|
|
182
|
-
};
|
|
183
153
|
|
|
184
154
|
class StageDragResize extends EventEmitter.EventEmitter {
|
|
185
155
|
constructor(config) {
|
|
186
156
|
super();
|
|
187
|
-
this.horizontalGuidelines =
|
|
188
|
-
this.verticalGuidelines =
|
|
157
|
+
this.horizontalGuidelines = [];
|
|
158
|
+
this.verticalGuidelines = [];
|
|
189
159
|
this.elementGuidelines = [];
|
|
190
160
|
this.mode = Mode.ABSOLUTE;
|
|
191
161
|
this.moveableOptions = {};
|
|
@@ -233,7 +203,9 @@
|
|
|
233
203
|
this.verticalGuidelines = guidelines;
|
|
234
204
|
this.moveableOptions.verticalGuidelines = guidelines;
|
|
235
205
|
}
|
|
236
|
-
this.
|
|
206
|
+
if (this.moveable) {
|
|
207
|
+
this.updateMoveable();
|
|
208
|
+
}
|
|
237
209
|
}
|
|
238
210
|
clearGuides() {
|
|
239
211
|
this.horizontalGuidelines = [];
|
|
@@ -534,7 +506,7 @@
|
|
|
534
506
|
elementGuidelines: this.elementGuidelines,
|
|
535
507
|
bounds: {
|
|
536
508
|
top: 0,
|
|
537
|
-
left:
|
|
509
|
+
left: -1,
|
|
538
510
|
right: this.container.clientWidth,
|
|
539
511
|
bottom: this.container.clientHeight,
|
|
540
512
|
...moveableOptions.bounds || {}
|
|
@@ -706,8 +678,8 @@
|
|
|
706
678
|
class Rule extends EventEmitter__default["default"] {
|
|
707
679
|
constructor(container) {
|
|
708
680
|
super();
|
|
709
|
-
this.horizontalGuidelines =
|
|
710
|
-
this.verticalGuidelines =
|
|
681
|
+
this.horizontalGuidelines = [];
|
|
682
|
+
this.verticalGuidelines = [];
|
|
711
683
|
this.getGuidesStyle = (type) => ({
|
|
712
684
|
position: "fixed",
|
|
713
685
|
zIndex: 1,
|
|
@@ -731,7 +703,6 @@
|
|
|
731
703
|
type: GuidesType.HORIZONTAL,
|
|
732
704
|
guides: this.horizontalGuidelines
|
|
733
705
|
});
|
|
734
|
-
globalThis.localStorage.setItem(H_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
735
706
|
};
|
|
736
707
|
this.vGuidesChangeGuidesHandler = (e) => {
|
|
737
708
|
this.verticalGuidelines = e.guides;
|
|
@@ -739,7 +710,6 @@
|
|
|
739
710
|
type: GuidesType.VERTICAL,
|
|
740
711
|
guides: this.verticalGuidelines
|
|
741
712
|
});
|
|
742
|
-
globalThis.localStorage.setItem(V_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
743
713
|
};
|
|
744
714
|
this.container = container;
|
|
745
715
|
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
|
|
@@ -760,25 +730,26 @@
|
|
|
760
730
|
showGuides: show
|
|
761
731
|
});
|
|
762
732
|
}
|
|
763
|
-
|
|
764
|
-
this.horizontalGuidelines =
|
|
765
|
-
this.verticalGuidelines =
|
|
766
|
-
this.vGuides.setState({
|
|
767
|
-
defaultGuides: []
|
|
768
|
-
});
|
|
733
|
+
setGuides([hLines, vLines]) {
|
|
734
|
+
this.horizontalGuidelines = hLines;
|
|
735
|
+
this.verticalGuidelines = vLines;
|
|
769
736
|
this.hGuides.setState({
|
|
770
|
-
defaultGuides:
|
|
737
|
+
defaultGuides: hLines
|
|
771
738
|
});
|
|
772
|
-
this.
|
|
773
|
-
|
|
774
|
-
guides: []
|
|
739
|
+
this.vGuides.setState({
|
|
740
|
+
defaultGuides: vLines
|
|
775
741
|
});
|
|
776
742
|
this.emit("changeGuides", {
|
|
777
743
|
type: GuidesType.HORIZONTAL,
|
|
778
|
-
guides:
|
|
744
|
+
guides: hLines
|
|
745
|
+
});
|
|
746
|
+
this.emit("changeGuides", {
|
|
747
|
+
type: GuidesType.VERTICAL,
|
|
748
|
+
guides: vLines
|
|
779
749
|
});
|
|
780
|
-
|
|
781
|
-
|
|
750
|
+
}
|
|
751
|
+
clearGuides() {
|
|
752
|
+
this.setGuides([[], []]);
|
|
782
753
|
}
|
|
783
754
|
showRule(show = true) {
|
|
784
755
|
if (show) {
|
|
@@ -1279,9 +1250,18 @@
|
|
|
1279
1250
|
}
|
|
1280
1251
|
}
|
|
1281
1252
|
|
|
1253
|
+
exports.DEFAULT_ZOOM = DEFAULT_ZOOM;
|
|
1254
|
+
exports.DRAG_EL_ID_PREFIX = DRAG_EL_ID_PREFIX;
|
|
1255
|
+
exports.GHOST_EL_ID_PREFIX = GHOST_EL_ID_PREFIX;
|
|
1256
|
+
exports.GuidesType = GuidesType;
|
|
1257
|
+
exports.HIGHLIGHT_EL_ID_PREFIX = HIGHLIGHT_EL_ID_PREFIX;
|
|
1258
|
+
exports.Mode = Mode;
|
|
1259
|
+
exports.MouseButton = MouseButton;
|
|
1260
|
+
exports.SELECTED_CLASS = SELECTED_CLASS;
|
|
1282
1261
|
exports.StageDragResize = StageDragResize;
|
|
1283
1262
|
exports.StageMask = StageMask;
|
|
1284
1263
|
exports.StageRender = StageRender;
|
|
1264
|
+
exports.ZIndex = ZIndex;
|
|
1285
1265
|
exports["default"] = StageCore;
|
|
1286
1266
|
|
|
1287
1267
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|