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