@tmagic/stage 1.0.0-rc.5 → 1.0.0-rc.8
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 +94 -84
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +94 -84
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/StageDragResize.d.ts +3 -1
- package/dist/types/src/TargetCalibrate.d.ts +3 -1
- package/dist/types/src/types.d.ts +9 -3
- package/package.json +5 -6
- package/src/StageDragResize.ts +88 -35
- package/src/StageHighlight.ts +1 -0
- package/src/StageRender.ts +0 -12
- package/src/TargetCalibrate.ts +15 -31
- package/src/types.ts +10 -3
- package/src/util.ts +2 -27
- package/LICENSE +0 -5432
package/dist/tmagic-stage.umd.js
CHANGED
|
@@ -53,29 +53,9 @@
|
|
|
53
53
|
return parents;
|
|
54
54
|
};
|
|
55
55
|
const getOffset = (el) => {
|
|
56
|
-
const { transform } = getComputedStyle(el);
|
|
57
56
|
const { offsetParent } = el;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (transform.indexOf("matrix") > -1) {
|
|
61
|
-
let a = 1;
|
|
62
|
-
let b = 1;
|
|
63
|
-
let c = 1;
|
|
64
|
-
let d = 1;
|
|
65
|
-
let e = 0;
|
|
66
|
-
let f = 0;
|
|
67
|
-
transform.replace(/matrix\((.+), (.+), (.+), (.+), (.+), (.+)\)/, ($0, $1, $2, $3, $4, $5, $6) => {
|
|
68
|
-
a = +$1;
|
|
69
|
-
b = +$2;
|
|
70
|
-
c = +$3;
|
|
71
|
-
d = +$4;
|
|
72
|
-
e = +$5;
|
|
73
|
-
f = +$6;
|
|
74
|
-
return transform;
|
|
75
|
-
});
|
|
76
|
-
left = a * left + c * top + e;
|
|
77
|
-
top = b * left + d * top + f;
|
|
78
|
-
}
|
|
57
|
+
const left = el.offsetLeft;
|
|
58
|
+
const top = el.offsetTop;
|
|
79
59
|
if (offsetParent) {
|
|
80
60
|
const parentOffset = getOffset(offsetParent);
|
|
81
61
|
return {
|
|
@@ -223,8 +203,8 @@
|
|
|
223
203
|
select(el, event) {
|
|
224
204
|
const oldTarget = this.target;
|
|
225
205
|
this.target = el;
|
|
226
|
-
this.init(el);
|
|
227
206
|
if (!this.moveable || this.target !== oldTarget) {
|
|
207
|
+
this.init(el);
|
|
228
208
|
this.moveableHelper = MoveableHelper__default["default"].create({
|
|
229
209
|
useBeforeRender: true,
|
|
230
210
|
useRender: false,
|
|
@@ -312,35 +292,34 @@
|
|
|
312
292
|
});
|
|
313
293
|
this.bindResizeEvent();
|
|
314
294
|
this.bindDragEvent();
|
|
295
|
+
this.bindRotateEvent();
|
|
296
|
+
this.bindScaleEvent();
|
|
315
297
|
}
|
|
316
298
|
bindResizeEvent() {
|
|
317
299
|
if (!this.moveable)
|
|
318
300
|
throw new Error("moveable \u4E3A\u521D\u59CB\u5316");
|
|
301
|
+
const frame = {
|
|
302
|
+
left: 0,
|
|
303
|
+
top: 0
|
|
304
|
+
};
|
|
319
305
|
this.moveable.on("resizeStart", (e) => {
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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;
|
|
326
314
|
if (!this.moveable || !this.target || !this.dragEl)
|
|
327
315
|
return;
|
|
328
316
|
const { beforeTranslate } = drag;
|
|
329
317
|
this.dragStatus = "ing" /* ING */;
|
|
318
|
+
this.moveableHelper?.onResize(e);
|
|
330
319
|
this.target.style.width = `${width}px`;
|
|
331
320
|
this.target.style.height = `${height}px`;
|
|
332
|
-
this.
|
|
333
|
-
this.
|
|
334
|
-
if (this.mode === Mode.SORTABLE) {
|
|
335
|
-
this.dragEl.style.top = `${beforeTranslate[1]}px`;
|
|
336
|
-
this.target.style.top = `0px`;
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
this.dragEl.style.left = `${beforeTranslate[0]}px`;
|
|
340
|
-
this.dragEl.style.top = `${beforeTranslate[1]}px`;
|
|
341
|
-
const offset = getAbsolutePosition(this.target, { left: beforeTranslate[0], top: beforeTranslate[1] });
|
|
342
|
-
this.target.style.left = `${offset.left}px`;
|
|
343
|
-
this.target.style.top = `${offset.top}px`;
|
|
321
|
+
this.target.style.left = `${frame.left + beforeTranslate[0]}px`;
|
|
322
|
+
this.target.style.top = `${frame.top + beforeTranslate[1]}px`;
|
|
344
323
|
}).on("resizeEnd", () => {
|
|
345
324
|
this.dragStatus = "end" /* END */;
|
|
346
325
|
this.update(true);
|
|
@@ -389,6 +368,54 @@
|
|
|
389
368
|
this.destroyGhostEl();
|
|
390
369
|
});
|
|
391
370
|
}
|
|
371
|
+
bindRotateEvent() {
|
|
372
|
+
if (!this.moveable)
|
|
373
|
+
throw new Error("moveable \u4E3A\u521D\u59CB\u5316");
|
|
374
|
+
this.moveable.on("rotateStart", (e) => {
|
|
375
|
+
this.dragStatus = "start" /* START */;
|
|
376
|
+
this.moveableHelper?.onRotateStart(e);
|
|
377
|
+
}).on("rotate", (e) => {
|
|
378
|
+
if (!this.target || !this.dragEl)
|
|
379
|
+
return;
|
|
380
|
+
this.dragStatus = "ing" /* ING */;
|
|
381
|
+
this.moveableHelper?.onRotate(e);
|
|
382
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
383
|
+
this.target.style.transform = frame?.toCSSObject().transform || "";
|
|
384
|
+
}).on("rotateEnd", (e) => {
|
|
385
|
+
this.dragStatus = "end" /* END */;
|
|
386
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
387
|
+
this.emit("update", {
|
|
388
|
+
el: this.target,
|
|
389
|
+
style: {
|
|
390
|
+
transform: frame?.get("transform")
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
bindScaleEvent() {
|
|
396
|
+
if (!this.moveable)
|
|
397
|
+
throw new Error("moveable \u4E3A\u521D\u59CB\u5316");
|
|
398
|
+
this.moveable.on("scaleStart", (e) => {
|
|
399
|
+
this.dragStatus = "start" /* START */;
|
|
400
|
+
this.moveableHelper?.onScaleStart(e);
|
|
401
|
+
}).on("scale", (e) => {
|
|
402
|
+
if (!this.target || !this.dragEl)
|
|
403
|
+
return;
|
|
404
|
+
this.dragStatus = "ing" /* ING */;
|
|
405
|
+
this.moveableHelper?.onScale(e);
|
|
406
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
407
|
+
this.target.style.transform = frame?.toCSSObject().transform || "";
|
|
408
|
+
}).on("scaleEnd", (e) => {
|
|
409
|
+
this.dragStatus = "end" /* END */;
|
|
410
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
411
|
+
this.emit("update", {
|
|
412
|
+
el: this.target,
|
|
413
|
+
style: {
|
|
414
|
+
transform: frame?.get("transform")
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
}
|
|
392
419
|
sort() {
|
|
393
420
|
if (!this.target || !this.ghostEl)
|
|
394
421
|
throw new Error("\u672A\u77E5\u9519\u8BEF");
|
|
@@ -409,12 +436,13 @@
|
|
|
409
436
|
}
|
|
410
437
|
}
|
|
411
438
|
update(isResize = false) {
|
|
412
|
-
|
|
413
|
-
|
|
439
|
+
if (!this.target)
|
|
440
|
+
return;
|
|
441
|
+
const offset = this.mode === Mode.SORTABLE ? { left: 0, top: 0 } : { left: this.target.offsetLeft, top: this.target.offsetTop };
|
|
414
442
|
const left = this.calcValueByFontsize(offset.left);
|
|
415
443
|
const top = this.calcValueByFontsize(offset.top);
|
|
416
|
-
const width = this.calcValueByFontsize(
|
|
417
|
-
const height = this.calcValueByFontsize(
|
|
444
|
+
const width = this.calcValueByFontsize(this.target.clientWidth);
|
|
445
|
+
const height = this.calcValueByFontsize(this.target.clientHeight);
|
|
418
446
|
this.emit("update", {
|
|
419
447
|
el: this.target,
|
|
420
448
|
style: isResize ? { left, top, width, height } : { left, top }
|
|
@@ -440,17 +468,21 @@
|
|
|
440
468
|
this.ghostEl = void 0;
|
|
441
469
|
}
|
|
442
470
|
updateDragEl(el) {
|
|
443
|
-
const { width, height } = el.getBoundingClientRect();
|
|
444
471
|
const offset = getOffset(el);
|
|
472
|
+
const { transform } = getComputedStyle(el);
|
|
445
473
|
this.dragEl.style.cssText = `
|
|
446
474
|
position: absolute;
|
|
475
|
+
transform: ${transform};
|
|
447
476
|
left: ${offset.left}px;
|
|
448
477
|
top: ${offset.top}px;
|
|
449
|
-
width: ${
|
|
450
|
-
height: ${
|
|
478
|
+
width: ${el.clientWidth}px;
|
|
479
|
+
height: ${el.clientHeight}px;
|
|
451
480
|
z-index: ${ZIndex.DRAG_EL};
|
|
452
481
|
`;
|
|
453
482
|
this.dragEl.id = `${DRAG_EL_ID_PREFIX}${el.id}`;
|
|
483
|
+
if (typeof this.core.config.updateDragEl === "function") {
|
|
484
|
+
this.core.config.updateDragEl(this.dragEl, el);
|
|
485
|
+
}
|
|
454
486
|
}
|
|
455
487
|
destroyDragEl() {
|
|
456
488
|
this.dragEl?.remove();
|
|
@@ -476,6 +508,8 @@
|
|
|
476
508
|
dragArea: false,
|
|
477
509
|
draggable: true,
|
|
478
510
|
resizable: true,
|
|
511
|
+
scalable: false,
|
|
512
|
+
rotatable: false,
|
|
479
513
|
snappable: isAbsolute || isFixed,
|
|
480
514
|
snapGap: isAbsolute || isFixed,
|
|
481
515
|
snapThreshold: 5,
|
|
@@ -574,49 +608,34 @@
|
|
|
574
608
|
this.parent = config.parent;
|
|
575
609
|
this.mask = config.mask;
|
|
576
610
|
this.dr = config.dr;
|
|
611
|
+
this.core = config.core;
|
|
577
612
|
this.operationEl = globalThis.document.createElement("div");
|
|
578
613
|
this.parent.append(this.operationEl);
|
|
579
614
|
}
|
|
580
615
|
update(el, prefix) {
|
|
581
|
-
const { width, height } = el.getBoundingClientRect();
|
|
582
616
|
const { left, top } = this.getOffset(el);
|
|
617
|
+
const { transform } = getComputedStyle(el);
|
|
583
618
|
this.operationEl.style.cssText = `
|
|
584
619
|
position: absolute;
|
|
620
|
+
transform: ${transform};
|
|
585
621
|
left: ${left}px;
|
|
586
622
|
top: ${top}px;
|
|
587
|
-
width: ${
|
|
588
|
-
height: ${
|
|
623
|
+
width: ${el.clientWidth}px;
|
|
624
|
+
height: ${el.clientHeight}px;
|
|
589
625
|
`;
|
|
590
626
|
this.operationEl.id = `${prefix}${el.id}`;
|
|
627
|
+
if (typeof this.core.config.updateDragEl === "function") {
|
|
628
|
+
this.core.config.updateDragEl(this.operationEl, el);
|
|
629
|
+
}
|
|
591
630
|
return this.operationEl;
|
|
592
631
|
}
|
|
593
632
|
destroy() {
|
|
594
633
|
this.operationEl?.remove();
|
|
595
634
|
}
|
|
596
635
|
getOffset(el) {
|
|
597
|
-
const { transform } = getComputedStyle(el);
|
|
598
636
|
const { offsetParent } = el;
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
if (transform.indexOf("matrix") > -1) {
|
|
602
|
-
let a = 1;
|
|
603
|
-
let b = 1;
|
|
604
|
-
let c = 1;
|
|
605
|
-
let d = 1;
|
|
606
|
-
let e = 0;
|
|
607
|
-
let f = 0;
|
|
608
|
-
transform.replace(/matrix\((.+), (.+), (.+), (.+), (.+), (.+)\)/, ($0, $1, $2, $3, $4, $5, $6) => {
|
|
609
|
-
a = +$1;
|
|
610
|
-
b = +$2;
|
|
611
|
-
c = +$3;
|
|
612
|
-
d = +$4;
|
|
613
|
-
e = +$5;
|
|
614
|
-
f = +$6;
|
|
615
|
-
return transform;
|
|
616
|
-
});
|
|
617
|
-
left = a * left + c * top + e;
|
|
618
|
-
top = b * left + d * top + f;
|
|
619
|
-
}
|
|
637
|
+
const left = el.offsetLeft;
|
|
638
|
+
const top = el.offsetTop;
|
|
620
639
|
if (offsetParent) {
|
|
621
640
|
const parentOffset = this.getOffset(offsetParent);
|
|
622
641
|
return {
|
|
@@ -657,7 +676,8 @@
|
|
|
657
676
|
this.calibrationTarget = new TargetCalibrate({
|
|
658
677
|
parent: this.core.mask.content,
|
|
659
678
|
mask: this.core.mask,
|
|
660
|
-
dr: this.core.dr
|
|
679
|
+
dr: this.core.dr,
|
|
680
|
+
core: this.core
|
|
661
681
|
});
|
|
662
682
|
}
|
|
663
683
|
highlight(el) {
|
|
@@ -1059,16 +1079,6 @@
|
|
|
1059
1079
|
this.iframe?.contentDocument?.body?.appendChild(el);
|
|
1060
1080
|
}
|
|
1061
1081
|
}
|
|
1062
|
-
if (this.contentWindow) {
|
|
1063
|
-
const style = this.contentWindow.document.createElement("style");
|
|
1064
|
-
style.id = "tmagic-stage-render";
|
|
1065
|
-
style.innerHTML = `
|
|
1066
|
-
.${SELECTED_CLASS}, .${SELECTED_CLASS}-parent {
|
|
1067
|
-
z-index: ${ZIndex.SELECTED_EL};
|
|
1068
|
-
}
|
|
1069
|
-
`;
|
|
1070
|
-
this.contentWindow.document.head.appendChild(style);
|
|
1071
|
-
}
|
|
1072
1082
|
};
|
|
1073
1083
|
this.core = core;
|
|
1074
1084
|
this.runtimeUrl = core.config.runtimeUrl || "";
|