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