@leafer-in/editor 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editor.cjs +1279 -1036
- package/dist/editor.esm.js +1258 -1034
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +1177 -1065
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.cjs.map +1 -1
- package/dist/editor.min.js +1 -1
- package/dist/editor.min.js.map +1 -1
- package/package.json +6 -6
- package/src/Editor.ts +35 -26
- package/src/decorator/data.ts +7 -5
- package/src/display/EditBox.ts +123 -54
- package/src/display/EditSelect.ts +13 -7
- package/src/display/Stroker.ts +8 -7
- package/src/editor/cursor.ts +10 -7
- package/src/editor/target.ts +2 -1
- package/src/event/EditorEvent.ts +2 -2
- package/src/helper/EditDataHelper.ts +12 -8
- package/src/index.ts +1 -1
- package/src/tool/TransformTool.ts +29 -31
- package/types/index.d.ts +43 -27
package/dist/editor.esm.js
CHANGED
|
@@ -1,79 +1,76 @@
|
|
|
1
|
-
import { Event, defineKey, isNull, MatrixHelper, BoundsHelper, LeafBoundsHelper, getMatrixData, getBoundsData, UI, Paint, Group, Rect, Bounds, LeafList, Direction9, AroundHelper, MathHelper, PointHelper, Box, ResizeEvent, Text, Matrix, Debug, LeafHelper, PropertyEvent, DataHelper, Plugin, RenderEvent, getPointData, Creator, dataType } from
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
-
***************************************************************************** */
|
|
19
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function __decorate(decorators, target, key, desc) {
|
|
23
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
25
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
26
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
30
|
-
var e = new Error(message);
|
|
31
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1
|
+
import { Event, isArray, defineKey, isNull, isObject, MatrixHelper, BoundsHelper, LeafBoundsHelper, getMatrixData, getBoundsData, UI, isString, Paint, Group, Rect, Bounds, LeafList, Direction9, AroundHelper, MathHelper, PointHelper, Box, isNumber, ResizeEvent, Text, Matrix, Debug, LeafHelper, PropertyEvent, isUndefined, DataHelper, Plugin, RenderEvent, getPointData, Creator, dataType } from "@leafer-ui/draw";
|
|
2
|
+
|
|
3
|
+
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, KeyEvent, RotateEvent, useModule } from "@leafer-ui/core";
|
|
4
|
+
|
|
5
|
+
import "@leafer-in/resize";
|
|
6
|
+
|
|
7
|
+
function __decorate(decorators, target, key, desc) {
|
|
8
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
14
|
+
var e = new Error(message);
|
|
15
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
32
16
|
};
|
|
33
17
|
|
|
34
18
|
function toList(value) {
|
|
35
|
-
return value ? (value
|
|
19
|
+
return value ? isArray(value) ? value : [ value ] : [];
|
|
36
20
|
}
|
|
21
|
+
|
|
37
22
|
class EditorEvent extends Event {
|
|
38
|
-
get list() {
|
|
39
|
-
|
|
23
|
+
get list() {
|
|
24
|
+
return toList(this.value);
|
|
25
|
+
}
|
|
26
|
+
get oldList() {
|
|
27
|
+
return toList(this.oldValue);
|
|
28
|
+
}
|
|
40
29
|
constructor(type, data) {
|
|
41
30
|
super(type);
|
|
42
|
-
if (data)
|
|
43
|
-
Object.assign(this, data);
|
|
31
|
+
if (data) Object.assign(this, data);
|
|
44
32
|
}
|
|
45
33
|
}
|
|
46
|
-
|
|
47
|
-
EditorEvent.
|
|
48
|
-
|
|
49
|
-
EditorEvent.
|
|
50
|
-
|
|
34
|
+
|
|
35
|
+
EditorEvent.BEFORE_SELECT = "editor.before_select";
|
|
36
|
+
|
|
37
|
+
EditorEvent.SELECT = "editor.select";
|
|
38
|
+
|
|
39
|
+
EditorEvent.AFTER_SELECT = "editor.after_select";
|
|
40
|
+
|
|
41
|
+
EditorEvent.BEFORE_HOVER = "editor.before_hover";
|
|
42
|
+
|
|
43
|
+
EditorEvent.HOVER = "editor.hover";
|
|
51
44
|
|
|
52
45
|
function targetAttr(fn) {
|
|
53
46
|
return (target, key) => {
|
|
54
|
-
const privateKey =
|
|
47
|
+
const privateKey = "_" + key;
|
|
55
48
|
defineKey(target, key, {
|
|
56
|
-
get() {
|
|
49
|
+
get() {
|
|
50
|
+
return this[privateKey];
|
|
51
|
+
},
|
|
57
52
|
set(value) {
|
|
58
53
|
const old = this[privateKey];
|
|
59
54
|
if (old !== value) {
|
|
60
55
|
if (this.config) {
|
|
61
|
-
const isSelect = key ===
|
|
56
|
+
const isSelect = key === "target";
|
|
62
57
|
if (isSelect) {
|
|
63
|
-
if (value
|
|
64
|
-
|
|
65
|
-
const { beforeSelect
|
|
58
|
+
if (isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1);
|
|
59
|
+
if (this.single) this.element.syncEventer = null;
|
|
60
|
+
const {beforeSelect: beforeSelect} = this.config;
|
|
66
61
|
if (beforeSelect) {
|
|
67
|
-
const check = beforeSelect({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
else if (check === false)
|
|
71
|
-
return;
|
|
62
|
+
const check = beforeSelect({
|
|
63
|
+
target: value
|
|
64
|
+
});
|
|
65
|
+
if (isObject(check)) value = check; else if (check === false) return;
|
|
72
66
|
}
|
|
73
67
|
}
|
|
74
68
|
const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
|
|
75
|
-
if (this.hasEvent(type))
|
|
76
|
-
|
|
69
|
+
if (this.hasEvent(type)) this.emitEvent(new EditorEvent(type, {
|
|
70
|
+
editor: this,
|
|
71
|
+
value: value,
|
|
72
|
+
oldValue: old
|
|
73
|
+
}));
|
|
77
74
|
}
|
|
78
75
|
this[privateKey] = value, fn(this, old);
|
|
79
76
|
}
|
|
@@ -81,20 +78,19 @@ function targetAttr(fn) {
|
|
|
81
78
|
});
|
|
82
79
|
};
|
|
83
80
|
}
|
|
81
|
+
|
|
84
82
|
function mergeConfigAttr() {
|
|
85
83
|
return (target, key) => {
|
|
86
84
|
defineKey(target, key, {
|
|
87
85
|
get() {
|
|
88
|
-
const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
|
|
89
|
-
if (element && element.editConfig)
|
|
90
|
-
|
|
86
|
+
const {config: config, element: element, dragPoint: dragPoint, editBox: editBox} = this, mergeConfig = Object.assign({}, config);
|
|
87
|
+
if (element && element.editConfig) Object.assign(mergeConfig, element.editConfig);
|
|
88
|
+
if (editBox.config) Object.assign(mergeConfig, editBox.config);
|
|
91
89
|
if (dragPoint) {
|
|
92
|
-
if (dragPoint.editConfig)
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
mergeConfig.
|
|
96
|
-
if (dragPoint.pointType === 'resize-rotate') {
|
|
97
|
-
mergeConfig.around || (mergeConfig.around = 'center');
|
|
90
|
+
if (dragPoint.editConfig) Object.assign(mergeConfig, dragPoint.editConfig);
|
|
91
|
+
if (mergeConfig.editSize === "font-size") mergeConfig.lockRatio = true;
|
|
92
|
+
if (dragPoint.pointType === "resize-rotate") {
|
|
93
|
+
mergeConfig.around || (mergeConfig.around = "center");
|
|
98
94
|
isNull(mergeConfig.lockRatio) && (mergeConfig.lockRatio = true);
|
|
99
95
|
}
|
|
100
96
|
}
|
|
@@ -104,43 +100,48 @@ function mergeConfigAttr() {
|
|
|
104
100
|
};
|
|
105
101
|
}
|
|
106
102
|
|
|
107
|
-
const { abs
|
|
108
|
-
|
|
109
|
-
const {
|
|
110
|
-
|
|
103
|
+
const {abs: abs} = Math;
|
|
104
|
+
|
|
105
|
+
const {copy: copy$1, scale: scale} = MatrixHelper;
|
|
106
|
+
|
|
107
|
+
const {setListWithFn: setListWithFn} = BoundsHelper;
|
|
108
|
+
|
|
109
|
+
const {worldBounds: worldBounds} = LeafBoundsHelper;
|
|
110
|
+
|
|
111
111
|
const matrix = getMatrixData();
|
|
112
|
+
|
|
112
113
|
const bounds$1 = getBoundsData();
|
|
114
|
+
|
|
113
115
|
class Stroker extends UI {
|
|
114
116
|
constructor() {
|
|
115
117
|
super();
|
|
116
118
|
this.list = [];
|
|
117
119
|
this.visible = 0;
|
|
118
120
|
this.hittable = false;
|
|
119
|
-
this.strokeAlign =
|
|
121
|
+
this.strokeAlign = "center";
|
|
120
122
|
}
|
|
121
123
|
setTarget(target, style) {
|
|
122
|
-
this.set(style);
|
|
124
|
+
if (style) this.set(style);
|
|
123
125
|
this.target = target;
|
|
124
126
|
this.update();
|
|
125
127
|
}
|
|
126
|
-
update() {
|
|
127
|
-
const { list
|
|
128
|
+
update(style) {
|
|
129
|
+
const {list: list} = this;
|
|
128
130
|
if (list.length) {
|
|
129
131
|
setListWithFn(bounds$1, list, worldBounds);
|
|
132
|
+
if (style) this.set(style);
|
|
130
133
|
this.set(bounds$1);
|
|
131
134
|
this.visible = true;
|
|
132
|
-
}
|
|
133
|
-
else
|
|
134
|
-
this.visible = 0;
|
|
135
|
+
} else this.visible = 0;
|
|
135
136
|
}
|
|
136
137
|
__draw(canvas, options) {
|
|
137
|
-
const { list
|
|
138
|
+
const {list: list} = this;
|
|
138
139
|
if (list.length) {
|
|
139
140
|
let leaf;
|
|
140
|
-
const data = this.__, { stroke, strokeWidth, fill } = data, { bounds
|
|
141
|
+
const data = this.__, {stroke: stroke, strokeWidth: strokeWidth, fill: fill} = data, {bounds: bounds} = options;
|
|
141
142
|
for (let i = 0; i < list.length; i++) {
|
|
142
143
|
leaf = list[i];
|
|
143
|
-
const { worldTransform, worldRenderBounds } = leaf;
|
|
144
|
+
const {worldTransform: worldTransform, worldRenderBounds: worldRenderBounds} = leaf;
|
|
144
145
|
if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
|
|
145
146
|
const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
|
|
146
147
|
copy$1(matrix, worldTransform);
|
|
@@ -150,22 +151,16 @@ class Stroker extends UI {
|
|
|
150
151
|
canvas.setWorld(matrix, options.matrix);
|
|
151
152
|
canvas.beginPath();
|
|
152
153
|
data.strokeWidth = strokeWidth;
|
|
153
|
-
const { x, y, width, height } = leaf.__layout.boxBounds;
|
|
154
|
+
const {x: x, y: y, width: width, height: height} = leaf.__layout.boxBounds;
|
|
154
155
|
canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
156
|
+
} else {
|
|
157
157
|
canvas.setWorld(matrix, options.matrix);
|
|
158
158
|
canvas.beginPath();
|
|
159
|
-
if (leaf.__.__useArrow)
|
|
160
|
-
leaf.__drawPath(canvas);
|
|
161
|
-
else
|
|
162
|
-
leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
|
|
159
|
+
if (leaf.__.__useArrow) leaf.__drawPath(canvas); else leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
|
|
163
160
|
data.strokeWidth = strokeWidth / abs(worldTransform.scaleX);
|
|
164
161
|
}
|
|
165
|
-
if (stroke)
|
|
166
|
-
|
|
167
|
-
if (fill)
|
|
168
|
-
typeof fill === 'string' ? Paint.fill(fill, this, canvas) : Paint.fills(fill, this, canvas);
|
|
162
|
+
if (stroke) isString(stroke) ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas);
|
|
163
|
+
if (fill) isString(fill) ? Paint.fill(fill, this, canvas) : Paint.fills(fill, this, canvas);
|
|
169
164
|
}
|
|
170
165
|
}
|
|
171
166
|
data.strokeWidth = strokeWidth;
|
|
@@ -176,28 +171,37 @@ class Stroker extends UI {
|
|
|
176
171
|
super.destroy();
|
|
177
172
|
}
|
|
178
173
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
174
|
+
|
|
175
|
+
__decorate([ targetAttr(onTarget$1) ], Stroker.prototype, "target", void 0);
|
|
176
|
+
|
|
182
177
|
function onTarget$1(stroker) {
|
|
183
178
|
const value = stroker.target;
|
|
184
|
-
stroker.list = value ? (value
|
|
179
|
+
stroker.list = value ? isArray(value) ? value : [ value ] : [];
|
|
185
180
|
}
|
|
186
181
|
|
|
187
182
|
class SelectArea extends Group {
|
|
188
183
|
constructor(data) {
|
|
189
184
|
super(data);
|
|
190
|
-
this.strokeArea = new Rect({
|
|
191
|
-
|
|
185
|
+
this.strokeArea = new Rect({
|
|
186
|
+
strokeAlign: "center"
|
|
187
|
+
});
|
|
188
|
+
this.fillArea = new Rect;
|
|
192
189
|
this.visible = 0;
|
|
193
190
|
this.hittable = false;
|
|
194
191
|
this.addMany(this.fillArea, this.strokeArea);
|
|
195
192
|
}
|
|
196
193
|
setStyle(style, userStyle) {
|
|
197
|
-
const { visible, stroke, strokeWidth } = style;
|
|
194
|
+
const {visible: visible, stroke: stroke, strokeWidth: strokeWidth} = style;
|
|
198
195
|
this.visible = visible;
|
|
199
|
-
this.strokeArea.reset(Object.assign({
|
|
200
|
-
|
|
196
|
+
this.strokeArea.reset(Object.assign({
|
|
197
|
+
stroke: stroke,
|
|
198
|
+
strokeWidth: strokeWidth
|
|
199
|
+
}, userStyle || {}));
|
|
200
|
+
this.fillArea.reset({
|
|
201
|
+
visible: userStyle ? false : true,
|
|
202
|
+
fill: stroke,
|
|
203
|
+
opacity: .2
|
|
204
|
+
});
|
|
201
205
|
}
|
|
202
206
|
setBounds(bounds) {
|
|
203
207
|
this.strokeArea.set(bounds);
|
|
@@ -207,14 +211,15 @@ class SelectArea extends Group {
|
|
|
207
211
|
|
|
208
212
|
const EditSelectHelper = {
|
|
209
213
|
findOne(path) {
|
|
210
|
-
return path.list.find(
|
|
214
|
+
return path.list.find(leaf => leaf.editable);
|
|
211
215
|
},
|
|
212
216
|
findByBounds(branch, bounds) {
|
|
213
217
|
const list = [];
|
|
214
|
-
eachFind([branch], list, bounds);
|
|
218
|
+
eachFind([ branch ], list, bounds);
|
|
215
219
|
return list;
|
|
216
220
|
}
|
|
217
221
|
};
|
|
222
|
+
|
|
218
223
|
function eachFind(children, list, bounds) {
|
|
219
224
|
let child, data;
|
|
220
225
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
@@ -222,65 +227,72 @@ function eachFind(children, list, bounds) {
|
|
|
222
227
|
if (data.hittable && data.visible && !data.locked && bounds.hit(child.__world)) {
|
|
223
228
|
if (data.editable) {
|
|
224
229
|
if (child.isBranch && !data.hitChildren) {
|
|
225
|
-
if (data.hitSelf)
|
|
226
|
-
list.push(child);
|
|
230
|
+
if (data.hitSelf) list.push(child);
|
|
227
231
|
continue;
|
|
228
|
-
}
|
|
229
|
-
else if (child.isFrame) {
|
|
232
|
+
} else if (child.isFrame) {
|
|
230
233
|
if (bounds.includes(child.__layout.boxBounds, child.__world)) {
|
|
231
234
|
list.push(child);
|
|
232
235
|
continue;
|
|
233
236
|
}
|
|
234
|
-
}
|
|
235
|
-
else if (bounds.hit(child.__layout.boxBounds, child.__world) && data.hitSelf)
|
|
236
|
-
list.push(child);
|
|
237
|
+
} else if (bounds.hit(child.__layout.boxBounds, child.__world) && data.hitSelf) list.push(child);
|
|
237
238
|
}
|
|
238
|
-
if (child.isBranch)
|
|
239
|
-
eachFind(child.children, list, bounds);
|
|
239
|
+
if (child.isBranch) eachFind(child.children, list, bounds);
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
const { findOne, findByBounds } = EditSelectHelper;
|
|
244
|
+
const {findOne: findOne, findByBounds: findByBounds} = EditSelectHelper;
|
|
245
|
+
|
|
245
246
|
class EditSelect extends Group {
|
|
246
|
-
get dragging() {
|
|
247
|
-
|
|
248
|
-
|
|
247
|
+
get dragging() {
|
|
248
|
+
return !!this.originList;
|
|
249
|
+
}
|
|
250
|
+
get running() {
|
|
251
|
+
const {editor: editor} = this;
|
|
252
|
+
return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector;
|
|
253
|
+
}
|
|
254
|
+
get isMoveMode() {
|
|
255
|
+
return this.app && this.app.interaction.moveMode;
|
|
256
|
+
}
|
|
249
257
|
constructor(editor) {
|
|
250
258
|
super();
|
|
251
|
-
this.hoverStroker = new Stroker
|
|
252
|
-
this.targetStroker = new Stroker
|
|
253
|
-
this.bounds = new Bounds
|
|
254
|
-
this.selectArea = new SelectArea
|
|
259
|
+
this.hoverStroker = new Stroker;
|
|
260
|
+
this.targetStroker = new Stroker;
|
|
261
|
+
this.bounds = new Bounds;
|
|
262
|
+
this.selectArea = new SelectArea;
|
|
255
263
|
this.__eventIds = [];
|
|
256
264
|
this.editor = editor;
|
|
257
265
|
this.addMany(this.targetStroker, this.hoverStroker, this.selectArea);
|
|
258
266
|
this.__listenEvents();
|
|
259
267
|
}
|
|
260
268
|
onHover() {
|
|
261
|
-
const { editor
|
|
269
|
+
const {editor: editor} = this;
|
|
262
270
|
if (this.running && !this.dragging && !editor.dragging) {
|
|
263
|
-
const { stroke, strokeWidth, hover, hoverStyle } = editor.mergeConfig;
|
|
264
|
-
this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, Object.assign({
|
|
265
|
-
|
|
266
|
-
|
|
271
|
+
const {stroke: stroke, strokeWidth: strokeWidth, hover: hover, hoverStyle: hoverStyle} = editor.mergeConfig;
|
|
272
|
+
this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, Object.assign({
|
|
273
|
+
stroke: stroke,
|
|
274
|
+
strokeWidth: strokeWidth
|
|
275
|
+
}, hoverStyle || {}));
|
|
276
|
+
} else {
|
|
267
277
|
this.hoverStroker.target = null;
|
|
268
278
|
}
|
|
269
279
|
}
|
|
270
280
|
onSelect() {
|
|
271
281
|
if (this.running) {
|
|
272
|
-
|
|
273
|
-
const { stroke, strokeWidth, selectedStyle } = mergeConfig;
|
|
274
|
-
this.targetStroker.setTarget(list, Object.assign({ stroke, strokeWidth: Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
|
|
282
|
+
this.targetStroker.setTarget(this.editor.list);
|
|
275
283
|
this.hoverStroker.target = null;
|
|
276
284
|
}
|
|
277
285
|
}
|
|
278
286
|
update() {
|
|
279
287
|
this.hoverStroker.update();
|
|
280
|
-
this.
|
|
288
|
+
const {stroke: stroke, strokeWidth: strokeWidth, selectedStyle: selectedStyle} = this.editor.mergedConfig;
|
|
289
|
+
this.targetStroker.update(Object.assign({
|
|
290
|
+
stroke: stroke,
|
|
291
|
+
strokeWidth: strokeWidth && Math.max(1, strokeWidth / 2)
|
|
292
|
+
}, selectedStyle || {}));
|
|
281
293
|
}
|
|
282
294
|
onPointerMove(e) {
|
|
283
|
-
const { app, editor } = this;
|
|
295
|
+
const {app: app, editor: editor} = this;
|
|
284
296
|
if (this.running && !this.isMoveMode && app.interaction.canHover && !app.interaction.dragging) {
|
|
285
297
|
const find = this.findUI(e);
|
|
286
298
|
editor.hoverTarget = editor.hasItem(find) ? null : find;
|
|
@@ -290,78 +302,66 @@ class EditSelect extends Group {
|
|
|
290
302
|
}
|
|
291
303
|
}
|
|
292
304
|
onBeforeDown(e) {
|
|
293
|
-
if (e.multiTouch)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (select === 'press') {
|
|
305
|
+
if (e.multiTouch) return;
|
|
306
|
+
const {select: select} = this.editor.mergeConfig;
|
|
307
|
+
if (select === "press") {
|
|
297
308
|
if (this.app.config.mobile) {
|
|
298
309
|
this.waitSelect = () => this.checkAndSelect(e);
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
310
|
+
} else {
|
|
301
311
|
this.checkAndSelect(e);
|
|
302
312
|
}
|
|
303
313
|
}
|
|
304
314
|
}
|
|
305
315
|
onTap(e) {
|
|
306
|
-
if (e.multiTouch)
|
|
307
|
-
|
|
308
|
-
const {
|
|
309
|
-
|
|
310
|
-
if (select === 'tap')
|
|
311
|
-
this.checkAndSelect(e);
|
|
312
|
-
else if (this.waitSelect)
|
|
313
|
-
this.waitSelect();
|
|
316
|
+
if (e.multiTouch) return;
|
|
317
|
+
const {editor: editor} = this;
|
|
318
|
+
const {select: select} = editor.mergeConfig;
|
|
319
|
+
if (select === "tap") this.checkAndSelect(e); else if (this.waitSelect) this.waitSelect();
|
|
314
320
|
if (this.needRemoveItem) {
|
|
315
321
|
editor.removeItem(this.needRemoveItem);
|
|
316
|
-
}
|
|
317
|
-
else if (this.isMoveMode) {
|
|
322
|
+
} else if (this.isMoveMode) {
|
|
318
323
|
editor.target = null;
|
|
319
324
|
}
|
|
320
325
|
}
|
|
321
326
|
checkAndSelect(e) {
|
|
322
327
|
this.needRemoveItem = null;
|
|
323
328
|
if (this.allowSelect(e)) {
|
|
324
|
-
const { editor
|
|
329
|
+
const {editor: editor} = this;
|
|
325
330
|
const find = this.findUI(e);
|
|
326
331
|
if (find) {
|
|
327
332
|
if (this.isMultipleSelect(e)) {
|
|
328
|
-
if (editor.hasItem(find))
|
|
329
|
-
|
|
330
|
-
else
|
|
331
|
-
editor.addItem(find);
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
333
|
+
if (editor.hasItem(find)) this.needRemoveItem = find; else editor.addItem(find);
|
|
334
|
+
} else {
|
|
334
335
|
editor.target = find;
|
|
335
336
|
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (!e.shiftKey)
|
|
339
|
-
editor.target = null;
|
|
337
|
+
} else if (this.allow(e.target)) {
|
|
338
|
+
if (!this.isHoldMultipleSelectKey(e)) editor.target = null;
|
|
340
339
|
}
|
|
341
340
|
}
|
|
342
341
|
}
|
|
343
342
|
onDragStart(e) {
|
|
344
|
-
if (e.multiTouch)
|
|
345
|
-
|
|
346
|
-
if (this.waitSelect)
|
|
347
|
-
this.waitSelect();
|
|
343
|
+
if (e.multiTouch) return;
|
|
344
|
+
if (this.waitSelect) this.waitSelect();
|
|
348
345
|
if (this.allowDrag(e)) {
|
|
349
|
-
const { editor
|
|
350
|
-
const { stroke, area } = editor.mergeConfig;
|
|
351
|
-
const { x, y } = e.getInnerPoint(this);
|
|
346
|
+
const {editor: editor} = this;
|
|
347
|
+
const {stroke: stroke, area: area} = editor.mergeConfig;
|
|
348
|
+
const {x: x, y: y} = e.getInnerPoint(this);
|
|
352
349
|
this.bounds.set(x, y);
|
|
353
|
-
this.selectArea.setStyle({
|
|
350
|
+
this.selectArea.setStyle({
|
|
351
|
+
visible: true,
|
|
352
|
+
stroke: stroke,
|
|
353
|
+
x: x,
|
|
354
|
+
y: y
|
|
355
|
+
}, area);
|
|
354
356
|
this.selectArea.setBounds(this.bounds.get());
|
|
355
357
|
this.originList = editor.leafList.clone();
|
|
356
358
|
}
|
|
357
359
|
}
|
|
358
360
|
onDrag(e) {
|
|
359
|
-
if (e.multiTouch)
|
|
360
|
-
|
|
361
|
-
if (this.editor.dragging)
|
|
362
|
-
return this.onDragEnd(e);
|
|
361
|
+
if (e.multiTouch) return;
|
|
362
|
+
if (this.editor.dragging) return this.onDragEnd(e);
|
|
363
363
|
if (this.dragging) {
|
|
364
|
-
const { editor
|
|
364
|
+
const {editor: editor} = this;
|
|
365
365
|
const total = e.getInnerTotal(this);
|
|
366
366
|
const dragBounds = this.bounds.clone().unsign();
|
|
367
367
|
const list = new LeafList(findByBounds(editor.app, dragBounds));
|
|
@@ -370,28 +370,27 @@ class EditSelect extends Group {
|
|
|
370
370
|
this.selectArea.setBounds(dragBounds.get());
|
|
371
371
|
if (list.length) {
|
|
372
372
|
const selectList = [];
|
|
373
|
-
this.originList.forEach(item => {
|
|
374
|
-
selectList.push(item);
|
|
375
|
-
|
|
376
|
-
|
|
373
|
+
this.originList.forEach(item => {
|
|
374
|
+
if (!list.has(item)) selectList.push(item);
|
|
375
|
+
});
|
|
376
|
+
list.forEach(item => {
|
|
377
|
+
if (!this.originList.has(item)) selectList.push(item);
|
|
378
|
+
});
|
|
377
379
|
if (selectList.length !== editor.list.length || editor.list.some((child, index) => child !== selectList[index])) {
|
|
378
380
|
editor.target = selectList;
|
|
379
381
|
}
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
+
} else {
|
|
382
383
|
editor.target = this.originList.list;
|
|
383
384
|
}
|
|
384
385
|
}
|
|
385
386
|
}
|
|
386
387
|
onDragEnd(e) {
|
|
387
|
-
if (e.multiTouch)
|
|
388
|
-
|
|
389
|
-
if (this.dragging)
|
|
390
|
-
this.originList = null, this.selectArea.visible = 0;
|
|
388
|
+
if (e.multiTouch) return;
|
|
389
|
+
if (this.dragging) this.originList = null, this.selectArea.visible = 0;
|
|
391
390
|
}
|
|
392
391
|
onAutoMove(e) {
|
|
393
392
|
if (this.dragging) {
|
|
394
|
-
const { x, y } = e.getLocalMove(this);
|
|
393
|
+
const {x: x, y: y} = e.getLocalMove(this);
|
|
395
394
|
this.bounds.x += x;
|
|
396
395
|
this.bounds.y += y;
|
|
397
396
|
}
|
|
@@ -400,11 +399,10 @@ class EditSelect extends Group {
|
|
|
400
399
|
return target.leafer !== this.editor.leafer;
|
|
401
400
|
}
|
|
402
401
|
allowDrag(e) {
|
|
403
|
-
const { boxSelect, multipleSelect } = this.editor.mergeConfig;
|
|
402
|
+
const {boxSelect: boxSelect, multipleSelect: multipleSelect} = this.editor.mergeConfig;
|
|
404
403
|
if (this.running && (multipleSelect && boxSelect) && !e.target.draggable) {
|
|
405
|
-
return
|
|
406
|
-
}
|
|
407
|
-
else {
|
|
404
|
+
return !this.editor.editing && this.allow(e.target) || this.isHoldMultipleSelectKey(e) && !findOne(e.path);
|
|
405
|
+
} else {
|
|
408
406
|
return false;
|
|
409
407
|
}
|
|
410
408
|
}
|
|
@@ -412,37 +410,31 @@ class EditSelect extends Group {
|
|
|
412
410
|
return this.running && !this.isMoveMode && !e.middle;
|
|
413
411
|
}
|
|
414
412
|
findDeepOne(e) {
|
|
415
|
-
const options = {
|
|
413
|
+
const options = {
|
|
414
|
+
exclude: new LeafList(this.editor.editBox.rect)
|
|
415
|
+
};
|
|
416
416
|
return findOne(e.target.leafer.interaction.findPath(e, options));
|
|
417
417
|
}
|
|
418
418
|
findUI(e) {
|
|
419
419
|
return this.isMultipleSelect(e) ? this.findDeepOne(e) : findOne(e.path);
|
|
420
420
|
}
|
|
421
421
|
isMultipleSelect(e) {
|
|
422
|
-
const { multipleSelect, continuousSelect } = this.editor.mergeConfig;
|
|
423
|
-
return multipleSelect && (e
|
|
422
|
+
const {multipleSelect: multipleSelect, continuousSelect: continuousSelect} = this.editor.mergeConfig;
|
|
423
|
+
return multipleSelect && (this.isHoldMultipleSelectKey(e) || continuousSelect);
|
|
424
|
+
}
|
|
425
|
+
isHoldMultipleSelectKey(e) {
|
|
426
|
+
const {multipleSelectKey: multipleSelectKey} = this.editor.mergedConfig;
|
|
427
|
+
if (multipleSelectKey) return e.isHoldKeys(multipleSelectKey);
|
|
428
|
+
return e.shiftKey;
|
|
424
429
|
}
|
|
425
430
|
__listenEvents() {
|
|
426
|
-
const { editor
|
|
431
|
+
const {editor: editor} = this;
|
|
427
432
|
editor.waitLeafer(() => {
|
|
428
|
-
const { app
|
|
433
|
+
const {app: app} = editor;
|
|
429
434
|
app.selector.proxy = editor;
|
|
430
|
-
this.__eventIds = [
|
|
431
|
-
editor.
|
|
432
|
-
|
|
433
|
-
[EditorEvent.SELECT, this.onSelect, this]
|
|
434
|
-
]),
|
|
435
|
-
app.on_([
|
|
436
|
-
[PointerEvent.MOVE, this.onPointerMove, this],
|
|
437
|
-
[PointerEvent.BEFORE_DOWN, this.onBeforeDown, this],
|
|
438
|
-
[PointerEvent.TAP, this.onTap, this],
|
|
439
|
-
[DragEvent.START, this.onDragStart, this, true],
|
|
440
|
-
[DragEvent.DRAG, this.onDrag, this],
|
|
441
|
-
[DragEvent.END, this.onDragEnd, this],
|
|
442
|
-
[MoveEvent.MOVE, this.onAutoMove, this],
|
|
443
|
-
[[ZoomEvent.ZOOM, MoveEvent.MOVE], () => { this.editor.hoverTarget = null; }],
|
|
444
|
-
])
|
|
445
|
-
];
|
|
435
|
+
this.__eventIds = [ editor.on_([ [ EditorEvent.HOVER, this.onHover, this ], [ EditorEvent.SELECT, this.onSelect, this ] ]), app.on_([ [ PointerEvent.MOVE, this.onPointerMove, this ], [ PointerEvent.BEFORE_DOWN, this.onBeforeDown, this ], [ PointerEvent.TAP, this.onTap, this ], [ DragEvent.START, this.onDragStart, this, true ], [ DragEvent.DRAG, this.onDrag, this ], [ DragEvent.END, this.onDragEnd, this ], [ MoveEvent.MOVE, this.onAutoMove, this ], [ [ ZoomEvent.ZOOM, MoveEvent.MOVE ], () => {
|
|
436
|
+
this.editor.hoverTarget = null;
|
|
437
|
+
} ] ]) ];
|
|
446
438
|
});
|
|
447
439
|
}
|
|
448
440
|
__removeListenEvents() {
|
|
@@ -455,14 +447,17 @@ class EditSelect extends Group {
|
|
|
455
447
|
}
|
|
456
448
|
}
|
|
457
449
|
|
|
458
|
-
const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft, left: left$1
|
|
459
|
-
|
|
460
|
-
const {
|
|
450
|
+
const {topLeft: topLeft, top: top, topRight: topRight, right: right$1, bottomRight: bottomRight, bottom: bottom, bottomLeft: bottomLeft, left: left$1} = Direction9;
|
|
451
|
+
|
|
452
|
+
const {toPoint: toPoint} = AroundHelper;
|
|
453
|
+
|
|
454
|
+
const {within: within} = MathHelper;
|
|
455
|
+
|
|
461
456
|
const EditDataHelper = {
|
|
462
457
|
getScaleData(target, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
|
|
463
458
|
let align, origin = {}, scaleX = 1, scaleY = 1;
|
|
464
|
-
const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = target;
|
|
465
|
-
const { width, height } = startBounds;
|
|
459
|
+
const {boxBounds: boxBounds, widthRange: widthRange, heightRange: heightRange, dragBounds: dragBounds, worldBoxBounds: worldBoxBounds} = target;
|
|
460
|
+
const {width: width, height: height} = startBounds;
|
|
466
461
|
if (around) {
|
|
467
462
|
totalMove.x *= 2;
|
|
468
463
|
totalMove.y *= 2;
|
|
@@ -480,88 +475,92 @@ const EditDataHelper = {
|
|
|
480
475
|
const bottomScale = (totalMove.y + height) / height;
|
|
481
476
|
const leftScale = (-totalMove.x + width) / width;
|
|
482
477
|
switch (direction) {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
478
|
+
case top:
|
|
479
|
+
scaleY = topScale;
|
|
480
|
+
align = "bottom";
|
|
481
|
+
break;
|
|
482
|
+
|
|
483
|
+
case right$1:
|
|
484
|
+
scaleX = rightScale;
|
|
485
|
+
align = "left";
|
|
486
|
+
break;
|
|
487
|
+
|
|
488
|
+
case bottom:
|
|
489
|
+
scaleY = bottomScale;
|
|
490
|
+
align = "top";
|
|
491
|
+
break;
|
|
492
|
+
|
|
493
|
+
case left$1:
|
|
494
|
+
scaleX = leftScale;
|
|
495
|
+
align = "right";
|
|
496
|
+
break;
|
|
497
|
+
|
|
498
|
+
case topLeft:
|
|
499
|
+
scaleY = topScale;
|
|
500
|
+
scaleX = leftScale;
|
|
501
|
+
align = "bottom-right";
|
|
502
|
+
break;
|
|
503
|
+
|
|
504
|
+
case topRight:
|
|
505
|
+
scaleY = topScale;
|
|
506
|
+
scaleX = rightScale;
|
|
507
|
+
align = "bottom-left";
|
|
508
|
+
break;
|
|
509
|
+
|
|
510
|
+
case bottomRight:
|
|
511
|
+
scaleY = bottomScale;
|
|
512
|
+
scaleX = rightScale;
|
|
513
|
+
align = "top-left";
|
|
514
|
+
break;
|
|
515
|
+
|
|
516
|
+
case bottomLeft:
|
|
517
|
+
scaleY = bottomScale;
|
|
518
|
+
scaleX = leftScale;
|
|
519
|
+
align = "top-right";
|
|
518
520
|
}
|
|
519
521
|
if (lockRatio) {
|
|
520
|
-
if (lockRatio ===
|
|
522
|
+
if (lockRatio === "corner" && direction % 2) {
|
|
521
523
|
lockRatio = false;
|
|
522
|
-
}
|
|
523
|
-
else {
|
|
524
|
+
} else {
|
|
524
525
|
let scale;
|
|
525
526
|
switch (direction) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
527
|
+
case top:
|
|
528
|
+
case bottom:
|
|
529
|
+
scale = scaleY;
|
|
530
|
+
break;
|
|
531
|
+
|
|
532
|
+
case left$1:
|
|
533
|
+
case right$1:
|
|
534
|
+
scale = scaleX;
|
|
535
|
+
break;
|
|
536
|
+
|
|
537
|
+
default:
|
|
538
|
+
scale = Math.sqrt(Math.abs(scaleX * scaleY));
|
|
536
539
|
}
|
|
537
540
|
scaleX = scaleX < 0 ? -scale : scale;
|
|
538
541
|
scaleY = scaleY < 0 ? -scale : scale;
|
|
539
542
|
}
|
|
540
543
|
}
|
|
541
544
|
const useScaleX = scaleX !== 1, useScaleY = scaleY !== 1;
|
|
542
|
-
if (useScaleX)
|
|
543
|
-
|
|
544
|
-
if (useScaleY)
|
|
545
|
-
scaleY /= changedScaleY;
|
|
545
|
+
if (useScaleX) scaleX /= changedScaleX;
|
|
546
|
+
if (useScaleY) scaleY /= changedScaleY;
|
|
546
547
|
if (!flipable) {
|
|
547
|
-
const { worldTransform
|
|
548
|
-
if (scaleX < 0)
|
|
549
|
-
|
|
550
|
-
if (scaleY < 0)
|
|
551
|
-
scaleY = 1 / boxBounds.height / worldTransform.scaleY;
|
|
548
|
+
const {worldTransform: worldTransform} = target;
|
|
549
|
+
if (scaleX < 0) scaleX = 1 / boxBounds.width / worldTransform.scaleX;
|
|
550
|
+
if (scaleY < 0) scaleY = 1 / boxBounds.height / worldTransform.scaleY;
|
|
552
551
|
}
|
|
553
552
|
toPoint(around || align, boxBounds, origin, true);
|
|
554
553
|
if (dragBounds) {
|
|
555
|
-
const allowBounds = dragBounds ===
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
scaleX *= fitScaleX;
|
|
563
|
-
|
|
564
|
-
|
|
554
|
+
const allowBounds = dragBounds === "parent" ? target.parent.boxBounds : dragBounds;
|
|
555
|
+
const childBounds = new Bounds(target.__localBoxBounds);
|
|
556
|
+
if (BoundsHelper.includes(new Bounds(allowBounds).spread(.1), childBounds)) {
|
|
557
|
+
childBounds.scaleOf(target.getLocalPointByInner(origin), scaleX, scaleY);
|
|
558
|
+
if (!BoundsHelper.includes(allowBounds, childBounds)) {
|
|
559
|
+
const realBounds = childBounds.getIntersect(allowBounds);
|
|
560
|
+
const fitScaleX = realBounds.width / childBounds.width, fitScaleY = realBounds.height / childBounds.height;
|
|
561
|
+
if (useScaleX) scaleX *= fitScaleX;
|
|
562
|
+
if (useScaleY) scaleY *= fitScaleY;
|
|
563
|
+
}
|
|
565
564
|
}
|
|
566
565
|
}
|
|
567
566
|
if (useScaleX && widthRange) {
|
|
@@ -572,123 +571,165 @@ const EditDataHelper = {
|
|
|
572
571
|
const nowHeight = boxBounds.height * target.scaleY;
|
|
573
572
|
scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
|
|
574
573
|
}
|
|
575
|
-
if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1)
|
|
576
|
-
|
|
577
|
-
if (
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
574
|
+
if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1) scaleX = (scaleX < 0 ? -1 : 1) / worldBoxBounds.width;
|
|
575
|
+
if (useScaleY && Math.abs(scaleY * worldBoxBounds.height) < 1) scaleY = (scaleY < 0 ? -1 : 1) / worldBoxBounds.height;
|
|
576
|
+
if (lockRatio && scaleX !== scaleY) scaleY = scaleX = Math.min(scaleX, scaleY);
|
|
577
|
+
return {
|
|
578
|
+
origin: origin,
|
|
579
|
+
scaleX: scaleX,
|
|
580
|
+
scaleY: scaleY,
|
|
581
|
+
direction: direction,
|
|
582
|
+
lockRatio: lockRatio,
|
|
583
|
+
around: around
|
|
584
|
+
};
|
|
582
585
|
},
|
|
583
586
|
getRotateData(target, direction, current, last, around) {
|
|
584
587
|
let align, origin = {};
|
|
585
588
|
switch (direction) {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
589
|
+
case topLeft:
|
|
590
|
+
align = "bottom-right";
|
|
591
|
+
break;
|
|
592
|
+
|
|
593
|
+
case topRight:
|
|
594
|
+
align = "bottom-left";
|
|
595
|
+
break;
|
|
596
|
+
|
|
597
|
+
case bottomRight:
|
|
598
|
+
align = "top-left";
|
|
599
|
+
break;
|
|
600
|
+
|
|
601
|
+
case bottomLeft:
|
|
602
|
+
align = "top-right";
|
|
603
|
+
break;
|
|
604
|
+
|
|
605
|
+
default:
|
|
606
|
+
align = "center";
|
|
600
607
|
}
|
|
601
608
|
toPoint(around || align, target.boxBounds, origin, true);
|
|
602
|
-
return {
|
|
609
|
+
return {
|
|
610
|
+
origin: origin,
|
|
611
|
+
rotation: PointHelper.getRotation(last, target.getWorldPointByBox(origin), current)
|
|
612
|
+
};
|
|
603
613
|
},
|
|
604
614
|
getSkewData(bounds, direction, move, around) {
|
|
605
615
|
let align, origin = {}, skewX = 0, skewY = 0;
|
|
606
616
|
let last;
|
|
607
617
|
switch (direction) {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
618
|
+
case top:
|
|
619
|
+
case topLeft:
|
|
620
|
+
last = {
|
|
621
|
+
x: .5,
|
|
622
|
+
y: 0
|
|
623
|
+
};
|
|
624
|
+
align = "bottom";
|
|
625
|
+
skewX = 1;
|
|
626
|
+
break;
|
|
627
|
+
|
|
628
|
+
case bottom:
|
|
629
|
+
case bottomRight:
|
|
630
|
+
last = {
|
|
631
|
+
x: .5,
|
|
632
|
+
y: 1
|
|
633
|
+
};
|
|
634
|
+
align = "top";
|
|
635
|
+
skewX = 1;
|
|
636
|
+
break;
|
|
637
|
+
|
|
638
|
+
case left$1:
|
|
639
|
+
case bottomLeft:
|
|
640
|
+
last = {
|
|
641
|
+
x: 0,
|
|
642
|
+
y: .5
|
|
643
|
+
};
|
|
644
|
+
align = "right";
|
|
645
|
+
skewY = 1;
|
|
646
|
+
break;
|
|
647
|
+
|
|
648
|
+
case right$1:
|
|
649
|
+
case topRight:
|
|
650
|
+
last = {
|
|
651
|
+
x: 1,
|
|
652
|
+
y: .5
|
|
653
|
+
};
|
|
654
|
+
align = "left";
|
|
655
|
+
skewY = 1;
|
|
656
|
+
}
|
|
657
|
+
const {width: width, height: height} = bounds;
|
|
633
658
|
last.x = last.x * width;
|
|
634
659
|
last.y = last.y * height;
|
|
635
660
|
toPoint(around || align, bounds, origin, true);
|
|
636
|
-
const rotation = PointHelper.getRotation(last, origin, {
|
|
661
|
+
const rotation = PointHelper.getRotation(last, origin, {
|
|
662
|
+
x: last.x + (skewX ? move.x : 0),
|
|
663
|
+
y: last.y + (skewY ? move.y : 0)
|
|
664
|
+
});
|
|
637
665
|
skewX ? skewX = -rotation : skewY = rotation;
|
|
638
|
-
return {
|
|
666
|
+
return {
|
|
667
|
+
origin: origin,
|
|
668
|
+
skewX: skewX,
|
|
669
|
+
skewY: skewY
|
|
670
|
+
};
|
|
639
671
|
},
|
|
640
672
|
getAround(around, altKey) {
|
|
641
|
-
return
|
|
673
|
+
return altKey && !around ? "center" : around;
|
|
642
674
|
},
|
|
643
675
|
getRotateDirection(direction, rotation, totalDirection = 8) {
|
|
644
676
|
direction = (direction + Math.round(rotation / (360 / totalDirection))) % totalDirection;
|
|
645
|
-
if (direction < 0)
|
|
646
|
-
direction += totalDirection;
|
|
677
|
+
if (direction < 0) direction += totalDirection;
|
|
647
678
|
return direction;
|
|
648
679
|
},
|
|
649
680
|
getFlipDirection(direction, flipedX, flipedY) {
|
|
650
681
|
if (flipedX) {
|
|
651
682
|
switch (direction) {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
683
|
+
case left$1:
|
|
684
|
+
direction = right$1;
|
|
685
|
+
break;
|
|
686
|
+
|
|
687
|
+
case topLeft:
|
|
688
|
+
direction = topRight;
|
|
689
|
+
break;
|
|
690
|
+
|
|
691
|
+
case bottomLeft:
|
|
692
|
+
direction = bottomRight;
|
|
693
|
+
break;
|
|
694
|
+
|
|
695
|
+
case right$1:
|
|
696
|
+
direction = left$1;
|
|
697
|
+
break;
|
|
698
|
+
|
|
699
|
+
case topRight:
|
|
700
|
+
direction = topLeft;
|
|
701
|
+
break;
|
|
702
|
+
|
|
703
|
+
case bottomRight:
|
|
704
|
+
direction = bottomLeft;
|
|
705
|
+
break;
|
|
670
706
|
}
|
|
671
707
|
}
|
|
672
708
|
if (flipedY) {
|
|
673
709
|
switch (direction) {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
710
|
+
case top:
|
|
711
|
+
direction = bottom;
|
|
712
|
+
break;
|
|
713
|
+
|
|
714
|
+
case topLeft:
|
|
715
|
+
direction = bottomLeft;
|
|
716
|
+
break;
|
|
717
|
+
|
|
718
|
+
case topRight:
|
|
719
|
+
direction = bottomRight;
|
|
720
|
+
break;
|
|
721
|
+
|
|
722
|
+
case bottom:
|
|
723
|
+
direction = top;
|
|
724
|
+
break;
|
|
725
|
+
|
|
726
|
+
case bottomLeft:
|
|
727
|
+
direction = topLeft;
|
|
728
|
+
break;
|
|
729
|
+
|
|
730
|
+
case bottomRight:
|
|
731
|
+
direction = topRight;
|
|
732
|
+
break;
|
|
692
733
|
}
|
|
693
734
|
}
|
|
694
735
|
return direction;
|
|
@@ -696,41 +737,43 @@ const EditDataHelper = {
|
|
|
696
737
|
};
|
|
697
738
|
|
|
698
739
|
const cacheCursors = {};
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
if (point.name ===
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
if (!point.cursor)
|
|
707
|
-
point.cursor = 'pointer';
|
|
740
|
+
|
|
741
|
+
function updatePointCursor(editBox, e) {
|
|
742
|
+
const {enterPoint: point, dragging: dragging, skewing: skewing, resizing: resizing, flippedX: flippedX, flippedY: flippedY} = editBox;
|
|
743
|
+
if (!point || !editBox.editor.editing || !editBox.canUse) return;
|
|
744
|
+
if (point.name === "circle") return;
|
|
745
|
+
if (point.pointType === "button") {
|
|
746
|
+
if (!point.cursor) point.cursor = "pointer";
|
|
708
747
|
return;
|
|
709
748
|
}
|
|
710
|
-
let { rotation
|
|
711
|
-
const { pointType
|
|
712
|
-
let showResize = pointType.includes(
|
|
713
|
-
if (showResize && rotateable && (
|
|
714
|
-
|
|
715
|
-
const
|
|
716
|
-
const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor);
|
|
749
|
+
let {rotation: rotation} = editBox;
|
|
750
|
+
const {pointType: pointType} = point, {resizeCursor: resizeCursor, rotateCursor: rotateCursor, skewCursor: skewCursor, resizeable: resizeable, rotateable: rotateable, skewable: skewable} = editBox.mergeConfig;
|
|
751
|
+
let showResize = pointType.includes("resize");
|
|
752
|
+
if (showResize && rotateable && (editBox.isHoldRotateKey(e) || !resizeable)) showResize = false;
|
|
753
|
+
const showSkew = skewable && !showResize && (point.name === "resize-line" || pointType === "skew");
|
|
754
|
+
const cursor = dragging ? skewing ? skewCursor : resizing ? resizeCursor : rotateCursor : showSkew ? skewCursor : showResize ? resizeCursor : rotateCursor;
|
|
717
755
|
rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45;
|
|
718
756
|
rotation = Math.round(MathHelper.formatRotation(rotation, true) / 2) * 2;
|
|
719
|
-
const { url, x, y } = cursor;
|
|
757
|
+
const {url: url, x: x, y: y} = cursor;
|
|
720
758
|
const key = url + rotation;
|
|
721
759
|
if (cacheCursors[key]) {
|
|
722
760
|
point.cursor = cacheCursors[key];
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
|
|
761
|
+
} else {
|
|
762
|
+
cacheCursors[key] = point.cursor = {
|
|
763
|
+
url: toDataURL(url, rotation),
|
|
764
|
+
x: x,
|
|
765
|
+
y: y
|
|
766
|
+
};
|
|
726
767
|
}
|
|
727
768
|
}
|
|
769
|
+
|
|
728
770
|
function updateMoveCursor(editBox) {
|
|
729
|
-
const { moveCursor, moveable } = editBox.mergeConfig;
|
|
730
|
-
editBox.rect.cursor = moveable ? moveCursor : undefined;
|
|
771
|
+
const {moveCursor: moveCursor, moveable: moveable} = editBox.mergeConfig;
|
|
772
|
+
if (editBox.canUse) editBox.rect.cursor = moveable ? moveCursor : undefined;
|
|
731
773
|
}
|
|
774
|
+
|
|
732
775
|
function toDataURL(svg, rotation) {
|
|
733
|
-
return '"data:image/svg+xml,' + encodeURIComponent(svg.replace(
|
|
776
|
+
return '"data:image/svg+xml,' + encodeURIComponent(svg.replace("{{rotation}}", rotation.toString())) + '"';
|
|
734
777
|
}
|
|
735
778
|
|
|
736
779
|
class EditPoint extends Box {
|
|
@@ -740,27 +783,70 @@ class EditPoint extends Box {
|
|
|
740
783
|
}
|
|
741
784
|
}
|
|
742
785
|
|
|
743
|
-
const fourDirection = [
|
|
786
|
+
const fourDirection = [ "top", "right", "bottom", "left" ], editConfig = undefined;
|
|
787
|
+
|
|
744
788
|
class EditBox extends Group {
|
|
745
789
|
get mergeConfig() {
|
|
746
|
-
const { config
|
|
747
|
-
return this.mergedConfig = config ? Object.assign(Object.assign({}, mergeConfig), config) : mergeConfig;
|
|
748
|
-
}
|
|
749
|
-
get target() {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
get
|
|
756
|
-
|
|
757
|
-
|
|
790
|
+
const {config: config} = this, {mergeConfig: mergeConfig, editBox: editBox} = this.editor;
|
|
791
|
+
return this.mergedConfig = config && editBox !== this ? Object.assign(Object.assign({}, mergeConfig), config) : mergeConfig;
|
|
792
|
+
}
|
|
793
|
+
get target() {
|
|
794
|
+
return this._target || this.editor.element;
|
|
795
|
+
}
|
|
796
|
+
set target(target) {
|
|
797
|
+
this._target = target;
|
|
798
|
+
}
|
|
799
|
+
get single() {
|
|
800
|
+
return !!this._target || this.editor.single;
|
|
801
|
+
}
|
|
802
|
+
get transformTool() {
|
|
803
|
+
return this._transformTool || this.editor;
|
|
804
|
+
}
|
|
805
|
+
set transformTool(tool) {
|
|
806
|
+
this._transformTool = tool;
|
|
807
|
+
}
|
|
808
|
+
get flipped() {
|
|
809
|
+
return this.flippedX || this.flippedY;
|
|
810
|
+
}
|
|
811
|
+
get flippedX() {
|
|
812
|
+
return this.scaleX < 0;
|
|
813
|
+
}
|
|
814
|
+
get flippedY() {
|
|
815
|
+
return this.scaleY < 0;
|
|
816
|
+
}
|
|
817
|
+
get flippedOne() {
|
|
818
|
+
return this.scaleX * this.scaleY < 0;
|
|
819
|
+
}
|
|
820
|
+
get canUse() {
|
|
821
|
+
return this.visible && this.view.visible;
|
|
822
|
+
}
|
|
823
|
+
get canGesture() {
|
|
824
|
+
if (!this.canUse) return false;
|
|
825
|
+
const {moveable: moveable, resizeable: resizeable, rotateable: rotateable} = this.mergeConfig;
|
|
826
|
+
return isString(moveable) || isString(resizeable) || isString(rotateable);
|
|
827
|
+
}
|
|
758
828
|
constructor(editor) {
|
|
759
829
|
super();
|
|
760
|
-
this.view = new Group
|
|
761
|
-
this.rect = new Box({
|
|
762
|
-
|
|
763
|
-
|
|
830
|
+
this.view = new Group;
|
|
831
|
+
this.rect = new Box({
|
|
832
|
+
name: "rect",
|
|
833
|
+
hitFill: "all",
|
|
834
|
+
hitStroke: "none",
|
|
835
|
+
strokeAlign: "center",
|
|
836
|
+
hitRadius: 5
|
|
837
|
+
});
|
|
838
|
+
this.circle = new EditPoint({
|
|
839
|
+
name: "circle",
|
|
840
|
+
strokeAlign: "center",
|
|
841
|
+
around: "center",
|
|
842
|
+
cursor: "crosshair",
|
|
843
|
+
hitRadius: 5
|
|
844
|
+
});
|
|
845
|
+
this.buttons = new Group({
|
|
846
|
+
around: "center",
|
|
847
|
+
hitSelf: false,
|
|
848
|
+
visible: 0
|
|
849
|
+
});
|
|
764
850
|
this.resizePoints = [];
|
|
765
851
|
this.rotatePoints = [];
|
|
766
852
|
this.resizeLines = [];
|
|
@@ -773,259 +859,325 @@ class EditBox extends Group {
|
|
|
773
859
|
}
|
|
774
860
|
create() {
|
|
775
861
|
let rotatePoint, resizeLine, resizePoint;
|
|
776
|
-
const { view, resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this;
|
|
777
|
-
const arounds = [
|
|
862
|
+
const {view: view, resizePoints: resizePoints, rotatePoints: rotatePoints, resizeLines: resizeLines, rect: rect, circle: circle, buttons: buttons} = this;
|
|
863
|
+
const arounds = [ "bottom-right", "bottom", "bottom-left", "left", "top-left", "top", "top-right", "right" ];
|
|
778
864
|
for (let i = 0; i < 8; i++) {
|
|
779
|
-
rotatePoint = new EditPoint({
|
|
865
|
+
rotatePoint = new EditPoint({
|
|
866
|
+
name: "rotate-point",
|
|
867
|
+
around: arounds[i],
|
|
868
|
+
width: 15,
|
|
869
|
+
height: 15,
|
|
870
|
+
hitFill: "all"
|
|
871
|
+
});
|
|
780
872
|
rotatePoints.push(rotatePoint);
|
|
781
|
-
this.listenPointEvents(rotatePoint,
|
|
873
|
+
this.listenPointEvents(rotatePoint, "rotate", i);
|
|
782
874
|
if (i % 2) {
|
|
783
|
-
resizeLine = new EditPoint({
|
|
875
|
+
resizeLine = new EditPoint({
|
|
876
|
+
name: "resize-line",
|
|
877
|
+
around: "center",
|
|
878
|
+
width: 10,
|
|
879
|
+
height: 10,
|
|
880
|
+
hitFill: "all"
|
|
881
|
+
});
|
|
784
882
|
resizeLines.push(resizeLine);
|
|
785
|
-
this.listenPointEvents(resizeLine,
|
|
883
|
+
this.listenPointEvents(resizeLine, "resize", i);
|
|
786
884
|
}
|
|
787
|
-
resizePoint = new EditPoint({
|
|
885
|
+
resizePoint = new EditPoint({
|
|
886
|
+
name: "resize-point",
|
|
887
|
+
hitRadius: 5
|
|
888
|
+
});
|
|
788
889
|
resizePoints.push(resizePoint);
|
|
789
|
-
this.listenPointEvents(resizePoint,
|
|
890
|
+
this.listenPointEvents(resizePoint, "resize", i);
|
|
790
891
|
}
|
|
791
|
-
this.listenPointEvents(circle,
|
|
892
|
+
this.listenPointEvents(circle, "rotate", 2);
|
|
792
893
|
view.addMany(...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints);
|
|
793
894
|
this.add(view);
|
|
794
895
|
}
|
|
795
896
|
load() {
|
|
796
|
-
const { target, mergeConfig, single, rect, circle, resizePoints } = this;
|
|
797
|
-
const { stroke, strokeWidth } = mergeConfig;
|
|
897
|
+
const {target: target, mergeConfig: mergeConfig, single: single, rect: rect, circle: circle, resizePoints: resizePoints} = this;
|
|
898
|
+
const {stroke: stroke, strokeWidth: strokeWidth} = mergeConfig;
|
|
798
899
|
const pointsStyle = this.getPointsStyle();
|
|
799
900
|
const middlePointsStyle = this.getMiddlePointsStyle();
|
|
901
|
+
this.visible = !target.locked;
|
|
800
902
|
let resizeP;
|
|
801
903
|
for (let i = 0; i < 8; i++) {
|
|
802
904
|
resizeP = resizePoints[i];
|
|
803
|
-
resizeP.set(this.getPointStyle(
|
|
804
|
-
|
|
805
|
-
resizeP.rotation = (i / 2) * 90;
|
|
905
|
+
resizeP.set(this.getPointStyle(i % 2 ? middlePointsStyle[(i - 1) / 2 % middlePointsStyle.length] : pointsStyle[i / 2 % pointsStyle.length]));
|
|
906
|
+
resizeP.rotation = (i - (i % 2 ? 1 : 0)) / 2 * 90;
|
|
806
907
|
}
|
|
807
908
|
circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
|
|
808
|
-
rect.set(Object.assign({
|
|
909
|
+
rect.set(Object.assign({
|
|
910
|
+
stroke: stroke,
|
|
911
|
+
strokeWidth: strokeWidth,
|
|
912
|
+
editConfig: editConfig
|
|
913
|
+
}, mergeConfig.rect || {}));
|
|
809
914
|
const syncEventer = single && this.transformTool.editTool;
|
|
810
915
|
rect.hittable = !syncEventer;
|
|
811
916
|
rect.syncEventer = syncEventer && this.editor;
|
|
812
917
|
if (syncEventer) {
|
|
813
918
|
target.syncEventer = rect;
|
|
814
|
-
this.app.interaction.bottomList = [{
|
|
919
|
+
this.app.interaction.bottomList = [ {
|
|
920
|
+
target: rect,
|
|
921
|
+
proxy: target
|
|
922
|
+
} ];
|
|
815
923
|
}
|
|
816
924
|
updateMoveCursor(this);
|
|
817
925
|
}
|
|
818
926
|
update() {
|
|
819
|
-
const { editor
|
|
820
|
-
const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds(
|
|
821
|
-
this.
|
|
822
|
-
this.
|
|
927
|
+
const {editor: editor} = this;
|
|
928
|
+
const {x: x, y: y, scaleX: scaleX, scaleY: scaleY, rotation: rotation, skewX: skewX, skewY: skewY, width: width, height: height} = this.target.getLayoutBounds("box", editor, true);
|
|
929
|
+
this.visible = !this.target.locked;
|
|
930
|
+
this.set({
|
|
931
|
+
x: x,
|
|
932
|
+
y: y,
|
|
933
|
+
scaleX: scaleX,
|
|
934
|
+
scaleY: scaleY,
|
|
935
|
+
rotation: rotation,
|
|
936
|
+
skewX: skewX,
|
|
937
|
+
skewY: skewY
|
|
938
|
+
});
|
|
939
|
+
this.updateBounds({
|
|
940
|
+
x: 0,
|
|
941
|
+
y: 0,
|
|
942
|
+
width: width,
|
|
943
|
+
height: height
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
unload() {
|
|
947
|
+
this.visible = false;
|
|
948
|
+
if (this.app) this.rect.syncEventer = this.app.interaction.bottomList = null;
|
|
823
949
|
}
|
|
824
950
|
updateBounds(bounds) {
|
|
825
|
-
const { editMask
|
|
826
|
-
const { mergeConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
|
|
827
|
-
const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask } = mergeConfig;
|
|
828
|
-
this.visible = !this.target.locked;
|
|
951
|
+
const {editMask: editMask} = this.editor;
|
|
952
|
+
const {mergeConfig: mergeConfig, single: single, rect: rect, circle: circle, buttons: buttons, resizePoints: resizePoints, rotatePoints: rotatePoints, resizeLines: resizeLines} = this;
|
|
953
|
+
const {middlePoint: middlePoint, resizeable: resizeable, rotateable: rotateable, hideOnSmall: hideOnSmall, editBox: editBox, mask: mask, spread: spread, hideRotatePoints: hideRotatePoints, hideResizeLines: hideResizeLines} = mergeConfig;
|
|
829
954
|
editMask.visible = mask ? true : 0;
|
|
955
|
+
if (spread) BoundsHelper.spread(bounds, spread);
|
|
830
956
|
if (this.view.worldOpacity) {
|
|
831
|
-
const { width, height } = bounds;
|
|
832
|
-
const smallSize =
|
|
957
|
+
const {width: width, height: height} = bounds;
|
|
958
|
+
const smallSize = isNumber(hideOnSmall) ? hideOnSmall : 10;
|
|
833
959
|
const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
|
|
834
960
|
let point = {}, rotateP, resizeP, resizeL;
|
|
835
961
|
for (let i = 0; i < 8; i++) {
|
|
836
962
|
AroundHelper.toPoint(AroundHelper.directionData[i], bounds, point);
|
|
837
963
|
resizeP = resizePoints[i];
|
|
838
964
|
rotateP = rotatePoints[i];
|
|
839
|
-
resizeL = resizeLines[Math.floor(i / 2)];
|
|
840
965
|
resizeP.set(point);
|
|
841
966
|
rotateP.set(point);
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
rotateP.visible = showPoints && rotateable && resizeable && !mergeConfig.rotatePoint;
|
|
967
|
+
resizeP.visible = showPoints && !!(resizeable || rotateable);
|
|
968
|
+
rotateP.visible = showPoints && rotateable && resizeable && !hideRotatePoints;
|
|
845
969
|
if (i % 2) {
|
|
970
|
+
resizeL = resizeLines[(i - 1) / 2];
|
|
971
|
+
resizeL.set(point);
|
|
972
|
+
resizeL.visible = resizeP.visible && !hideResizeLines;
|
|
846
973
|
resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
|
|
847
|
-
if ((
|
|
974
|
+
if ((i + 1) / 2 % 2) {
|
|
848
975
|
resizeL.width = width;
|
|
849
|
-
if (hideOnSmall && resizeP.width * 2 > width)
|
|
850
|
-
|
|
851
|
-
}
|
|
852
|
-
else {
|
|
976
|
+
if (hideOnSmall && resizeP.width * 2 > width) resizeP.visible = false;
|
|
977
|
+
} else {
|
|
853
978
|
resizeL.height = height;
|
|
854
|
-
resizeP.
|
|
855
|
-
if (hideOnSmall && resizeP.width * 2 > height)
|
|
856
|
-
resizeP.visible = false;
|
|
979
|
+
if (hideOnSmall && resizeP.width * 2 > height) resizeP.visible = false;
|
|
857
980
|
}
|
|
858
981
|
}
|
|
859
982
|
}
|
|
860
983
|
circle.visible = showPoints && rotateable && !!(mergeConfig.circle || mergeConfig.rotatePoint);
|
|
861
|
-
if (circle.visible)
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
984
|
+
if (circle.visible) this.layoutCircle();
|
|
985
|
+
if (rect.path) rect.path = null;
|
|
986
|
+
rect.set(Object.assign(Object.assign({}, bounds), {
|
|
987
|
+
visible: single ? editBox : true
|
|
988
|
+
}));
|
|
866
989
|
buttons.visible = showPoints && buttons.children.length > 0 || 0;
|
|
867
|
-
if (buttons.visible)
|
|
868
|
-
|
|
869
|
-
}
|
|
870
|
-
else
|
|
871
|
-
rect.set(bounds);
|
|
990
|
+
if (buttons.visible) this.layoutButtons();
|
|
991
|
+
} else rect.set(bounds);
|
|
872
992
|
}
|
|
873
993
|
layoutCircle() {
|
|
874
|
-
const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = this.mergedConfig;
|
|
875
|
-
const direction = fourDirection.indexOf(circleDirection || (
|
|
994
|
+
const {circleDirection: circleDirection, circleMargin: circleMargin, buttonsMargin: buttonsMargin, buttonsDirection: buttonsDirection, middlePoint: middlePoint} = this.mergedConfig;
|
|
995
|
+
const direction = fourDirection.indexOf(circleDirection || (this.buttons.children.length && buttonsDirection === "bottom" ? "top" : "bottom"));
|
|
876
996
|
this.setButtonPosition(this.circle, direction, circleMargin || buttonsMargin, !!middlePoint);
|
|
877
997
|
}
|
|
878
998
|
layoutButtons() {
|
|
879
|
-
const { buttons
|
|
880
|
-
const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.mergedConfig;
|
|
881
|
-
const { flippedX, flippedY } = this;
|
|
999
|
+
const {buttons: buttons} = this;
|
|
1000
|
+
const {buttonsDirection: buttonsDirection, buttonsFixed: buttonsFixed, buttonsMargin: buttonsMargin, middlePoint: middlePoint} = this.mergedConfig;
|
|
1001
|
+
const {flippedX: flippedX, flippedY: flippedY} = this;
|
|
882
1002
|
let index = fourDirection.indexOf(buttonsDirection);
|
|
883
|
-
if (
|
|
884
|
-
if (buttonsFixed)
|
|
885
|
-
index = (index + 2) % 4;
|
|
1003
|
+
if (index % 2 && flippedX || (index + 1) % 2 && flippedY) {
|
|
1004
|
+
if (buttonsFixed) index = (index + 2) % 4;
|
|
886
1005
|
}
|
|
887
1006
|
const direction = buttonsFixed ? EditDataHelper.getRotateDirection(index, this.flippedOne ? this.rotation : -this.rotation, 4) : index;
|
|
888
1007
|
this.setButtonPosition(buttons, direction, buttonsMargin, !!middlePoint);
|
|
889
|
-
if (buttonsFixed)
|
|
890
|
-
buttons.rotation = (direction - index) * 90;
|
|
1008
|
+
if (buttonsFixed) buttons.rotation = (direction - index) * 90;
|
|
891
1009
|
buttons.scaleX = flippedX ? -1 : 1;
|
|
892
1010
|
buttons.scaleY = flippedY ? -1 : 1;
|
|
893
1011
|
}
|
|
894
1012
|
setButtonPosition(buttons, direction, buttonsMargin, useMiddlePoint) {
|
|
895
1013
|
const point = this.resizePoints[direction * 2 + 1];
|
|
896
1014
|
const useX = direction % 2;
|
|
897
|
-
const sign =
|
|
1015
|
+
const sign = !direction || direction === 3 ? -1 : 1;
|
|
898
1016
|
const useWidth = direction % 2;
|
|
899
|
-
const margin = (buttonsMargin + (useWidth ? (
|
|
1017
|
+
const margin = (buttonsMargin + (useWidth ? (useMiddlePoint ? point.width : 0) + buttons.boxBounds.width : (useMiddlePoint ? point.height : 0) + buttons.boxBounds.height) / 2) * sign;
|
|
900
1018
|
if (useX) {
|
|
901
1019
|
buttons.x = point.x + margin;
|
|
902
1020
|
buttons.y = point.y;
|
|
903
|
-
}
|
|
904
|
-
else {
|
|
1021
|
+
} else {
|
|
905
1022
|
buttons.x = point.x;
|
|
906
1023
|
buttons.y = point.y + margin;
|
|
907
1024
|
}
|
|
908
1025
|
}
|
|
909
|
-
unload() {
|
|
910
|
-
this.visible = false;
|
|
911
|
-
}
|
|
912
1026
|
getPointStyle(userStyle) {
|
|
913
|
-
const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.mergedConfig;
|
|
914
|
-
const defaultStyle = {
|
|
1027
|
+
const {stroke: stroke, strokeWidth: strokeWidth, pointFill: pointFill, pointSize: pointSize, pointRadius: pointRadius} = this.mergedConfig;
|
|
1028
|
+
const defaultStyle = {
|
|
1029
|
+
fill: pointFill,
|
|
1030
|
+
stroke: stroke,
|
|
1031
|
+
strokeWidth: strokeWidth,
|
|
1032
|
+
around: "center",
|
|
1033
|
+
strokeAlign: "center",
|
|
1034
|
+
width: pointSize,
|
|
1035
|
+
height: pointSize,
|
|
1036
|
+
cornerRadius: pointRadius,
|
|
1037
|
+
offsetX: 0,
|
|
1038
|
+
offsetY: 0,
|
|
1039
|
+
editConfig: editConfig
|
|
1040
|
+
};
|
|
915
1041
|
return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
|
|
916
1042
|
}
|
|
917
1043
|
getPointsStyle() {
|
|
918
|
-
const { point
|
|
919
|
-
return point
|
|
1044
|
+
const {point: point} = this.mergedConfig;
|
|
1045
|
+
return isArray(point) ? point : [ point ];
|
|
920
1046
|
}
|
|
921
1047
|
getMiddlePointsStyle() {
|
|
922
|
-
const { middlePoint
|
|
923
|
-
return middlePoint
|
|
924
|
-
}
|
|
925
|
-
onSelect(e) {
|
|
926
|
-
if (e.oldList.length === 1) {
|
|
927
|
-
e.oldList[0].syncEventer = null;
|
|
928
|
-
if (this.app)
|
|
929
|
-
this.app.interaction.bottomList = null;
|
|
930
|
-
}
|
|
1048
|
+
const {middlePoint: middlePoint} = this.mergedConfig;
|
|
1049
|
+
return isArray(middlePoint) ? middlePoint : middlePoint ? [ middlePoint ] : this.getPointsStyle();
|
|
931
1050
|
}
|
|
932
1051
|
onDragStart(e) {
|
|
933
1052
|
this.dragging = true;
|
|
934
|
-
const point = this.dragPoint = e.current, { pointType
|
|
935
|
-
const { editor, dragStartData } = this, { target } = this;
|
|
936
|
-
if (point.name ===
|
|
937
|
-
this.moving = true;
|
|
938
|
-
editor.opacity =
|
|
1053
|
+
const point = this.dragPoint = e.current, {pointType: pointType} = point;
|
|
1054
|
+
const {editor: editor, dragStartData: dragStartData} = this, {target: target} = this, {moveable: moveable, resizeable: resizeable, rotateable: rotateable, skewable: skewable, hideOnMove: hideOnMove} = this.mergeConfig;
|
|
1055
|
+
if (point.name === "rect") {
|
|
1056
|
+
moveable && (this.moving = true);
|
|
1057
|
+
editor.opacity = hideOnMove ? 0 : 1;
|
|
1058
|
+
} else {
|
|
1059
|
+
if (pointType.includes("rotate") || this.isHoldRotateKey(e) || !resizeable) {
|
|
1060
|
+
rotateable && (this.rotating = true);
|
|
1061
|
+
if (pointType === "resize-rotate") resizeable && (this.resizing = true); else if (point.name === "resize-line") skewable && (this.skewing = true),
|
|
1062
|
+
this.rotating = false;
|
|
1063
|
+
} else if (pointType === "resize") resizeable && (this.resizing = true);
|
|
1064
|
+
if (pointType === "skew") skewable && (this.skewing = true);
|
|
939
1065
|
}
|
|
940
1066
|
dragStartData.x = e.x;
|
|
941
1067
|
dragStartData.y = e.y;
|
|
942
|
-
dragStartData.point = {
|
|
943
|
-
|
|
1068
|
+
dragStartData.point = {
|
|
1069
|
+
x: target.x,
|
|
1070
|
+
y: target.y
|
|
1071
|
+
};
|
|
1072
|
+
dragStartData.bounds = Object.assign({}, target.getLayoutBounds("box", "local"));
|
|
944
1073
|
dragStartData.rotation = target.rotation;
|
|
945
|
-
if (pointType && pointType.includes(
|
|
946
|
-
ResizeEvent.resizingKeys = editor.leafList.keys;
|
|
1074
|
+
if (pointType && pointType.includes("resize")) ResizeEvent.resizingKeys = editor.leafList.keys;
|
|
947
1075
|
}
|
|
948
1076
|
onDragEnd(e) {
|
|
949
|
-
this.
|
|
1077
|
+
if (this.mergeConfig.dragLimitAnimate && this.moving) this.transformTool.onMove(e);
|
|
950
1078
|
this.dragPoint = null;
|
|
951
|
-
this.
|
|
952
|
-
const { name, pointType } = e.current;
|
|
953
|
-
if (name ===
|
|
954
|
-
|
|
955
|
-
if (pointType && pointType.includes('resize'))
|
|
956
|
-
ResizeEvent.resizingKeys = null;
|
|
1079
|
+
this.resetDoing();
|
|
1080
|
+
const {name: name, pointType: pointType} = e.current;
|
|
1081
|
+
if (name === "rect") this.editor.opacity = 1;
|
|
1082
|
+
if (pointType && pointType.includes("resize")) ResizeEvent.resizingKeys = null;
|
|
957
1083
|
}
|
|
958
1084
|
onDrag(e) {
|
|
959
|
-
const { transformTool
|
|
960
|
-
if (
|
|
1085
|
+
const {transformTool: transformTool, moving: moving, resizing: resizing, rotating: rotating, skewing: skewing} = this;
|
|
1086
|
+
if (moving) {
|
|
961
1087
|
transformTool.onMove(e);
|
|
962
1088
|
updateMoveCursor(this);
|
|
1089
|
+
} else if (resizing || rotating || skewing) {
|
|
1090
|
+
const point = e.current;
|
|
1091
|
+
if (point.pointType) this.enterPoint = point;
|
|
1092
|
+
if (rotating) transformTool.onRotate(e);
|
|
1093
|
+
if (resizing) transformTool.onScale(e);
|
|
1094
|
+
if (skewing) transformTool.onSkew(e);
|
|
1095
|
+
updatePointCursor(this, e);
|
|
963
1096
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1097
|
+
}
|
|
1098
|
+
resetDoing() {
|
|
1099
|
+
if (this.canUse) this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false;
|
|
1100
|
+
}
|
|
1101
|
+
onMove(e) {
|
|
1102
|
+
if (this.canGesture && e.moveType !== "drag") {
|
|
1103
|
+
e.stop();
|
|
1104
|
+
if (isString(this.mergeConfig.moveable)) {
|
|
1105
|
+
this.gesturing = this.moving = true;
|
|
1106
|
+
this.transformTool.onMove(e);
|
|
970
1107
|
}
|
|
971
|
-
else if (pointType === 'resize')
|
|
972
|
-
transformTool.onScale(e);
|
|
973
|
-
if (pointType === 'skew')
|
|
974
|
-
transformTool.onSkew(e);
|
|
975
|
-
updateCursor(this, e);
|
|
976
1108
|
}
|
|
977
1109
|
}
|
|
1110
|
+
onScale(e) {
|
|
1111
|
+
if (this.canGesture) {
|
|
1112
|
+
e.stop();
|
|
1113
|
+
if (isString(this.mergeConfig.resizeable)) {
|
|
1114
|
+
this.gesturing = this.resizing = true;
|
|
1115
|
+
this.transformTool.onScale(e);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
onRotate(e) {
|
|
1120
|
+
if (this.canGesture) {
|
|
1121
|
+
e.stop();
|
|
1122
|
+
if (isString(this.mergeConfig.rotateable)) {
|
|
1123
|
+
this.gesturing = this.rotating = true;
|
|
1124
|
+
this.transformTool.onRotate(e);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
isHoldRotateKey(e) {
|
|
1129
|
+
const {rotateKey: rotateKey} = this.mergedConfig;
|
|
1130
|
+
if (rotateKey) return e.isHoldKeys(rotateKey);
|
|
1131
|
+
return e.metaKey || e.ctrlKey;
|
|
1132
|
+
}
|
|
978
1133
|
onKey(e) {
|
|
979
|
-
|
|
1134
|
+
updatePointCursor(this, e);
|
|
980
1135
|
}
|
|
981
1136
|
onArrow(e) {
|
|
982
|
-
const { editor } = this;
|
|
983
|
-
if (editor.editing && this.mergeConfig.keyEvent) {
|
|
1137
|
+
const {editor: editor, transformTool: transformTool} = this;
|
|
1138
|
+
if (this.canUse && editor.editing && this.mergeConfig.keyEvent) {
|
|
984
1139
|
let x = 0, y = 0;
|
|
985
1140
|
const distance = e.shiftKey ? 10 : 1;
|
|
986
1141
|
switch (e.code) {
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1142
|
+
case "ArrowDown":
|
|
1143
|
+
y = distance;
|
|
1144
|
+
break;
|
|
1145
|
+
|
|
1146
|
+
case "ArrowUp":
|
|
1147
|
+
y = -distance;
|
|
1148
|
+
break;
|
|
1149
|
+
|
|
1150
|
+
case "ArrowLeft":
|
|
1151
|
+
x = -distance;
|
|
1152
|
+
break;
|
|
1153
|
+
|
|
1154
|
+
case "ArrowRight":
|
|
1155
|
+
x = distance;
|
|
998
1156
|
}
|
|
999
|
-
if (x || y)
|
|
1000
|
-
editor.move(x, y);
|
|
1157
|
+
if (x || y) transformTool.move(x, y);
|
|
1001
1158
|
}
|
|
1002
1159
|
}
|
|
1003
1160
|
onDoubleTap(e) {
|
|
1004
|
-
const { openInner, preventEditInner } = this.mergeConfig;
|
|
1005
|
-
if (openInner ===
|
|
1006
|
-
this.openInner(e);
|
|
1161
|
+
const {openInner: openInner, preventEditInner: preventEditInner} = this.mergeConfig;
|
|
1162
|
+
if (openInner === "double" && !preventEditInner) this.openInner(e);
|
|
1007
1163
|
}
|
|
1008
1164
|
onLongPress(e) {
|
|
1009
|
-
const { openInner, preventEditInner } = this.mergeConfig;
|
|
1010
|
-
if (openInner ===
|
|
1011
|
-
this.openInner(e);
|
|
1165
|
+
const {openInner: openInner, preventEditInner: preventEditInner} = this.mergeConfig;
|
|
1166
|
+
if (openInner === "long" && preventEditInner) this.openInner(e);
|
|
1012
1167
|
}
|
|
1013
1168
|
openInner(e) {
|
|
1014
|
-
const { editor, target } = this;
|
|
1169
|
+
const {editor: editor, target: target} = this;
|
|
1015
1170
|
if (this.single) {
|
|
1016
|
-
if (target.locked)
|
|
1017
|
-
return;
|
|
1171
|
+
if (target.locked) return;
|
|
1018
1172
|
if (target.isBranch && !target.editInner) {
|
|
1019
1173
|
if (target.textBox) {
|
|
1020
|
-
const { children
|
|
1174
|
+
const {children: children} = target;
|
|
1021
1175
|
const find = children.find(item => item.editable && item instanceof Text) || children.find(item => item instanceof Text);
|
|
1022
|
-
if (find)
|
|
1023
|
-
return editor.openInnerEditor(find);
|
|
1176
|
+
if (find) return editor.openInnerEditor(find);
|
|
1024
1177
|
}
|
|
1025
1178
|
editor.openGroup(target);
|
|
1026
1179
|
editor.target = editor.selector.findDeepOne(e);
|
|
1027
|
-
}
|
|
1028
|
-
else {
|
|
1180
|
+
} else {
|
|
1029
1181
|
editor.openInnerEditor();
|
|
1030
1182
|
}
|
|
1031
1183
|
}
|
|
@@ -1033,31 +1185,19 @@ class EditBox extends Group {
|
|
|
1033
1185
|
listenPointEvents(point, type, direction) {
|
|
1034
1186
|
point.direction = direction;
|
|
1035
1187
|
point.pointType = type;
|
|
1036
|
-
const events = [
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
];
|
|
1042
|
-
if (point.name !== 'circle')
|
|
1043
|
-
events.push([PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(this, e); }]);
|
|
1188
|
+
const events = [ [ DragEvent.START, this.onDragStart, this ], [ DragEvent.DRAG, this.onDrag, this ], [ DragEvent.END, this.onDragEnd, this ], [ PointerEvent.LEAVE, () => {
|
|
1189
|
+
this.enterPoint = null;
|
|
1190
|
+
} ] ];
|
|
1191
|
+
if (point.name !== "circle") events.push([ PointerEvent.ENTER, e => {
|
|
1192
|
+
this.enterPoint = point, updatePointCursor(this, e);
|
|
1193
|
+
} ]);
|
|
1044
1194
|
this.__eventIds.push(point.on_(events));
|
|
1045
1195
|
}
|
|
1046
1196
|
__listenEvents() {
|
|
1047
|
-
const { rect, editor, __eventIds: events
|
|
1048
|
-
events.push(
|
|
1049
|
-
[DragEvent.START, this.onDragStart, this],
|
|
1050
|
-
[DragEvent.DRAG, this.onDrag, this],
|
|
1051
|
-
[DragEvent.END, this.onDragEnd, this],
|
|
1052
|
-
[PointerEvent.ENTER, () => updateMoveCursor(this)],
|
|
1053
|
-
[PointerEvent.DOUBLE_TAP, this.onDoubleTap, this],
|
|
1054
|
-
[PointerEvent.LONG_PRESS, this.onLongPress, this]
|
|
1055
|
-
]));
|
|
1197
|
+
const {rect: rect, editor: editor, __eventIds: events} = this;
|
|
1198
|
+
events.push(rect.on_([ [ DragEvent.START, this.onDragStart, this ], [ DragEvent.DRAG, this.onDrag, this ], [ DragEvent.END, this.onDragEnd, this ], [ PointerEvent.ENTER, () => updateMoveCursor(this) ], [ PointerEvent.DOUBLE_TAP, this.onDoubleTap, this ], [ PointerEvent.LONG_PRESS, this.onLongPress, this ] ]));
|
|
1056
1199
|
this.waitLeafer(() => {
|
|
1057
|
-
events.push(editor.app.on_([
|
|
1058
|
-
[[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
|
|
1059
|
-
[KeyEvent.DOWN, this.onArrow, this]
|
|
1060
|
-
]));
|
|
1200
|
+
events.push(editor.app.on_([ [ [ KeyEvent.HOLD, KeyEvent.UP ], this.onKey, this ], [ KeyEvent.DOWN, this.onArrow, this ], [ MoveEvent.BEFORE_MOVE, this.onMove, this, true ], [ ZoomEvent.BEFORE_ZOOM, this.onScale, this, true ], [ RotateEvent.BEFORE_ROTATE, this.onRotate, this, true ], [ MoveEvent.END, this.resetDoing, this ], [ ZoomEvent.END, this.resetDoing, this ], [ RotateEvent.END, this.resetDoing, this ] ]));
|
|
1061
1201
|
});
|
|
1062
1202
|
}
|
|
1063
1203
|
__removeListenEvents() {
|
|
@@ -1070,7 +1210,13 @@ class EditBox extends Group {
|
|
|
1070
1210
|
}
|
|
1071
1211
|
}
|
|
1072
1212
|
|
|
1073
|
-
const bigBounds = {
|
|
1213
|
+
const bigBounds = {
|
|
1214
|
+
x: 0,
|
|
1215
|
+
y: 0,
|
|
1216
|
+
width: 1e5,
|
|
1217
|
+
height: 1e5
|
|
1218
|
+
};
|
|
1219
|
+
|
|
1074
1220
|
class EditMask extends UI {
|
|
1075
1221
|
constructor(editor) {
|
|
1076
1222
|
super();
|
|
@@ -1083,18 +1229,18 @@ class EditMask extends UI {
|
|
|
1083
1229
|
Object.assign(this.__world, bigBounds);
|
|
1084
1230
|
}
|
|
1085
1231
|
__draw(canvas, options) {
|
|
1086
|
-
const { editor
|
|
1232
|
+
const {editor: editor} = this, {mask: mask} = editor.mergedConfig;
|
|
1087
1233
|
if (mask && editor.editing) {
|
|
1088
|
-
canvas.fillWorld(canvas.bounds, mask === true ?
|
|
1089
|
-
if (options.bounds && !options.bounds.hit(editor.editBox.rect.__world, options.matrix))
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1234
|
+
canvas.fillWorld(canvas.bounds, mask === true ? "rgba(0,0,0,0.8)" : mask);
|
|
1235
|
+
if (options.bounds && !options.bounds.hit(editor.editBox.rect.__world, options.matrix)) return;
|
|
1236
|
+
canvas.saveBlendMode("destination-out");
|
|
1237
|
+
options = Object.assign(Object.assign({}, options), {
|
|
1238
|
+
shape: true
|
|
1239
|
+
});
|
|
1093
1240
|
editor.list.forEach(item => {
|
|
1094
1241
|
item.__render(canvas, options);
|
|
1095
|
-
const { parent
|
|
1096
|
-
if (parent && parent.textBox)
|
|
1097
|
-
parent.__renderShape(canvas, options);
|
|
1242
|
+
const {parent: parent} = item;
|
|
1243
|
+
if (parent && parent.textBox) parent.__renderShape(canvas, options);
|
|
1098
1244
|
});
|
|
1099
1245
|
canvas.restoreBlendMode();
|
|
1100
1246
|
}
|
|
@@ -1105,78 +1251,47 @@ class EditMask extends UI {
|
|
|
1105
1251
|
}
|
|
1106
1252
|
}
|
|
1107
1253
|
|
|
1108
|
-
const filterStyle =
|
|
1109
|
-
|
|
1110
|
-
<
|
|
1111
|
-
|
|
1112
|
-
<
|
|
1113
|
-
|
|
1114
|
-
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg"
|
|
1115
|
-
<g filter="url(#f)">
|
|
1116
|
-
<g transform="rotate({{rotation}},12,12)">
|
|
1117
|
-
<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>
|
|
1118
|
-
<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>
|
|
1119
|
-
</g>
|
|
1120
|
-
</g>
|
|
1121
|
-
<defs>
|
|
1122
|
-
<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">
|
|
1123
|
-
${filterStyle}
|
|
1124
|
-
</filter>
|
|
1125
|
-
</defs>
|
|
1126
|
-
</svg>
|
|
1127
|
-
`;
|
|
1128
|
-
const rotateSVG = `
|
|
1129
|
-
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">
|
|
1130
|
-
<g filter="url(#f)">
|
|
1131
|
-
<g transform="rotate(135,12,12),rotate({{rotation}},12,12)">
|
|
1132
|
-
<path d="M20.4 8H21.4L20.8 7.1L17.3 2.6L17 2.1L16.6 2.6L13.1 7.1L12.5 8H13.5H15.4C14.9 11.8 11.8 14.9 8 15.4V13.5V12.5L7.1 13.1L2.6 16.6L2.1 17L2.6 17.3L7.1 20.8L8 21.4V20.4V18.4C13.5 17.9 17.9 13.5 18.4 8H20.4Z" stroke="white"/>
|
|
1133
|
-
<path fill-rule="evenodd" d="M17 3L20.4 7.5H17.9C17.7 13.1 13.1 17.7 7.5 17.9V20.4L3 17L7.5 13.5V15.9C12.0 15.7 15.7 12.0 15.9 7.5H13.5L17 3Z" fill="black"/>
|
|
1134
|
-
</g>
|
|
1135
|
-
</g>
|
|
1136
|
-
<defs>
|
|
1137
|
-
<filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">
|
|
1138
|
-
${filterStyle}
|
|
1139
|
-
</filter>
|
|
1140
|
-
</defs>
|
|
1141
|
-
</svg>
|
|
1142
|
-
`;
|
|
1143
|
-
const skewSVG = `
|
|
1144
|
-
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">
|
|
1145
|
-
<g filter="url(#f)">
|
|
1146
|
-
<g transform="rotate(90,12,12),rotate({{rotation}},12,12)">
|
|
1147
|
-
<path d="M21 10.4L21 11.4L23.8 11.4L21.6 9.6L21 10.4ZM17 10.4V11.4L17 11.4L17 10.4ZM15.5 6L16.1 5.2L14.5 3.9V6H15.5ZM15.5 8.4V9.4H16.5V8.4H15.5ZM6 8.4V7.4H5V8.4H6ZM6 10.4H5V11.4H6V10.4ZM7 14.4V13.4L7 13.4L7 14.4ZM3 14.4L3 13.4L0.1 13.4L2.3 15.2L3 14.4ZM8.5 18.9L7.8 19.7L9.5 21.0V18.9H8.5ZM8.5 16.4V15.4H7.5V16.4H8.5ZM19 16.4V17.4H20V16.4H19ZM19 14.4H20V13.4H19V14.4ZM21 9.4L17 9.4L17 11.4L21 11.4L21 9.4ZM14.8 6.7L20.3 11.2L21.6 9.6L16.1 5.2L14.8 6.7ZM16.5 8.4V6H14.5V8.4H16.5ZM6 9.4H15.5V7.4H6V9.4ZM7 10.4V8.4H5V10.4H7ZM15.5 9.4H6V11.4H15.5V9.4ZM17 9.4H15.5V11.4H17V9.4ZM7 15.4H8.5V13.4H7V15.4ZM3 15.4L7 15.4L7 13.4L3 13.4L3 15.4ZM9.1 18.1L3.6 13.6L2.3 15.2L7.8 19.7L9.1 18.1ZM7.5 16.4V18.9H9.5V16.4H7.5ZM19 15.4H8.5V17.4H19V15.4ZM18 14.4V16.4H20V14.4H18ZM8.5 15.4H19V13.4H8.5V15.4Z" fill="white"/>
|
|
1148
|
-
<path fill-rule="evenodd" d="M17 10.4L21 10.4L15.5 6V8.4H6V10.4H15.5H17ZM8.5 14.4H7L3 14.4L8.5 18.9V16.4H19V14.4H8.5Z" fill="black"/>
|
|
1149
|
-
</g>
|
|
1150
|
-
</g>
|
|
1151
|
-
<defs>
|
|
1152
|
-
<filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >
|
|
1153
|
-
${filterStyle}
|
|
1154
|
-
</filter>
|
|
1155
|
-
</defs>
|
|
1156
|
-
</svg>
|
|
1157
|
-
`;
|
|
1254
|
+
const filterStyle = `\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>`;
|
|
1255
|
+
|
|
1256
|
+
const resizeSVG = `\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${filterStyle}\n</filter>\n</defs>\n</svg>\n`;
|
|
1257
|
+
|
|
1258
|
+
const rotateSVG = `\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(135,12,12),rotate({{rotation}},12,12)">\n<path d="M20.4 8H21.4L20.8 7.1L17.3 2.6L17 2.1L16.6 2.6L13.1 7.1L12.5 8H13.5H15.4C14.9 11.8 11.8 14.9 8 15.4V13.5V12.5L7.1 13.1L2.6 16.6L2.1 17L2.6 17.3L7.1 20.8L8 21.4V20.4V18.4C13.5 17.9 17.9 13.5 18.4 8H20.4Z" stroke="white"/>\n<path fill-rule="evenodd" d="M17 3L20.4 7.5H17.9C17.7 13.1 13.1 17.7 7.5 17.9V20.4L3 17L7.5 13.5V15.9C12.0 15.7 15.7 12.0 15.9 7.5H13.5L17 3Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">\n${filterStyle}\n</filter>\n</defs>\n</svg>\n`;
|
|
1259
|
+
|
|
1260
|
+
const skewSVG = `\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(90,12,12),rotate({{rotation}},12,12)">\n<path d="M21 10.4L21 11.4L23.8 11.4L21.6 9.6L21 10.4ZM17 10.4V11.4L17 11.4L17 10.4ZM15.5 6L16.1 5.2L14.5 3.9V6H15.5ZM15.5 8.4V9.4H16.5V8.4H15.5ZM6 8.4V7.4H5V8.4H6ZM6 10.4H5V11.4H6V10.4ZM7 14.4V13.4L7 13.4L7 14.4ZM3 14.4L3 13.4L0.1 13.4L2.3 15.2L3 14.4ZM8.5 18.9L7.8 19.7L9.5 21.0V18.9H8.5ZM8.5 16.4V15.4H7.5V16.4H8.5ZM19 16.4V17.4H20V16.4H19ZM19 14.4H20V13.4H19V14.4ZM21 9.4L17 9.4L17 11.4L21 11.4L21 9.4ZM14.8 6.7L20.3 11.2L21.6 9.6L16.1 5.2L14.8 6.7ZM16.5 8.4V6H14.5V8.4H16.5ZM6 9.4H15.5V7.4H6V9.4ZM7 10.4V8.4H5V10.4H7ZM15.5 9.4H6V11.4H15.5V9.4ZM17 9.4H15.5V11.4H17V9.4ZM7 15.4H8.5V13.4H7V15.4ZM3 15.4L7 15.4L7 13.4L3 13.4L3 15.4ZM9.1 18.1L3.6 13.6L2.3 15.2L7.8 19.7L9.1 18.1ZM7.5 16.4V18.9H9.5V16.4H7.5ZM19 15.4H8.5V17.4H19V15.4ZM18 14.4V16.4H20V14.4H18ZM8.5 15.4H19V13.4H8.5V15.4Z" fill="white"/>\n<path fill-rule="evenodd" d="M17 10.4L21 10.4L15.5 6V8.4H6V10.4H15.5H17ZM8.5 14.4H7L3 14.4L8.5 18.9V16.4H19V14.4H8.5Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >\n${filterStyle}\n</filter>\n</defs>\n</svg>\n`;
|
|
1158
1261
|
|
|
1159
1262
|
const config = {
|
|
1160
|
-
editSize:
|
|
1263
|
+
editSize: "size",
|
|
1161
1264
|
keyEvent: true,
|
|
1162
|
-
stroke:
|
|
1265
|
+
stroke: "#836DFF",
|
|
1163
1266
|
strokeWidth: 2,
|
|
1164
|
-
pointFill:
|
|
1267
|
+
pointFill: "#FFFFFF",
|
|
1165
1268
|
pointSize: 10,
|
|
1166
1269
|
pointRadius: 16,
|
|
1167
1270
|
rotateGap: 45,
|
|
1168
|
-
buttonsDirection:
|
|
1271
|
+
buttonsDirection: "bottom",
|
|
1169
1272
|
buttonsMargin: 12,
|
|
1170
1273
|
hideOnSmall: true,
|
|
1171
|
-
moveCursor:
|
|
1172
|
-
resizeCursor: {
|
|
1173
|
-
|
|
1174
|
-
|
|
1274
|
+
moveCursor: "move",
|
|
1275
|
+
resizeCursor: {
|
|
1276
|
+
url: resizeSVG,
|
|
1277
|
+
x: 12,
|
|
1278
|
+
y: 12
|
|
1279
|
+
},
|
|
1280
|
+
rotateCursor: {
|
|
1281
|
+
url: rotateSVG,
|
|
1282
|
+
x: 12,
|
|
1283
|
+
y: 12
|
|
1284
|
+
},
|
|
1285
|
+
skewCursor: {
|
|
1286
|
+
url: skewSVG,
|
|
1287
|
+
x: 12,
|
|
1288
|
+
y: 12
|
|
1289
|
+
},
|
|
1175
1290
|
selector: true,
|
|
1176
1291
|
editBox: true,
|
|
1177
1292
|
hover: true,
|
|
1178
|
-
select:
|
|
1179
|
-
openInner:
|
|
1293
|
+
select: "press",
|
|
1294
|
+
openInner: "double",
|
|
1180
1295
|
multipleSelect: true,
|
|
1181
1296
|
boxSelect: true,
|
|
1182
1297
|
moveable: true,
|
|
@@ -1186,34 +1301,36 @@ const config = {
|
|
|
1186
1301
|
skewable: true
|
|
1187
1302
|
};
|
|
1188
1303
|
|
|
1189
|
-
const bounds = new Bounds
|
|
1304
|
+
const bounds = new Bounds;
|
|
1305
|
+
|
|
1190
1306
|
function simulate(editor) {
|
|
1191
|
-
const { simulateTarget, list } = editor;
|
|
1192
|
-
const { zoomLayer
|
|
1307
|
+
const {simulateTarget: simulateTarget, list: list} = editor;
|
|
1308
|
+
const {zoomLayer: zoomLayer} = list[0].leafer;
|
|
1193
1309
|
simulateTarget.safeChange(() => {
|
|
1194
|
-
bounds.setListWithFn(list,
|
|
1195
|
-
if (bounds.width === 0)
|
|
1196
|
-
|
|
1197
|
-
if (bounds.height === 0)
|
|
1198
|
-
bounds.height = 0.1;
|
|
1310
|
+
bounds.setListWithFn(list, leaf => leaf.getBounds("box", "page"));
|
|
1311
|
+
if (bounds.width === 0) bounds.width = .1;
|
|
1312
|
+
if (bounds.height === 0) bounds.height = .1;
|
|
1199
1313
|
simulateTarget.reset(bounds.get());
|
|
1200
1314
|
});
|
|
1201
1315
|
zoomLayer.add(simulateTarget);
|
|
1202
1316
|
}
|
|
1203
1317
|
|
|
1204
1318
|
function onTarget(editor, oldValue) {
|
|
1205
|
-
const { target
|
|
1319
|
+
const {target: target} = editor;
|
|
1206
1320
|
if (target) {
|
|
1207
1321
|
editor.leafList = target instanceof LeafList ? target : new LeafList(target);
|
|
1208
|
-
if (editor.multiple)
|
|
1209
|
-
|
|
1210
|
-
}
|
|
1211
|
-
else {
|
|
1322
|
+
if (editor.multiple) simulate(editor);
|
|
1323
|
+
} else {
|
|
1212
1324
|
editor.simulateTarget.remove();
|
|
1213
1325
|
editor.leafList.reset();
|
|
1214
1326
|
}
|
|
1215
|
-
editor.closeInnerEditor();
|
|
1216
|
-
|
|
1327
|
+
editor.closeInnerEditor(true);
|
|
1328
|
+
editor.unloadEditTool();
|
|
1329
|
+
const data = {
|
|
1330
|
+
editor: editor,
|
|
1331
|
+
value: target,
|
|
1332
|
+
oldValue: oldValue
|
|
1333
|
+
};
|
|
1217
1334
|
editor.emitEvent(new EditorEvent(EditorEvent.SELECT, data));
|
|
1218
1335
|
editor.checkOpenedGroups();
|
|
1219
1336
|
if (editor.editing) {
|
|
@@ -1221,28 +1338,33 @@ function onTarget(editor, oldValue) {
|
|
|
1221
1338
|
editor.updateEditTool();
|
|
1222
1339
|
editor.listenTargetEvents();
|
|
1223
1340
|
});
|
|
1224
|
-
}
|
|
1225
|
-
else {
|
|
1341
|
+
} else {
|
|
1226
1342
|
editor.updateEditTool();
|
|
1227
1343
|
editor.removeTargetEvents();
|
|
1228
1344
|
}
|
|
1229
1345
|
editor.emitEvent(new EditorEvent(EditorEvent.AFTER_SELECT, data));
|
|
1230
1346
|
}
|
|
1347
|
+
|
|
1231
1348
|
function onHover(editor, oldValue) {
|
|
1232
|
-
editor.emitEvent(new EditorEvent(EditorEvent.HOVER, {
|
|
1349
|
+
editor.emitEvent(new EditorEvent(EditorEvent.HOVER, {
|
|
1350
|
+
editor: editor,
|
|
1351
|
+
value: editor.hoverTarget,
|
|
1352
|
+
oldValue: oldValue
|
|
1353
|
+
}));
|
|
1233
1354
|
}
|
|
1234
1355
|
|
|
1235
1356
|
const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
|
|
1357
|
+
|
|
1236
1358
|
const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
|
|
1359
|
+
|
|
1237
1360
|
const EditorHelper = {
|
|
1238
1361
|
group(list, element, userGroup) {
|
|
1239
1362
|
list.sort(reverseOrder);
|
|
1240
|
-
const { app, parent } = list[0];
|
|
1363
|
+
const {app: app, parent: parent} = list[0];
|
|
1241
1364
|
let group;
|
|
1242
1365
|
if (userGroup && userGroup.add) {
|
|
1243
1366
|
group = userGroup;
|
|
1244
|
-
}
|
|
1245
|
-
else {
|
|
1367
|
+
} else {
|
|
1246
1368
|
group = new Group(userGroup);
|
|
1247
1369
|
}
|
|
1248
1370
|
parent.addAt(group, parent.children.indexOf(list[0]));
|
|
@@ -1258,22 +1380,18 @@ const EditorHelper = {
|
|
|
1258
1380
|
return group;
|
|
1259
1381
|
},
|
|
1260
1382
|
ungroup(list) {
|
|
1261
|
-
const { app
|
|
1383
|
+
const {app: app} = list[0];
|
|
1262
1384
|
const ungroupList = [];
|
|
1263
1385
|
app.lockLayout();
|
|
1264
1386
|
list.forEach(leaf => {
|
|
1265
1387
|
if (leaf.isBranch) {
|
|
1266
|
-
const { parent, children } = leaf;
|
|
1388
|
+
const {parent: parent, children: children} = leaf;
|
|
1267
1389
|
while (children.length) {
|
|
1268
1390
|
ungroupList.push(children[0]);
|
|
1269
1391
|
children[0].dropTo(parent, parent.children.indexOf(leaf));
|
|
1270
1392
|
}
|
|
1271
|
-
if (leaf.isBranchLeaf)
|
|
1272
|
-
|
|
1273
|
-
else
|
|
1274
|
-
leaf.remove();
|
|
1275
|
-
}
|
|
1276
|
-
else {
|
|
1393
|
+
if (leaf.isBranchLeaf) ungroupList.push(leaf); else leaf.remove();
|
|
1394
|
+
} else {
|
|
1277
1395
|
ungroupList.push(leaf);
|
|
1278
1396
|
}
|
|
1279
1397
|
});
|
|
@@ -1283,30 +1401,31 @@ const EditorHelper = {
|
|
|
1283
1401
|
toTop(list) {
|
|
1284
1402
|
list.sort(order);
|
|
1285
1403
|
list.forEach(leaf => {
|
|
1286
|
-
if (leaf.parent)
|
|
1287
|
-
leaf.parent.add(leaf);
|
|
1404
|
+
if (leaf.parent) leaf.parent.add(leaf);
|
|
1288
1405
|
});
|
|
1289
1406
|
},
|
|
1290
1407
|
toBottom(list) {
|
|
1291
1408
|
list.sort(reverseOrder);
|
|
1292
1409
|
list.forEach(leaf => {
|
|
1293
|
-
if (leaf.parent)
|
|
1294
|
-
leaf.parent.addAt(leaf, 0);
|
|
1410
|
+
if (leaf.parent) leaf.parent.addAt(leaf, 0);
|
|
1295
1411
|
});
|
|
1296
1412
|
}
|
|
1297
1413
|
};
|
|
1298
1414
|
|
|
1299
|
-
const debug = Debug.get(
|
|
1415
|
+
const debug = Debug.get("EditToolCreator");
|
|
1416
|
+
|
|
1300
1417
|
function registerEditTool() {
|
|
1301
|
-
return
|
|
1418
|
+
return target => {
|
|
1302
1419
|
EditToolCreator.register(target);
|
|
1303
1420
|
};
|
|
1304
1421
|
}
|
|
1422
|
+
|
|
1305
1423
|
const registerInnerEditor = registerEditTool;
|
|
1424
|
+
|
|
1306
1425
|
const EditToolCreator = {
|
|
1307
1426
|
list: {},
|
|
1308
1427
|
register(EditTool) {
|
|
1309
|
-
const { tag
|
|
1428
|
+
const {tag: tag} = EditTool.prototype;
|
|
1310
1429
|
list[tag] && debug.repeat(tag);
|
|
1311
1430
|
list[tag] = EditTool;
|
|
1312
1431
|
},
|
|
@@ -1314,45 +1433,70 @@ const EditToolCreator = {
|
|
|
1314
1433
|
return new list[tag](editor);
|
|
1315
1434
|
}
|
|
1316
1435
|
};
|
|
1317
|
-
|
|
1436
|
+
|
|
1437
|
+
const {list: list} = EditToolCreator;
|
|
1318
1438
|
|
|
1319
1439
|
class InnerEditorEvent extends EditorEvent {
|
|
1320
1440
|
constructor(type, data) {
|
|
1321
1441
|
super(type, data);
|
|
1322
1442
|
}
|
|
1323
1443
|
}
|
|
1324
|
-
|
|
1325
|
-
InnerEditorEvent.
|
|
1326
|
-
|
|
1327
|
-
InnerEditorEvent.
|
|
1444
|
+
|
|
1445
|
+
InnerEditorEvent.BEFORE_OPEN = "innerEditor.before_open";
|
|
1446
|
+
|
|
1447
|
+
InnerEditorEvent.OPEN = "innerEditor.open";
|
|
1448
|
+
|
|
1449
|
+
InnerEditorEvent.BEFORE_CLOSE = "innerEditor.before_close";
|
|
1450
|
+
|
|
1451
|
+
InnerEditorEvent.CLOSE = "innerEditor.close";
|
|
1328
1452
|
|
|
1329
1453
|
class EditorGroupEvent extends EditorEvent {
|
|
1330
1454
|
constructor(type, data) {
|
|
1331
1455
|
super(type, data);
|
|
1332
1456
|
}
|
|
1333
1457
|
}
|
|
1334
|
-
|
|
1335
|
-
EditorGroupEvent.
|
|
1336
|
-
|
|
1337
|
-
EditorGroupEvent.
|
|
1338
|
-
|
|
1339
|
-
EditorGroupEvent.
|
|
1340
|
-
|
|
1341
|
-
EditorGroupEvent.
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1458
|
+
|
|
1459
|
+
EditorGroupEvent.BEFORE_GROUP = "editor.before_group";
|
|
1460
|
+
|
|
1461
|
+
EditorGroupEvent.GROUP = "editor.group";
|
|
1462
|
+
|
|
1463
|
+
EditorGroupEvent.BEFORE_UNGROUP = "editor.before_ungroup";
|
|
1464
|
+
|
|
1465
|
+
EditorGroupEvent.UNGROUP = "editor.ungroup";
|
|
1466
|
+
|
|
1467
|
+
EditorGroupEvent.BEFORE_OPEN = "editor.before_open_group";
|
|
1468
|
+
|
|
1469
|
+
EditorGroupEvent.OPEN = "editor.open_group";
|
|
1470
|
+
|
|
1471
|
+
EditorGroupEvent.BEFORE_CLOSE = "editor.before_close_group";
|
|
1472
|
+
|
|
1473
|
+
EditorGroupEvent.CLOSE = "editor.close_group";
|
|
1474
|
+
|
|
1475
|
+
const {updateMatrix: updateMatrix} = LeafHelper;
|
|
1476
|
+
|
|
1477
|
+
const checkMap = {
|
|
1478
|
+
x: 1,
|
|
1479
|
+
y: 1,
|
|
1480
|
+
scaleX: 1,
|
|
1481
|
+
scaleY: 1,
|
|
1482
|
+
rotation: 1,
|
|
1483
|
+
skewX: 1,
|
|
1484
|
+
skewY: 1
|
|
1485
|
+
}, origin = "top-left";
|
|
1486
|
+
|
|
1345
1487
|
class SimulateElement extends Rect {
|
|
1346
|
-
get __tag() {
|
|
1488
|
+
get __tag() {
|
|
1489
|
+
return "SimulateElement";
|
|
1490
|
+
}
|
|
1347
1491
|
constructor(editor) {
|
|
1348
1492
|
super();
|
|
1349
1493
|
this.checkChange = true;
|
|
1350
1494
|
this.canChange = true;
|
|
1351
1495
|
this.visible = this.hittable = false;
|
|
1352
|
-
this.on(PropertyEvent.CHANGE,
|
|
1496
|
+
this.on(PropertyEvent.CHANGE, event => {
|
|
1353
1497
|
if (this.checkChange && checkMap[event.attrName]) {
|
|
1354
|
-
const { attrName, newValue, oldValue } = event;
|
|
1355
|
-
const addValue = attrName[0] ===
|
|
1498
|
+
const {attrName: attrName, newValue: newValue, oldValue: oldValue} = event;
|
|
1499
|
+
const addValue = attrName[0] === "s" ? (newValue || 1) / (oldValue || 1) : (newValue || 0) - (oldValue || 0);
|
|
1356
1500
|
this.canChange = false;
|
|
1357
1501
|
const data = this.__;
|
|
1358
1502
|
data[attrName] = oldValue;
|
|
@@ -1364,26 +1508,32 @@ class SimulateElement extends Rect {
|
|
|
1364
1508
|
updateMatrix(this);
|
|
1365
1509
|
this.changedTransform = new Matrix(this.__world).divide(oldMatrix);
|
|
1366
1510
|
switch (attrName) {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1511
|
+
case "x":
|
|
1512
|
+
editor.move(addValue, 0);
|
|
1513
|
+
break;
|
|
1514
|
+
|
|
1515
|
+
case "y":
|
|
1516
|
+
editor.move(0, addValue);
|
|
1517
|
+
break;
|
|
1518
|
+
|
|
1519
|
+
case "rotation":
|
|
1520
|
+
editor.rotateOf(origin, addValue);
|
|
1521
|
+
break;
|
|
1522
|
+
|
|
1523
|
+
case "scaleX":
|
|
1524
|
+
editor.scaleOf(origin, addValue, 1);
|
|
1525
|
+
break;
|
|
1526
|
+
|
|
1527
|
+
case "scaleY":
|
|
1528
|
+
editor.scaleOf(origin, 1, addValue);
|
|
1529
|
+
break;
|
|
1530
|
+
|
|
1531
|
+
case "skewX":
|
|
1532
|
+
editor.skewOf(origin, addValue, 0);
|
|
1533
|
+
break;
|
|
1534
|
+
|
|
1535
|
+
case "skewY":
|
|
1536
|
+
editor.skewOf(origin, 0, addValue);
|
|
1387
1537
|
}
|
|
1388
1538
|
this.canChange = true;
|
|
1389
1539
|
}
|
|
@@ -1403,222 +1553,253 @@ class EditorMoveEvent extends EditorEvent {
|
|
|
1403
1553
|
super(type, data);
|
|
1404
1554
|
}
|
|
1405
1555
|
}
|
|
1406
|
-
|
|
1407
|
-
EditorMoveEvent.
|
|
1556
|
+
|
|
1557
|
+
EditorMoveEvent.BEFORE_MOVE = "editor.before_move";
|
|
1558
|
+
|
|
1559
|
+
EditorMoveEvent.MOVE = "editor.move";
|
|
1408
1560
|
|
|
1409
1561
|
class EditorScaleEvent extends EditorEvent {
|
|
1410
1562
|
constructor(type, data) {
|
|
1411
1563
|
super(type, data);
|
|
1412
1564
|
}
|
|
1413
1565
|
}
|
|
1414
|
-
|
|
1415
|
-
EditorScaleEvent.
|
|
1566
|
+
|
|
1567
|
+
EditorScaleEvent.BEFORE_SCALE = "editor.before_scale";
|
|
1568
|
+
|
|
1569
|
+
EditorScaleEvent.SCALE = "editor.scale";
|
|
1416
1570
|
|
|
1417
1571
|
class EditorRotateEvent extends EditorEvent {
|
|
1418
1572
|
constructor(type, data) {
|
|
1419
1573
|
super(type, data);
|
|
1420
1574
|
}
|
|
1421
1575
|
}
|
|
1422
|
-
|
|
1423
|
-
EditorRotateEvent.
|
|
1576
|
+
|
|
1577
|
+
EditorRotateEvent.BEFORE_ROTATE = "editor.before_rotate";
|
|
1578
|
+
|
|
1579
|
+
EditorRotateEvent.ROTATE = "editor.rotate";
|
|
1424
1580
|
|
|
1425
1581
|
class EditorSkewEvent extends EditorEvent {
|
|
1426
1582
|
constructor(type, data) {
|
|
1427
1583
|
super(type, data);
|
|
1428
1584
|
}
|
|
1429
1585
|
}
|
|
1430
|
-
|
|
1431
|
-
EditorSkewEvent.
|
|
1586
|
+
|
|
1587
|
+
EditorSkewEvent.BEFORE_SKEW = "editor.before_skew";
|
|
1588
|
+
|
|
1589
|
+
EditorSkewEvent.SKEW = "editor.skew";
|
|
1432
1590
|
|
|
1433
1591
|
class TransformTool {
|
|
1434
1592
|
onMove(e) {
|
|
1435
|
-
const { target, mergeConfig, dragStartData } = this.editBox;
|
|
1593
|
+
const {target: target, mergeConfig: mergeConfig, dragStartData: dragStartData, app: app} = this.editBox;
|
|
1594
|
+
let move, {dragLimitAnimate: dragLimitAnimate} = mergeConfig;
|
|
1595
|
+
if (isUndefined(dragLimitAnimate)) dragLimitAnimate = app && app.config.pointer.dragLimitAnimate;
|
|
1596
|
+
const isMoveEnd = e.type === DragEvent.END || e.type === DragEvent.END;
|
|
1597
|
+
const checkLimitMove = !dragLimitAnimate || isMoveEnd;
|
|
1436
1598
|
if (e instanceof MoveEvent) {
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
else {
|
|
1447
|
-
const total = { x: e.totalX, y: e.totalY };
|
|
1599
|
+
move = e.getLocalMove(target);
|
|
1600
|
+
if (checkLimitMove) DragEvent.limitMove(target, move);
|
|
1601
|
+
} else {
|
|
1602
|
+
const total = {
|
|
1603
|
+
x: e.totalX,
|
|
1604
|
+
y: e.totalY
|
|
1605
|
+
};
|
|
1448
1606
|
if (e.shiftKey) {
|
|
1449
|
-
if (Math.abs(total.x) > Math.abs(total.y))
|
|
1450
|
-
total.y = 0;
|
|
1451
|
-
else
|
|
1452
|
-
total.x = 0;
|
|
1607
|
+
if (Math.abs(total.x) > Math.abs(total.y)) total.y = 0; else total.x = 0;
|
|
1453
1608
|
}
|
|
1454
|
-
|
|
1609
|
+
move = DragEvent.getValidMove(target, dragStartData.point, total, checkLimitMove);
|
|
1455
1610
|
}
|
|
1611
|
+
if (dragLimitAnimate && isMoveEnd) LeafHelper.animateMove(this, move, isNumber(dragLimitAnimate) ? dragLimitAnimate : .3); else this.move(move);
|
|
1456
1612
|
}
|
|
1457
1613
|
onScale(e) {
|
|
1458
|
-
const { target, mergeConfig, single, dragStartData } = this.editBox;
|
|
1459
|
-
let { around, lockRatio
|
|
1614
|
+
const {target: target, mergeConfig: mergeConfig, single: single, dragStartData: dragStartData} = this.editBox;
|
|
1615
|
+
let {around: around, lockRatio: lockRatio, flipable: flipable, editSize: editSize} = mergeConfig;
|
|
1460
1616
|
if (e instanceof ZoomEvent) {
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
const
|
|
1466
|
-
if (e.shiftKey || target.lockRatio)
|
|
1467
|
-
lockRatio = true;
|
|
1468
|
-
const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, e.getInnerTotal(target), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === 'scale');
|
|
1617
|
+
this.scaleOf(target.getBoxPoint(e), e.scale, e.scale);
|
|
1618
|
+
} else {
|
|
1619
|
+
const {direction: direction} = e.current;
|
|
1620
|
+
if (e.shiftKey || target.lockRatio) lockRatio = true;
|
|
1621
|
+
const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, e.getInnerTotal(target), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === "scale");
|
|
1469
1622
|
if (this.editTool && this.editTool.onScaleWithDrag) {
|
|
1470
1623
|
data.drag = e;
|
|
1471
1624
|
this.scaleWithDrag(data);
|
|
1472
|
-
}
|
|
1473
|
-
else {
|
|
1625
|
+
} else {
|
|
1474
1626
|
this.scaleOf(data.origin, data.scaleX, data.scaleY);
|
|
1475
1627
|
}
|
|
1476
1628
|
}
|
|
1477
1629
|
}
|
|
1478
1630
|
onRotate(e) {
|
|
1479
|
-
const { target, mergeConfig, dragStartData } = this.editBox;
|
|
1480
|
-
const {
|
|
1481
|
-
const { direction
|
|
1482
|
-
if (skewable && name === 'resize-line')
|
|
1483
|
-
return this.onSkew(e);
|
|
1631
|
+
const {target: target, mergeConfig: mergeConfig, dragStartData: dragStartData} = this.editBox;
|
|
1632
|
+
const {around: around, rotateAround: rotateAround, rotateGap: rotateGap} = mergeConfig;
|
|
1633
|
+
const {direction: direction} = e.current;
|
|
1484
1634
|
let origin, rotation;
|
|
1485
1635
|
if (e instanceof RotateEvent) {
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
rotation = -rotation;
|
|
1492
|
-
}
|
|
1493
|
-
else {
|
|
1494
|
-
const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : (target.around || target.origin || around || 'center'));
|
|
1495
|
-
rotation = data.rotation;
|
|
1636
|
+
rotation = e.rotation;
|
|
1637
|
+
origin = rotateAround ? AroundHelper.getPoint(rotateAround, target.boxBounds) : target.getBoxPoint(e);
|
|
1638
|
+
} else {
|
|
1639
|
+
const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : rotateAround || target.around || target.origin || around || "center");
|
|
1640
|
+
rotation = dragStartData.rotation + data.rotation - target.rotation;
|
|
1496
1641
|
origin = data.origin;
|
|
1497
1642
|
}
|
|
1498
|
-
if (target.scaleX * target.scaleY < 0)
|
|
1499
|
-
rotation = -rotation;
|
|
1500
|
-
if (e instanceof DragEvent)
|
|
1501
|
-
rotation = dragStartData.rotation + rotation - target.rotation;
|
|
1502
1643
|
rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, target.rotation), 2);
|
|
1503
|
-
if (!rotation)
|
|
1504
|
-
return;
|
|
1644
|
+
if (!rotation) return;
|
|
1505
1645
|
this.rotateOf(origin, rotation);
|
|
1506
1646
|
}
|
|
1507
1647
|
onSkew(e) {
|
|
1508
|
-
const { target, mergeConfig } = this.editBox;
|
|
1509
|
-
const { around
|
|
1510
|
-
const { origin, skewX, skewY } = EditDataHelper.getSkewData(target.boxBounds, e.current.direction, e.getInnerMove(target), EditDataHelper.getAround(around, e.altKey));
|
|
1511
|
-
if (!skewX && !skewY)
|
|
1512
|
-
return;
|
|
1648
|
+
const {target: target, mergeConfig: mergeConfig} = this.editBox;
|
|
1649
|
+
const {around: around} = mergeConfig;
|
|
1650
|
+
const {origin: origin, skewX: skewX, skewY: skewY} = EditDataHelper.getSkewData(target.boxBounds, e.current.direction, e.getInnerMove(target), EditDataHelper.getAround(around, e.altKey));
|
|
1651
|
+
if (!skewX && !skewY) return;
|
|
1513
1652
|
this.skewOf(origin, skewX, skewY);
|
|
1514
1653
|
}
|
|
1515
1654
|
move(x, y = 0) {
|
|
1516
|
-
if (!this.checkTransform(
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
const { target, mergeConfig, single, editor } = this.editBox;
|
|
1521
|
-
const { beforeMove } = mergeConfig;
|
|
1655
|
+
if (!this.checkTransform("moveable")) return;
|
|
1656
|
+
if (isObject(x)) y = x.y, x = x.x;
|
|
1657
|
+
const {target: target, mergeConfig: mergeConfig, single: single, editor: editor} = this.editBox;
|
|
1658
|
+
const {beforeMove: beforeMove} = mergeConfig;
|
|
1522
1659
|
if (beforeMove) {
|
|
1523
|
-
const check = beforeMove({
|
|
1524
|
-
|
|
1525
|
-
x
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1660
|
+
const check = beforeMove({
|
|
1661
|
+
target: target,
|
|
1662
|
+
x: x,
|
|
1663
|
+
y: y
|
|
1664
|
+
});
|
|
1665
|
+
if (isObject(check)) x = check.x, y = check.y; else if (check === false) return;
|
|
1666
|
+
}
|
|
1667
|
+
const world = target.getWorldPointByLocal({
|
|
1668
|
+
x: x,
|
|
1669
|
+
y: y
|
|
1670
|
+
}, null, true);
|
|
1671
|
+
if (!single) target.safeChange(() => target.move(x, y));
|
|
1672
|
+
const data = {
|
|
1673
|
+
target: target,
|
|
1674
|
+
editor: editor,
|
|
1675
|
+
moveX: world.x,
|
|
1676
|
+
moveY: world.y
|
|
1677
|
+
};
|
|
1533
1678
|
this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
|
|
1534
1679
|
const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
|
|
1535
1680
|
this.doMove(event);
|
|
1536
1681
|
this.emitEvent(event);
|
|
1537
1682
|
}
|
|
1538
1683
|
scaleWithDrag(data) {
|
|
1539
|
-
if (!this.checkTransform(
|
|
1540
|
-
|
|
1541
|
-
const {
|
|
1542
|
-
const { beforeScale } = mergeConfig;
|
|
1684
|
+
if (!this.checkTransform("resizeable")) return;
|
|
1685
|
+
const {target: target, mergeConfig: mergeConfig, editor: editor} = this.editBox;
|
|
1686
|
+
const {beforeScale: beforeScale} = mergeConfig;
|
|
1543
1687
|
if (beforeScale) {
|
|
1544
|
-
const { origin, scaleX, scaleY, drag } = data;
|
|
1545
|
-
const check = beforeScale({
|
|
1546
|
-
|
|
1547
|
-
|
|
1688
|
+
const {origin: origin, scaleX: scaleX, scaleY: scaleY, drag: drag} = data;
|
|
1689
|
+
const check = beforeScale({
|
|
1690
|
+
target: target,
|
|
1691
|
+
drag: drag,
|
|
1692
|
+
origin: origin,
|
|
1693
|
+
scaleX: scaleX,
|
|
1694
|
+
scaleY: scaleY
|
|
1695
|
+
});
|
|
1696
|
+
if (check === false) return;
|
|
1548
1697
|
}
|
|
1549
|
-
data = Object.assign(Object.assign({}, data), {
|
|
1698
|
+
data = Object.assign(Object.assign({}, data), {
|
|
1699
|
+
target: target,
|
|
1700
|
+
editor: editor,
|
|
1701
|
+
worldOrigin: target.getWorldPoint(data.origin)
|
|
1702
|
+
});
|
|
1550
1703
|
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1551
1704
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1552
1705
|
this.editTool.onScaleWithDrag(event);
|
|
1553
1706
|
this.emitEvent(event);
|
|
1554
1707
|
}
|
|
1555
1708
|
scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
|
|
1556
|
-
if (!this.checkTransform(
|
|
1557
|
-
|
|
1558
|
-
const {
|
|
1559
|
-
const { beforeScale } = mergeConfig;
|
|
1709
|
+
if (!this.checkTransform("resizeable")) return;
|
|
1710
|
+
const {target: target, mergeConfig: mergeConfig, single: single, editor: editor} = this.editBox;
|
|
1711
|
+
const {beforeScale: beforeScale} = mergeConfig;
|
|
1560
1712
|
if (beforeScale) {
|
|
1561
|
-
const check = beforeScale({
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1713
|
+
const check = beforeScale({
|
|
1714
|
+
target: target,
|
|
1715
|
+
origin: origin,
|
|
1716
|
+
scaleX: scaleX,
|
|
1717
|
+
scaleY: scaleY
|
|
1718
|
+
});
|
|
1719
|
+
if (isObject(check)) scaleX = check.scaleX, scaleY = check.scaleY; else if (check === false) return;
|
|
1566
1720
|
}
|
|
1567
1721
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1568
1722
|
const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
|
|
1569
|
-
const data = {
|
|
1723
|
+
const data = {
|
|
1724
|
+
target: target,
|
|
1725
|
+
editor: editor,
|
|
1726
|
+
worldOrigin: worldOrigin,
|
|
1727
|
+
scaleX: scaleX,
|
|
1728
|
+
scaleY: scaleY,
|
|
1729
|
+
transform: transform
|
|
1730
|
+
};
|
|
1570
1731
|
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1571
1732
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1572
1733
|
this.doScale(event);
|
|
1573
1734
|
this.emitEvent(event);
|
|
1574
1735
|
}
|
|
1575
1736
|
flip(axis) {
|
|
1576
|
-
if (!this.checkTransform(
|
|
1577
|
-
|
|
1578
|
-
const
|
|
1579
|
-
const worldOrigin = this.getWorldOrigin('center');
|
|
1737
|
+
if (!this.checkTransform("resizeable")) return;
|
|
1738
|
+
const {target: target, single: single, editor: editor} = this.editBox;
|
|
1739
|
+
const worldOrigin = this.getWorldOrigin("center");
|
|
1580
1740
|
const transform = !single ? this.getChangedTransform(() => target.safeChange(() => target.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(target, axis));
|
|
1581
|
-
const data = {
|
|
1741
|
+
const data = {
|
|
1742
|
+
target: target,
|
|
1743
|
+
editor: editor,
|
|
1744
|
+
worldOrigin: worldOrigin,
|
|
1745
|
+
scaleX: axis === "x" ? -1 : 1,
|
|
1746
|
+
scaleY: axis === "y" ? -1 : 1,
|
|
1747
|
+
transform: transform
|
|
1748
|
+
};
|
|
1582
1749
|
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1583
1750
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1584
1751
|
this.doScale(event);
|
|
1585
1752
|
this.emitEvent(event);
|
|
1586
1753
|
}
|
|
1587
1754
|
rotateOf(origin, rotation) {
|
|
1588
|
-
if (!this.checkTransform(
|
|
1589
|
-
|
|
1590
|
-
const {
|
|
1591
|
-
const { beforeRotate } = mergeConfig;
|
|
1755
|
+
if (!this.checkTransform("rotateable")) return;
|
|
1756
|
+
const {target: target, mergeConfig: mergeConfig, single: single, editor: editor} = this.editBox;
|
|
1757
|
+
const {beforeRotate: beforeRotate} = mergeConfig;
|
|
1592
1758
|
if (beforeRotate) {
|
|
1593
|
-
const check = beforeRotate({
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1759
|
+
const check = beforeRotate({
|
|
1760
|
+
target: target,
|
|
1761
|
+
origin: origin,
|
|
1762
|
+
rotation: rotation
|
|
1763
|
+
});
|
|
1764
|
+
if (isNumber(check)) rotation = check; else if (check === false) return;
|
|
1598
1765
|
}
|
|
1599
1766
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1600
1767
|
const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
|
|
1601
|
-
const data = {
|
|
1768
|
+
const data = {
|
|
1769
|
+
target: target,
|
|
1770
|
+
editor: editor,
|
|
1771
|
+
worldOrigin: worldOrigin,
|
|
1772
|
+
rotation: rotation,
|
|
1773
|
+
transform: transform
|
|
1774
|
+
};
|
|
1602
1775
|
this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
|
|
1603
1776
|
const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
|
|
1604
1777
|
this.doRotate(event);
|
|
1605
1778
|
this.emitEvent(event);
|
|
1606
1779
|
}
|
|
1607
1780
|
skewOf(origin, skewX, skewY = 0, _resize) {
|
|
1608
|
-
if (!this.checkTransform(
|
|
1609
|
-
|
|
1610
|
-
const {
|
|
1611
|
-
const { beforeSkew } = mergeConfig;
|
|
1781
|
+
if (!this.checkTransform("skewable")) return;
|
|
1782
|
+
const {target: target, mergeConfig: mergeConfig, single: single, editor: editor} = this.editBox;
|
|
1783
|
+
const {beforeSkew: beforeSkew} = mergeConfig;
|
|
1612
1784
|
if (beforeSkew) {
|
|
1613
|
-
const check = beforeSkew({
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1785
|
+
const check = beforeSkew({
|
|
1786
|
+
target: target,
|
|
1787
|
+
origin: origin,
|
|
1788
|
+
skewX: skewX,
|
|
1789
|
+
skewY: skewY
|
|
1790
|
+
});
|
|
1791
|
+
if (isObject(check)) skewX = check.skewX, skewY = check.skewY; else if (check === false) return;
|
|
1618
1792
|
}
|
|
1619
1793
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1620
1794
|
const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
|
|
1621
|
-
const data = {
|
|
1795
|
+
const data = {
|
|
1796
|
+
target: target,
|
|
1797
|
+
editor: editor,
|
|
1798
|
+
worldOrigin: worldOrigin,
|
|
1799
|
+
skewX: skewX,
|
|
1800
|
+
skewY: skewY,
|
|
1801
|
+
transform: transform
|
|
1802
|
+
};
|
|
1622
1803
|
this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
|
|
1623
1804
|
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
|
|
1624
1805
|
this.doSkew(event);
|
|
@@ -1637,17 +1818,16 @@ class TransformTool {
|
|
|
1637
1818
|
this.editTool.onSkew(event);
|
|
1638
1819
|
}
|
|
1639
1820
|
checkTransform(type) {
|
|
1640
|
-
const { target, mergeConfig } = this.editBox;
|
|
1821
|
+
const {target: target, mergeConfig: mergeConfig} = this.editBox;
|
|
1641
1822
|
return target && !target.locked && mergeConfig[type];
|
|
1642
1823
|
}
|
|
1643
1824
|
getWorldOrigin(origin) {
|
|
1644
|
-
const { target
|
|
1825
|
+
const {target: target} = this.editBox;
|
|
1645
1826
|
return target.getWorldPoint(LeafHelper.getInnerOrigin(target, origin));
|
|
1646
1827
|
}
|
|
1647
1828
|
getChangedTransform(func) {
|
|
1648
|
-
const { target, single } = this.editBox;
|
|
1649
|
-
if (!single && !target.canChange)
|
|
1650
|
-
return target.changedTransform;
|
|
1829
|
+
const {target: target, single: single} = this.editBox;
|
|
1830
|
+
if (!single && !target.canChange) return target.changedTransform;
|
|
1651
1831
|
const oldMatrix = new Matrix(target.worldTransform);
|
|
1652
1832
|
func();
|
|
1653
1833
|
return new Matrix(target.worldTransform).divide(oldMatrix);
|
|
@@ -1658,21 +1838,55 @@ class TransformTool {
|
|
|
1658
1838
|
}
|
|
1659
1839
|
|
|
1660
1840
|
let Editor = class Editor extends Group {
|
|
1661
|
-
get list() {
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
get
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
get
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
get
|
|
1671
|
-
|
|
1841
|
+
get list() {
|
|
1842
|
+
return this.leafList.list;
|
|
1843
|
+
}
|
|
1844
|
+
get dragHoverExclude() {
|
|
1845
|
+
return [ this.editBox.rect ];
|
|
1846
|
+
}
|
|
1847
|
+
get editing() {
|
|
1848
|
+
return !!this.list.length;
|
|
1849
|
+
}
|
|
1850
|
+
get groupOpening() {
|
|
1851
|
+
return !!this.openedGroupList.length;
|
|
1852
|
+
}
|
|
1853
|
+
get multiple() {
|
|
1854
|
+
return this.list.length > 1;
|
|
1855
|
+
}
|
|
1856
|
+
get single() {
|
|
1857
|
+
return this.list.length === 1;
|
|
1858
|
+
}
|
|
1859
|
+
get dragPoint() {
|
|
1860
|
+
return this.editBox.dragPoint;
|
|
1861
|
+
}
|
|
1862
|
+
get dragging() {
|
|
1863
|
+
return this.editBox.dragging;
|
|
1864
|
+
}
|
|
1865
|
+
get gesturing() {
|
|
1866
|
+
return this.editBox.gesturing;
|
|
1867
|
+
}
|
|
1868
|
+
get moving() {
|
|
1869
|
+
return this.editBox.moving;
|
|
1870
|
+
}
|
|
1871
|
+
get resizing() {
|
|
1872
|
+
return this.editBox.resizing;
|
|
1873
|
+
}
|
|
1874
|
+
get rotating() {
|
|
1875
|
+
return this.editBox.rotating;
|
|
1876
|
+
}
|
|
1877
|
+
get skewing() {
|
|
1878
|
+
return this.editBox.skewing;
|
|
1879
|
+
}
|
|
1880
|
+
get element() {
|
|
1881
|
+
return this.multiple ? this.simulateTarget : this.list[0];
|
|
1882
|
+
}
|
|
1883
|
+
get buttons() {
|
|
1884
|
+
return this.editBox.buttons;
|
|
1885
|
+
}
|
|
1672
1886
|
constructor(userConfig, data) {
|
|
1673
1887
|
super(data);
|
|
1674
|
-
this.leafList = new LeafList
|
|
1675
|
-
this.openedGroupList = new LeafList
|
|
1888
|
+
this.leafList = new LeafList;
|
|
1889
|
+
this.openedGroupList = new LeafList;
|
|
1676
1890
|
this.simulateTarget = new SimulateElement(this);
|
|
1677
1891
|
this.editBox = new EditBox(this);
|
|
1678
1892
|
this.editToolList = {};
|
|
@@ -1680,12 +1894,10 @@ let Editor = class Editor extends Group {
|
|
|
1680
1894
|
this.editMask = new EditMask(this);
|
|
1681
1895
|
this.targetEventIds = [];
|
|
1682
1896
|
let mergedConfig = DataHelper.clone(config);
|
|
1683
|
-
if (userConfig)
|
|
1684
|
-
mergedConfig = DataHelper.default(userConfig, mergedConfig);
|
|
1897
|
+
if (userConfig) mergedConfig = DataHelper.default(userConfig, mergedConfig);
|
|
1685
1898
|
this.mergedConfig = this.config = mergedConfig;
|
|
1686
1899
|
this.addMany(this.editMask, this.selector, this.editBox);
|
|
1687
|
-
if (!Plugin.has(
|
|
1688
|
-
this.config.editSize = 'scale';
|
|
1900
|
+
if (!Plugin.has("resize")) this.config.editSize = "scale";
|
|
1689
1901
|
}
|
|
1690
1902
|
select(target) {
|
|
1691
1903
|
this.target = target;
|
|
@@ -1697,62 +1909,66 @@ let Editor = class Editor extends Group {
|
|
|
1697
1909
|
return this.leafList.has(item);
|
|
1698
1910
|
}
|
|
1699
1911
|
addItem(item) {
|
|
1700
|
-
if (!this.hasItem(item) && !item.locked)
|
|
1701
|
-
this.leafList.add(item), this.target = this.leafList.list;
|
|
1912
|
+
if (!this.hasItem(item) && !item.locked) this.leafList.add(item), this.target = this.leafList.list;
|
|
1702
1913
|
}
|
|
1703
1914
|
removeItem(item) {
|
|
1704
|
-
if (this.hasItem(item))
|
|
1705
|
-
this.leafList.remove(item), this.target = this.leafList.list;
|
|
1915
|
+
if (this.hasItem(item)) this.leafList.remove(item), this.target = this.leafList.list;
|
|
1706
1916
|
}
|
|
1707
1917
|
shiftItem(item) {
|
|
1708
1918
|
this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
|
|
1709
1919
|
}
|
|
1710
1920
|
update() {
|
|
1711
1921
|
if (this.editing) {
|
|
1712
|
-
if (!this.element.parent)
|
|
1713
|
-
|
|
1714
|
-
if (this.innerEditing)
|
|
1715
|
-
this.innerEditor.update();
|
|
1922
|
+
if (!this.element.parent) return this.cancel();
|
|
1923
|
+
if (this.innerEditing) this.innerEditor.update();
|
|
1716
1924
|
this.editTool.update();
|
|
1717
1925
|
this.selector.update();
|
|
1718
1926
|
}
|
|
1719
1927
|
}
|
|
1720
1928
|
updateEditBox() {
|
|
1721
|
-
if (this.multiple)
|
|
1722
|
-
simulate(this);
|
|
1929
|
+
if (this.multiple) simulate(this);
|
|
1723
1930
|
this.update();
|
|
1724
1931
|
}
|
|
1725
1932
|
updateEditTool() {
|
|
1933
|
+
this.unloadEditTool();
|
|
1934
|
+
if (this.editing) {
|
|
1935
|
+
const name = this.element.editOuter || "EditTool";
|
|
1936
|
+
const tool = this.editTool = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
|
|
1937
|
+
this.editBox.load();
|
|
1938
|
+
tool.load();
|
|
1939
|
+
this.update();
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
unloadEditTool() {
|
|
1726
1943
|
let tool = this.editTool;
|
|
1727
1944
|
if (tool) {
|
|
1728
1945
|
this.editBox.unload();
|
|
1729
1946
|
tool.unload();
|
|
1730
1947
|
this.editTool = null;
|
|
1731
1948
|
}
|
|
1732
|
-
if (this.editing) {
|
|
1733
|
-
const tag = this.element.editOuter || 'EditTool';
|
|
1734
|
-
tool = this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
|
|
1735
|
-
this.editBox.load();
|
|
1736
|
-
tool.load();
|
|
1737
|
-
this.update();
|
|
1738
|
-
}
|
|
1739
1949
|
}
|
|
1740
1950
|
getEditSize(_ui) {
|
|
1741
1951
|
return this.mergeConfig.editSize;
|
|
1742
1952
|
}
|
|
1743
|
-
onMove(_e) {
|
|
1744
|
-
onScale(_e) {
|
|
1745
|
-
onRotate(_e) {
|
|
1746
|
-
onSkew(_e) {
|
|
1747
|
-
move(_x, _y = 0) {
|
|
1748
|
-
scaleWithDrag(_data) {
|
|
1749
|
-
scaleOf(_origin, scaleX, _scaleY = scaleX, _resize) {
|
|
1750
|
-
flip(_axis) {
|
|
1751
|
-
rotateOf(_origin, _rotation) {
|
|
1752
|
-
skewOf(_origin, _skewX, _skewY = 0, _resize) {
|
|
1753
|
-
checkTransform(_type) {
|
|
1754
|
-
|
|
1755
|
-
|
|
1953
|
+
onMove(_e) {}
|
|
1954
|
+
onScale(_e) {}
|
|
1955
|
+
onRotate(_e) {}
|
|
1956
|
+
onSkew(_e) {}
|
|
1957
|
+
move(_x, _y = 0) {}
|
|
1958
|
+
scaleWithDrag(_data) {}
|
|
1959
|
+
scaleOf(_origin, scaleX, _scaleY = scaleX, _resize) {}
|
|
1960
|
+
flip(_axis) {}
|
|
1961
|
+
rotateOf(_origin, _rotation) {}
|
|
1962
|
+
skewOf(_origin, _skewX, _skewY = 0, _resize) {}
|
|
1963
|
+
checkTransform(_type) {
|
|
1964
|
+
return undefined;
|
|
1965
|
+
}
|
|
1966
|
+
getWorldOrigin(_origin) {
|
|
1967
|
+
return undefined;
|
|
1968
|
+
}
|
|
1969
|
+
getChangedTransform(_func) {
|
|
1970
|
+
return undefined;
|
|
1971
|
+
}
|
|
1756
1972
|
group(userGroup) {
|
|
1757
1973
|
if (this.multiple) {
|
|
1758
1974
|
this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
|
|
@@ -1762,7 +1978,7 @@ let Editor = class Editor extends Group {
|
|
|
1762
1978
|
return this.target;
|
|
1763
1979
|
}
|
|
1764
1980
|
ungroup() {
|
|
1765
|
-
const { list
|
|
1981
|
+
const {list: list} = this;
|
|
1766
1982
|
if (list.length) {
|
|
1767
1983
|
list.forEach(item => item.isBranch && this.emitGroupEvent(EditorGroupEvent.BEFORE_UNGROUP, item));
|
|
1768
1984
|
this.target = EditorHelper.ungroup(list);
|
|
@@ -1785,16 +2001,14 @@ let Editor = class Editor extends Group {
|
|
|
1785
2001
|
checkOpenedGroups() {
|
|
1786
2002
|
const opened = this.openedGroupList;
|
|
1787
2003
|
if (opened.length) {
|
|
1788
|
-
let { list
|
|
1789
|
-
if (this.editing)
|
|
1790
|
-
list = [], opened.forEach(item => this.list.every(leaf => !LeafHelper.hasParent(leaf, item)) && list.push(item));
|
|
2004
|
+
let {list: list} = opened;
|
|
2005
|
+
if (this.editing) list = [], opened.forEach(item => this.list.every(leaf => !LeafHelper.hasParent(leaf, item)) && list.push(item));
|
|
1791
2006
|
list.forEach(item => this.closeGroup(item));
|
|
1792
2007
|
}
|
|
1793
|
-
if (this.editing && !this.selector.dragging)
|
|
1794
|
-
this.checkDeepSelect();
|
|
2008
|
+
if (this.editing && !this.selector.dragging) this.checkDeepSelect();
|
|
1795
2009
|
}
|
|
1796
2010
|
checkDeepSelect() {
|
|
1797
|
-
let parent, { list
|
|
2011
|
+
let parent, {list: list} = this;
|
|
1798
2012
|
for (let i = 0; i < list.length; i++) {
|
|
1799
2013
|
parent = list[i].parent;
|
|
1800
2014
|
while (parent && !parent.hitChildren) {
|
|
@@ -1804,42 +2018,48 @@ let Editor = class Editor extends Group {
|
|
|
1804
2018
|
}
|
|
1805
2019
|
}
|
|
1806
2020
|
emitGroupEvent(type, group) {
|
|
1807
|
-
const event = new EditorGroupEvent(type, {
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
2021
|
+
const event = new EditorGroupEvent(type, {
|
|
2022
|
+
editTarget: group
|
|
2023
|
+
});
|
|
2024
|
+
if (!group || !group.syncEventer) this.emitEvent(event);
|
|
2025
|
+
if (group) group.emitEvent(event);
|
|
1811
2026
|
}
|
|
1812
|
-
openInnerEditor(target, select) {
|
|
1813
|
-
|
|
1814
|
-
|
|
2027
|
+
openInnerEditor(target, nameOrSelect, select) {
|
|
2028
|
+
let name;
|
|
2029
|
+
if (isString(nameOrSelect)) name = nameOrSelect; else if (!select) select = nameOrSelect;
|
|
2030
|
+
if (target && select) this.target = target;
|
|
1815
2031
|
if (this.single) {
|
|
1816
2032
|
const editTarget = target || this.element;
|
|
1817
|
-
|
|
1818
|
-
if (
|
|
2033
|
+
name || (name = editTarget.editInner);
|
|
2034
|
+
if (name && EditToolCreator.list[name]) {
|
|
1819
2035
|
this.editTool.unload();
|
|
1820
2036
|
this.innerEditing = true;
|
|
1821
|
-
this.innerEditor = this.editToolList[
|
|
2037
|
+
this.innerEditor = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
|
|
1822
2038
|
this.innerEditor.editTarget = editTarget;
|
|
1823
2039
|
this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN);
|
|
1824
2040
|
this.innerEditor.load();
|
|
1825
2041
|
this.emitInnerEvent(InnerEditorEvent.OPEN);
|
|
2042
|
+
console.log("hello");
|
|
1826
2043
|
}
|
|
1827
2044
|
}
|
|
1828
2045
|
}
|
|
1829
|
-
closeInnerEditor() {
|
|
2046
|
+
closeInnerEditor(onlyInnerEditor) {
|
|
1830
2047
|
if (this.innerEditing) {
|
|
1831
2048
|
this.innerEditing = false;
|
|
1832
2049
|
this.emitInnerEvent(InnerEditorEvent.BEFORE_CLOSE);
|
|
1833
2050
|
this.innerEditor.unload();
|
|
1834
2051
|
this.emitInnerEvent(InnerEditorEvent.CLOSE);
|
|
1835
|
-
this.
|
|
2052
|
+
if (!onlyInnerEditor) this.updateEditTool();
|
|
1836
2053
|
this.innerEditor = null;
|
|
1837
2054
|
}
|
|
1838
2055
|
}
|
|
1839
2056
|
emitInnerEvent(type) {
|
|
1840
|
-
const { innerEditor
|
|
1841
|
-
const event = new InnerEditorEvent(type, {
|
|
1842
|
-
|
|
2057
|
+
const {innerEditor: innerEditor} = this, {editTarget: editTarget} = innerEditor;
|
|
2058
|
+
const event = new InnerEditorEvent(type, {
|
|
2059
|
+
editTarget: editTarget,
|
|
2060
|
+
innerEditor: innerEditor
|
|
2061
|
+
});
|
|
2062
|
+
if (!editTarget.syncEventer) this.emitEvent(event);
|
|
1843
2063
|
editTarget.emitEvent(event);
|
|
1844
2064
|
}
|
|
1845
2065
|
lock() {
|
|
@@ -1863,35 +2083,23 @@ let Editor = class Editor extends Group {
|
|
|
1863
2083
|
}
|
|
1864
2084
|
}
|
|
1865
2085
|
onAppRenderStart(app) {
|
|
1866
|
-
if (this.targetChanged = app.children.some(leafer => leafer !== this.leafer && leafer.renderer.changed))
|
|
1867
|
-
this.editBox.forceRender();
|
|
2086
|
+
if (this.targetChanged = app.children.some(leafer => leafer !== this.leafer && leafer.renderer.changed)) this.editBox.forceRender();
|
|
1868
2087
|
}
|
|
1869
2088
|
onRenderStart() {
|
|
1870
|
-
if (this.targetChanged)
|
|
1871
|
-
this.update();
|
|
2089
|
+
if (this.targetChanged) this.update();
|
|
1872
2090
|
}
|
|
1873
2091
|
listenTargetEvents() {
|
|
1874
2092
|
if (!this.targetEventIds.length) {
|
|
1875
|
-
const { app, leafer, editMask } = this;
|
|
1876
|
-
this.targetEventIds = [
|
|
1877
|
-
|
|
1878
|
-
app.on_([
|
|
1879
|
-
[RenderEvent.CHILD_START, this.onAppRenderStart, this],
|
|
1880
|
-
[MoveEvent.BEFORE_MOVE, this.onMove, this, true],
|
|
1881
|
-
[ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
|
|
1882
|
-
[RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
|
|
1883
|
-
])
|
|
1884
|
-
];
|
|
1885
|
-
if (editMask.visible)
|
|
1886
|
-
editMask.forceRender();
|
|
2093
|
+
const {app: app, leafer: leafer, editMask: editMask} = this;
|
|
2094
|
+
this.targetEventIds = [ leafer.on_(RenderEvent.START, this.onRenderStart, this), app.on_(RenderEvent.CHILD_START, this.onAppRenderStart, this) ];
|
|
2095
|
+
if (editMask.visible) editMask.forceRender();
|
|
1887
2096
|
}
|
|
1888
2097
|
}
|
|
1889
2098
|
removeTargetEvents() {
|
|
1890
|
-
const { targetEventIds, editMask } = this;
|
|
2099
|
+
const {targetEventIds: targetEventIds, editMask: editMask} = this;
|
|
1891
2100
|
if (targetEventIds.length) {
|
|
1892
2101
|
this.off_(targetEventIds);
|
|
1893
|
-
if (editMask.visible)
|
|
1894
|
-
editMask.forceRender();
|
|
2102
|
+
if (editMask.visible) editMask.forceRender();
|
|
1895
2103
|
}
|
|
1896
2104
|
}
|
|
1897
2105
|
destroy() {
|
|
@@ -1905,64 +2113,64 @@ let Editor = class Editor extends Group {
|
|
|
1905
2113
|
}
|
|
1906
2114
|
}
|
|
1907
2115
|
};
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
__decorate([
|
|
1912
|
-
|
|
1913
|
-
], Editor.prototype, "
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
], Editor.prototype, "target", void 0);
|
|
1917
|
-
Editor = __decorate([
|
|
1918
|
-
useModule(TransformTool, ['editBox', 'editTool', 'emitEvent'])
|
|
1919
|
-
], Editor);
|
|
2116
|
+
|
|
2117
|
+
__decorate([ mergeConfigAttr() ], Editor.prototype, "mergeConfig", void 0);
|
|
2118
|
+
|
|
2119
|
+
__decorate([ targetAttr(onHover) ], Editor.prototype, "hoverTarget", void 0);
|
|
2120
|
+
|
|
2121
|
+
__decorate([ targetAttr(onTarget) ], Editor.prototype, "target", void 0);
|
|
2122
|
+
|
|
2123
|
+
Editor = __decorate([ useModule(TransformTool, [ "editBox", "editTool", "emitEvent" ]) ], Editor);
|
|
1920
2124
|
|
|
1921
2125
|
class InnerEditor {
|
|
1922
2126
|
static registerInnerEditor() {
|
|
1923
2127
|
EditToolCreator.register(this);
|
|
1924
2128
|
}
|
|
1925
|
-
get tag() {
|
|
1926
|
-
|
|
1927
|
-
|
|
2129
|
+
get tag() {
|
|
2130
|
+
return "InnerEditor";
|
|
2131
|
+
}
|
|
2132
|
+
get mode() {
|
|
2133
|
+
return "focus";
|
|
2134
|
+
}
|
|
2135
|
+
get editBox() {
|
|
2136
|
+
return this.editor.editBox;
|
|
2137
|
+
}
|
|
1928
2138
|
constructor(editor) {
|
|
1929
2139
|
this.eventIds = [];
|
|
1930
2140
|
this.editor = editor;
|
|
1931
2141
|
this.create();
|
|
1932
2142
|
}
|
|
1933
|
-
onCreate() {
|
|
2143
|
+
onCreate() {}
|
|
1934
2144
|
create() {
|
|
1935
|
-
this.view = new Group
|
|
2145
|
+
this.view = new Group;
|
|
1936
2146
|
this.onCreate();
|
|
1937
2147
|
}
|
|
1938
|
-
onLoad() {
|
|
2148
|
+
onLoad() {}
|
|
1939
2149
|
load() {
|
|
1940
|
-
const { editor
|
|
2150
|
+
const {editor: editor} = this;
|
|
1941
2151
|
if (editor) {
|
|
1942
|
-
if (editor.app && this.mode ===
|
|
1943
|
-
editor.selector.hittable = editor.app.tree.hitChildren = false;
|
|
2152
|
+
if (editor.app && this.mode === "focus") editor.selector.hittable = editor.app.tree.hitChildren = false;
|
|
1944
2153
|
this.onLoad();
|
|
1945
2154
|
}
|
|
1946
2155
|
}
|
|
1947
|
-
onUpdate() {
|
|
1948
|
-
update() {
|
|
1949
|
-
|
|
2156
|
+
onUpdate() {}
|
|
2157
|
+
update() {
|
|
2158
|
+
this.onUpdate();
|
|
2159
|
+
}
|
|
2160
|
+
onUnload() {}
|
|
1950
2161
|
unload() {
|
|
1951
|
-
const { editor
|
|
2162
|
+
const {editor: editor} = this;
|
|
1952
2163
|
if (editor) {
|
|
1953
|
-
if (editor.app && this.mode ===
|
|
1954
|
-
editor.selector.hittable = editor.app.tree.hitChildren = true;
|
|
2164
|
+
if (editor.app && this.mode === "focus") editor.selector.hittable = editor.app.tree.hitChildren = true;
|
|
1955
2165
|
this.onUnload();
|
|
1956
2166
|
}
|
|
1957
2167
|
}
|
|
1958
|
-
onDestroy() {
|
|
2168
|
+
onDestroy() {}
|
|
1959
2169
|
destroy() {
|
|
1960
2170
|
this.onDestroy();
|
|
1961
2171
|
if (this.editor) {
|
|
1962
|
-
if (this.view)
|
|
1963
|
-
|
|
1964
|
-
if (this.eventIds)
|
|
1965
|
-
this.editor.off_(this.eventIds);
|
|
2172
|
+
if (this.view) this.view.destroy();
|
|
2173
|
+
if (this.eventIds) this.editor.off_(this.eventIds);
|
|
1966
2174
|
this.editor = this.view = this.eventIds = null;
|
|
1967
2175
|
}
|
|
1968
2176
|
}
|
|
@@ -1972,50 +2180,45 @@ let EditTool = class EditTool extends InnerEditor {
|
|
|
1972
2180
|
static registerEditTool() {
|
|
1973
2181
|
EditToolCreator.register(this);
|
|
1974
2182
|
}
|
|
1975
|
-
get tag() {
|
|
2183
|
+
get tag() {
|
|
2184
|
+
return "EditTool";
|
|
2185
|
+
}
|
|
1976
2186
|
onMove(e) {
|
|
1977
|
-
const { moveX, moveY, editor } = e;
|
|
1978
|
-
const { app, list } = editor;
|
|
2187
|
+
const {moveX: moveX, moveY: moveY, editor: editor} = e;
|
|
2188
|
+
const {app: app, list: list} = editor;
|
|
1979
2189
|
app.lockLayout();
|
|
1980
|
-
list.forEach(target => {
|
|
2190
|
+
list.forEach(target => {
|
|
2191
|
+
target.moveWorld(moveX, moveY);
|
|
2192
|
+
});
|
|
1981
2193
|
app.unlockLayout();
|
|
1982
2194
|
}
|
|
1983
2195
|
onScale(e) {
|
|
1984
|
-
const { scaleX, scaleY, transform, worldOrigin, editor } = e;
|
|
1985
|
-
const { app, list } = editor;
|
|
2196
|
+
const {scaleX: scaleX, scaleY: scaleY, transform: transform, worldOrigin: worldOrigin, editor: editor} = e;
|
|
2197
|
+
const {app: app, list: list} = editor;
|
|
1986
2198
|
app.lockLayout();
|
|
1987
2199
|
list.forEach(target => {
|
|
1988
|
-
const resize = editor.getEditSize(target) !==
|
|
1989
|
-
if (transform)
|
|
1990
|
-
target.transformWorld(transform, resize);
|
|
1991
|
-
else
|
|
1992
|
-
target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize);
|
|
2200
|
+
const resize = editor.getEditSize(target) !== "scale";
|
|
2201
|
+
if (transform) target.transformWorld(transform, resize); else target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize);
|
|
1993
2202
|
});
|
|
1994
2203
|
app.unlockLayout();
|
|
1995
2204
|
}
|
|
1996
2205
|
onRotate(e) {
|
|
1997
|
-
const { rotation, transform, worldOrigin, editor } = e;
|
|
1998
|
-
const { app, list } = editor;
|
|
2206
|
+
const {rotation: rotation, transform: transform, worldOrigin: worldOrigin, editor: editor} = e;
|
|
2207
|
+
const {app: app, list: list} = editor;
|
|
1999
2208
|
app.lockLayout();
|
|
2000
2209
|
list.forEach(target => {
|
|
2001
|
-
const resize = editor.getEditSize(target) !==
|
|
2002
|
-
if (transform)
|
|
2003
|
-
target.transformWorld(transform, resize);
|
|
2004
|
-
else
|
|
2005
|
-
target.rotateOfWorld(worldOrigin, rotation);
|
|
2210
|
+
const resize = editor.getEditSize(target) !== "scale";
|
|
2211
|
+
if (transform) target.transformWorld(transform, resize); else target.rotateOfWorld(worldOrigin, rotation);
|
|
2006
2212
|
});
|
|
2007
2213
|
app.unlockLayout();
|
|
2008
2214
|
}
|
|
2009
2215
|
onSkew(e) {
|
|
2010
|
-
const { skewX, skewY, transform, worldOrigin, editor } = e;
|
|
2011
|
-
const { app, list } = editor;
|
|
2216
|
+
const {skewX: skewX, skewY: skewY, transform: transform, worldOrigin: worldOrigin, editor: editor} = e;
|
|
2217
|
+
const {app: app, list: list} = editor;
|
|
2012
2218
|
app.lockLayout();
|
|
2013
2219
|
list.forEach(target => {
|
|
2014
|
-
const resize = editor.getEditSize(target) !==
|
|
2015
|
-
if (transform)
|
|
2016
|
-
target.transformWorld(transform, resize);
|
|
2017
|
-
else
|
|
2018
|
-
target.skewOfWorld(worldOrigin, skewX, skewY, resize);
|
|
2220
|
+
const resize = editor.getEditSize(target) !== "scale";
|
|
2221
|
+
if (transform) target.transformWorld(transform, resize); else target.skewOfWorld(worldOrigin, skewX, skewY, resize);
|
|
2019
2222
|
});
|
|
2020
2223
|
app.unlockLayout();
|
|
2021
2224
|
}
|
|
@@ -2032,41 +2235,42 @@ let EditTool = class EditTool extends InnerEditor {
|
|
|
2032
2235
|
this.onUnload();
|
|
2033
2236
|
}
|
|
2034
2237
|
};
|
|
2035
|
-
EditTool = __decorate([
|
|
2036
|
-
registerEditTool()
|
|
2037
|
-
], EditTool);
|
|
2038
2238
|
|
|
2039
|
-
|
|
2040
|
-
|
|
2239
|
+
EditTool = __decorate([ registerEditTool() ], EditTool);
|
|
2240
|
+
|
|
2241
|
+
const {left: left, right: right} = Direction9;
|
|
2242
|
+
|
|
2243
|
+
const {move: move, copy: copy, toNumberPoints: toNumberPoints} = PointHelper;
|
|
2244
|
+
|
|
2041
2245
|
let LineEditTool = class LineEditTool extends EditTool {
|
|
2042
2246
|
constructor() {
|
|
2043
2247
|
super(...arguments);
|
|
2044
2248
|
this.scaleOfEvent = true;
|
|
2045
2249
|
}
|
|
2046
|
-
get tag() {
|
|
2250
|
+
get tag() {
|
|
2251
|
+
return "LineEditTool";
|
|
2252
|
+
}
|
|
2047
2253
|
onScaleWithDrag(e) {
|
|
2048
|
-
const { drag, direction, lockRatio, around } = e;
|
|
2254
|
+
const {drag: drag, direction: direction, lockRatio: lockRatio, around: around} = e;
|
|
2049
2255
|
const line = e.target;
|
|
2050
2256
|
const isDragFrom = direction === left;
|
|
2051
2257
|
if (line.pathInputed) {
|
|
2052
|
-
const { path
|
|
2053
|
-
const { from, to } = this.getFromToByPath(path);
|
|
2258
|
+
const {path: path} = line.__;
|
|
2259
|
+
const {from: from, to: to} = this.getFromToByPath(path);
|
|
2054
2260
|
this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
|
|
2055
2261
|
path[1] = from.x, path[2] = from.y;
|
|
2056
2262
|
path[4] = to.x, path[5] = to.y;
|
|
2057
2263
|
line.path = path;
|
|
2058
|
-
}
|
|
2059
|
-
|
|
2060
|
-
const {
|
|
2061
|
-
const { from, to } = this.getFromToByPoints(points);
|
|
2264
|
+
} else if (line.points) {
|
|
2265
|
+
const {points: points} = line;
|
|
2266
|
+
const {from: from, to: to} = this.getFromToByPoints(points);
|
|
2062
2267
|
this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
|
|
2063
2268
|
points[0] = from.x, points[1] = from.y;
|
|
2064
2269
|
points[2] = to.x, points[3] = to.y;
|
|
2065
2270
|
line.points = points;
|
|
2066
|
-
}
|
|
2067
|
-
else {
|
|
2271
|
+
} else {
|
|
2068
2272
|
const from = getPointData();
|
|
2069
|
-
const { toPoint
|
|
2273
|
+
const {toPoint: toPoint} = line;
|
|
2070
2274
|
line.rotation = 0;
|
|
2071
2275
|
this.dragPoint(from, toPoint, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
|
|
2072
2276
|
line.getLocalPointByInner(from, null, null, true);
|
|
@@ -2079,48 +2283,52 @@ let LineEditTool = class LineEditTool extends EditTool {
|
|
|
2079
2283
|
}
|
|
2080
2284
|
getInnerMove(ui, event, lockRatio) {
|
|
2081
2285
|
const movePoint = event.getInnerMove(ui);
|
|
2082
|
-
if (lockRatio)
|
|
2083
|
-
Math.abs(movePoint.x) > Math.abs(movePoint.y) ? movePoint.y = 0 : movePoint.x = 0;
|
|
2286
|
+
if (lockRatio) Math.abs(movePoint.x) > Math.abs(movePoint.y) ? movePoint.y = 0 : movePoint.x = 0;
|
|
2084
2287
|
return movePoint;
|
|
2085
2288
|
}
|
|
2086
2289
|
getFromToByPath(path) {
|
|
2087
2290
|
return {
|
|
2088
|
-
from: {
|
|
2089
|
-
|
|
2291
|
+
from: {
|
|
2292
|
+
x: path[1],
|
|
2293
|
+
y: path[2]
|
|
2294
|
+
},
|
|
2295
|
+
to: {
|
|
2296
|
+
x: path[4],
|
|
2297
|
+
y: path[5]
|
|
2298
|
+
}
|
|
2090
2299
|
};
|
|
2091
2300
|
}
|
|
2092
2301
|
getFromToByPoints(originPoints) {
|
|
2093
2302
|
const points = toNumberPoints(originPoints);
|
|
2094
2303
|
return {
|
|
2095
|
-
from: {
|
|
2096
|
-
|
|
2304
|
+
from: {
|
|
2305
|
+
x: points[0],
|
|
2306
|
+
y: points[1]
|
|
2307
|
+
},
|
|
2308
|
+
to: {
|
|
2309
|
+
x: points[2],
|
|
2310
|
+
y: points[3]
|
|
2311
|
+
}
|
|
2097
2312
|
};
|
|
2098
2313
|
}
|
|
2099
2314
|
dragPoint(fromPoint, toPoint, isDragFrom, around, movePoint) {
|
|
2100
|
-
const { x, y } = movePoint;
|
|
2315
|
+
const {x: x, y: y} = movePoint;
|
|
2101
2316
|
if (isDragFrom) {
|
|
2102
2317
|
move(fromPoint, x, y);
|
|
2103
|
-
if (around)
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
else {
|
|
2107
|
-
if (around)
|
|
2108
|
-
move(fromPoint, -x, -y);
|
|
2318
|
+
if (around) move(toPoint, -x, -y);
|
|
2319
|
+
} else {
|
|
2320
|
+
if (around) move(fromPoint, -x, -y);
|
|
2109
2321
|
move(toPoint, x, y);
|
|
2110
2322
|
}
|
|
2111
2323
|
}
|
|
2112
|
-
onSkew(_e) {
|
|
2113
|
-
}
|
|
2324
|
+
onSkew(_e) {}
|
|
2114
2325
|
onUpdate() {
|
|
2115
|
-
const { editBox
|
|
2326
|
+
const {editBox: editBox} = this, {rotatePoints: rotatePoints, resizeLines: resizeLines, resizePoints: resizePoints, rect: rect} = editBox;
|
|
2116
2327
|
const line = this.editor.element;
|
|
2117
2328
|
let fromTo, leftOrRight;
|
|
2118
|
-
if (line.pathInputed)
|
|
2119
|
-
fromTo = this.getFromToByPath(line.__.path);
|
|
2120
|
-
else if (line.points)
|
|
2121
|
-
fromTo = this.getFromToByPoints(line.__.points);
|
|
2329
|
+
if (line.pathInputed) fromTo = this.getFromToByPath(line.__.path); else if (line.points) fromTo = this.getFromToByPoints(line.__.points);
|
|
2122
2330
|
if (fromTo) {
|
|
2123
|
-
const { from, to } = fromTo;
|
|
2331
|
+
const {from: from, to: to} = fromTo;
|
|
2124
2332
|
line.innerToWorld(from, from, false, editBox);
|
|
2125
2333
|
line.innerToWorld(to, to, false, editBox);
|
|
2126
2334
|
rect.pen.clearPath().moveTo(from.x, from.y).lineTo(to.x, to.y);
|
|
@@ -2130,33 +2338,49 @@ let LineEditTool = class LineEditTool extends EditTool {
|
|
|
2130
2338
|
copy(rotatePoints[3], to);
|
|
2131
2339
|
}
|
|
2132
2340
|
for (let i = 0; i < 8; i++) {
|
|
2133
|
-
if (i < 4)
|
|
2134
|
-
resizeLines[i].visible = false;
|
|
2341
|
+
if (i < 4) resizeLines[i].visible = false;
|
|
2135
2342
|
leftOrRight = i === left || i === right;
|
|
2136
2343
|
resizePoints[i].visible = leftOrRight;
|
|
2137
2344
|
rotatePoints[i].visible = fromTo ? false : leftOrRight;
|
|
2138
2345
|
}
|
|
2139
2346
|
}
|
|
2140
2347
|
};
|
|
2141
|
-
LineEditTool = __decorate([
|
|
2142
|
-
registerEditTool()
|
|
2143
|
-
], LineEditTool);
|
|
2144
2348
|
|
|
2145
|
-
|
|
2146
|
-
|
|
2349
|
+
LineEditTool = __decorate([ registerEditTool() ], LineEditTool);
|
|
2350
|
+
|
|
2351
|
+
Plugin.add("editor", "resize");
|
|
2352
|
+
|
|
2353
|
+
Creator.editor = function(options, app) {
|
|
2147
2354
|
const editor = new Editor(options);
|
|
2148
|
-
if (app)
|
|
2149
|
-
app.sky.add(app.editor = editor);
|
|
2355
|
+
if (app) app.sky.add(app.editor = editor);
|
|
2150
2356
|
return editor;
|
|
2151
2357
|
};
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
UI.addAttr(
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2358
|
+
|
|
2359
|
+
Box.addAttr("textBox", false, dataType);
|
|
2360
|
+
|
|
2361
|
+
UI.addAttr("editConfig", undefined, dataType);
|
|
2362
|
+
|
|
2363
|
+
UI.addAttr("editOuter", ui => {
|
|
2364
|
+
ui.updateLayout();
|
|
2365
|
+
return ui.__.__isLinePath ? "LineEditTool" : "EditTool";
|
|
2366
|
+
}, dataType);
|
|
2367
|
+
|
|
2368
|
+
UI.addAttr("editInner", "PathEditor", dataType);
|
|
2369
|
+
|
|
2370
|
+
Group.addAttr("editInner", "", dataType);
|
|
2371
|
+
|
|
2372
|
+
Text.addAttr("editInner", "TextEditor", dataType);
|
|
2373
|
+
|
|
2374
|
+
UI.setEditConfig = function(config) {
|
|
2375
|
+
this.changeAttr("editConfig", config);
|
|
2376
|
+
};
|
|
2377
|
+
|
|
2378
|
+
UI.setEditOuter = function(toolName) {
|
|
2379
|
+
this.changeAttr("editOuter", toolName);
|
|
2380
|
+
};
|
|
2381
|
+
|
|
2382
|
+
UI.setEditInner = function(editorName) {
|
|
2383
|
+
this.changeAttr("editInner", editorName);
|
|
2384
|
+
};
|
|
2161
2385
|
|
|
2162
2386
|
export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, TransformTool, registerEditTool, registerInnerEditor };
|