@tmagic/stage 1.0.0-rc.6 → 1.0.0-rc.9
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 +107 -84
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +107 -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 +102 -45
- package/src/StageHighlight.ts +1 -0
- 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,38 @@
|
|
|
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 */;
|
|
330
|
-
this.
|
|
331
|
-
this.target.style.height = `${height}px`;
|
|
332
|
-
this.dragEl.style.width = `${width}px`;
|
|
333
|
-
this.dragEl.style.height = `${height}px`;
|
|
318
|
+
this.moveableHelper?.onResize(e);
|
|
334
319
|
if (this.mode === Mode.SORTABLE) {
|
|
335
|
-
this.
|
|
336
|
-
|
|
337
|
-
|
|
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`;
|
|
338
324
|
}
|
|
339
|
-
this.
|
|
340
|
-
this.
|
|
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`;
|
|
325
|
+
this.target.style.width = `${width}px`;
|
|
326
|
+
this.target.style.height = `${height}px`;
|
|
344
327
|
}).on("resizeEnd", () => {
|
|
345
328
|
this.dragStatus = "end" /* END */;
|
|
346
329
|
this.update(true);
|
|
@@ -349,7 +332,10 @@
|
|
|
349
332
|
bindDragEvent() {
|
|
350
333
|
if (!this.moveable)
|
|
351
334
|
throw new Error("moveable \u4E3A\u521D\u59CB\u5316");
|
|
352
|
-
|
|
335
|
+
const frame = {
|
|
336
|
+
left: 0,
|
|
337
|
+
top: 0
|
|
338
|
+
};
|
|
353
339
|
this.moveable.on("dragStart", (e) => {
|
|
354
340
|
if (!this.target)
|
|
355
341
|
throw new Error("\u672A\u9009\u4E2D\u7EC4\u4EF6");
|
|
@@ -358,22 +344,19 @@
|
|
|
358
344
|
if (this.mode === Mode.SORTABLE) {
|
|
359
345
|
this.ghostEl = this.generateGhostEl(this.target);
|
|
360
346
|
}
|
|
347
|
+
frame.top = this.target.offsetTop;
|
|
348
|
+
frame.left = this.target.offsetLeft;
|
|
361
349
|
}).on("drag", (e) => {
|
|
362
350
|
if (!this.target || !this.dragEl)
|
|
363
351
|
return;
|
|
364
|
-
if (!offset) {
|
|
365
|
-
offset = getAbsolutePosition(this.target, { left: 0, top: 0 });
|
|
366
|
-
}
|
|
367
352
|
this.dragStatus = "ing" /* ING */;
|
|
368
|
-
const { left, top } = e;
|
|
369
353
|
if (this.ghostEl) {
|
|
370
|
-
this.
|
|
371
|
-
this.ghostEl.style.top = `${top + offset.top}px`;
|
|
354
|
+
this.ghostEl.style.top = `${frame.top + e.beforeTranslate[1]}px`;
|
|
372
355
|
return;
|
|
373
356
|
}
|
|
374
357
|
this.moveableHelper?.onDrag(e);
|
|
375
|
-
this.target.style.left = `${left +
|
|
376
|
-
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`;
|
|
377
360
|
}).on("dragEnd", () => {
|
|
378
361
|
if (this.dragStatus === "ing" /* ING */) {
|
|
379
362
|
switch (this.mode) {
|
|
@@ -384,11 +367,58 @@
|
|
|
384
367
|
this.update();
|
|
385
368
|
}
|
|
386
369
|
}
|
|
387
|
-
offset = null;
|
|
388
370
|
this.dragStatus = "end" /* END */;
|
|
389
371
|
this.destroyGhostEl();
|
|
390
372
|
});
|
|
391
373
|
}
|
|
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
|
+
});
|
|
420
|
+
});
|
|
421
|
+
}
|
|
392
422
|
sort() {
|
|
393
423
|
if (!this.target || !this.ghostEl)
|
|
394
424
|
throw new Error("\u672A\u77E5\u9519\u8BEF");
|
|
@@ -409,12 +439,13 @@
|
|
|
409
439
|
}
|
|
410
440
|
}
|
|
411
441
|
update(isResize = false) {
|
|
412
|
-
|
|
413
|
-
|
|
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 };
|
|
414
445
|
const left = this.calcValueByFontsize(offset.left);
|
|
415
446
|
const top = this.calcValueByFontsize(offset.top);
|
|
416
|
-
const width = this.calcValueByFontsize(
|
|
417
|
-
const height = this.calcValueByFontsize(
|
|
447
|
+
const width = this.calcValueByFontsize(this.target.clientWidth);
|
|
448
|
+
const height = this.calcValueByFontsize(this.target.clientHeight);
|
|
418
449
|
this.emit("update", {
|
|
419
450
|
el: this.target,
|
|
420
451
|
style: isResize ? { left, top, width, height } : { left, top }
|
|
@@ -440,17 +471,21 @@
|
|
|
440
471
|
this.ghostEl = void 0;
|
|
441
472
|
}
|
|
442
473
|
updateDragEl(el) {
|
|
443
|
-
const { width, height } = el.getBoundingClientRect();
|
|
444
474
|
const offset = getOffset(el);
|
|
475
|
+
const { transform } = getComputedStyle(el);
|
|
445
476
|
this.dragEl.style.cssText = `
|
|
446
477
|
position: absolute;
|
|
478
|
+
transform: ${transform};
|
|
447
479
|
left: ${offset.left}px;
|
|
448
480
|
top: ${offset.top}px;
|
|
449
|
-
width: ${
|
|
450
|
-
height: ${
|
|
481
|
+
width: ${el.clientWidth}px;
|
|
482
|
+
height: ${el.clientHeight}px;
|
|
451
483
|
z-index: ${ZIndex.DRAG_EL};
|
|
452
484
|
`;
|
|
453
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
|
+
}
|
|
454
489
|
}
|
|
455
490
|
destroyDragEl() {
|
|
456
491
|
this.dragEl?.remove();
|
|
@@ -476,6 +511,8 @@
|
|
|
476
511
|
dragArea: false,
|
|
477
512
|
draggable: true,
|
|
478
513
|
resizable: true,
|
|
514
|
+
scalable: false,
|
|
515
|
+
rotatable: false,
|
|
479
516
|
snappable: isAbsolute || isFixed,
|
|
480
517
|
snapGap: isAbsolute || isFixed,
|
|
481
518
|
snapThreshold: 5,
|
|
@@ -574,49 +611,34 @@
|
|
|
574
611
|
this.parent = config.parent;
|
|
575
612
|
this.mask = config.mask;
|
|
576
613
|
this.dr = config.dr;
|
|
614
|
+
this.core = config.core;
|
|
577
615
|
this.operationEl = globalThis.document.createElement("div");
|
|
578
616
|
this.parent.append(this.operationEl);
|
|
579
617
|
}
|
|
580
618
|
update(el, prefix) {
|
|
581
|
-
const { width, height } = el.getBoundingClientRect();
|
|
582
619
|
const { left, top } = this.getOffset(el);
|
|
620
|
+
const { transform } = getComputedStyle(el);
|
|
583
621
|
this.operationEl.style.cssText = `
|
|
584
622
|
position: absolute;
|
|
623
|
+
transform: ${transform};
|
|
585
624
|
left: ${left}px;
|
|
586
625
|
top: ${top}px;
|
|
587
|
-
width: ${
|
|
588
|
-
height: ${
|
|
626
|
+
width: ${el.clientWidth}px;
|
|
627
|
+
height: ${el.clientHeight}px;
|
|
589
628
|
`;
|
|
590
629
|
this.operationEl.id = `${prefix}${el.id}`;
|
|
630
|
+
if (typeof this.core.config.updateDragEl === "function") {
|
|
631
|
+
this.core.config.updateDragEl(this.operationEl, el);
|
|
632
|
+
}
|
|
591
633
|
return this.operationEl;
|
|
592
634
|
}
|
|
593
635
|
destroy() {
|
|
594
636
|
this.operationEl?.remove();
|
|
595
637
|
}
|
|
596
638
|
getOffset(el) {
|
|
597
|
-
const { transform } = getComputedStyle(el);
|
|
598
639
|
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
|
-
}
|
|
640
|
+
const left = el.offsetLeft;
|
|
641
|
+
const top = el.offsetTop;
|
|
620
642
|
if (offsetParent) {
|
|
621
643
|
const parentOffset = this.getOffset(offsetParent);
|
|
622
644
|
return {
|
|
@@ -657,7 +679,8 @@
|
|
|
657
679
|
this.calibrationTarget = new TargetCalibrate({
|
|
658
680
|
parent: this.core.mask.content,
|
|
659
681
|
mask: this.core.mask,
|
|
660
|
-
dr: this.core.dr
|
|
682
|
+
dr: this.core.dr,
|
|
683
|
+
core: this.core
|
|
661
684
|
});
|
|
662
685
|
}
|
|
663
686
|
highlight(el) {
|