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