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