@leafer-in/editor 1.0.0-rc.21 → 1.0.0-rc.23
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/editor.cjs +1718 -0
- package/dist/editor.esm.js +497 -328
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +498 -327
- package/dist/editor.min.cjs +1 -0
- package/dist/editor.min.js +1 -1
- package/package.json +12 -6
- package/src/Editor.ts +114 -30
- package/src/config.ts +2 -1
- package/src/display/EditBox.ts +126 -71
- package/src/display/EditPoint.ts +3 -3
- package/src/display/EditSelect.ts +40 -35
- package/src/display/Stroker.ts +16 -19
- package/src/editor/cursor.ts +3 -3
- package/src/editor/target.ts +3 -1
- package/src/event/EditorScaleEvent.ts +3 -2
- package/src/helper/EditDataHelper.ts +34 -33
- package/src/index.ts +29 -6
- package/src/tool/EditTool.ts +36 -12
- package/src/tool/EditToolCreator.ts +32 -0
- package/src/tool/InnerEditor.ts +64 -0
- package/src/tool/LineEditTool.ts +8 -8
- package/types/index.d.ts +96 -43
- package/src/tool/index.ts +0 -21
package/dist/editor.js
CHANGED
|
@@ -247,34 +247,29 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
247
247
|
this.strokeAlign = 'center';
|
|
248
248
|
}
|
|
249
249
|
setTarget(target, style) {
|
|
250
|
-
|
|
251
|
-
this.set({ stroke, strokeWidth });
|
|
250
|
+
this.set(style);
|
|
252
251
|
this.target = target;
|
|
253
252
|
}
|
|
254
253
|
__draw(canvas, options) {
|
|
255
254
|
const { list } = this;
|
|
256
255
|
if (list.length) {
|
|
257
256
|
let leaf;
|
|
258
|
-
const { stroke, strokeWidth } = this.__;
|
|
257
|
+
const { stroke, strokeWidth, fill } = this.__;
|
|
259
258
|
const { bounds } = options;
|
|
260
259
|
for (let i = 0; i < list.length; i++) {
|
|
261
260
|
leaf = list[i];
|
|
262
261
|
if (bounds && bounds.hit(leaf.__world, options.matrix)) {
|
|
263
|
-
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const { x, y, width, height } = leaf.__layout.boxBounds;
|
|
273
|
-
canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
|
|
274
|
-
drewPath = true;
|
|
275
|
-
}
|
|
262
|
+
const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
|
|
263
|
+
if (aScaleX !== aScaleY) {
|
|
264
|
+
copy(matrix, leaf.__world);
|
|
265
|
+
scale(matrix, 1 / aScaleX, 1 / aScaleY);
|
|
266
|
+
canvas.setWorld(matrix, options.matrix);
|
|
267
|
+
canvas.beginPath();
|
|
268
|
+
this.__.strokeWidth = strokeWidth;
|
|
269
|
+
const { x, y, width, height } = leaf.__layout.boxBounds;
|
|
270
|
+
canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
|
|
276
271
|
}
|
|
277
|
-
|
|
272
|
+
else {
|
|
278
273
|
canvas.setWorld(leaf.__world, options.matrix);
|
|
279
274
|
canvas.beginPath();
|
|
280
275
|
if (leaf.__.__useArrow) {
|
|
@@ -285,7 +280,10 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
285
280
|
}
|
|
286
281
|
this.__.strokeWidth = strokeWidth / abs(leaf.__world.scaleX);
|
|
287
282
|
}
|
|
288
|
-
|
|
283
|
+
if (stroke)
|
|
284
|
+
typeof stroke === 'string' ? draw.Paint.stroke(stroke, this, canvas) : draw.Paint.strokes(stroke, this, canvas);
|
|
285
|
+
if (fill)
|
|
286
|
+
typeof fill === 'string' ? draw.Paint.fill(fill, this, canvas) : draw.Paint.fills(fill, this, canvas);
|
|
289
287
|
}
|
|
290
288
|
}
|
|
291
289
|
this.__.strokeWidth = strokeWidth;
|
|
@@ -355,7 +353,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
355
353
|
const { findOne } = EditSelectHelper;
|
|
356
354
|
class EditSelect extends draw.Group {
|
|
357
355
|
get dragging() { return !!this.originList; }
|
|
358
|
-
get running() { return this.editor.hittable &&
|
|
356
|
+
get running() { const { editor } = this; return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector; }
|
|
359
357
|
get isMoveMode() { return this.app && this.app.interaction.moveMode; }
|
|
360
358
|
constructor(editor) {
|
|
361
359
|
super();
|
|
@@ -371,8 +369,8 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
371
369
|
onHover() {
|
|
372
370
|
const { editor } = this;
|
|
373
371
|
if (this.running && !this.dragging && !editor.dragging) {
|
|
374
|
-
const { stroke, strokeWidth, hover } = editor.
|
|
375
|
-
this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, { stroke, strokeWidth });
|
|
372
|
+
const { stroke, strokeWidth, hover, hoverStyle } = editor.mergeConfig;
|
|
373
|
+
this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, Object.assign({ stroke, strokeWidth }, (hoverStyle || {})));
|
|
376
374
|
}
|
|
377
375
|
else {
|
|
378
376
|
this.hoverStroker.target = null;
|
|
@@ -380,20 +378,20 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
380
378
|
}
|
|
381
379
|
onSelect() {
|
|
382
380
|
if (this.running) {
|
|
383
|
-
const { config, list } = this.editor;
|
|
381
|
+
const { mergeConfig: config, list } = this.editor;
|
|
384
382
|
const { stroke, strokeWidth } = config;
|
|
385
383
|
this.targetStroker.setTarget(list, { stroke, strokeWidth: Math.max(1, strokeWidth / 2) });
|
|
386
384
|
this.hoverStroker.target = null;
|
|
387
385
|
}
|
|
388
386
|
}
|
|
389
387
|
update() {
|
|
390
|
-
if (this.
|
|
388
|
+
if (this.targetStroker.target)
|
|
391
389
|
this.targetStroker.forceUpdate();
|
|
392
390
|
}
|
|
393
391
|
onPointerMove(e) {
|
|
394
392
|
const { app, editor } = this;
|
|
395
393
|
if (this.running && !this.isMoveMode && app.config.pointer.hover && !app.interaction.dragging) {
|
|
396
|
-
const find =
|
|
394
|
+
const find = this.findUI(e);
|
|
397
395
|
editor.hoverTarget = editor.hasItem(find) ? null : find;
|
|
398
396
|
}
|
|
399
397
|
if (this.isMoveMode) {
|
|
@@ -401,43 +399,37 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
401
399
|
}
|
|
402
400
|
}
|
|
403
401
|
onBeforeDown(e) {
|
|
404
|
-
const { select } = this.editor.
|
|
402
|
+
const { select } = this.editor.mergeConfig;
|
|
405
403
|
if (select === 'press')
|
|
406
|
-
this.checkAndSelect(e
|
|
404
|
+
this.checkAndSelect(e);
|
|
407
405
|
}
|
|
408
406
|
onTap(e) {
|
|
409
407
|
const { editor } = this;
|
|
410
|
-
const { select
|
|
408
|
+
const { select } = editor.mergeConfig;
|
|
411
409
|
if (select === 'tap')
|
|
412
410
|
this.checkAndSelect(e);
|
|
413
|
-
if (this.
|
|
414
|
-
|
|
415
|
-
if (find)
|
|
416
|
-
editor.shiftItem(find);
|
|
417
|
-
else if (!e.shiftKey && continuousSelect)
|
|
418
|
-
editor.target = null;
|
|
411
|
+
if (this.needRemoveItem) {
|
|
412
|
+
editor.removeItem(this.needRemoveItem);
|
|
419
413
|
}
|
|
420
414
|
else if (this.isMoveMode) {
|
|
421
415
|
editor.target = null;
|
|
422
416
|
}
|
|
423
|
-
this.lastDownLeaf = null;
|
|
424
417
|
}
|
|
425
|
-
checkAndSelect(e
|
|
426
|
-
|
|
418
|
+
checkAndSelect(e) {
|
|
419
|
+
this.needRemoveItem = null;
|
|
420
|
+
if (this.allowSelect(e)) {
|
|
427
421
|
const { editor } = this;
|
|
428
|
-
const find = this.
|
|
422
|
+
const find = this.findUI(e);
|
|
429
423
|
if (find) {
|
|
430
|
-
if (e
|
|
431
|
-
editor.
|
|
424
|
+
if (this.isMultipleSelect(e)) {
|
|
425
|
+
if (editor.hasItem(find))
|
|
426
|
+
this.needRemoveItem = find;
|
|
427
|
+
else
|
|
428
|
+
editor.addItem(find);
|
|
432
429
|
}
|
|
433
430
|
else {
|
|
434
431
|
editor.target = find;
|
|
435
432
|
}
|
|
436
|
-
if (isDownType) {
|
|
437
|
-
editor.updateLayout();
|
|
438
|
-
if (!find.locked)
|
|
439
|
-
this.app.interaction.updateDownData(e, { findList: [editor.editBox.rect] }, editor.config.dualEvent);
|
|
440
|
-
}
|
|
441
433
|
}
|
|
442
434
|
else if (this.allow(e.target)) {
|
|
443
435
|
if (!e.shiftKey)
|
|
@@ -446,12 +438,12 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
446
438
|
}
|
|
447
439
|
}
|
|
448
440
|
onDragStart(e) {
|
|
449
|
-
if (this.
|
|
441
|
+
if (this.allowDrag(e)) {
|
|
450
442
|
const { editor } = this;
|
|
451
|
-
const { stroke,
|
|
443
|
+
const { stroke, area } = editor.mergeConfig;
|
|
452
444
|
const { x, y } = e.getInner(this);
|
|
453
445
|
this.bounds.set(x, y);
|
|
454
|
-
this.selectArea.setStyle({ visible: true, stroke,
|
|
446
|
+
this.selectArea.setStyle({ visible: true, stroke, x, y }, area);
|
|
455
447
|
this.selectArea.setBounds(this.bounds.get());
|
|
456
448
|
this.originList = editor.leafList.clone();
|
|
457
449
|
}
|
|
@@ -499,17 +491,26 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
499
491
|
return target.leafer !== this.editor.leafer;
|
|
500
492
|
}
|
|
501
493
|
allowDrag(e) {
|
|
502
|
-
if (this.editor.
|
|
503
|
-
return (!this.editor.
|
|
494
|
+
if (this.running && this.editor.mergeConfig.boxSelect && !e.target.draggable) {
|
|
495
|
+
return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path));
|
|
504
496
|
}
|
|
505
497
|
else {
|
|
506
498
|
return false;
|
|
507
499
|
}
|
|
508
500
|
}
|
|
501
|
+
allowSelect(e) {
|
|
502
|
+
return this.running && !this.isMoveMode && !e.middle;
|
|
503
|
+
}
|
|
509
504
|
findDeepOne(e) {
|
|
510
505
|
const options = { exclude: new draw.LeafList(this.editor.editBox.rect) };
|
|
511
506
|
return findOne(e.target.leafer.interaction.findPath(e, options));
|
|
512
507
|
}
|
|
508
|
+
findUI(e) {
|
|
509
|
+
return this.isMultipleSelect(e) ? this.findDeepOne(e) : findOne(e.path);
|
|
510
|
+
}
|
|
511
|
+
isMultipleSelect(e) {
|
|
512
|
+
return e.shiftKey || this.editor.mergeConfig.continuousSelect;
|
|
513
|
+
}
|
|
513
514
|
__listenEvents() {
|
|
514
515
|
const { editor } = this;
|
|
515
516
|
editor.waitLeafer(() => {
|
|
@@ -536,29 +537,17 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
536
537
|
}
|
|
537
538
|
}
|
|
538
539
|
destroy() {
|
|
539
|
-
this.editor = this.originList = this.
|
|
540
|
+
this.editor = this.originList = this.needRemoveItem = null;
|
|
540
541
|
this.__removeListenEvents();
|
|
541
542
|
super.destroy();
|
|
542
543
|
}
|
|
543
544
|
}
|
|
544
545
|
|
|
545
|
-
|
|
546
|
-
(function (IDirection8) {
|
|
547
|
-
IDirection8[IDirection8["topLeft"] = 0] = "topLeft";
|
|
548
|
-
IDirection8[IDirection8["top"] = 1] = "top";
|
|
549
|
-
IDirection8[IDirection8["topRight"] = 2] = "topRight";
|
|
550
|
-
IDirection8[IDirection8["right"] = 3] = "right";
|
|
551
|
-
IDirection8[IDirection8["bottomRight"] = 4] = "bottomRight";
|
|
552
|
-
IDirection8[IDirection8["bottom"] = 5] = "bottom";
|
|
553
|
-
IDirection8[IDirection8["bottomLeft"] = 6] = "bottomLeft";
|
|
554
|
-
IDirection8[IDirection8["left"] = 7] = "left";
|
|
555
|
-
})(IDirection8 || (IDirection8 = {}));
|
|
556
|
-
|
|
557
|
-
const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft, left: left$1 } = IDirection8;
|
|
546
|
+
const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft, left: left$1 } = draw.Direction9;
|
|
558
547
|
const { toPoint } = draw.AroundHelper;
|
|
559
548
|
const EditDataHelper = {
|
|
560
549
|
getScaleData(bounds, direction, pointMove, lockRatio, around) {
|
|
561
|
-
let origin, scaleX = 1, scaleY = 1;
|
|
550
|
+
let align, origin = {}, scaleX = 1, scaleY = 1;
|
|
562
551
|
const { width, height } = bounds;
|
|
563
552
|
if (around) {
|
|
564
553
|
pointMove.x *= 2;
|
|
@@ -575,101 +564,100 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
575
564
|
switch (direction) {
|
|
576
565
|
case top:
|
|
577
566
|
scaleY = topScale;
|
|
578
|
-
|
|
567
|
+
align = 'bottom';
|
|
579
568
|
break;
|
|
580
569
|
case right$1:
|
|
581
570
|
scaleX = rightScale;
|
|
582
|
-
|
|
571
|
+
align = 'left';
|
|
583
572
|
break;
|
|
584
573
|
case bottom:
|
|
585
574
|
scaleY = bottomScale;
|
|
586
|
-
|
|
575
|
+
align = 'top';
|
|
587
576
|
break;
|
|
588
577
|
case left$1:
|
|
589
578
|
scaleX = leftScale;
|
|
590
|
-
|
|
579
|
+
align = 'right';
|
|
591
580
|
break;
|
|
592
581
|
case topLeft:
|
|
593
582
|
scaleY = topScale;
|
|
594
583
|
scaleX = leftScale;
|
|
595
|
-
|
|
584
|
+
align = 'bottom-right';
|
|
596
585
|
break;
|
|
597
586
|
case topRight:
|
|
598
587
|
scaleY = topScale;
|
|
599
588
|
scaleX = rightScale;
|
|
600
|
-
|
|
589
|
+
align = 'bottom-left';
|
|
601
590
|
break;
|
|
602
591
|
case bottomRight:
|
|
603
592
|
scaleY = bottomScale;
|
|
604
593
|
scaleX = rightScale;
|
|
605
|
-
|
|
594
|
+
align = 'top-left';
|
|
606
595
|
break;
|
|
607
596
|
case bottomLeft:
|
|
608
597
|
scaleY = bottomScale;
|
|
609
598
|
scaleX = leftScale;
|
|
610
|
-
|
|
599
|
+
align = 'top-right';
|
|
611
600
|
}
|
|
612
601
|
if (lockRatio) {
|
|
613
602
|
const unlockSide = lockRatio === 'corner' && direction % 2;
|
|
614
603
|
if (!unlockSide) {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
scaleY = scaleX;
|
|
604
|
+
const scale = Math.sqrt(Math.abs(scaleX * scaleY));
|
|
605
|
+
scaleX = scaleX < 0 ? -scale : scale;
|
|
606
|
+
scaleY = scaleY < 0 ? -scale : scale;
|
|
619
607
|
}
|
|
620
608
|
}
|
|
621
|
-
toPoint(around ||
|
|
609
|
+
toPoint(around || align, bounds, origin);
|
|
622
610
|
return { origin, scaleX, scaleY, direction, lockRatio, around };
|
|
623
611
|
},
|
|
624
612
|
getRotateData(bounds, direction, current, last, around) {
|
|
625
|
-
let origin;
|
|
613
|
+
let align, origin = {};
|
|
626
614
|
switch (direction) {
|
|
627
615
|
case topLeft:
|
|
628
|
-
|
|
616
|
+
align = 'bottom-right';
|
|
629
617
|
break;
|
|
630
618
|
case topRight:
|
|
631
|
-
|
|
619
|
+
align = 'bottom-left';
|
|
632
620
|
break;
|
|
633
621
|
case bottomRight:
|
|
634
|
-
|
|
622
|
+
align = 'top-left';
|
|
635
623
|
break;
|
|
636
624
|
case bottomLeft:
|
|
637
|
-
|
|
625
|
+
align = 'top-right';
|
|
638
626
|
break;
|
|
639
627
|
default:
|
|
640
|
-
|
|
628
|
+
align = 'center';
|
|
641
629
|
}
|
|
642
|
-
toPoint(around ||
|
|
630
|
+
toPoint(around || align, bounds, origin);
|
|
643
631
|
return { origin, rotation: draw.PointHelper.getRotation(last, origin, current) };
|
|
644
632
|
},
|
|
645
633
|
getSkewData(bounds, direction, move, around) {
|
|
646
|
-
let origin, skewX = 0, skewY = 0;
|
|
634
|
+
let align, origin = {}, skewX = 0, skewY = 0;
|
|
647
635
|
let last;
|
|
648
636
|
switch (direction) {
|
|
649
637
|
case top:
|
|
650
638
|
last = { x: 0.5, y: 0 };
|
|
651
|
-
|
|
639
|
+
align = 'bottom';
|
|
652
640
|
skewX = 1;
|
|
653
641
|
break;
|
|
654
642
|
case bottom:
|
|
655
643
|
last = { x: 0.5, y: 1 };
|
|
656
|
-
|
|
644
|
+
align = 'top';
|
|
657
645
|
skewX = 1;
|
|
658
646
|
break;
|
|
659
647
|
case left$1:
|
|
660
648
|
last = { x: 0, y: 0.5 };
|
|
661
|
-
|
|
649
|
+
align = 'right';
|
|
662
650
|
skewY = 1;
|
|
663
651
|
break;
|
|
664
652
|
case right$1:
|
|
665
653
|
last = { x: 1, y: 0.5 };
|
|
666
|
-
|
|
654
|
+
align = 'left';
|
|
667
655
|
skewY = 1;
|
|
668
656
|
}
|
|
669
657
|
const { x, y, width, height } = bounds;
|
|
670
658
|
last.x = x + last.x * width;
|
|
671
659
|
last.y = y + last.y * height;
|
|
672
|
-
toPoint(around ||
|
|
660
|
+
toPoint(around || align, bounds, origin);
|
|
673
661
|
const rotation = draw.PointHelper.getRotation(last, origin, { x: last.x + (skewX ? move.x : 0), y: last.y + (skewY ? move.y : 0) });
|
|
674
662
|
skewX ? skewX = -rotation : skewY = rotation;
|
|
675
663
|
return { origin, skewX, skewY };
|
|
@@ -735,12 +723,12 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
735
723
|
const cacheCursors = {};
|
|
736
724
|
function updateCursor(editor, e) {
|
|
737
725
|
const { editBox } = editor, point = editBox.enterPoint;
|
|
738
|
-
if (!point || !editor.
|
|
726
|
+
if (!point || !editor.editing || !editBox.visible)
|
|
739
727
|
return;
|
|
740
728
|
if (point.name === 'circle')
|
|
741
729
|
return;
|
|
742
730
|
let { rotation } = editBox;
|
|
743
|
-
const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.
|
|
731
|
+
const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
|
|
744
732
|
const { pointType } = point, { flippedX, flippedY } = editBox;
|
|
745
733
|
let showResize = pointType === 'resize';
|
|
746
734
|
if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
|
|
@@ -759,7 +747,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
759
747
|
}
|
|
760
748
|
}
|
|
761
749
|
function updateMoveCursor(editor) {
|
|
762
|
-
editor.editBox.rect.cursor = editor.
|
|
750
|
+
editor.editBox.rect.cursor = editor.mergeConfig.moveCursor;
|
|
763
751
|
}
|
|
764
752
|
function toDataURL(svg, rotation) {
|
|
765
753
|
return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
|
|
@@ -776,6 +764,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
776
764
|
get flippedOne() { return this.scaleX * this.scaleY < 0; }
|
|
777
765
|
constructor(editor) {
|
|
778
766
|
super();
|
|
767
|
+
this.view = new draw.Group();
|
|
779
768
|
this.rect = new draw.Box({ name: 'rect', hitFill: 'all', hitStroke: 'none', strokeAlign: 'center', hitRadius: 5 });
|
|
780
769
|
this.circle = new EditPoint({ name: 'circle', strokeAlign: 'center', around: 'center', cursor: 'crosshair', hitRadius: 5 });
|
|
781
770
|
this.buttons = new draw.Group({ around: 'center', hitSelf: false });
|
|
@@ -790,8 +779,8 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
790
779
|
}
|
|
791
780
|
create() {
|
|
792
781
|
let rotatePoint, resizeLine, resizePoint;
|
|
793
|
-
const { resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this;
|
|
794
|
-
const arounds = [
|
|
782
|
+
const { view, resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this;
|
|
783
|
+
const arounds = ['bottom-right', 'bottom', 'bottom-left', 'left', 'top-left', 'top', 'top-right', 'right'];
|
|
795
784
|
for (let i = 0; i < 8; i++) {
|
|
796
785
|
rotatePoint = new EditPoint({ name: 'rotate-point', around: arounds[i], width: 15, height: 15, hitFill: "all" });
|
|
797
786
|
rotatePoints.push(rotatePoint);
|
|
@@ -801,62 +790,80 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
801
790
|
resizeLines.push(resizeLine);
|
|
802
791
|
this.listenPointEvents(resizeLine, 'resize', i);
|
|
803
792
|
}
|
|
804
|
-
resizePoint = new EditPoint({ name: 'resize-point',
|
|
793
|
+
resizePoint = new EditPoint({ name: 'resize-point', hitRadius: 5 });
|
|
805
794
|
resizePoints.push(resizePoint);
|
|
806
795
|
this.listenPointEvents(resizePoint, 'resize', i);
|
|
807
796
|
}
|
|
808
797
|
buttons.add(circle);
|
|
809
798
|
this.listenPointEvents(circle, 'rotate', 2);
|
|
810
|
-
|
|
799
|
+
view.addMany(...rotatePoints, rect, buttons, ...resizeLines, ...resizePoints);
|
|
800
|
+
this.add(view);
|
|
811
801
|
}
|
|
812
|
-
|
|
813
|
-
const {
|
|
814
|
-
const {
|
|
815
|
-
const {
|
|
816
|
-
const { middlePoint, resizeable, rotateable, stroke, strokeWidth, hideOnSmall } = config;
|
|
802
|
+
load() {
|
|
803
|
+
const { mergeConfig, element, single } = this.editor;
|
|
804
|
+
const { rect, circle, resizePoints } = this;
|
|
805
|
+
const { stroke, strokeWidth, moveable } = mergeConfig;
|
|
817
806
|
const pointsStyle = this.getPointsStyle();
|
|
818
807
|
const middlePointsStyle = this.getMiddlePointsStyle();
|
|
819
|
-
|
|
820
|
-
const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
|
|
821
|
-
this.visible = list[0] && !list[0].locked;
|
|
822
|
-
let point = {}, style, rotateP, resizeP, resizeL;
|
|
808
|
+
let resizeP;
|
|
823
809
|
for (let i = 0; i < 8; i++) {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
resizeP.set(style);
|
|
828
|
-
resizeP.set(point), rotateP.set(point), resizeL.set(point);
|
|
829
|
-
resizeP.visible = resizeL.visible = showPoints && (resizeable || rotateable);
|
|
830
|
-
rotateP.visible = showPoints && rotateable && resizeable && !config.rotatePoint;
|
|
831
|
-
if (i % 2) {
|
|
832
|
-
resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
|
|
833
|
-
if (((i + 1) / 2) % 2) {
|
|
834
|
-
resizeL.width = width;
|
|
835
|
-
if (resizeP.width > width - 30)
|
|
836
|
-
resizeP.visible = false;
|
|
837
|
-
}
|
|
838
|
-
else {
|
|
839
|
-
resizeL.height = height;
|
|
840
|
-
resizeP.rotation = 90;
|
|
841
|
-
if (resizeP.width > height - 30)
|
|
842
|
-
resizeP.visible = false;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
else {
|
|
810
|
+
resizeP = resizePoints[i];
|
|
811
|
+
resizeP.set(this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]));
|
|
812
|
+
if (!(i % 2))
|
|
846
813
|
resizeP.rotation = (i / 2) * 90;
|
|
814
|
+
}
|
|
815
|
+
circle.set(this.getPointStyle(mergeConfig.rotatePoint || pointsStyle[0]));
|
|
816
|
+
rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
|
|
817
|
+
rect.hittable = !single && moveable;
|
|
818
|
+
element.syncEventer = (single && moveable) ? rect : null;
|
|
819
|
+
this.app.interaction.bottomList = (single && moveable) ? [{ target: rect, proxy: element }] : null;
|
|
820
|
+
this.visible = !element.locked;
|
|
821
|
+
}
|
|
822
|
+
update(bounds) {
|
|
823
|
+
if (this.view.worldOpacity) {
|
|
824
|
+
const { mergeConfig } = this.editor;
|
|
825
|
+
const { width, height } = bounds;
|
|
826
|
+
const { rect, circle, resizePoints, rotatePoints, resizeLines } = this;
|
|
827
|
+
const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig;
|
|
828
|
+
const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
|
|
829
|
+
const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
|
|
830
|
+
let point = {}, rotateP, resizeP, resizeL;
|
|
831
|
+
for (let i = 0; i < 8; i++) {
|
|
832
|
+
draw.AroundHelper.toPoint(draw.AroundHelper.directionData[i], bounds, point);
|
|
833
|
+
resizeP = resizePoints[i];
|
|
834
|
+
rotateP = rotatePoints[i];
|
|
835
|
+
resizeL = resizeLines[Math.floor(i / 2)];
|
|
836
|
+
resizeP.set(point);
|
|
837
|
+
rotateP.set(point);
|
|
838
|
+
resizeL.set(point);
|
|
839
|
+
resizeP.visible = resizeL.visible = showPoints && (resizeable || rotateable);
|
|
840
|
+
rotateP.visible = showPoints && rotateable && resizeable && !mergeConfig.rotatePoint;
|
|
841
|
+
if (i % 2) {
|
|
842
|
+
resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
|
|
843
|
+
if (((i + 1) / 2) % 2) {
|
|
844
|
+
resizeL.width = width;
|
|
845
|
+
if (resizeP.width > width - 30)
|
|
846
|
+
resizeP.visible = false;
|
|
847
|
+
}
|
|
848
|
+
else {
|
|
849
|
+
resizeL.height = height;
|
|
850
|
+
resizeP.rotation = 90;
|
|
851
|
+
if (resizeP.width > height - 30)
|
|
852
|
+
resizeP.visible = false;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
847
855
|
}
|
|
856
|
+
circle.visible = showPoints && rotateable && !!mergeConfig.rotatePoint;
|
|
857
|
+
rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
|
|
858
|
+
const buttonVisible = showPoints && (circle.visible || this.buttons.children.length > 1);
|
|
859
|
+
this.buttons.visible = buttonVisible;
|
|
860
|
+
if (buttonVisible)
|
|
861
|
+
this.layoutButtons();
|
|
848
862
|
}
|
|
849
|
-
circle.visible = showPoints && rotateable && !!config.rotatePoint;
|
|
850
|
-
circle.set(this.getPointStyle(config.rotatePoint || pointsStyle[0]));
|
|
851
|
-
rect.set(Object.assign({ stroke, strokeWidth }, (config.rect || {})));
|
|
852
|
-
rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
|
|
853
|
-
rect.hittable = config.moveable;
|
|
854
|
-
this.buttons.visible = showPoints;
|
|
855
|
-
this.layoutButtons();
|
|
856
863
|
}
|
|
857
864
|
layoutButtons() {
|
|
858
865
|
const { buttons, resizePoints } = this;
|
|
859
|
-
const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.editor.
|
|
866
|
+
const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.editor.mergeConfig;
|
|
860
867
|
const { flippedX, flippedY } = this;
|
|
861
868
|
let index = fourDirection.indexOf(buttonsDirection);
|
|
862
869
|
if ((index % 2 && flippedX) || ((index + 1) % 2 && flippedY)) {
|
|
@@ -883,37 +890,46 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
883
890
|
buttons.scaleY = flippedY ? -1 : 1;
|
|
884
891
|
}
|
|
885
892
|
}
|
|
893
|
+
unload() {
|
|
894
|
+
this.visible = false;
|
|
895
|
+
}
|
|
886
896
|
getPointStyle(userStyle) {
|
|
887
|
-
const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.
|
|
888
|
-
const defaultStyle = { fill: pointFill, stroke, strokeWidth, width: pointSize, height: pointSize, cornerRadius: pointRadius };
|
|
897
|
+
const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
|
|
898
|
+
const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius };
|
|
889
899
|
return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
|
|
890
900
|
}
|
|
891
901
|
getPointsStyle() {
|
|
892
|
-
const { point } = this.editor.
|
|
902
|
+
const { point } = this.editor.mergeConfig;
|
|
893
903
|
return point instanceof Array ? point : [point];
|
|
894
904
|
}
|
|
895
905
|
getMiddlePointsStyle() {
|
|
896
|
-
const { middlePoint } = this.editor.
|
|
906
|
+
const { middlePoint } = this.editor.mergeConfig;
|
|
897
907
|
return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
|
|
898
908
|
}
|
|
909
|
+
onSelect(e) {
|
|
910
|
+
if (e.oldList.length === 1)
|
|
911
|
+
e.oldList[0].syncEventer = this.app.interaction.bottomList = null;
|
|
912
|
+
}
|
|
899
913
|
onDragStart(e) {
|
|
900
914
|
this.dragging = true;
|
|
901
|
-
if (e.
|
|
915
|
+
if (e.current.name === 'rect') {
|
|
916
|
+
const { editor } = this;
|
|
902
917
|
this.moving = true;
|
|
903
|
-
|
|
918
|
+
editor.dragStartPoint = { x: editor.element.x, y: editor.element.y };
|
|
919
|
+
editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
|
|
904
920
|
}
|
|
905
921
|
}
|
|
906
922
|
onDragEnd(e) {
|
|
907
923
|
this.dragging = false;
|
|
908
924
|
this.moving = false;
|
|
909
|
-
if (e.
|
|
925
|
+
if (e.current.name === 'rect')
|
|
910
926
|
this.editor.opacity = 1;
|
|
911
927
|
}
|
|
912
928
|
onDrag(e) {
|
|
913
929
|
const { editor } = this;
|
|
914
930
|
const point = this.enterPoint = e.current;
|
|
915
|
-
if (point.pointType === 'rotate' || e.metaKey || e.ctrlKey || !editor.
|
|
916
|
-
if (editor.
|
|
931
|
+
if (point.pointType === 'rotate' || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
|
|
932
|
+
if (editor.mergeConfig.rotateable)
|
|
917
933
|
editor.onRotate(e);
|
|
918
934
|
}
|
|
919
935
|
else {
|
|
@@ -922,7 +938,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
922
938
|
updateCursor(editor, e);
|
|
923
939
|
}
|
|
924
940
|
onArrow(e) {
|
|
925
|
-
if (this.editor.
|
|
941
|
+
if (this.editor.editing && this.editor.mergeConfig.keyEvent) {
|
|
926
942
|
const move = { x: 0, y: 0 };
|
|
927
943
|
const distance = e.shiftKey ? 10 : 1;
|
|
928
944
|
switch (e.code) {
|
|
@@ -938,13 +954,29 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
938
954
|
case 'ArrowRight':
|
|
939
955
|
move.x = distance;
|
|
940
956
|
}
|
|
941
|
-
|
|
942
|
-
this.editor.move(move.x, move.y);
|
|
957
|
+
this.editor.move(move);
|
|
943
958
|
}
|
|
944
959
|
}
|
|
945
|
-
|
|
960
|
+
onDoubleTap(e) {
|
|
961
|
+
if (this.editor.mergeConfig.openInner === 'double')
|
|
962
|
+
this.openInner(e);
|
|
963
|
+
}
|
|
964
|
+
onLongPress(e) {
|
|
965
|
+
if (this.editor.mergeConfig.openInner === 'long')
|
|
966
|
+
this.openInner(e);
|
|
967
|
+
}
|
|
968
|
+
openInner(e) {
|
|
946
969
|
const { editor } = this;
|
|
947
|
-
if (editor.single
|
|
970
|
+
if (editor.single) {
|
|
971
|
+
const { element } = editor;
|
|
972
|
+
if (element.isBranch) {
|
|
973
|
+
editor.openGroup(element);
|
|
974
|
+
editor.target = editor.selector.findDeepOne(e);
|
|
975
|
+
}
|
|
976
|
+
else {
|
|
977
|
+
editor.openInnerEditor();
|
|
978
|
+
}
|
|
979
|
+
}
|
|
948
980
|
}
|
|
949
981
|
listenPointEvents(point, type, direction) {
|
|
950
982
|
const { editor } = this;
|
|
@@ -960,12 +992,13 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
960
992
|
__listenEvents() {
|
|
961
993
|
const { rect, editor } = this;
|
|
962
994
|
this.__eventIds = [
|
|
963
|
-
editor.on_(EditorEvent.SELECT,
|
|
995
|
+
editor.on_(EditorEvent.SELECT, this.onSelect, this),
|
|
964
996
|
rect.on_(core.DragEvent.START, this.onDragStart, this),
|
|
965
997
|
rect.on_(core.DragEvent.DRAG, editor.onMove, editor),
|
|
966
998
|
rect.on_(core.DragEvent.END, this.onDragEnd, this),
|
|
967
999
|
rect.on_(core.PointerEvent.ENTER, () => updateMoveCursor(editor)),
|
|
968
|
-
rect.on_(core.PointerEvent.
|
|
1000
|
+
rect.on_(core.PointerEvent.DOUBLE_TAP, this.onDoubleTap, this),
|
|
1001
|
+
rect.on_(core.PointerEvent.LONG_PRESS, this.onLongPress, this)
|
|
969
1002
|
];
|
|
970
1003
|
}
|
|
971
1004
|
__removeListenEvents() {
|
|
@@ -1031,7 +1064,7 @@ ${filterStyle}
|
|
|
1031
1064
|
`;
|
|
1032
1065
|
|
|
1033
1066
|
const config = {
|
|
1034
|
-
editSize: '
|
|
1067
|
+
editSize: 'size',
|
|
1035
1068
|
keyEvent: true,
|
|
1036
1069
|
stroke: '#836DFF',
|
|
1037
1070
|
strokeWidth: 2,
|
|
@@ -1049,6 +1082,7 @@ ${filterStyle}
|
|
|
1049
1082
|
selector: true,
|
|
1050
1083
|
hover: true,
|
|
1051
1084
|
select: 'press',
|
|
1085
|
+
openInner: 'double',
|
|
1052
1086
|
boxSelect: true,
|
|
1053
1087
|
moveable: true,
|
|
1054
1088
|
resizeable: true,
|
|
@@ -1056,148 +1090,6 @@ ${filterStyle}
|
|
|
1056
1090
|
skewable: true
|
|
1057
1091
|
};
|
|
1058
1092
|
|
|
1059
|
-
class EditTool {
|
|
1060
|
-
constructor() {
|
|
1061
|
-
this.tag = 'EditTool';
|
|
1062
|
-
}
|
|
1063
|
-
onMove(e) {
|
|
1064
|
-
const { moveX, moveY, editor } = e;
|
|
1065
|
-
const { app, list } = editor;
|
|
1066
|
-
app.lockLayout();
|
|
1067
|
-
list.forEach(target => {
|
|
1068
|
-
target.moveWorld(moveX, moveY);
|
|
1069
|
-
});
|
|
1070
|
-
app.unlockLayout();
|
|
1071
|
-
}
|
|
1072
|
-
onScale(e) {
|
|
1073
|
-
const { scaleX, scaleY, transform, worldOrigin, editor } = e;
|
|
1074
|
-
const { app, list } = editor;
|
|
1075
|
-
app.lockLayout();
|
|
1076
|
-
list.forEach(target => {
|
|
1077
|
-
const resize = editor.getEditSize(target) === 'size';
|
|
1078
|
-
if (transform) {
|
|
1079
|
-
target.transformWorld(transform, resize);
|
|
1080
|
-
}
|
|
1081
|
-
else {
|
|
1082
|
-
target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize);
|
|
1083
|
-
}
|
|
1084
|
-
});
|
|
1085
|
-
app.unlockLayout();
|
|
1086
|
-
}
|
|
1087
|
-
onRotate(e) {
|
|
1088
|
-
const { rotation, transform, worldOrigin, editor } = e;
|
|
1089
|
-
const { app, list } = editor;
|
|
1090
|
-
app.lockLayout();
|
|
1091
|
-
list.forEach(target => {
|
|
1092
|
-
const resize = editor.getEditSize(target) === 'size';
|
|
1093
|
-
if (transform) {
|
|
1094
|
-
target.transformWorld(transform, resize);
|
|
1095
|
-
}
|
|
1096
|
-
else {
|
|
1097
|
-
target.rotateOfWorld(worldOrigin, rotation);
|
|
1098
|
-
}
|
|
1099
|
-
});
|
|
1100
|
-
app.unlockLayout();
|
|
1101
|
-
}
|
|
1102
|
-
onSkew(e) {
|
|
1103
|
-
const { skewX, skewY, transform, worldOrigin, editor } = e;
|
|
1104
|
-
const { app, list } = editor;
|
|
1105
|
-
app.lockLayout();
|
|
1106
|
-
list.forEach(target => {
|
|
1107
|
-
const resize = editor.getEditSize(target) === 'size';
|
|
1108
|
-
if (transform) {
|
|
1109
|
-
target.transformWorld(transform, resize);
|
|
1110
|
-
}
|
|
1111
|
-
else {
|
|
1112
|
-
target.skewOfWorld(worldOrigin, skewX, skewY, resize);
|
|
1113
|
-
}
|
|
1114
|
-
});
|
|
1115
|
-
app.unlockLayout();
|
|
1116
|
-
}
|
|
1117
|
-
update(editor) {
|
|
1118
|
-
const { simulateTarget, element } = editor;
|
|
1119
|
-
if (editor.multiple)
|
|
1120
|
-
simulateTarget.parent.updateLayout();
|
|
1121
|
-
const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = element.getLayoutBounds('box', editor, true);
|
|
1122
|
-
editor.editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
|
|
1123
|
-
editor.editBox.update({ x: 0, y: 0, width, height });
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
EditTool.list = [];
|
|
1127
|
-
|
|
1128
|
-
const { left, right } = IDirection8;
|
|
1129
|
-
class LineEditTool extends EditTool {
|
|
1130
|
-
constructor() {
|
|
1131
|
-
super(...arguments);
|
|
1132
|
-
this.tag = 'LineEditTool';
|
|
1133
|
-
this.scaleOfEvent = true;
|
|
1134
|
-
}
|
|
1135
|
-
onScaleWithDrag(e) {
|
|
1136
|
-
const { drag, direction, lockRatio, around } = e;
|
|
1137
|
-
const target = e.target;
|
|
1138
|
-
const fromPoint = draw.getPointData();
|
|
1139
|
-
const { toPoint } = target;
|
|
1140
|
-
target.rotation = 0;
|
|
1141
|
-
let { x, y } = drag.getInnerMove(target);
|
|
1142
|
-
if (lockRatio) {
|
|
1143
|
-
if (Math.abs(x) > Math.abs(y)) {
|
|
1144
|
-
y = 0;
|
|
1145
|
-
}
|
|
1146
|
-
else {
|
|
1147
|
-
x = 0;
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
if (direction === left) {
|
|
1151
|
-
fromPoint.x += x;
|
|
1152
|
-
fromPoint.y += y;
|
|
1153
|
-
if (around) {
|
|
1154
|
-
toPoint.x -= x;
|
|
1155
|
-
toPoint.y -= y;
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
else {
|
|
1159
|
-
if (around) {
|
|
1160
|
-
fromPoint.x -= x;
|
|
1161
|
-
fromPoint.y -= y;
|
|
1162
|
-
}
|
|
1163
|
-
toPoint.x += x;
|
|
1164
|
-
toPoint.y += y;
|
|
1165
|
-
}
|
|
1166
|
-
target.getLocalPointByInner(fromPoint, null, null, true);
|
|
1167
|
-
target.getLocalPointByInner(toPoint, null, null, true);
|
|
1168
|
-
target.x = fromPoint.x;
|
|
1169
|
-
target.y = fromPoint.y;
|
|
1170
|
-
target.getInnerPointByLocal(toPoint, null, null, true);
|
|
1171
|
-
target.toPoint = toPoint;
|
|
1172
|
-
}
|
|
1173
|
-
onSkew(_e) {
|
|
1174
|
-
}
|
|
1175
|
-
update(editor) {
|
|
1176
|
-
const { rotatePoints, resizeLines, resizePoints } = editor.editBox;
|
|
1177
|
-
super.update(editor);
|
|
1178
|
-
for (let i = 0; i < 8; i++) {
|
|
1179
|
-
if (i < 4)
|
|
1180
|
-
resizeLines[i].visible = false;
|
|
1181
|
-
resizePoints[i].visible = rotatePoints[i].visible = (i === left || i === right);
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
function getEditTool(list) {
|
|
1187
|
-
if (list.length === 1) {
|
|
1188
|
-
const leaf = list[0];
|
|
1189
|
-
if (leaf instanceof draw.Line && !leaf.points) {
|
|
1190
|
-
return new LineEditTool();
|
|
1191
|
-
}
|
|
1192
|
-
else {
|
|
1193
|
-
return new EditTool();
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
else {
|
|
1197
|
-
return new EditTool();
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
1093
|
function simulate(editor) {
|
|
1202
1094
|
const { simulateTarget, leafList: targetList } = editor;
|
|
1203
1095
|
const { x, y, width, height } = new draw.Bounds().setListWithFn(targetList.list, (leaf) => leaf.worldBoxBounds);
|
|
@@ -1215,7 +1107,8 @@ ${filterStyle}
|
|
|
1215
1107
|
editor.leafList.reset();
|
|
1216
1108
|
}
|
|
1217
1109
|
editor.emitEvent(new EditorEvent(EditorEvent.SELECT, { editor, value: target, oldValue }));
|
|
1218
|
-
|
|
1110
|
+
editor.checkOpenedGroups();
|
|
1111
|
+
if (editor.editing) {
|
|
1219
1112
|
editor.waitLeafer(() => {
|
|
1220
1113
|
if (editor.multiple)
|
|
1221
1114
|
simulate(editor);
|
|
@@ -1226,6 +1119,7 @@ ${filterStyle}
|
|
|
1226
1119
|
});
|
|
1227
1120
|
}
|
|
1228
1121
|
else {
|
|
1122
|
+
editor.updateEditTool();
|
|
1229
1123
|
editor.removeTargetEvents();
|
|
1230
1124
|
}
|
|
1231
1125
|
}
|
|
@@ -1294,26 +1188,55 @@ ${filterStyle}
|
|
|
1294
1188
|
}
|
|
1295
1189
|
};
|
|
1296
1190
|
|
|
1191
|
+
const debug = draw.Debug.get('EditToolCreator');
|
|
1192
|
+
function registerEditTool() {
|
|
1193
|
+
return (target) => {
|
|
1194
|
+
EditToolCreator.register(target);
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
const registerInnerEditor = registerEditTool;
|
|
1198
|
+
const EditToolCreator = {
|
|
1199
|
+
list: {},
|
|
1200
|
+
register(EditTool) {
|
|
1201
|
+
const { tag } = EditTool.prototype;
|
|
1202
|
+
list[tag] ? debug.repeat(tag) : (list[tag] = EditTool);
|
|
1203
|
+
},
|
|
1204
|
+
get(tag, editor) {
|
|
1205
|
+
return new list[tag](editor);
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
const { list } = EditToolCreator;
|
|
1209
|
+
|
|
1297
1210
|
class Editor extends draw.Group {
|
|
1298
1211
|
get list() { return this.leafList.list; }
|
|
1299
|
-
get
|
|
1212
|
+
get editing() { return !!this.list.length; }
|
|
1213
|
+
get groupOpening() { return !!this.openedGroupList.length; }
|
|
1300
1214
|
get multiple() { return this.list.length > 1; }
|
|
1301
1215
|
get single() { return this.list.length === 1; }
|
|
1216
|
+
get dragging() { return this.editBox.dragging; }
|
|
1302
1217
|
get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
|
|
1303
1218
|
get buttons() { return this.editBox.buttons; }
|
|
1304
|
-
get dragging() { return this.editBox.dragging; }
|
|
1305
1219
|
constructor(userConfig, data) {
|
|
1306
1220
|
super(data);
|
|
1307
1221
|
this.config = config;
|
|
1222
|
+
this.mergeConfig = config;
|
|
1308
1223
|
this.leafList = new draw.LeafList();
|
|
1224
|
+
this.openedGroupList = new draw.LeafList();
|
|
1309
1225
|
this.simulateTarget = new draw.Rect({ visible: false });
|
|
1310
1226
|
this.editBox = new EditBox(this);
|
|
1227
|
+
this.editToolList = {};
|
|
1311
1228
|
this.selector = new EditSelect(this);
|
|
1312
1229
|
this.targetEventIds = [];
|
|
1313
1230
|
if (userConfig)
|
|
1314
1231
|
this.config = draw.DataHelper.default(userConfig, this.config);
|
|
1315
1232
|
this.addMany(this.selector, this.editBox);
|
|
1316
1233
|
}
|
|
1234
|
+
select(target) {
|
|
1235
|
+
this.target = target;
|
|
1236
|
+
}
|
|
1237
|
+
cancel() {
|
|
1238
|
+
this.target = null;
|
|
1239
|
+
}
|
|
1317
1240
|
hasItem(item) {
|
|
1318
1241
|
return this.leafList.has(item);
|
|
1319
1242
|
}
|
|
@@ -1329,38 +1252,46 @@ ${filterStyle}
|
|
|
1329
1252
|
this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
|
|
1330
1253
|
}
|
|
1331
1254
|
update() {
|
|
1332
|
-
if (this.
|
|
1333
|
-
if (this.
|
|
1334
|
-
this.
|
|
1255
|
+
if (this.editing) {
|
|
1256
|
+
if (this.innerEditing)
|
|
1257
|
+
this.innerEditor.update();
|
|
1258
|
+
this.editTool.update();
|
|
1335
1259
|
this.selector.update();
|
|
1336
1260
|
}
|
|
1337
1261
|
}
|
|
1338
1262
|
updateEditTool() {
|
|
1339
|
-
|
|
1263
|
+
const tool = this.editTool;
|
|
1264
|
+
if (tool) {
|
|
1265
|
+
this.editBox.unload();
|
|
1266
|
+
tool.unload();
|
|
1267
|
+
this.editTool = null;
|
|
1268
|
+
}
|
|
1269
|
+
if (this.editing) {
|
|
1270
|
+
const tag = this.single ? this.list[0].editOuter : 'EditTool';
|
|
1271
|
+
this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
|
|
1272
|
+
const { editConfig } = this.element;
|
|
1273
|
+
this.mergeConfig = this.single && editConfig ? Object.assign(Object.assign({}, this.mergeConfig), editConfig) : this.config;
|
|
1274
|
+
this.editBox.load();
|
|
1275
|
+
this.editTool.load();
|
|
1276
|
+
}
|
|
1340
1277
|
}
|
|
1341
|
-
getEditSize(
|
|
1342
|
-
|
|
1343
|
-
return editSize === 'auto' ? ui.editSize : editSize;
|
|
1278
|
+
getEditSize(_ui) {
|
|
1279
|
+
return this.mergeConfig.editSize;
|
|
1344
1280
|
}
|
|
1345
1281
|
onMove(e) {
|
|
1346
|
-
const
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
else if (lockMove === 'y')
|
|
1351
|
-
move.x = 0;
|
|
1352
|
-
else if (e.shiftKey) {
|
|
1353
|
-
if (Math.abs(move.x) > Math.abs(move.y))
|
|
1354
|
-
move.y = 0;
|
|
1282
|
+
const total = { x: e.totalX, y: e.totalY };
|
|
1283
|
+
if (e.shiftKey) {
|
|
1284
|
+
if (Math.abs(total.x) > Math.abs(total.y))
|
|
1285
|
+
total.y = 0;
|
|
1355
1286
|
else
|
|
1356
|
-
|
|
1287
|
+
total.x = 0;
|
|
1357
1288
|
}
|
|
1358
|
-
this.move(
|
|
1289
|
+
this.move(core.DragEvent.getValidMove(this.element, this.dragStartPoint, total));
|
|
1359
1290
|
}
|
|
1360
1291
|
onScale(e) {
|
|
1361
1292
|
const { element } = this;
|
|
1362
1293
|
const { direction } = e.current;
|
|
1363
|
-
let { around, lockRatio } = this.
|
|
1294
|
+
let { around, lockRatio } = this.mergeConfig;
|
|
1364
1295
|
if (e.shiftKey)
|
|
1365
1296
|
lockRatio = true;
|
|
1366
1297
|
const data = EditDataHelper.getScaleData(element.boxBounds, direction, e.getInnerMove(element), lockRatio, EditDataHelper.getAround(around, e.altKey));
|
|
@@ -1373,7 +1304,7 @@ ${filterStyle}
|
|
|
1373
1304
|
}
|
|
1374
1305
|
}
|
|
1375
1306
|
onRotate(e) {
|
|
1376
|
-
const { skewable, around, rotateGap } = this.
|
|
1307
|
+
const { skewable, around, rotateGap } = this.mergeConfig;
|
|
1377
1308
|
const { direction, name } = e.current;
|
|
1378
1309
|
if (skewable && name === 'resize-line')
|
|
1379
1310
|
return this.onSkew(e);
|
|
@@ -1397,17 +1328,17 @@ ${filterStyle}
|
|
|
1397
1328
|
}
|
|
1398
1329
|
onSkew(e) {
|
|
1399
1330
|
const { element } = this;
|
|
1400
|
-
const { around } = this.
|
|
1331
|
+
const { around } = this.mergeConfig;
|
|
1401
1332
|
const { origin, skewX, skewY } = EditDataHelper.getSkewData(element.boxBounds, e.current.direction, e.getInnerMove(element), EditDataHelper.getAround(around, e.altKey));
|
|
1402
1333
|
if (!skewX && !skewY)
|
|
1403
1334
|
return;
|
|
1404
1335
|
this.skewOf(origin, skewX, skewY);
|
|
1405
1336
|
}
|
|
1406
|
-
move(x, y) {
|
|
1407
|
-
if (!this.
|
|
1337
|
+
move(x, y = 0) {
|
|
1338
|
+
if (!this.mergeConfig.moveable || this.element.locked)
|
|
1408
1339
|
return;
|
|
1409
1340
|
const { element } = this;
|
|
1410
|
-
const world = element.getWorldPointByLocal({ x, y }, null, true);
|
|
1341
|
+
const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
|
|
1411
1342
|
const event = new EditorMoveEvent(EditorMoveEvent.MOVE, { target: element, editor: this, moveX: world.x, moveY: world.y });
|
|
1412
1343
|
this.editTool.onMove(event);
|
|
1413
1344
|
this.emitEvent(event);
|
|
@@ -1472,6 +1403,44 @@ ${filterStyle}
|
|
|
1472
1403
|
this.target = EditorHelper.ungroup(this.list);
|
|
1473
1404
|
return this.list;
|
|
1474
1405
|
}
|
|
1406
|
+
openGroup(group) {
|
|
1407
|
+
this.openedGroupList.add(group);
|
|
1408
|
+
group.hitChildren = true;
|
|
1409
|
+
}
|
|
1410
|
+
closeGroup(group) {
|
|
1411
|
+
this.openedGroupList.remove(group);
|
|
1412
|
+
group.hitChildren = false;
|
|
1413
|
+
}
|
|
1414
|
+
checkOpenedGroups() {
|
|
1415
|
+
const opened = this.openedGroupList;
|
|
1416
|
+
if (opened.length) {
|
|
1417
|
+
let { list } = opened;
|
|
1418
|
+
if (this.editing)
|
|
1419
|
+
list = [], opened.forEach(item => this.list.every(leaf => !draw.LeafHelper.hasParent(leaf, item)) && list.push(item));
|
|
1420
|
+
list.forEach(item => this.closeGroup(item));
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
openInnerEditor() {
|
|
1424
|
+
if (this.single) {
|
|
1425
|
+
const tag = this.element.editInner;
|
|
1426
|
+
if (tag) {
|
|
1427
|
+
if (EditToolCreator.list[tag]) {
|
|
1428
|
+
this.editTool.unload();
|
|
1429
|
+
this.innerEditing = true;
|
|
1430
|
+
this.innerEditor = this.editToolList[tag] || EditToolCreator.get(tag, this);
|
|
1431
|
+
this.innerEditor.load();
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
closeInnerEditor() {
|
|
1437
|
+
if (this.innerEditing) {
|
|
1438
|
+
this.innerEditing = false;
|
|
1439
|
+
this.innerEditor.unload();
|
|
1440
|
+
this.editTool.load();
|
|
1441
|
+
this.innerEditor = null;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1475
1444
|
lock() {
|
|
1476
1445
|
this.list.forEach(leaf => leaf.locked = true);
|
|
1477
1446
|
this.update();
|
|
@@ -1512,7 +1481,9 @@ ${filterStyle}
|
|
|
1512
1481
|
destroy() {
|
|
1513
1482
|
if (!this.destroyed) {
|
|
1514
1483
|
this.simulateTarget.destroy();
|
|
1515
|
-
|
|
1484
|
+
Object.values(this.editToolList).forEach(item => item.destroy());
|
|
1485
|
+
this.editToolList = {};
|
|
1486
|
+
this.target = this.hoverTarget = this.simulateTarget = this.editTool = this.innerEditor = null;
|
|
1516
1487
|
super.destroy();
|
|
1517
1488
|
}
|
|
1518
1489
|
}
|
|
@@ -1524,16 +1495,214 @@ ${filterStyle}
|
|
|
1524
1495
|
targetAttr(onTarget)
|
|
1525
1496
|
], Editor.prototype, "target", void 0);
|
|
1526
1497
|
|
|
1527
|
-
|
|
1528
|
-
|
|
1498
|
+
class InnerEditor {
|
|
1499
|
+
static registerInnerEditor() {
|
|
1500
|
+
EditToolCreator.register(this);
|
|
1501
|
+
}
|
|
1502
|
+
get tag() { return 'InnerEditor'; }
|
|
1503
|
+
get editBox() { return this.editor.editBox; }
|
|
1504
|
+
constructor(editor) {
|
|
1505
|
+
this.editor = editor;
|
|
1506
|
+
this.create();
|
|
1507
|
+
}
|
|
1508
|
+
onCreate() { }
|
|
1509
|
+
create() {
|
|
1510
|
+
this.view = new draw.Group();
|
|
1511
|
+
this.onCreate();
|
|
1512
|
+
}
|
|
1513
|
+
onLoad() { }
|
|
1514
|
+
load() {
|
|
1515
|
+
this.editor.selector.hittable = this.editor.app.tree.hitChildren = false;
|
|
1516
|
+
this.onLoad();
|
|
1517
|
+
}
|
|
1518
|
+
onUpdate() { }
|
|
1519
|
+
update() { this.onUpdate(); }
|
|
1520
|
+
onUnload() { }
|
|
1521
|
+
unload() {
|
|
1522
|
+
this.editor.selector.hittable = this.editor.app.tree.hitChildren = true;
|
|
1523
|
+
this.onUnload();
|
|
1524
|
+
}
|
|
1525
|
+
onDestroy() { }
|
|
1526
|
+
destroy() {
|
|
1527
|
+
this.onDestroy();
|
|
1528
|
+
if (this.editor) {
|
|
1529
|
+
if (this.view)
|
|
1530
|
+
this.view.destroy();
|
|
1531
|
+
if (this.eventIds)
|
|
1532
|
+
this.editor.off_(this.eventIds);
|
|
1533
|
+
this.editor = this.view = this.eventIds = null;
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
exports.EditTool = class EditTool extends InnerEditor {
|
|
1539
|
+
static registerEditTool() {
|
|
1540
|
+
EditToolCreator.register(this);
|
|
1541
|
+
}
|
|
1542
|
+
get tag() { return 'EditTool'; }
|
|
1543
|
+
onMove(e) {
|
|
1544
|
+
const { moveX, moveY, editor } = e;
|
|
1545
|
+
const { app, list } = editor;
|
|
1546
|
+
app.lockLayout();
|
|
1547
|
+
list.forEach(target => {
|
|
1548
|
+
target.moveWorld(moveX, moveY);
|
|
1549
|
+
});
|
|
1550
|
+
app.unlockLayout();
|
|
1551
|
+
}
|
|
1552
|
+
onScale(e) {
|
|
1553
|
+
const { scaleX, scaleY, transform, worldOrigin, editor } = e;
|
|
1554
|
+
const { app, list } = editor;
|
|
1555
|
+
app.lockLayout();
|
|
1556
|
+
list.forEach(target => {
|
|
1557
|
+
const resize = editor.getEditSize(target) === 'size';
|
|
1558
|
+
if (transform) {
|
|
1559
|
+
target.transformWorld(transform, resize);
|
|
1560
|
+
}
|
|
1561
|
+
else {
|
|
1562
|
+
target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize);
|
|
1563
|
+
}
|
|
1564
|
+
});
|
|
1565
|
+
app.unlockLayout();
|
|
1566
|
+
}
|
|
1567
|
+
onRotate(e) {
|
|
1568
|
+
const { rotation, transform, worldOrigin, editor } = e;
|
|
1569
|
+
const { app, list } = editor;
|
|
1570
|
+
app.lockLayout();
|
|
1571
|
+
list.forEach(target => {
|
|
1572
|
+
const resize = editor.getEditSize(target) === 'size';
|
|
1573
|
+
if (transform) {
|
|
1574
|
+
target.transformWorld(transform, resize);
|
|
1575
|
+
}
|
|
1576
|
+
else {
|
|
1577
|
+
target.rotateOfWorld(worldOrigin, rotation);
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
app.unlockLayout();
|
|
1581
|
+
}
|
|
1582
|
+
onSkew(e) {
|
|
1583
|
+
const { skewX, skewY, transform, worldOrigin, editor } = e;
|
|
1584
|
+
const { app, list } = editor;
|
|
1585
|
+
app.lockLayout();
|
|
1586
|
+
list.forEach(target => {
|
|
1587
|
+
const resize = editor.getEditSize(target) === 'size';
|
|
1588
|
+
if (transform) {
|
|
1589
|
+
target.transformWorld(transform, resize);
|
|
1590
|
+
}
|
|
1591
|
+
else {
|
|
1592
|
+
target.skewOfWorld(worldOrigin, skewX, skewY, resize);
|
|
1593
|
+
}
|
|
1594
|
+
});
|
|
1595
|
+
app.unlockLayout();
|
|
1596
|
+
}
|
|
1597
|
+
load() {
|
|
1598
|
+
this.editBox.view.visible = true;
|
|
1599
|
+
this.onLoad();
|
|
1600
|
+
}
|
|
1601
|
+
update() {
|
|
1602
|
+
const { editor, editBox } = this;
|
|
1603
|
+
const { simulateTarget, element } = editor;
|
|
1604
|
+
if (editor.multiple)
|
|
1605
|
+
simulateTarget.parent.updateLayout();
|
|
1606
|
+
const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = element.getLayoutBounds('box', editor, true);
|
|
1607
|
+
editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
|
|
1608
|
+
editBox.update({ x: 0, y: 0, width, height });
|
|
1609
|
+
this.onUpdate();
|
|
1610
|
+
}
|
|
1611
|
+
unload() {
|
|
1612
|
+
this.editBox.view.visible = false;
|
|
1613
|
+
this.onUnload();
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
exports.EditTool = __decorate([
|
|
1617
|
+
registerEditTool()
|
|
1618
|
+
], exports.EditTool);
|
|
1619
|
+
|
|
1620
|
+
const { left, right } = draw.Direction9;
|
|
1621
|
+
exports.LineEditTool = class LineEditTool extends exports.EditTool {
|
|
1622
|
+
constructor() {
|
|
1623
|
+
super(...arguments);
|
|
1624
|
+
this.scaleOfEvent = true;
|
|
1625
|
+
}
|
|
1626
|
+
get tag() { return 'LineEditTool'; }
|
|
1627
|
+
onScaleWithDrag(e) {
|
|
1628
|
+
const { drag, direction, lockRatio, around } = e;
|
|
1629
|
+
const target = e.target;
|
|
1630
|
+
const fromPoint = draw.getPointData();
|
|
1631
|
+
const { toPoint } = target;
|
|
1632
|
+
target.rotation = 0;
|
|
1633
|
+
let { x, y } = drag.getInnerMove(target);
|
|
1634
|
+
if (lockRatio) {
|
|
1635
|
+
if (Math.abs(x) > Math.abs(y)) {
|
|
1636
|
+
y = 0;
|
|
1637
|
+
}
|
|
1638
|
+
else {
|
|
1639
|
+
x = 0;
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
if (direction === left) {
|
|
1643
|
+
fromPoint.x += x;
|
|
1644
|
+
fromPoint.y += y;
|
|
1645
|
+
if (around) {
|
|
1646
|
+
toPoint.x -= x;
|
|
1647
|
+
toPoint.y -= y;
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
else {
|
|
1651
|
+
if (around) {
|
|
1652
|
+
fromPoint.x -= x;
|
|
1653
|
+
fromPoint.y -= y;
|
|
1654
|
+
}
|
|
1655
|
+
toPoint.x += x;
|
|
1656
|
+
toPoint.y += y;
|
|
1657
|
+
}
|
|
1658
|
+
target.getLocalPointByInner(fromPoint, null, null, true);
|
|
1659
|
+
target.getLocalPointByInner(toPoint, null, null, true);
|
|
1660
|
+
target.x = fromPoint.x;
|
|
1661
|
+
target.y = fromPoint.y;
|
|
1662
|
+
target.getInnerPointByLocal(toPoint, null, null, true);
|
|
1663
|
+
target.toPoint = toPoint;
|
|
1664
|
+
}
|
|
1665
|
+
onSkew(_e) {
|
|
1666
|
+
}
|
|
1667
|
+
onUpdate() {
|
|
1668
|
+
const { rotatePoints, resizeLines, resizePoints } = this.editor.editBox;
|
|
1669
|
+
for (let i = 0; i < 8; i++) {
|
|
1670
|
+
if (i < 4)
|
|
1671
|
+
resizeLines[i].visible = false;
|
|
1672
|
+
resizePoints[i].visible = rotatePoints[i].visible = (i === left || i === right);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
};
|
|
1676
|
+
exports.LineEditTool = __decorate([
|
|
1677
|
+
registerEditTool()
|
|
1678
|
+
], exports.LineEditTool);
|
|
1679
|
+
|
|
1680
|
+
draw.Creator.editor = function (options) { return new Editor(options); };
|
|
1681
|
+
draw.UI.setEditConfig = function (config) {
|
|
1682
|
+
draw.defineKey(this.prototype, 'editConfig', {
|
|
1683
|
+
get() { return typeof config === 'function' ? config(this) : config; }
|
|
1684
|
+
});
|
|
1685
|
+
};
|
|
1686
|
+
draw.UI.setEditOuter = function (toolName) {
|
|
1687
|
+
draw.defineKey(this.prototype, 'editOuter', {
|
|
1688
|
+
get() { return typeof toolName === 'string' ? toolName : toolName(this); }
|
|
1689
|
+
});
|
|
1690
|
+
};
|
|
1691
|
+
draw.UI.setEditInner = function (editorName) {
|
|
1692
|
+
draw.defineKey(this.prototype, 'editInner', {
|
|
1693
|
+
get() { return typeof editorName === 'string' ? editorName : editorName(this); }
|
|
1694
|
+
});
|
|
1529
1695
|
};
|
|
1696
|
+
draw.Line.setEditOuter(function (line) {
|
|
1697
|
+
return (line.points || line.pathInputed) ? 'EditTool' : 'LineEditTool';
|
|
1698
|
+
});
|
|
1530
1699
|
|
|
1531
1700
|
exports.EditBox = EditBox;
|
|
1532
1701
|
exports.EditDataHelper = EditDataHelper;
|
|
1533
1702
|
exports.EditPoint = EditPoint;
|
|
1534
1703
|
exports.EditSelect = EditSelect;
|
|
1535
1704
|
exports.EditSelectHelper = EditSelectHelper;
|
|
1536
|
-
exports.
|
|
1705
|
+
exports.EditToolCreator = EditToolCreator;
|
|
1537
1706
|
exports.Editor = Editor;
|
|
1538
1707
|
exports.EditorEvent = EditorEvent;
|
|
1539
1708
|
exports.EditorHelper = EditorHelper;
|
|
@@ -1541,9 +1710,11 @@ ${filterStyle}
|
|
|
1541
1710
|
exports.EditorRotateEvent = EditorRotateEvent;
|
|
1542
1711
|
exports.EditorScaleEvent = EditorScaleEvent;
|
|
1543
1712
|
exports.EditorSkewEvent = EditorSkewEvent;
|
|
1544
|
-
exports.
|
|
1713
|
+
exports.InnerEditor = InnerEditor;
|
|
1545
1714
|
exports.SelectArea = SelectArea;
|
|
1546
1715
|
exports.Stroker = Stroker;
|
|
1716
|
+
exports.registerEditTool = registerEditTool;
|
|
1717
|
+
exports.registerInnerEditor = registerInnerEditor;
|
|
1547
1718
|
|
|
1548
1719
|
return exports;
|
|
1549
1720
|
|