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