@tmagic/stage 1.0.0-rc.9 → 1.0.2
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 +45 -76
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +53 -75
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/Rule.d.ts +1 -0
- package/dist/types/src/StageCore.d.ts +1 -1
- package/dist/types/src/const.d.ts +1 -3
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/types.d.ts +1 -1
- package/dist/types/src/util.d.ts +5 -6
- package/package.json +5 -5
- package/src/Rule.ts +22 -25
- package/src/StageCore.ts +2 -2
- package/src/StageDragResize.ts +13 -10
- package/src/StageRender.ts +12 -5
- package/src/const.ts +1 -4
- package/src/index.ts +1 -0
- package/src/types.ts +1 -1
- package/src/util.ts +13 -43
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,31 +77,15 @@ const isSameDomain = (targetUrl = "", source = globalThis.location.host) => {
|
|
|
79
77
|
return true;
|
|
80
78
|
return getHost(targetUrl) === source;
|
|
81
79
|
};
|
|
82
|
-
const isAbsolute = (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
};
|
|
87
|
-
const isRelative = (el) => {
|
|
88
|
-
if (!el)
|
|
89
|
-
return false;
|
|
90
|
-
return getComputedStyle(el).position === "relative";
|
|
91
|
-
};
|
|
92
|
-
const isStatic = (el) => {
|
|
93
|
-
if (!el)
|
|
94
|
-
return false;
|
|
95
|
-
return getComputedStyle(el).position === "static";
|
|
96
|
-
};
|
|
97
|
-
const isFixed = (el) => {
|
|
98
|
-
if (!el)
|
|
99
|
-
return false;
|
|
100
|
-
return getComputedStyle(el).position === "fixed";
|
|
101
|
-
};
|
|
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";
|
|
102
84
|
const isFixedParent = (el) => {
|
|
103
85
|
let fixed = false;
|
|
104
86
|
let dom = el;
|
|
105
87
|
while (dom) {
|
|
106
|
-
fixed = isFixed(dom);
|
|
88
|
+
fixed = isFixed(getComputedStyle(dom));
|
|
107
89
|
if (fixed) {
|
|
108
90
|
break;
|
|
109
91
|
}
|
|
@@ -118,21 +100,21 @@ const isFixedParent = (el) => {
|
|
|
118
100
|
const getMode = (el) => {
|
|
119
101
|
if (isFixedParent(el))
|
|
120
102
|
return Mode.FIXED;
|
|
121
|
-
|
|
103
|
+
const style = getComputedStyle(el);
|
|
104
|
+
if (isStatic(style) || isRelative(style))
|
|
122
105
|
return Mode.SORTABLE;
|
|
123
106
|
return Mode.ABSOLUTE;
|
|
124
107
|
};
|
|
125
108
|
const getScrollParent = (element, includeHidden = false) => {
|
|
126
109
|
let style = getComputedStyle(element);
|
|
127
110
|
const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
|
|
128
|
-
if (isFixed(
|
|
111
|
+
if (isFixed(style))
|
|
129
112
|
return null;
|
|
130
113
|
for (let parent = element; parent.parentElement; ) {
|
|
131
114
|
parent = parent.parentElement;
|
|
132
115
|
style = getComputedStyle(parent);
|
|
133
|
-
if (isAbsolute(
|
|
116
|
+
if (isAbsolute(style) && isStatic(style))
|
|
134
117
|
continue;
|
|
135
|
-
}
|
|
136
118
|
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX))
|
|
137
119
|
return parent;
|
|
138
120
|
}
|
|
@@ -161,29 +143,12 @@ const addSelectedClassName = (el, doc) => {
|
|
|
161
143
|
item.classList.add(`${SELECTED_CLASS}-parents`);
|
|
162
144
|
});
|
|
163
145
|
};
|
|
164
|
-
const getGuideLineFromCache = (type) => {
|
|
165
|
-
const key = {
|
|
166
|
-
[GuidesType.HORIZONTAL]: H_GUIDE_LINE_STORAGE_KEY,
|
|
167
|
-
[GuidesType.VERTICAL]: V_GUIDE_LINE_STORAGE_KEY
|
|
168
|
-
}[type];
|
|
169
|
-
if (!key)
|
|
170
|
-
return [];
|
|
171
|
-
const guideLineCacheData = globalThis.localStorage.getItem(key);
|
|
172
|
-
if (guideLineCacheData) {
|
|
173
|
-
try {
|
|
174
|
-
return JSON.parse(guideLineCacheData) || [];
|
|
175
|
-
} catch (e) {
|
|
176
|
-
console.error(e);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return [];
|
|
180
|
-
};
|
|
181
146
|
|
|
182
147
|
class StageDragResize extends EventEmitter {
|
|
183
148
|
constructor(config) {
|
|
184
149
|
super();
|
|
185
|
-
this.horizontalGuidelines =
|
|
186
|
-
this.verticalGuidelines =
|
|
150
|
+
this.horizontalGuidelines = [];
|
|
151
|
+
this.verticalGuidelines = [];
|
|
187
152
|
this.elementGuidelines = [];
|
|
188
153
|
this.mode = Mode.ABSOLUTE;
|
|
189
154
|
this.moveableOptions = {};
|
|
@@ -215,7 +180,7 @@ class StageDragResize extends EventEmitter {
|
|
|
215
180
|
if (!this.moveable)
|
|
216
181
|
throw new Error("\u672A\u521D\u59CB\u5316moveable");
|
|
217
182
|
if (!el)
|
|
218
|
-
throw new Error("\
|
|
183
|
+
throw new Error("\u672A\u9009\u4E2D\u4EFB\u4F55\u8282\u70B9");
|
|
219
184
|
this.target = el;
|
|
220
185
|
this.init(el);
|
|
221
186
|
Object.entries(this.moveableOptions).forEach(([key, value]) => {
|
|
@@ -231,7 +196,9 @@ class StageDragResize extends EventEmitter {
|
|
|
231
196
|
this.verticalGuidelines = guidelines;
|
|
232
197
|
this.moveableOptions.verticalGuidelines = guidelines;
|
|
233
198
|
}
|
|
234
|
-
this.
|
|
199
|
+
if (this.moveable) {
|
|
200
|
+
this.updateMoveable();
|
|
201
|
+
}
|
|
235
202
|
}
|
|
236
203
|
clearGuides() {
|
|
237
204
|
this.horizontalGuidelines = [];
|
|
@@ -290,7 +257,7 @@ class StageDragResize extends EventEmitter {
|
|
|
290
257
|
}
|
|
291
258
|
bindResizeEvent() {
|
|
292
259
|
if (!this.moveable)
|
|
293
|
-
throw new Error("moveable \
|
|
260
|
+
throw new Error("moveable \u672A\u521D\u59CB\u5316");
|
|
294
261
|
const frame = {
|
|
295
262
|
left: 0,
|
|
296
263
|
top: 0
|
|
@@ -324,7 +291,7 @@ class StageDragResize extends EventEmitter {
|
|
|
324
291
|
}
|
|
325
292
|
bindDragEvent() {
|
|
326
293
|
if (!this.moveable)
|
|
327
|
-
throw new Error("moveable \
|
|
294
|
+
throw new Error("moveable \u672A\u521D\u59CB\u5316");
|
|
328
295
|
const frame = {
|
|
329
296
|
left: 0,
|
|
330
297
|
top: 0
|
|
@@ -366,7 +333,7 @@ class StageDragResize extends EventEmitter {
|
|
|
366
333
|
}
|
|
367
334
|
bindRotateEvent() {
|
|
368
335
|
if (!this.moveable)
|
|
369
|
-
throw new Error("moveable \
|
|
336
|
+
throw new Error("moveable \u672A\u521D\u59CB\u5316");
|
|
370
337
|
this.moveable.on("rotateStart", (e) => {
|
|
371
338
|
this.dragStatus = "start" /* START */;
|
|
372
339
|
this.moveableHelper?.onRotateStart(e);
|
|
@@ -390,7 +357,7 @@ class StageDragResize extends EventEmitter {
|
|
|
390
357
|
}
|
|
391
358
|
bindScaleEvent() {
|
|
392
359
|
if (!this.moveable)
|
|
393
|
-
throw new Error("moveable \
|
|
360
|
+
throw new Error("moveable \u672A\u521D\u59CB\u5316");
|
|
394
361
|
this.moveable.on("scaleStart", (e) => {
|
|
395
362
|
this.dragStatus = "start" /* START */;
|
|
396
363
|
this.moveableHelper?.onScaleStart(e);
|
|
@@ -532,7 +499,7 @@ class StageDragResize extends EventEmitter {
|
|
|
532
499
|
elementGuidelines: this.elementGuidelines,
|
|
533
500
|
bounds: {
|
|
534
501
|
top: 0,
|
|
535
|
-
left:
|
|
502
|
+
left: -1,
|
|
536
503
|
right: this.container.clientWidth,
|
|
537
504
|
bottom: this.container.clientHeight,
|
|
538
505
|
...moveableOptions.bounds || {}
|
|
@@ -704,8 +671,8 @@ class StageHighlight extends EventEmitter {
|
|
|
704
671
|
class Rule extends EventEmitter$1 {
|
|
705
672
|
constructor(container) {
|
|
706
673
|
super();
|
|
707
|
-
this.horizontalGuidelines =
|
|
708
|
-
this.verticalGuidelines =
|
|
674
|
+
this.horizontalGuidelines = [];
|
|
675
|
+
this.verticalGuidelines = [];
|
|
709
676
|
this.getGuidesStyle = (type) => ({
|
|
710
677
|
position: "fixed",
|
|
711
678
|
zIndex: 1,
|
|
@@ -729,7 +696,6 @@ class Rule extends EventEmitter$1 {
|
|
|
729
696
|
type: GuidesType.HORIZONTAL,
|
|
730
697
|
guides: this.horizontalGuidelines
|
|
731
698
|
});
|
|
732
|
-
globalThis.localStorage.setItem(H_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
733
699
|
};
|
|
734
700
|
this.vGuidesChangeGuidesHandler = (e) => {
|
|
735
701
|
this.verticalGuidelines = e.guides;
|
|
@@ -737,7 +703,6 @@ class Rule extends EventEmitter$1 {
|
|
|
737
703
|
type: GuidesType.VERTICAL,
|
|
738
704
|
guides: this.verticalGuidelines
|
|
739
705
|
});
|
|
740
|
-
globalThis.localStorage.setItem(V_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
741
706
|
};
|
|
742
707
|
this.container = container;
|
|
743
708
|
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
|
|
@@ -758,25 +723,26 @@ class Rule extends EventEmitter$1 {
|
|
|
758
723
|
showGuides: show
|
|
759
724
|
});
|
|
760
725
|
}
|
|
761
|
-
|
|
762
|
-
this.horizontalGuidelines =
|
|
763
|
-
this.verticalGuidelines =
|
|
764
|
-
this.vGuides.setState({
|
|
765
|
-
defaultGuides: []
|
|
766
|
-
});
|
|
726
|
+
setGuides([hLines, vLines]) {
|
|
727
|
+
this.horizontalGuidelines = hLines;
|
|
728
|
+
this.verticalGuidelines = vLines;
|
|
767
729
|
this.hGuides.setState({
|
|
768
|
-
defaultGuides:
|
|
730
|
+
defaultGuides: hLines
|
|
769
731
|
});
|
|
770
|
-
this.
|
|
771
|
-
|
|
772
|
-
guides: []
|
|
732
|
+
this.vGuides.setState({
|
|
733
|
+
defaultGuides: vLines
|
|
773
734
|
});
|
|
774
735
|
this.emit("changeGuides", {
|
|
775
736
|
type: GuidesType.HORIZONTAL,
|
|
776
|
-
guides:
|
|
737
|
+
guides: hLines
|
|
777
738
|
});
|
|
778
|
-
|
|
779
|
-
|
|
739
|
+
this.emit("changeGuides", {
|
|
740
|
+
type: GuidesType.VERTICAL,
|
|
741
|
+
guides: vLines
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
clearGuides() {
|
|
745
|
+
this.setGuides([[], []]);
|
|
780
746
|
}
|
|
781
747
|
showRule(show = true) {
|
|
782
748
|
if (show) {
|
|
@@ -1068,13 +1034,18 @@ class StageRender extends EventEmitter {
|
|
|
1068
1034
|
});
|
|
1069
1035
|
};
|
|
1070
1036
|
this.loadHandler = async () => {
|
|
1071
|
-
this.
|
|
1037
|
+
this.contentWindow = this.iframe?.contentWindow;
|
|
1038
|
+
this.contentWindow.magic = this.getMagicApi();
|
|
1072
1039
|
if (this.render) {
|
|
1073
1040
|
const el = await this.render(this.core);
|
|
1074
1041
|
if (el) {
|
|
1075
1042
|
this.iframe?.contentDocument?.body?.appendChild(el);
|
|
1076
1043
|
}
|
|
1077
1044
|
}
|
|
1045
|
+
this.emit("onload");
|
|
1046
|
+
this.contentWindow.postMessage({
|
|
1047
|
+
tmagicRuntimeReady: true
|
|
1048
|
+
}, "*");
|
|
1078
1049
|
};
|
|
1079
1050
|
this.core = core;
|
|
1080
1051
|
this.runtimeUrl = core.config.runtimeUrl || "";
|
|
@@ -1098,8 +1069,6 @@ class StageRender extends EventEmitter {
|
|
|
1098
1069
|
this.iframe.srcdoc = html;
|
|
1099
1070
|
}
|
|
1100
1071
|
el.appendChild(this.iframe);
|
|
1101
|
-
this.contentWindow = this.iframe?.contentWindow;
|
|
1102
|
-
this.contentWindow.magic = this.getMagicApi();
|
|
1103
1072
|
} else {
|
|
1104
1073
|
throw Error("mount \u5931\u8D25");
|
|
1105
1074
|
}
|
|
@@ -1243,10 +1212,10 @@ class StageCore extends EventEmitter {
|
|
|
1243
1212
|
setZoom(zoom = DEFAULT_ZOOM) {
|
|
1244
1213
|
this.zoom = zoom;
|
|
1245
1214
|
}
|
|
1246
|
-
mount(el) {
|
|
1215
|
+
async mount(el) {
|
|
1247
1216
|
this.container = el;
|
|
1248
1217
|
const { mask, renderer } = this;
|
|
1249
|
-
renderer.mount(el);
|
|
1218
|
+
await renderer.mount(el);
|
|
1250
1219
|
mask.mount(el);
|
|
1251
1220
|
this.emit("mounted");
|
|
1252
1221
|
}
|
|
@@ -1274,5 +1243,5 @@ class StageCore extends EventEmitter {
|
|
|
1274
1243
|
}
|
|
1275
1244
|
}
|
|
1276
1245
|
|
|
1277
|
-
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 };
|
|
1278
1247
|
//# sourceMappingURL=tmagic-stage.es.js.map
|