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