@tmagic/stage 1.0.0-rc.1 → 1.0.0-rc.10
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 +215 -115
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +215 -115
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/StageDragResize.d.ts +14 -2
- package/dist/types/src/StageMask.d.ts +2 -0
- package/dist/types/src/TargetCalibrate.d.ts +3 -1
- package/dist/types/src/const.d.ts +24 -1
- package/dist/types/src/types.d.ts +12 -3
- package/dist/types/src/util.d.ts +3 -2
- package/package.json +5 -5
- package/src/Rule.ts +13 -5
- package/src/StageCore.ts +6 -1
- package/src/StageDragResize.ts +150 -61
- package/src/StageHighlight.ts +1 -0
- package/src/StageMask.ts +37 -6
- package/src/StageRender.ts +0 -12
- package/src/TargetCalibrate.ts +15 -31
- package/src/const.ts +24 -2
- package/src/types.ts +13 -3
- package/src/util.ts +40 -29
- package/LICENSE +0 -5432
package/dist/tmagic-stage.umd.js
CHANGED
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
var ZIndex = /* @__PURE__ */ ((ZIndex2) => {
|
|
24
24
|
ZIndex2["MASK"] = "99999";
|
|
25
25
|
ZIndex2["SELECTED_EL"] = "666";
|
|
26
|
+
ZIndex2["GHOST_EL"] = "700";
|
|
27
|
+
ZIndex2["DRAG_EL"] = "9";
|
|
26
28
|
return ZIndex2;
|
|
27
29
|
})(ZIndex || {});
|
|
28
30
|
var MouseButton = /* @__PURE__ */ ((MouseButton2) => {
|
|
@@ -38,31 +40,22 @@
|
|
|
38
40
|
return Mode2;
|
|
39
41
|
})(Mode || {});
|
|
40
42
|
const SELECTED_CLASS = "tmagic-stage-selected-area";
|
|
43
|
+
const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
|
|
44
|
+
const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
|
|
41
45
|
|
|
46
|
+
const getParents = (el, relative) => {
|
|
47
|
+
let cur = el.parentElement;
|
|
48
|
+
const parents = [];
|
|
49
|
+
while (cur && cur !== relative) {
|
|
50
|
+
parents.push(cur);
|
|
51
|
+
cur = cur.parentElement;
|
|
52
|
+
}
|
|
53
|
+
return parents;
|
|
54
|
+
};
|
|
42
55
|
const getOffset = (el) => {
|
|
43
|
-
const { transform } = getComputedStyle(el);
|
|
44
56
|
const { offsetParent } = el;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (transform.indexOf("matrix") > -1) {
|
|
48
|
-
let a = 1;
|
|
49
|
-
let b = 1;
|
|
50
|
-
let c = 1;
|
|
51
|
-
let d = 1;
|
|
52
|
-
let e = 0;
|
|
53
|
-
let f = 0;
|
|
54
|
-
transform.replace(/matrix\((.+), (.+), (.+), (.+), (.+), (.+)\)/, ($0, $1, $2, $3, $4, $5, $6) => {
|
|
55
|
-
a = +$1;
|
|
56
|
-
b = +$2;
|
|
57
|
-
c = +$3;
|
|
58
|
-
d = +$4;
|
|
59
|
-
e = +$5;
|
|
60
|
-
f = +$6;
|
|
61
|
-
return transform;
|
|
62
|
-
});
|
|
63
|
-
left = a * left + c * top + e;
|
|
64
|
-
top = b * left + d * top + f;
|
|
65
|
-
}
|
|
57
|
+
const left = el.offsetLeft;
|
|
58
|
+
const top = el.offsetTop;
|
|
66
59
|
if (offsetParent) {
|
|
67
60
|
const parentOffset = getOffset(offsetParent);
|
|
68
61
|
return {
|
|
@@ -163,18 +156,41 @@
|
|
|
163
156
|
if (oldEl) {
|
|
164
157
|
oldEl.classList.remove(SELECTED_CLASS);
|
|
165
158
|
oldEl.parentNode?.classList.remove(`${SELECTED_CLASS}-parent`);
|
|
159
|
+
doc.querySelectorAll(`.${SELECTED_CLASS}-parents`).forEach((item) => {
|
|
160
|
+
item.classList.remove(`${SELECTED_CLASS}-parents`);
|
|
161
|
+
});
|
|
166
162
|
}
|
|
167
163
|
};
|
|
168
|
-
const addSelectedClassName = (el) => {
|
|
164
|
+
const addSelectedClassName = (el, doc) => {
|
|
169
165
|
el.classList.add(SELECTED_CLASS);
|
|
170
166
|
el.parentNode?.classList.add(`${SELECTED_CLASS}-parent`);
|
|
167
|
+
getParents(el, doc.body).forEach((item) => {
|
|
168
|
+
item.classList.add(`${SELECTED_CLASS}-parents`);
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
const getGuideLineFromCache = (type) => {
|
|
172
|
+
const key = {
|
|
173
|
+
[GuidesType.HORIZONTAL]: H_GUIDE_LINE_STORAGE_KEY,
|
|
174
|
+
[GuidesType.VERTICAL]: V_GUIDE_LINE_STORAGE_KEY
|
|
175
|
+
}[type];
|
|
176
|
+
if (!key)
|
|
177
|
+
return [];
|
|
178
|
+
const guideLineCacheData = globalThis.localStorage.getItem(key);
|
|
179
|
+
if (guideLineCacheData) {
|
|
180
|
+
try {
|
|
181
|
+
return JSON.parse(guideLineCacheData) || [];
|
|
182
|
+
} catch (e) {
|
|
183
|
+
console.error(e);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return [];
|
|
171
187
|
};
|
|
172
188
|
|
|
173
189
|
class StageDragResize extends EventEmitter.EventEmitter {
|
|
174
190
|
constructor(config) {
|
|
175
191
|
super();
|
|
176
|
-
this.horizontalGuidelines =
|
|
177
|
-
this.verticalGuidelines =
|
|
192
|
+
this.horizontalGuidelines = getGuideLineFromCache(GuidesType.HORIZONTAL);
|
|
193
|
+
this.verticalGuidelines = getGuideLineFromCache(GuidesType.VERTICAL);
|
|
178
194
|
this.elementGuidelines = [];
|
|
179
195
|
this.mode = Mode.ABSOLUTE;
|
|
180
196
|
this.moveableOptions = {};
|
|
@@ -187,8 +203,8 @@
|
|
|
187
203
|
select(el, event) {
|
|
188
204
|
const oldTarget = this.target;
|
|
189
205
|
this.target = el;
|
|
190
|
-
this.init(el);
|
|
191
206
|
if (!this.moveable || this.target !== oldTarget) {
|
|
207
|
+
this.init(el);
|
|
192
208
|
this.moveableHelper = MoveableHelper__default["default"].create({
|
|
193
209
|
useBeforeRender: true,
|
|
194
210
|
useRender: false,
|
|
@@ -249,6 +265,26 @@
|
|
|
249
265
|
target: this.dragEl
|
|
250
266
|
});
|
|
251
267
|
}
|
|
268
|
+
setElementGuidelines(nodes) {
|
|
269
|
+
this.elementGuidelines.forEach((node) => {
|
|
270
|
+
node.remove();
|
|
271
|
+
});
|
|
272
|
+
this.elementGuidelines = [];
|
|
273
|
+
if (this.mode === Mode.ABSOLUTE) {
|
|
274
|
+
const frame = document.createDocumentFragment();
|
|
275
|
+
for (const node of nodes) {
|
|
276
|
+
const { width, height } = node.getBoundingClientRect();
|
|
277
|
+
if (node === this.target)
|
|
278
|
+
continue;
|
|
279
|
+
const { left, top } = getOffset(node);
|
|
280
|
+
const elementGuideline = document.createElement("div");
|
|
281
|
+
elementGuideline.style.cssText = `position: absolute;width: ${width}px;height: ${height}px;top: ${top}px;left: ${left}px`;
|
|
282
|
+
this.elementGuidelines.push(elementGuideline);
|
|
283
|
+
frame.append(elementGuideline);
|
|
284
|
+
}
|
|
285
|
+
this.container.append(frame);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
252
288
|
initMoveable() {
|
|
253
289
|
this.moveable?.destroy();
|
|
254
290
|
this.moveable = new Moveable__default["default"](this.container, {
|
|
@@ -256,35 +292,38 @@
|
|
|
256
292
|
});
|
|
257
293
|
this.bindResizeEvent();
|
|
258
294
|
this.bindDragEvent();
|
|
295
|
+
this.bindRotateEvent();
|
|
296
|
+
this.bindScaleEvent();
|
|
259
297
|
}
|
|
260
298
|
bindResizeEvent() {
|
|
261
299
|
if (!this.moveable)
|
|
262
300
|
throw new Error("moveable \u4E3A\u521D\u59CB\u5316");
|
|
301
|
+
const frame = {
|
|
302
|
+
left: 0,
|
|
303
|
+
top: 0
|
|
304
|
+
};
|
|
263
305
|
this.moveable.on("resizeStart", (e) => {
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
306
|
+
if (!this.target)
|
|
307
|
+
return;
|
|
308
|
+
this.dragStatus = "start" /* START */;
|
|
309
|
+
this.moveableHelper?.onResizeStart(e);
|
|
310
|
+
frame.top = this.target.offsetTop;
|
|
311
|
+
frame.left = this.target.offsetLeft;
|
|
312
|
+
}).on("resize", (e) => {
|
|
313
|
+
const { width, height, drag } = e;
|
|
270
314
|
if (!this.moveable || !this.target || !this.dragEl)
|
|
271
315
|
return;
|
|
272
316
|
const { beforeTranslate } = drag;
|
|
273
317
|
this.dragStatus = "ing" /* ING */;
|
|
274
|
-
this.
|
|
275
|
-
this.target.style.height = `${height}px`;
|
|
276
|
-
this.dragEl.style.width = `${width}px`;
|
|
277
|
-
this.dragEl.style.height = `${height}px`;
|
|
318
|
+
this.moveableHelper?.onResize(e);
|
|
278
319
|
if (this.mode === Mode.SORTABLE) {
|
|
279
|
-
this.
|
|
280
|
-
|
|
281
|
-
|
|
320
|
+
this.target.style.top = "0px";
|
|
321
|
+
} else {
|
|
322
|
+
this.target.style.left = `${frame.left + beforeTranslate[0]}px`;
|
|
323
|
+
this.target.style.top = `${frame.top + beforeTranslate[1]}px`;
|
|
282
324
|
}
|
|
283
|
-
this.
|
|
284
|
-
this.
|
|
285
|
-
const offset = getAbsolutePosition(this.target, { left: beforeTranslate[0], top: beforeTranslate[1] });
|
|
286
|
-
this.target.style.left = `${offset.left}px`;
|
|
287
|
-
this.target.style.top = `${offset.top}px`;
|
|
325
|
+
this.target.style.width = `${width}px`;
|
|
326
|
+
this.target.style.height = `${height}px`;
|
|
288
327
|
}).on("resizeEnd", () => {
|
|
289
328
|
this.dragStatus = "end" /* END */;
|
|
290
329
|
this.update(true);
|
|
@@ -293,7 +332,10 @@
|
|
|
293
332
|
bindDragEvent() {
|
|
294
333
|
if (!this.moveable)
|
|
295
334
|
throw new Error("moveable \u4E3A\u521D\u59CB\u5316");
|
|
296
|
-
|
|
335
|
+
const frame = {
|
|
336
|
+
left: 0,
|
|
337
|
+
top: 0
|
|
338
|
+
};
|
|
297
339
|
this.moveable.on("dragStart", (e) => {
|
|
298
340
|
if (!this.target)
|
|
299
341
|
throw new Error("\u672A\u9009\u4E2D\u7EC4\u4EF6");
|
|
@@ -302,22 +344,19 @@
|
|
|
302
344
|
if (this.mode === Mode.SORTABLE) {
|
|
303
345
|
this.ghostEl = this.generateGhostEl(this.target);
|
|
304
346
|
}
|
|
347
|
+
frame.top = this.target.offsetTop;
|
|
348
|
+
frame.left = this.target.offsetLeft;
|
|
305
349
|
}).on("drag", (e) => {
|
|
306
350
|
if (!this.target || !this.dragEl)
|
|
307
351
|
return;
|
|
308
|
-
if (!offset) {
|
|
309
|
-
offset = getAbsolutePosition(this.target, { left: 0, top: 0 });
|
|
310
|
-
}
|
|
311
352
|
this.dragStatus = "ing" /* ING */;
|
|
312
|
-
const { left, top } = e;
|
|
313
353
|
if (this.ghostEl) {
|
|
314
|
-
this.
|
|
315
|
-
this.ghostEl.style.top = `${top + offset.top}px`;
|
|
354
|
+
this.ghostEl.style.top = `${frame.top + e.beforeTranslate[1]}px`;
|
|
316
355
|
return;
|
|
317
356
|
}
|
|
318
357
|
this.moveableHelper?.onDrag(e);
|
|
319
|
-
this.target.style.left = `${left +
|
|
320
|
-
this.target.style.top = `${top +
|
|
358
|
+
this.target.style.left = `${frame.left + e.beforeTranslate[0]}px`;
|
|
359
|
+
this.target.style.top = `${frame.top + e.beforeTranslate[1]}px`;
|
|
321
360
|
}).on("dragEnd", () => {
|
|
322
361
|
if (this.dragStatus === "ing" /* ING */) {
|
|
323
362
|
switch (this.mode) {
|
|
@@ -328,18 +367,57 @@
|
|
|
328
367
|
this.update();
|
|
329
368
|
}
|
|
330
369
|
}
|
|
331
|
-
offset = null;
|
|
332
370
|
this.dragStatus = "end" /* END */;
|
|
333
371
|
this.destroyGhostEl();
|
|
334
372
|
});
|
|
335
373
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
374
|
+
bindRotateEvent() {
|
|
375
|
+
if (!this.moveable)
|
|
376
|
+
throw new Error("moveable \u4E3A\u521D\u59CB\u5316");
|
|
377
|
+
this.moveable.on("rotateStart", (e) => {
|
|
378
|
+
this.dragStatus = "start" /* START */;
|
|
379
|
+
this.moveableHelper?.onRotateStart(e);
|
|
380
|
+
}).on("rotate", (e) => {
|
|
381
|
+
if (!this.target || !this.dragEl)
|
|
382
|
+
return;
|
|
383
|
+
this.dragStatus = "ing" /* ING */;
|
|
384
|
+
this.moveableHelper?.onRotate(e);
|
|
385
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
386
|
+
this.target.style.transform = frame?.toCSSObject().transform || "";
|
|
387
|
+
}).on("rotateEnd", (e) => {
|
|
388
|
+
this.dragStatus = "end" /* END */;
|
|
389
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
390
|
+
this.emit("update", {
|
|
391
|
+
el: this.target,
|
|
392
|
+
style: {
|
|
393
|
+
transform: frame?.get("transform")
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
bindScaleEvent() {
|
|
399
|
+
if (!this.moveable)
|
|
400
|
+
throw new Error("moveable \u4E3A\u521D\u59CB\u5316");
|
|
401
|
+
this.moveable.on("scaleStart", (e) => {
|
|
402
|
+
this.dragStatus = "start" /* START */;
|
|
403
|
+
this.moveableHelper?.onScaleStart(e);
|
|
404
|
+
}).on("scale", (e) => {
|
|
405
|
+
if (!this.target || !this.dragEl)
|
|
406
|
+
return;
|
|
407
|
+
this.dragStatus = "ing" /* ING */;
|
|
408
|
+
this.moveableHelper?.onScale(e);
|
|
409
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
410
|
+
this.target.style.transform = frame?.toCSSObject().transform || "";
|
|
411
|
+
}).on("scaleEnd", (e) => {
|
|
412
|
+
this.dragStatus = "end" /* END */;
|
|
413
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
414
|
+
this.emit("update", {
|
|
415
|
+
el: this.target,
|
|
416
|
+
style: {
|
|
417
|
+
transform: frame?.get("transform")
|
|
418
|
+
}
|
|
419
|
+
});
|
|
341
420
|
});
|
|
342
|
-
return getSnapElements(el).filter((element) => element !== this.target && !this.target?.contains(element) && element !== mask.page);
|
|
343
421
|
}
|
|
344
422
|
sort() {
|
|
345
423
|
if (!this.target || !this.ghostEl)
|
|
@@ -361,12 +439,13 @@
|
|
|
361
439
|
}
|
|
362
440
|
}
|
|
363
441
|
update(isResize = false) {
|
|
364
|
-
|
|
365
|
-
|
|
442
|
+
if (!this.target)
|
|
443
|
+
return;
|
|
444
|
+
const offset = this.mode === Mode.SORTABLE ? { left: 0, top: 0 } : { left: this.target.offsetLeft, top: this.target.offsetTop };
|
|
366
445
|
const left = this.calcValueByFontsize(offset.left);
|
|
367
446
|
const top = this.calcValueByFontsize(offset.top);
|
|
368
|
-
const width = this.calcValueByFontsize(
|
|
369
|
-
const height = this.calcValueByFontsize(
|
|
447
|
+
const width = this.calcValueByFontsize(this.target.clientWidth);
|
|
448
|
+
const height = this.calcValueByFontsize(this.target.clientHeight);
|
|
370
449
|
this.emit("update", {
|
|
371
450
|
el: this.target,
|
|
372
451
|
style: isResize ? { left, top, width, height } : { left, top }
|
|
@@ -379,7 +458,7 @@
|
|
|
379
458
|
const ghostEl = el.cloneNode(true);
|
|
380
459
|
const { top, left } = getAbsolutePosition(el, getOffset(el));
|
|
381
460
|
ghostEl.id = `${GHOST_EL_ID_PREFIX}${el.id}`;
|
|
382
|
-
ghostEl.style.zIndex =
|
|
461
|
+
ghostEl.style.zIndex = ZIndex.GHOST_EL;
|
|
383
462
|
ghostEl.style.opacity = ".5";
|
|
384
463
|
ghostEl.style.position = "absolute";
|
|
385
464
|
ghostEl.style.left = `${left}px`;
|
|
@@ -392,17 +471,21 @@
|
|
|
392
471
|
this.ghostEl = void 0;
|
|
393
472
|
}
|
|
394
473
|
updateDragEl(el) {
|
|
395
|
-
const { width, height } = el.getBoundingClientRect();
|
|
396
474
|
const offset = getOffset(el);
|
|
475
|
+
const { transform } = getComputedStyle(el);
|
|
397
476
|
this.dragEl.style.cssText = `
|
|
398
477
|
position: absolute;
|
|
478
|
+
transform: ${transform};
|
|
399
479
|
left: ${offset.left}px;
|
|
400
480
|
top: ${offset.top}px;
|
|
401
|
-
width: ${
|
|
402
|
-
height: ${
|
|
403
|
-
z-index:
|
|
481
|
+
width: ${el.clientWidth}px;
|
|
482
|
+
height: ${el.clientHeight}px;
|
|
483
|
+
z-index: ${ZIndex.DRAG_EL};
|
|
404
484
|
`;
|
|
405
485
|
this.dragEl.id = `${DRAG_EL_ID_PREFIX}${el.id}`;
|
|
486
|
+
if (typeof this.core.config.updateDragEl === "function") {
|
|
487
|
+
this.core.config.updateDragEl(this.dragEl, el);
|
|
488
|
+
}
|
|
406
489
|
}
|
|
407
490
|
destroyDragEl() {
|
|
408
491
|
this.dragEl?.remove();
|
|
@@ -416,6 +499,11 @@
|
|
|
416
499
|
if (typeof moveableOptions === "function") {
|
|
417
500
|
moveableOptions = moveableOptions(this.core);
|
|
418
501
|
}
|
|
502
|
+
const elementGuidelines = moveableOptions.elementGuidelines || this.target.parentElement?.children || [];
|
|
503
|
+
this.setElementGuidelines(elementGuidelines);
|
|
504
|
+
if (moveableOptions.elementGuidelines) {
|
|
505
|
+
delete moveableOptions.elementGuidelines;
|
|
506
|
+
}
|
|
419
507
|
return {
|
|
420
508
|
origin: false,
|
|
421
509
|
rootContainer: this.core.container,
|
|
@@ -423,6 +511,8 @@
|
|
|
423
511
|
dragArea: false,
|
|
424
512
|
draggable: true,
|
|
425
513
|
resizable: true,
|
|
514
|
+
scalable: false,
|
|
515
|
+
rotatable: false,
|
|
426
516
|
snappable: isAbsolute || isFixed,
|
|
427
517
|
snapGap: isAbsolute || isFixed,
|
|
428
518
|
snapThreshold: 5,
|
|
@@ -521,49 +611,34 @@
|
|
|
521
611
|
this.parent = config.parent;
|
|
522
612
|
this.mask = config.mask;
|
|
523
613
|
this.dr = config.dr;
|
|
614
|
+
this.core = config.core;
|
|
524
615
|
this.operationEl = globalThis.document.createElement("div");
|
|
525
616
|
this.parent.append(this.operationEl);
|
|
526
617
|
}
|
|
527
618
|
update(el, prefix) {
|
|
528
|
-
const { width, height } = el.getBoundingClientRect();
|
|
529
619
|
const { left, top } = this.getOffset(el);
|
|
620
|
+
const { transform } = getComputedStyle(el);
|
|
530
621
|
this.operationEl.style.cssText = `
|
|
531
622
|
position: absolute;
|
|
623
|
+
transform: ${transform};
|
|
532
624
|
left: ${left}px;
|
|
533
625
|
top: ${top}px;
|
|
534
|
-
width: ${
|
|
535
|
-
height: ${
|
|
626
|
+
width: ${el.clientWidth}px;
|
|
627
|
+
height: ${el.clientHeight}px;
|
|
536
628
|
`;
|
|
537
629
|
this.operationEl.id = `${prefix}${el.id}`;
|
|
630
|
+
if (typeof this.core.config.updateDragEl === "function") {
|
|
631
|
+
this.core.config.updateDragEl(this.operationEl, el);
|
|
632
|
+
}
|
|
538
633
|
return this.operationEl;
|
|
539
634
|
}
|
|
540
635
|
destroy() {
|
|
541
636
|
this.operationEl?.remove();
|
|
542
637
|
}
|
|
543
638
|
getOffset(el) {
|
|
544
|
-
const { transform } = getComputedStyle(el);
|
|
545
639
|
const { offsetParent } = el;
|
|
546
|
-
|
|
547
|
-
|
|
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
|
-
}
|
|
640
|
+
const left = el.offsetLeft;
|
|
641
|
+
const top = el.offsetTop;
|
|
567
642
|
if (offsetParent) {
|
|
568
643
|
const parentOffset = this.getOffset(offsetParent);
|
|
569
644
|
return {
|
|
@@ -604,7 +679,8 @@
|
|
|
604
679
|
this.calibrationTarget = new TargetCalibrate({
|
|
605
680
|
parent: this.core.mask.content,
|
|
606
681
|
mask: this.core.mask,
|
|
607
|
-
dr: this.core.dr
|
|
682
|
+
dr: this.core.dr,
|
|
683
|
+
core: this.core
|
|
608
684
|
});
|
|
609
685
|
}
|
|
610
686
|
highlight(el) {
|
|
@@ -635,8 +711,8 @@
|
|
|
635
711
|
class Rule extends EventEmitter__default["default"] {
|
|
636
712
|
constructor(container) {
|
|
637
713
|
super();
|
|
638
|
-
this.horizontalGuidelines =
|
|
639
|
-
this.verticalGuidelines =
|
|
714
|
+
this.horizontalGuidelines = getGuideLineFromCache(GuidesType.HORIZONTAL);
|
|
715
|
+
this.verticalGuidelines = getGuideLineFromCache(GuidesType.VERTICAL);
|
|
640
716
|
this.getGuidesStyle = (type) => ({
|
|
641
717
|
position: "fixed",
|
|
642
718
|
zIndex: 1,
|
|
@@ -660,6 +736,7 @@
|
|
|
660
736
|
type: GuidesType.HORIZONTAL,
|
|
661
737
|
guides: this.horizontalGuidelines
|
|
662
738
|
});
|
|
739
|
+
globalThis.localStorage.setItem(H_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
663
740
|
};
|
|
664
741
|
this.vGuidesChangeGuidesHandler = (e) => {
|
|
665
742
|
this.verticalGuidelines = e.guides;
|
|
@@ -667,10 +744,11 @@
|
|
|
667
744
|
type: GuidesType.VERTICAL,
|
|
668
745
|
guides: this.verticalGuidelines
|
|
669
746
|
});
|
|
747
|
+
globalThis.localStorage.setItem(V_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
670
748
|
};
|
|
671
749
|
this.container = container;
|
|
672
|
-
this.hGuides = this.createGuides(GuidesType.HORIZONTAL);
|
|
673
|
-
this.vGuides = this.createGuides(GuidesType.VERTICAL);
|
|
750
|
+
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
|
|
751
|
+
this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
|
|
674
752
|
this.hGuides.on("changeGuides", this.hGuidesChangeGuidesHandler);
|
|
675
753
|
this.vGuides.on("changeGuides", this.vGuidesChangeGuidesHandler);
|
|
676
754
|
this.containerResizeObserver = new ResizeObserver(() => {
|
|
@@ -704,6 +782,8 @@
|
|
|
704
782
|
type: GuidesType.HORIZONTAL,
|
|
705
783
|
guides: []
|
|
706
784
|
});
|
|
785
|
+
globalThis.localStorage.setItem(V_GUIDE_LINE_STORAGE_KEY, "[]");
|
|
786
|
+
globalThis.localStorage.setItem(H_GUIDE_LINE_STORAGE_KEY, "[]");
|
|
707
787
|
}
|
|
708
788
|
showRule(show = true) {
|
|
709
789
|
if (show) {
|
|
@@ -787,6 +867,7 @@
|
|
|
787
867
|
this.wrapperWidth = 0;
|
|
788
868
|
this.maxScrollTop = 0;
|
|
789
869
|
this.maxScrollLeft = 0;
|
|
870
|
+
this.intersectionObserver = null;
|
|
790
871
|
this.mode = Mode.ABSOLUTE;
|
|
791
872
|
this.pageResizeObserver = null;
|
|
792
873
|
this.wrapperResizeObserver = null;
|
|
@@ -826,7 +907,6 @@
|
|
|
826
907
|
if (this.maxScrollLeft > 0) {
|
|
827
908
|
this.scrollLeft = this.scrollLeft + deltaX;
|
|
828
909
|
}
|
|
829
|
-
this.fixScrollValue();
|
|
830
910
|
this.scroll();
|
|
831
911
|
this.emit("scroll", event);
|
|
832
912
|
};
|
|
@@ -858,15 +938,33 @@
|
|
|
858
938
|
this.page = page;
|
|
859
939
|
this.pageScrollParent = getScrollParent(page) || this.core.renderer.contentWindow?.document.documentElement || null;
|
|
860
940
|
this.pageResizeObserver?.disconnect();
|
|
941
|
+
this.wrapperResizeObserver?.disconnect();
|
|
942
|
+
this.intersectionObserver?.disconnect();
|
|
943
|
+
if (typeof IntersectionObserver !== "undefined") {
|
|
944
|
+
this.intersectionObserver = new IntersectionObserver((entries) => {
|
|
945
|
+
entries.forEach((entry) => {
|
|
946
|
+
const { target, intersectionRatio } = entry;
|
|
947
|
+
if (intersectionRatio <= 0) {
|
|
948
|
+
this.scrollIntoView(target);
|
|
949
|
+
}
|
|
950
|
+
this.intersectionObserver?.unobserve(target);
|
|
951
|
+
});
|
|
952
|
+
}, {
|
|
953
|
+
root: this.pageScrollParent,
|
|
954
|
+
rootMargin: "0px",
|
|
955
|
+
threshold: 1
|
|
956
|
+
});
|
|
957
|
+
}
|
|
861
958
|
if (typeof ResizeObserver !== "undefined") {
|
|
862
959
|
this.pageResizeObserver = new ResizeObserver((entries) => {
|
|
863
960
|
const [entry] = entries;
|
|
864
961
|
const { clientHeight, clientWidth } = entry.target;
|
|
865
962
|
this.setHeight(clientHeight);
|
|
866
963
|
this.setWidth(clientWidth);
|
|
867
|
-
this.fixScrollValue();
|
|
868
964
|
this.scroll();
|
|
869
|
-
this.core.dr.
|
|
965
|
+
if (this.core.dr.moveable) {
|
|
966
|
+
this.core.dr.updateMoveable();
|
|
967
|
+
}
|
|
870
968
|
});
|
|
871
969
|
this.pageResizeObserver.observe(page);
|
|
872
970
|
this.wrapperResizeObserver = new ResizeObserver((entries) => {
|
|
@@ -888,6 +986,14 @@
|
|
|
888
986
|
setLayout(el) {
|
|
889
987
|
this.setMode(isFixedParent(el) ? Mode.FIXED : Mode.ABSOLUTE);
|
|
890
988
|
}
|
|
989
|
+
scrollIntoView(el) {
|
|
990
|
+
el.scrollIntoView();
|
|
991
|
+
if (!this.pageScrollParent)
|
|
992
|
+
return;
|
|
993
|
+
this.scrollLeft = this.pageScrollParent.scrollLeft;
|
|
994
|
+
this.scrollTop = this.pageScrollParent.scrollTop;
|
|
995
|
+
this.scroll();
|
|
996
|
+
}
|
|
891
997
|
destroy() {
|
|
892
998
|
this.content?.remove();
|
|
893
999
|
this.page = null;
|
|
@@ -898,6 +1004,7 @@
|
|
|
898
1004
|
super.destroy();
|
|
899
1005
|
}
|
|
900
1006
|
scroll() {
|
|
1007
|
+
this.fixScrollValue();
|
|
901
1008
|
let { scrollLeft, scrollTop } = this;
|
|
902
1009
|
if (this.pageScrollParent) {
|
|
903
1010
|
this.pageScrollParent.scrollTo({
|
|
@@ -926,10 +1033,10 @@
|
|
|
926
1033
|
this.content.style.width = `${width}px`;
|
|
927
1034
|
}
|
|
928
1035
|
setMaxScrollLeft() {
|
|
929
|
-
this.maxScrollLeft = this.width - this.wrapperWidth;
|
|
1036
|
+
this.maxScrollLeft = Math.max(this.width - this.wrapperWidth, 0);
|
|
930
1037
|
}
|
|
931
1038
|
setMaxScrollTop() {
|
|
932
|
-
this.maxScrollTop = this.height - this.wrapperHeight;
|
|
1039
|
+
this.maxScrollTop = Math.max(this.height - this.wrapperHeight, 0);
|
|
933
1040
|
}
|
|
934
1041
|
fixScrollValue() {
|
|
935
1042
|
if (this.scrollTop < 0)
|
|
@@ -975,16 +1082,6 @@
|
|
|
975
1082
|
this.iframe?.contentDocument?.body?.appendChild(el);
|
|
976
1083
|
}
|
|
977
1084
|
}
|
|
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
1085
|
};
|
|
989
1086
|
this.core = core;
|
|
990
1087
|
this.runtimeUrl = core.config.runtimeUrl || "";
|
|
@@ -1103,11 +1200,14 @@
|
|
|
1103
1200
|
}
|
|
1104
1201
|
this.mask.setLayout(el);
|
|
1105
1202
|
this.dr.select(el, event);
|
|
1203
|
+
if (this.config.autoScrollIntoView || el.dataset.autoScrollIntoView) {
|
|
1204
|
+
this.mask.intersectionObserver?.observe(el);
|
|
1205
|
+
}
|
|
1106
1206
|
this.selectedDom = el;
|
|
1107
1207
|
if (this.renderer.contentWindow) {
|
|
1108
1208
|
removeSelectedClassName(this.renderer.contentWindow.document);
|
|
1109
1209
|
if (this.selectedDom) {
|
|
1110
|
-
addSelectedClassName(this.selectedDom);
|
|
1210
|
+
addSelectedClassName(this.selectedDom, this.renderer.contentWindow.document);
|
|
1111
1211
|
}
|
|
1112
1212
|
}
|
|
1113
1213
|
}
|