@tmagic/stage 1.0.0-rc.6 → 1.0.0-rc.7
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 +84 -72
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +84 -72
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/StageDragResize.d.ts +2 -0
- package/dist/types/src/types.d.ts +7 -3
- package/package.json +5 -6
- package/src/StageDragResize.ts +82 -32
- package/src/TargetCalibrate.ts +6 -30
- package/src/types.ts +8 -3
- package/src/util.ts +2 -27
- package/LICENSE +0 -5432
package/dist/tmagic-stage.es.js
CHANGED
|
@@ -46,29 +46,9 @@ const getParents = (el, relative) => {
|
|
|
46
46
|
return parents;
|
|
47
47
|
};
|
|
48
48
|
const getOffset = (el) => {
|
|
49
|
-
const { transform } = getComputedStyle(el);
|
|
50
49
|
const { offsetParent } = el;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (transform.indexOf("matrix") > -1) {
|
|
54
|
-
let a = 1;
|
|
55
|
-
let b = 1;
|
|
56
|
-
let c = 1;
|
|
57
|
-
let d = 1;
|
|
58
|
-
let e = 0;
|
|
59
|
-
let f = 0;
|
|
60
|
-
transform.replace(/matrix\((.+), (.+), (.+), (.+), (.+), (.+)\)/, ($0, $1, $2, $3, $4, $5, $6) => {
|
|
61
|
-
a = +$1;
|
|
62
|
-
b = +$2;
|
|
63
|
-
c = +$3;
|
|
64
|
-
d = +$4;
|
|
65
|
-
e = +$5;
|
|
66
|
-
f = +$6;
|
|
67
|
-
return transform;
|
|
68
|
-
});
|
|
69
|
-
left = a * left + c * top + e;
|
|
70
|
-
top = b * left + d * top + f;
|
|
71
|
-
}
|
|
50
|
+
const left = el.offsetLeft;
|
|
51
|
+
const top = el.offsetTop;
|
|
72
52
|
if (offsetParent) {
|
|
73
53
|
const parentOffset = getOffset(offsetParent);
|
|
74
54
|
return {
|
|
@@ -305,35 +285,34 @@ class StageDragResize extends EventEmitter {
|
|
|
305
285
|
});
|
|
306
286
|
this.bindResizeEvent();
|
|
307
287
|
this.bindDragEvent();
|
|
288
|
+
this.bindRotateEvent();
|
|
289
|
+
this.bindScaleEvent();
|
|
308
290
|
}
|
|
309
291
|
bindResizeEvent() {
|
|
310
292
|
if (!this.moveable)
|
|
311
293
|
throw new Error("moveable \u4E3A\u521D\u59CB\u5316");
|
|
294
|
+
const frame = {
|
|
295
|
+
left: 0,
|
|
296
|
+
top: 0
|
|
297
|
+
};
|
|
312
298
|
this.moveable.on("resizeStart", (e) => {
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
299
|
+
if (!this.target)
|
|
300
|
+
return;
|
|
301
|
+
this.dragStatus = "start" /* START */;
|
|
302
|
+
this.moveableHelper?.onResizeStart(e);
|
|
303
|
+
frame.top = this.target.offsetTop;
|
|
304
|
+
frame.left = this.target.offsetLeft;
|
|
305
|
+
}).on("resize", (e) => {
|
|
306
|
+
const { width, height, drag } = e;
|
|
319
307
|
if (!this.moveable || !this.target || !this.dragEl)
|
|
320
308
|
return;
|
|
321
309
|
const { beforeTranslate } = drag;
|
|
322
310
|
this.dragStatus = "ing" /* ING */;
|
|
311
|
+
this.moveableHelper?.onResize(e);
|
|
323
312
|
this.target.style.width = `${width}px`;
|
|
324
313
|
this.target.style.height = `${height}px`;
|
|
325
|
-
this.
|
|
326
|
-
this.
|
|
327
|
-
if (this.mode === Mode.SORTABLE) {
|
|
328
|
-
this.dragEl.style.top = `${beforeTranslate[1]}px`;
|
|
329
|
-
this.target.style.top = `0px`;
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
this.dragEl.style.left = `${beforeTranslate[0]}px`;
|
|
333
|
-
this.dragEl.style.top = `${beforeTranslate[1]}px`;
|
|
334
|
-
const offset = getAbsolutePosition(this.target, { left: beforeTranslate[0], top: beforeTranslate[1] });
|
|
335
|
-
this.target.style.left = `${offset.left}px`;
|
|
336
|
-
this.target.style.top = `${offset.top}px`;
|
|
314
|
+
this.target.style.left = `${frame.left + beforeTranslate[0]}px`;
|
|
315
|
+
this.target.style.top = `${frame.top + beforeTranslate[1]}px`;
|
|
337
316
|
}).on("resizeEnd", () => {
|
|
338
317
|
this.dragStatus = "end" /* END */;
|
|
339
318
|
this.update(true);
|
|
@@ -382,6 +361,54 @@ class StageDragResize extends EventEmitter {
|
|
|
382
361
|
this.destroyGhostEl();
|
|
383
362
|
});
|
|
384
363
|
}
|
|
364
|
+
bindRotateEvent() {
|
|
365
|
+
if (!this.moveable)
|
|
366
|
+
throw new Error("moveable \u4E3A\u521D\u59CB\u5316");
|
|
367
|
+
this.moveable.on("rotateStart", (e) => {
|
|
368
|
+
this.dragStatus = "start" /* START */;
|
|
369
|
+
this.moveableHelper?.onRotateStart(e);
|
|
370
|
+
}).on("rotate", (e) => {
|
|
371
|
+
if (!this.target || !this.dragEl)
|
|
372
|
+
return;
|
|
373
|
+
this.dragStatus = "ing" /* ING */;
|
|
374
|
+
this.moveableHelper?.onRotate(e);
|
|
375
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
376
|
+
this.target.style.transform = frame?.toCSSObject().transform || "";
|
|
377
|
+
}).on("rotateEnd", (e) => {
|
|
378
|
+
this.dragStatus = "end" /* END */;
|
|
379
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
380
|
+
this.emit("update", {
|
|
381
|
+
el: this.target,
|
|
382
|
+
style: {
|
|
383
|
+
transform: frame?.get("transform")
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
bindScaleEvent() {
|
|
389
|
+
if (!this.moveable)
|
|
390
|
+
throw new Error("moveable \u4E3A\u521D\u59CB\u5316");
|
|
391
|
+
this.moveable.on("scaleStart", (e) => {
|
|
392
|
+
this.dragStatus = "start" /* START */;
|
|
393
|
+
this.moveableHelper?.onScaleStart(e);
|
|
394
|
+
}).on("scale", (e) => {
|
|
395
|
+
if (!this.target || !this.dragEl)
|
|
396
|
+
return;
|
|
397
|
+
this.dragStatus = "ing" /* ING */;
|
|
398
|
+
this.moveableHelper?.onScale(e);
|
|
399
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
400
|
+
this.target.style.transform = frame?.toCSSObject().transform || "";
|
|
401
|
+
}).on("scaleEnd", (e) => {
|
|
402
|
+
this.dragStatus = "end" /* END */;
|
|
403
|
+
const frame = this.moveableHelper?.getFrame(e.target);
|
|
404
|
+
this.emit("update", {
|
|
405
|
+
el: this.target,
|
|
406
|
+
style: {
|
|
407
|
+
transform: frame?.get("transform")
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
}
|
|
385
412
|
sort() {
|
|
386
413
|
if (!this.target || !this.ghostEl)
|
|
387
414
|
throw new Error("\u672A\u77E5\u9519\u8BEF");
|
|
@@ -402,12 +429,13 @@ class StageDragResize extends EventEmitter {
|
|
|
402
429
|
}
|
|
403
430
|
}
|
|
404
431
|
update(isResize = false) {
|
|
405
|
-
|
|
406
|
-
|
|
432
|
+
if (!this.target)
|
|
433
|
+
return;
|
|
434
|
+
const offset = this.mode === Mode.SORTABLE ? { left: 0, top: 0 } : { left: this.target.offsetLeft, top: this.target.offsetTop };
|
|
407
435
|
const left = this.calcValueByFontsize(offset.left);
|
|
408
436
|
const top = this.calcValueByFontsize(offset.top);
|
|
409
|
-
const width = this.calcValueByFontsize(
|
|
410
|
-
const height = this.calcValueByFontsize(
|
|
437
|
+
const width = this.calcValueByFontsize(this.target.clientWidth);
|
|
438
|
+
const height = this.calcValueByFontsize(this.target.clientHeight);
|
|
411
439
|
this.emit("update", {
|
|
412
440
|
el: this.target,
|
|
413
441
|
style: isResize ? { left, top, width, height } : { left, top }
|
|
@@ -433,14 +461,15 @@ class StageDragResize extends EventEmitter {
|
|
|
433
461
|
this.ghostEl = void 0;
|
|
434
462
|
}
|
|
435
463
|
updateDragEl(el) {
|
|
436
|
-
const { width, height } = el.getBoundingClientRect();
|
|
437
464
|
const offset = getOffset(el);
|
|
465
|
+
const { transform } = getComputedStyle(el);
|
|
438
466
|
this.dragEl.style.cssText = `
|
|
439
467
|
position: absolute;
|
|
468
|
+
transform: ${transform};
|
|
440
469
|
left: ${offset.left}px;
|
|
441
470
|
top: ${offset.top}px;
|
|
442
|
-
width: ${
|
|
443
|
-
height: ${
|
|
471
|
+
width: ${el.clientWidth}px;
|
|
472
|
+
height: ${el.clientHeight}px;
|
|
444
473
|
z-index: ${ZIndex.DRAG_EL};
|
|
445
474
|
`;
|
|
446
475
|
this.dragEl.id = `${DRAG_EL_ID_PREFIX}${el.id}`;
|
|
@@ -469,6 +498,8 @@ class StageDragResize extends EventEmitter {
|
|
|
469
498
|
dragArea: false,
|
|
470
499
|
draggable: true,
|
|
471
500
|
resizable: true,
|
|
501
|
+
scalable: false,
|
|
502
|
+
rotatable: false,
|
|
472
503
|
snappable: isAbsolute || isFixed,
|
|
473
504
|
snapGap: isAbsolute || isFixed,
|
|
474
505
|
snapThreshold: 5,
|
|
@@ -571,14 +602,15 @@ class TargetCalibrate extends EventEmitter {
|
|
|
571
602
|
this.parent.append(this.operationEl);
|
|
572
603
|
}
|
|
573
604
|
update(el, prefix) {
|
|
574
|
-
const { width, height } = el.getBoundingClientRect();
|
|
575
605
|
const { left, top } = this.getOffset(el);
|
|
606
|
+
const { transform } = getComputedStyle(el);
|
|
576
607
|
this.operationEl.style.cssText = `
|
|
577
608
|
position: absolute;
|
|
609
|
+
transform: ${transform};
|
|
578
610
|
left: ${left}px;
|
|
579
611
|
top: ${top}px;
|
|
580
|
-
width: ${
|
|
581
|
-
height: ${
|
|
612
|
+
width: ${el.clientWidth}px;
|
|
613
|
+
height: ${el.clientHeight}px;
|
|
582
614
|
`;
|
|
583
615
|
this.operationEl.id = `${prefix}${el.id}`;
|
|
584
616
|
return this.operationEl;
|
|
@@ -587,29 +619,9 @@ class TargetCalibrate extends EventEmitter {
|
|
|
587
619
|
this.operationEl?.remove();
|
|
588
620
|
}
|
|
589
621
|
getOffset(el) {
|
|
590
|
-
const { transform } = getComputedStyle(el);
|
|
591
622
|
const { offsetParent } = el;
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
if (transform.indexOf("matrix") > -1) {
|
|
595
|
-
let a = 1;
|
|
596
|
-
let b = 1;
|
|
597
|
-
let c = 1;
|
|
598
|
-
let d = 1;
|
|
599
|
-
let e = 0;
|
|
600
|
-
let f = 0;
|
|
601
|
-
transform.replace(/matrix\((.+), (.+), (.+), (.+), (.+), (.+)\)/, ($0, $1, $2, $3, $4, $5, $6) => {
|
|
602
|
-
a = +$1;
|
|
603
|
-
b = +$2;
|
|
604
|
-
c = +$3;
|
|
605
|
-
d = +$4;
|
|
606
|
-
e = +$5;
|
|
607
|
-
f = +$6;
|
|
608
|
-
return transform;
|
|
609
|
-
});
|
|
610
|
-
left = a * left + c * top + e;
|
|
611
|
-
top = b * left + d * top + f;
|
|
612
|
-
}
|
|
623
|
+
const left = el.offsetLeft;
|
|
624
|
+
const top = el.offsetTop;
|
|
613
625
|
if (offsetParent) {
|
|
614
626
|
const parentOffset = this.getOffset(offsetParent);
|
|
615
627
|
return {
|