@gedit/editor-2d 0.2.45 → 0.2.47
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/lib/browser/model/editor2d-document.d.ts +11 -2
- package/lib/browser/model/editor2d-document.d.ts.map +1 -1
- package/lib/browser/model/editor2d-document.js +44 -8
- package/lib/browser/model/editor2d-document.js.map +1 -1
- package/lib/browser/model/editor2d-model-container.d.ts.map +1 -1
- package/lib/browser/model/editor2d-model-container.js +1 -1
- package/lib/browser/model/editor2d-model-container.js.map +1 -1
- package/lib/browser/model/editor2d-model.d.ts +2 -0
- package/lib/browser/model/editor2d-model.d.ts.map +1 -1
- package/lib/browser/model/editor2d-model.js +5 -0
- package/lib/browser/model/editor2d-model.js.map +1 -1
- package/lib/browser/model/editor2d.d.ts +2 -0
- package/lib/browser/model/editor2d.d.ts.map +1 -1
- package/lib/browser/model/editor2d.js +4 -2
- package/lib/browser/model/editor2d.js.map +1 -1
- package/lib/browser/playground/canvas-draw.d.ts.map +1 -1
- package/lib/browser/playground/canvas-draw.js +30 -27
- package/lib/browser/playground/canvas-draw.js.map +1 -1
- package/lib/browser/playground/canvas-layer.d.ts +14 -2
- package/lib/browser/playground/canvas-layer.d.ts.map +1 -1
- package/lib/browser/playground/canvas-layer.js +96 -50
- package/lib/browser/playground/canvas-layer.js.map +1 -1
- package/lib/browser/playground/index.d.ts +2 -0
- package/lib/browser/playground/index.d.ts.map +1 -1
- package/lib/browser/playground/index.js +2 -0
- package/lib/browser/playground/index.js.map +1 -1
- package/lib/browser/playground/path-edit/index.d.ts +4 -0
- package/lib/browser/playground/path-edit/index.d.ts.map +1 -0
- package/lib/browser/playground/path-edit/index.js +20 -0
- package/lib/browser/playground/path-edit/index.js.map +1 -0
- package/lib/browser/playground/path-edit/path-edit-layer-move-point.d.ts +18 -0
- package/lib/browser/playground/path-edit/path-edit-layer-move-point.d.ts.map +1 -0
- package/lib/browser/playground/path-edit/path-edit-layer-move-point.js +52 -0
- package/lib/browser/playground/path-edit/path-edit-layer-move-point.js.map +1 -0
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.d.ts +21 -0
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.d.ts.map +1 -0
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.js +158 -0
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.js.map +1 -0
- package/lib/browser/playground/path-edit/utils.d.ts +37 -0
- package/lib/browser/playground/path-edit/utils.d.ts.map +1 -0
- package/lib/browser/playground/path-edit/utils.js +236 -0
- package/lib/browser/playground/path-edit/utils.js.map +1 -0
- package/lib/browser/playground/path-edit-layer.d.ts +32 -12
- package/lib/browser/playground/path-edit-layer.d.ts.map +1 -1
- package/lib/browser/playground/path-edit-layer.js +460 -146
- package/lib/browser/playground/path-edit-layer.js.map +1 -1
- package/lib/browser/playground/playground-context.d.ts +5 -2
- package/lib/browser/playground/playground-context.d.ts.map +1 -1
- package/lib/browser/playground/playground-context.js +13 -2
- package/lib/browser/playground/playground-context.js.map +1 -1
- package/lib/browser/playground/playground-contribution.d.ts +2 -1
- package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
- package/lib/browser/playground/playground-contribution.js +4 -21
- package/lib/browser/playground/playground-contribution.js.map +1 -1
- package/lib/browser/playground/selection-entity-manager.d.ts.map +1 -1
- package/lib/browser/playground/selection-entity-manager.js +24 -8
- package/lib/browser/playground/selection-entity-manager.js.map +1 -1
- package/lib/browser/playground/selector-extend-renderer.d.ts +2 -1
- package/lib/browser/playground/selector-extend-renderer.d.ts.map +1 -1
- package/lib/browser/playground/selector-extend-renderer.js +50 -21
- package/lib/browser/playground/selector-extend-renderer.js.map +1 -1
- package/lib/browser/utils/snapshot.d.ts +1 -0
- package/lib/browser/utils/snapshot.d.ts.map +1 -1
- package/lib/browser/utils/snapshot.js +11 -0
- package/lib/browser/utils/snapshot.js.map +1 -1
- package/package.json +9 -7
- package/src/browser/model/editor2d-document.ts +44 -6
- package/src/browser/model/editor2d-model-container.ts +2 -0
- package/src/browser/model/editor2d-model.ts +2 -0
- package/src/browser/model/editor2d.ts +4 -1
- package/src/browser/playground/canvas-draw.ts +30 -25
- package/src/browser/playground/canvas-layer.ts +97 -52
- package/src/browser/playground/index.ts +2 -0
- package/src/browser/playground/path-edit/index.ts +3 -0
- package/src/browser/playground/path-edit/path-edit-layer-move-point.tsx +108 -0
- package/src/browser/playground/path-edit/path-edit-layer-svg-path.tsx +283 -0
- package/src/browser/playground/path-edit/utils.tsx +285 -0
- package/src/browser/playground/path-edit-layer.tsx +563 -216
- package/src/browser/playground/playground-context.ts +7 -1
- package/src/browser/playground/playground-contribution.ts +2 -21
- package/src/browser/playground/selection-entity-manager.tsx +34 -6
- package/src/browser/playground/selector-extend-renderer.tsx +69 -37
- package/src/browser/style/path-edit-layer.less +17 -30
- package/src/browser/svg/pen_close.svg +24 -0
- package/src/browser/utils/snapshot.ts +11 -0
- package/lib/browser/playground/path-edit-layer-move-point.d.ts +0 -15
- package/lib/browser/playground/path-edit-layer-move-point.d.ts.map +0 -1
- package/lib/browser/playground/path-edit-layer-move-point.js +0 -47
- package/lib/browser/playground/path-edit-layer-move-point.js.map +0 -1
- package/lib/browser/playground/path-edit-layer-svg-path.d.ts +0 -11
- package/lib/browser/playground/path-edit-layer-svg-path.d.ts.map +0 -1
- package/lib/browser/playground/path-edit-layer-svg-path.js +0 -21
- package/lib/browser/playground/path-edit-layer-svg-path.js.map +0 -1
- package/src/browser/playground/path-edit-layer-move-point.tsx +0 -71
- package/src/browser/playground/path-edit-layer-svg-path.tsx +0 -50
|
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.PathEditLayer = void 0;
|
|
12
|
+
exports.PathEditLayer = exports.PathEditLayerEventContext = void 0;
|
|
13
13
|
const React = require("react");
|
|
14
14
|
const playground_1 = require("@gedit/playground");
|
|
15
15
|
const document_entity_1 = require("./entities/document-entity");
|
|
@@ -18,9 +18,8 @@ const render_engine_1 = require("@gedit/render-engine");
|
|
|
18
18
|
const tree_1 = require("@gedit/tree");
|
|
19
19
|
const canvas_draw_1 = require("@gedit/canvas-draw");
|
|
20
20
|
const utils_1 = require("@gedit/utils");
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const EDIT_PATH_STATE = 'ADD_PATH';
|
|
21
|
+
const path_edit_1 = require("./path-edit");
|
|
22
|
+
exports.PathEditLayerEventContext = React.createContext({});
|
|
24
23
|
/**
|
|
25
24
|
* 动态绘制层
|
|
26
25
|
*/
|
|
@@ -29,69 +28,272 @@ class PathEditLayer extends playground_1.Layer {
|
|
|
29
28
|
super(...arguments);
|
|
30
29
|
this.node = browser_1.domUtils.createDivWithClass('gedit-path-edit-layer');
|
|
31
30
|
}
|
|
31
|
+
get document() {
|
|
32
|
+
return this.documentEntity.config.document;
|
|
33
|
+
}
|
|
32
34
|
get isEnabled() {
|
|
33
|
-
return this.editorState.is(EDIT_PATH_STATE);
|
|
35
|
+
return this.editorState.is(playground_1.EditorState.EDIT_PATH_STATE.id);
|
|
34
36
|
}
|
|
35
37
|
onZoom(scale) {
|
|
36
38
|
browser_1.domUtils.setStyle(this.node, {
|
|
37
39
|
transform: `scale(${scale})`,
|
|
38
40
|
});
|
|
39
41
|
}
|
|
42
|
+
addDispose(disposable) {
|
|
43
|
+
this.toDispose.pushAll(disposable);
|
|
44
|
+
}
|
|
45
|
+
reNodeData() {
|
|
46
|
+
this.currentPathNode = undefined;
|
|
47
|
+
this.startPos = undefined;
|
|
48
|
+
this.pathPointSelection.clearSelection();
|
|
49
|
+
this.pathPointSelection.selectMode = playground_1.PathSelectMode.ADD_PATH;
|
|
50
|
+
}
|
|
51
|
+
updateNodeData() {
|
|
52
|
+
var _a;
|
|
53
|
+
const nodeData = (0, path_edit_1.updatePathNodeData)(this.currentPathNode);
|
|
54
|
+
(_a = this.document) === null || _a === void 0 ? void 0 : _a.updateNode(this.currentPathNode, nodeData, true);
|
|
55
|
+
}
|
|
56
|
+
// 选中的是第一个点
|
|
57
|
+
isOnePoint(point) {
|
|
58
|
+
var _a;
|
|
59
|
+
const { selection = [] } = this.pathPointSelection || {};
|
|
60
|
+
const { paths = [] } = ((_a = this.currentPathNode) === null || _a === void 0 ? void 0 : _a.path) || {};
|
|
61
|
+
const firstPoint = paths[0];
|
|
62
|
+
return point
|
|
63
|
+
? point.id === firstPoint.id
|
|
64
|
+
: selection.length === 1 && selection[0].pointId === firstPoint.id;
|
|
65
|
+
}
|
|
66
|
+
// 选中的是最后一点
|
|
67
|
+
isLastPoint(point) {
|
|
68
|
+
var _a;
|
|
69
|
+
const { selection = [] } = this.pathPointSelection || {};
|
|
70
|
+
const { paths = [] } = ((_a = this.currentPathNode) === null || _a === void 0 ? void 0 : _a.path) || {};
|
|
71
|
+
const lastPoint = paths[paths.length - 1];
|
|
72
|
+
return point
|
|
73
|
+
? point.id === lastPoint.id
|
|
74
|
+
: selection.length === 1 && selection[0].pointId === lastPoint.id;
|
|
75
|
+
}
|
|
76
|
+
getPointIsStartOrEnd(point) {
|
|
77
|
+
var _a;
|
|
78
|
+
const { selection = [] } = this.pathPointSelection || {};
|
|
79
|
+
const { paths = [] } = ((_a = this.currentPathNode) === null || _a === void 0 ? void 0 : _a.path) || {};
|
|
80
|
+
if (point) {
|
|
81
|
+
return (point.id === paths[0].id || point.id === paths[paths.length - 1].id);
|
|
82
|
+
}
|
|
83
|
+
return !!(
|
|
84
|
+
// 不是第一个或最后一个
|
|
85
|
+
(selection.length === 1 &&
|
|
86
|
+
(selection[0].pointId === paths[0].id ||
|
|
87
|
+
selection[0].pointId === paths[paths.length - 1].id)));
|
|
88
|
+
}
|
|
40
89
|
onReady() {
|
|
41
90
|
var _a;
|
|
42
91
|
this.toDispose.pushAll([
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// 如果只有一个点代表绘制不成功,则删除
|
|
49
|
-
/* if (
|
|
50
|
-
!this.currentPathNode.path ||
|
|
51
|
-
(this.currentPathNode.path &&
|
|
52
|
-
this.currentPathNode.path.paths.length <= 1)
|
|
53
|
-
) {
|
|
54
|
-
this.document?.delNode(this.currentPathNode);
|
|
55
|
-
} */
|
|
56
|
-
this.selectId = undefined;
|
|
57
|
-
this.currentPathNode = undefined;
|
|
92
|
+
this.context.historyService.onHistoryBack(e => {
|
|
93
|
+
this.reNodeData();
|
|
94
|
+
this.pathPointSelection.selectMode = playground_1.PathSelectMode.ADD_PATH;
|
|
95
|
+
this.pathPointSelection.clearSelection();
|
|
96
|
+
this.editorState.toDefaultState();
|
|
58
97
|
}),
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
98
|
+
this.editorState.onStateChange(() => {
|
|
99
|
+
var _a;
|
|
100
|
+
/**
|
|
101
|
+
* 1. 不是路径编辑状态时,清空数据
|
|
102
|
+
* 2. 是路径编辑状态时
|
|
103
|
+
* - 1.有选中节点时,设置当前节点为选中节点;选中最后一个点
|
|
104
|
+
* -- 1. 闭合路程径时,切换到区域与贝赛尔点选择模式;
|
|
105
|
+
* -- 2. 非闭合路径时,切换编辑模式;
|
|
106
|
+
* - 2. 未选中时节点时, 设置编辑模式;
|
|
107
|
+
*/
|
|
108
|
+
if (!this.isEnabled) {
|
|
109
|
+
this.reNodeData();
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
if (!this.pathPointSelection) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const selectNodes = ((_a = this.document) === null || _a === void 0 ? void 0 : _a.getSelectedNodes()) || [];
|
|
116
|
+
if (selectNodes.length &&
|
|
117
|
+
selectNodes[0].displayType === render_engine_1.GameObjectBaseType.PATH) {
|
|
118
|
+
// 选中一个 path 路径时;
|
|
119
|
+
this.currentPathNode = selectNodes[0];
|
|
120
|
+
const selectionNode = [
|
|
121
|
+
{
|
|
122
|
+
pointId: this.currentPathNode.path.paths[this.currentPathNode.path.paths.length - 1].id,
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
this.currentPathNode.path.closed
|
|
126
|
+
? this.pathPointSelection.enterSelectBezierMode(selectionNode)
|
|
127
|
+
: this.pathPointSelection.enterPathMode(selectionNode);
|
|
128
|
+
}
|
|
129
|
+
else if (!selectNodes.length) {
|
|
130
|
+
// 未选中时,清空数据
|
|
131
|
+
this.pathPointSelection.selectMode = playground_1.PathSelectMode.ADD_PATH;
|
|
132
|
+
}
|
|
66
133
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
134
|
+
}),
|
|
135
|
+
// 区域选择点模式
|
|
136
|
+
this.selectorConfig.onConfigChanged(() => {
|
|
69
137
|
var _a;
|
|
70
|
-
if (this.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
138
|
+
if (!this.pathPointSelection) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (this.pathPointSelection.selectMode !== playground_1.PathSelectMode.ADD_PATH) {
|
|
142
|
+
const selectBound = this.selectorConfig.toRectangle(this.config.finalScale);
|
|
143
|
+
const { paths = [], closed } = ((_a = this.currentPathNode) === null || _a === void 0 ? void 0 : _a.path) || {};
|
|
144
|
+
const pathSelects = [];
|
|
145
|
+
paths.forEach(p => {
|
|
146
|
+
const { x: $x, y: $y } = p;
|
|
147
|
+
const x = $x + this.currentPathNode.position.x;
|
|
148
|
+
const y = $y + this.currentPathNode.position.y;
|
|
149
|
+
const wh = (4 / this.config.finalScale) * 2;
|
|
150
|
+
if (x >= selectBound.x && // 左
|
|
151
|
+
x + wh <= selectBound.x + selectBound.width && // 右
|
|
152
|
+
y >= selectBound.y && // 上
|
|
153
|
+
y + wh <= selectBound.y + selectBound.height // 下
|
|
154
|
+
) {
|
|
155
|
+
pathSelects.push({
|
|
156
|
+
pointId: p.id,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
this.pathPointSelection.selection = pathSelects;
|
|
161
|
+
// 闭合路径的,切到选择加贝赛点模式;
|
|
162
|
+
if (closed) {
|
|
163
|
+
this.pathPointSelection.selectMode = playground_1.PathSelectMode.SELECT_BEZIER;
|
|
164
|
+
}
|
|
165
|
+
// this.pathPointSelection.enterSelectMode(pathSelects);
|
|
79
166
|
}
|
|
80
167
|
}),
|
|
81
|
-
|
|
82
|
-
|
|
168
|
+
// 退出路径编辑
|
|
169
|
+
/* this.editorState.onCancel(EDIT_PATH_STATE, () => {
|
|
170
|
+
console.log('sdfsd');
|
|
171
|
+
/* if (!this.currentPathNode) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// 如果只有一个点代表绘制不成功,则删除
|
|
175
|
+
/* if (
|
|
176
|
+
!this.currentPathNode.path ||
|
|
177
|
+
(this.currentPathNode.path &&
|
|
178
|
+
this.currentPathNode.path.paths.length <= 1)
|
|
179
|
+
) {
|
|
180
|
+
this.document?.delNode(this.currentPathNode);
|
|
181
|
+
}
|
|
182
|
+
this.reNodeData();
|
|
183
|
+
}), */
|
|
184
|
+
// 画布新增点点击事件;
|
|
185
|
+
this.listenPlaygroundEvent('mousedown', (event) => {
|
|
186
|
+
// 只在左键点击时绘制
|
|
187
|
+
if (event.buttons !== 1) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
this.startDrag(event.clientX, event.clientY, {
|
|
191
|
+
onDragStart: e => {
|
|
192
|
+
var _a, _b, _c;
|
|
193
|
+
// 当前编辑模式为路径编辑
|
|
194
|
+
if (this.editorState.is(playground_1.EditorState.EDIT_PATH_STATE.id)) {
|
|
195
|
+
const { selectMode } = this.pathPointSelection || {};
|
|
196
|
+
/**
|
|
197
|
+
* 拦截画布点击事件,不处理绘制;
|
|
198
|
+
* 1. 闭合路径时;
|
|
199
|
+
* 2. 带区域选择模式时;
|
|
200
|
+
* 3. 多点选择时;
|
|
201
|
+
*/
|
|
202
|
+
if (
|
|
203
|
+
// 判断当前 select 是否 path 路径
|
|
204
|
+
(this.currentPathNode && this.currentPathNode.path.closed) ||
|
|
205
|
+
selectMode !== playground_1.PathSelectMode.ADD_PATH ||
|
|
206
|
+
(((_a = this.pathPointSelection) === null || _a === void 0 ? void 0 : _a.selection) &&
|
|
207
|
+
this.pathPointSelection.selection.length > 1)) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const { position = { x: 0, y: 0 } } = this.currentPathNode || {};
|
|
211
|
+
this.startPos = {
|
|
212
|
+
x: (0, canvas_draw_1.toFixedValue)(e.endPos.x / (((_b = this.config) === null || _b === void 0 ? void 0 : _b.finalScale) || 1) - position.x, 4),
|
|
213
|
+
y: (0, canvas_draw_1.toFixedValue)(e.endPos.y / (((_c = this.config) === null || _c === void 0 ? void 0 : _c.finalScale) || 1) - position.y, 4),
|
|
214
|
+
}; // this.getPosFromMouseEvent(e);
|
|
215
|
+
this.startPos.id = (0, utils_1.generateUuid)();
|
|
216
|
+
this.startPos.type = canvas_draw_1.PATH_FUNC_TYPE.STRAIGHT;
|
|
217
|
+
this.initPath(this.startPos);
|
|
218
|
+
this.pathPointSelection.enterPathMode([
|
|
219
|
+
{
|
|
220
|
+
pointId: this.startPos.id,
|
|
221
|
+
},
|
|
222
|
+
]);
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
onDrag: e => {
|
|
226
|
+
var _a, _b;
|
|
227
|
+
if (!this.startPos) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
// const pos = this.getPosFromMouseEvent(e);
|
|
231
|
+
const { position = { x: 0, y: 0 }, path } = this.currentPathNode || {};
|
|
232
|
+
const x = e.endPos.x / (((_a = this.config) === null || _a === void 0 ? void 0 : _a.finalScale) || 1) - position.x;
|
|
233
|
+
const y = e.endPos.y / (((_b = this.config) === null || _b === void 0 ? void 0 : _b.finalScale) || 1) - position.y;
|
|
234
|
+
const pathNode = path === null || path === void 0 ? void 0 : path.paths.find(c => { var _a; return c.id === ((_a = this.startPos) === null || _a === void 0 ? void 0 : _a.id); });
|
|
235
|
+
// 生成贝赛尔点;
|
|
236
|
+
if (pathNode &&
|
|
237
|
+
Math.max(Math.abs(x - this.startPos.x), Math.abs(y - this.startPos.y)) >= 5) {
|
|
238
|
+
const x1 = pathNode.x * 2 - x;
|
|
239
|
+
const y1 = pathNode.y * 2 - y;
|
|
240
|
+
const reverse = this.isOnePoint();
|
|
241
|
+
pathNode.x2 = (0, canvas_draw_1.toFixedValue)(reverse ? x1 : x, 4);
|
|
242
|
+
pathNode.y2 = (0, canvas_draw_1.toFixedValue)(reverse ? y1 : y, 4);
|
|
243
|
+
pathNode.x1 = (0, canvas_draw_1.toFixedValue)(reverse ? x : x1, 4);
|
|
244
|
+
pathNode.y1 = (0, canvas_draw_1.toFixedValue)(reverse ? y : y1, 4);
|
|
245
|
+
pathNode.type = canvas_draw_1.PATH_FUNC_TYPE.EQUAL;
|
|
246
|
+
// console.log(this.startPos, path?.paths);
|
|
247
|
+
this.updateNodeData();
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
onDragEnd: () => {
|
|
251
|
+
this.startPos = undefined;
|
|
252
|
+
},
|
|
253
|
+
});
|
|
83
254
|
}),
|
|
84
255
|
// 图层发生变化时退出模式
|
|
85
256
|
(_a = this.selectionService) === null || _a === void 0 ? void 0 : _a.onSelectionChanged(e => {
|
|
86
257
|
var _a;
|
|
87
|
-
|
|
258
|
+
const { isEnabled, pathPointSelection } = this;
|
|
259
|
+
if (isEnabled) {
|
|
260
|
+
if (!pathPointSelection) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
// 选中的是 path 路径时
|
|
88
264
|
const selectNodes = ((_a = this.document) === null || _a === void 0 ? void 0 : _a.getSelectedNodes()) || [];
|
|
265
|
+
if (selectNodes.length === 1 &&
|
|
266
|
+
selectNodes[0].displayType === render_engine_1.GameObjectBaseType.PATH) {
|
|
267
|
+
// 选中一个 path 路径
|
|
268
|
+
if (!this.currentPathNode ||
|
|
269
|
+
selectNodes[0].id !== this.currentPathNode.id) {
|
|
270
|
+
// 选中的不是当前的 path 路径, 切换 currentPathNode;
|
|
271
|
+
this.currentPathNode = selectNodes[0];
|
|
272
|
+
const selectionNode = [
|
|
273
|
+
{
|
|
274
|
+
pointId: this.currentPathNode.path.paths[this.currentPathNode.path.paths.length - 1].id,
|
|
275
|
+
},
|
|
276
|
+
];
|
|
277
|
+
// 切换时先选中最后一个点
|
|
278
|
+
this.currentPathNode.path.closed
|
|
279
|
+
? pathPointSelection.enterSelectBezierMode(selectionNode)
|
|
280
|
+
: pathPointSelection.enterPathMode(selectionNode);
|
|
281
|
+
}
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
89
284
|
if (selectNodes.length &&
|
|
90
285
|
(selectNodes[0].displayType !== render_engine_1.GameObjectBaseType.PATH ||
|
|
91
286
|
selectNodes.length !== 1)) {
|
|
287
|
+
// 选中多个或者选中的不是 path 路径,退出路径编辑,切换到默认模式;
|
|
92
288
|
this.editorState.toDefaultState();
|
|
289
|
+
return;
|
|
93
290
|
}
|
|
94
291
|
}
|
|
292
|
+
this.reNodeData();
|
|
293
|
+
}),
|
|
294
|
+
// path point 选择变化;
|
|
295
|
+
this.pathPointSelection.onSelectionChanged(e => {
|
|
296
|
+
this.draw();
|
|
95
297
|
}),
|
|
96
298
|
]);
|
|
97
299
|
}
|
|
@@ -99,122 +301,224 @@ class PathEditLayer extends playground_1.Layer {
|
|
|
99
301
|
* 创建路径
|
|
100
302
|
* @param pos - 当前鼠标点击的位置
|
|
101
303
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (!this.document)
|
|
304
|
+
initPath(pos) {
|
|
305
|
+
if (!this.document) {
|
|
105
306
|
return;
|
|
106
|
-
// 判断当前 select 是否 path 路径
|
|
107
|
-
const selectedNodes = ((_a = this.document) === null || _a === void 0 ? void 0 : _a.getSelectedNodes()) || [];
|
|
108
|
-
if (selectedNodes.length === 1 && selectedNodes[0].displayType === 'path') {
|
|
109
|
-
this.currentPathNode = selectedNodes[0];
|
|
110
307
|
}
|
|
111
|
-
//
|
|
308
|
+
// 没有选中节点,点击画布时,创建一个新节点;
|
|
112
309
|
if (!this.currentPathNode) {
|
|
113
|
-
this.currentPathNode = this.document.createDisplayNode(render_engine_1.GameObjectBaseType.PATH);
|
|
310
|
+
this.currentPathNode = this.document.createDisplayNode(render_engine_1.GameObjectBaseType.PATH, undefined, { x: 0, y: 0 });
|
|
114
311
|
this.currentPathNode.selected = true;
|
|
312
|
+
this.context.selection.clearSelection();
|
|
115
313
|
this.context.selection.addSelection({
|
|
116
314
|
node: this.currentPathNode,
|
|
117
315
|
type: tree_1.TreeSelection.SelectionType.TOGGLE,
|
|
118
316
|
});
|
|
119
317
|
}
|
|
120
|
-
this.
|
|
121
|
-
this.currentPathNode.path.paths.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
path
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
); */
|
|
318
|
+
this.currentPathNode.path.paths = this.currentPathNode.path.paths || []; // array 会被复用,复制一个,保证不会被修改
|
|
319
|
+
if (this.isOnePoint() && this.currentPathNode.path.paths.length > 1) {
|
|
320
|
+
// 第一帧
|
|
321
|
+
this.currentPathNode.path.paths.unshift(pos);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
this.currentPathNode.path.paths.push(pos);
|
|
325
|
+
}
|
|
326
|
+
// 创建时坐标是 0, 需要换线更新坐标;
|
|
327
|
+
setTimeout(() => {
|
|
328
|
+
this.updateNodeData();
|
|
329
|
+
});
|
|
133
330
|
}
|
|
134
|
-
|
|
135
|
-
|
|
331
|
+
onBezierPointMove(pos) {
|
|
332
|
+
const { key, path: p } = this.bezierStartPos;
|
|
333
|
+
const { path = { paths: [] } } = this.currentPathNode || {};
|
|
334
|
+
const pathNode = path.paths.find(c => c.id === p.id);
|
|
335
|
+
if (!pathNode || !this.currentPathNode) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
(0, path_edit_1.setBezierMovePoint)(pathNode, key, pos);
|
|
339
|
+
this.updateNodeData();
|
|
136
340
|
}
|
|
137
341
|
onBezierPointMouseDown(e, p, key) {
|
|
342
|
+
if (e.buttons !== 1) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
138
345
|
e.preventDefault();
|
|
139
346
|
e.stopPropagation();
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
347
|
+
const pos = this.getPosFromMouseEvent(e);
|
|
348
|
+
this.bezierStartPos = {
|
|
349
|
+
x: pos.x,
|
|
350
|
+
y: pos.y,
|
|
351
|
+
key,
|
|
352
|
+
path: p,
|
|
353
|
+
};
|
|
354
|
+
this.pathPointSelection.enterSelectBezierMode([
|
|
355
|
+
{
|
|
356
|
+
pointId: p.id,
|
|
357
|
+
bezierKey: key,
|
|
358
|
+
},
|
|
359
|
+
]);
|
|
143
360
|
this.startDrag(e.clientX, e.clientY, {
|
|
144
|
-
|
|
145
|
-
onDrag(dragEvent) {
|
|
361
|
+
onDrag: e => {
|
|
146
362
|
var _a, _b;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
if (typeof p.x2 === 'number') {
|
|
154
|
-
p.x2 = p.x2 - p.x + x;
|
|
363
|
+
if (this.bezierStartPos) {
|
|
364
|
+
const { position = { x: 0, y: 0 } } = this.currentPathNode || {};
|
|
365
|
+
const x = e.endPos.x / (((_a = this.config) === null || _a === void 0 ? void 0 : _a.finalScale) || 1) - position.x;
|
|
366
|
+
const y = e.endPos.y / (((_b = this.config) === null || _b === void 0 ? void 0 : _b.finalScale) || 1) - position.y;
|
|
367
|
+
this.onBezierPointMove({ x, y });
|
|
155
368
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (typeof p.y2 === 'number') {
|
|
160
|
-
p.y2 = p.y2 - p.y + y;
|
|
161
|
-
}
|
|
162
|
-
p.x = x;
|
|
163
|
-
p.y = y;
|
|
164
|
-
document.updateNode(node, {}, true);
|
|
369
|
+
},
|
|
370
|
+
onDragEnd: () => {
|
|
371
|
+
this.bezierStartPos = undefined;
|
|
165
372
|
},
|
|
166
373
|
});
|
|
167
|
-
this.currentPointId = p.id;
|
|
168
|
-
e.preventDefault();
|
|
169
|
-
e.stopPropagation();
|
|
170
|
-
}
|
|
171
|
-
onHideMovePoint() {
|
|
172
|
-
this.hideMovePoint = true;
|
|
173
374
|
this.draw();
|
|
174
375
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
this.
|
|
376
|
+
// 注册 playground 事件
|
|
377
|
+
onSceneAddEvent(e, cb, toDispose) {
|
|
378
|
+
const event = this.listenPlaygroundEvent(e, cb);
|
|
379
|
+
if (toDispose) {
|
|
380
|
+
this.toDispose.push(event);
|
|
381
|
+
}
|
|
382
|
+
return event;
|
|
178
383
|
}
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
return
|
|
384
|
+
onPointMouseDown(e, currentPoint) {
|
|
385
|
+
if (e.buttons !== 1) {
|
|
386
|
+
return;
|
|
182
387
|
}
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (!this.currentPointId) {
|
|
188
|
-
points.push(paths[paths.length - 1]);
|
|
388
|
+
// 如果在 selection 里拖动所有点, 没有则切换当前 selection 里的点
|
|
389
|
+
const { pathPointSelection } = this;
|
|
390
|
+
if (!pathPointSelection) {
|
|
391
|
+
return;
|
|
189
392
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
393
|
+
let selection = (pathPointSelection === null || pathPointSelection === void 0 ? void 0 : pathPointSelection.selection) || [];
|
|
394
|
+
const node = this.currentPathNode;
|
|
395
|
+
const selectionNode = [
|
|
396
|
+
{
|
|
397
|
+
pointId: currentPoint.id,
|
|
398
|
+
},
|
|
399
|
+
];
|
|
400
|
+
/**
|
|
401
|
+
* 1. 选中一个点时;更新 selection;
|
|
402
|
+
* - 1. 选中的是第一个点或最后一个点时,切换到编辑模式;
|
|
403
|
+
* - 2. 选中的是中间点时,切换到区域选择加贝赛尔点模式;
|
|
404
|
+
* - 3. 关闭路径时,切换到区域选择加贝赛尔点模式;
|
|
405
|
+
* 2. 选中多个点时;
|
|
406
|
+
* - 1. 在选择器里时,不更新 selection,切换到区域选择加贝赛尔点模式;
|
|
407
|
+
* - 2. 不在选择器里时, 更新 selection;
|
|
408
|
+
* -- 1. 选中的是第一个点或最后一个点时,切换到编辑模式;
|
|
409
|
+
* --- 1. 闭合路径时,切换到区域选择加贝赛尔点模式;
|
|
410
|
+
* --- 2. 非闭合路径时,切换到编辑模式;
|
|
411
|
+
* -- 2. 选中的是中间点时,切换到区域选择加贝赛尔点模式;
|
|
412
|
+
*/
|
|
413
|
+
const isStartOrEnd = this.getPointIsStartOrEnd(currentPoint);
|
|
414
|
+
if (selection.length === 1) {
|
|
415
|
+
if (isStartOrEnd && !node.path.closed) {
|
|
416
|
+
pathPointSelection.enterPathMode(selectionNode);
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
pathPointSelection.enterSelectBezierMode(selectionNode);
|
|
420
|
+
}
|
|
193
421
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
transform: `translate(${p.x}px, ${p.y}px) rotate(${((0, canvas_draw_1.asVec)({ x: p.x1 || 0, y: p.y1 || 0 }, p).ang / Math.PI) * 180}deg)`,
|
|
199
|
-
} }), React.createElement("div", { key: `x1_${i}`, className: "gedit-path-edit-layer-point-bezier", style: {
|
|
200
|
-
transform: `translate(${p.x1}px, ${p.y1}px) scale(${1 / this.config.finalScale})`,
|
|
201
|
-
}, onMouseDown: e => {
|
|
202
|
-
this.onBezierPointMouseDown(e, p, '1');
|
|
203
|
-
}, onMouseEnter: this.onHideMovePoint.bind(this), onMouseLeave: this.onShowMovePoint.bind(this) }));
|
|
422
|
+
else {
|
|
423
|
+
const inSelection = selection.some(c => c.pointId === currentPoint.id);
|
|
424
|
+
if (inSelection) {
|
|
425
|
+
pathPointSelection.selectMode = playground_1.PathSelectMode.SELECT_BEZIER;
|
|
204
426
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
427
|
+
else {
|
|
428
|
+
if ((isStartOrEnd && node.path.closed) || !isStartOrEnd) {
|
|
429
|
+
pathPointSelection.enterSelectBezierMode(selectionNode);
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
pathPointSelection.enterPathMode(selectionNode);
|
|
433
|
+
}
|
|
212
434
|
}
|
|
435
|
+
}
|
|
436
|
+
this.config.finalScale;
|
|
437
|
+
const startNodeClone = (0, utils_1.deepClone)(node.path.paths);
|
|
438
|
+
this.startDrag(e.clientX, e.clientY, {
|
|
439
|
+
// 拖动
|
|
440
|
+
onDrag: dragEvent => {
|
|
441
|
+
var _a, _b;
|
|
442
|
+
selection = (pathPointSelection === null || pathPointSelection === void 0 ? void 0 : pathPointSelection.selection) || [];
|
|
443
|
+
const { position = { x: 0, y: 0 } } = node;
|
|
444
|
+
const selectionNodes = selection
|
|
445
|
+
.map(s => node.path.paths.find(p => p.id === s.pointId))
|
|
446
|
+
.filter(c => c);
|
|
447
|
+
const delta = selectionNodes.map(c => {
|
|
448
|
+
const point = node.path.paths.find(p => p.id === c.id);
|
|
449
|
+
const current = node.path.paths.find(p => p.id === currentPoint.id);
|
|
450
|
+
if (point.id === currentPoint.id) {
|
|
451
|
+
return { x: 0, y: 0 };
|
|
452
|
+
}
|
|
453
|
+
return {
|
|
454
|
+
x: point.x - current.x,
|
|
455
|
+
y: point.y - current.y,
|
|
456
|
+
};
|
|
457
|
+
});
|
|
458
|
+
const startNode = selectionNodes.map((s) => startNodeClone.find((c) => c.id === s.id));
|
|
459
|
+
const x = dragEvent.endPos.x / (((_a = this.config) === null || _a === void 0 ? void 0 : _a.finalScale) || 1) - position.x;
|
|
460
|
+
const y = dragEvent.endPos.y / (((_b = this.config) === null || _b === void 0 ? void 0 : _b.finalScale) || 1) - position.y;
|
|
461
|
+
selectionNodes.forEach((p, i) => {
|
|
462
|
+
const start = startNode[i];
|
|
463
|
+
const d = delta[i];
|
|
464
|
+
const deltaX = x - start.x + d.x;
|
|
465
|
+
const deltaY = y - start.y + d.y;
|
|
466
|
+
if (typeof p.x1 === 'number') {
|
|
467
|
+
p.x1 = (0, canvas_draw_1.toFixedValue)(start.x1 + deltaX, 4);
|
|
468
|
+
}
|
|
469
|
+
if (typeof p.x2 === 'number') {
|
|
470
|
+
p.x2 = (0, canvas_draw_1.toFixedValue)(start.x2 + deltaX, 4);
|
|
471
|
+
}
|
|
472
|
+
if (typeof p.y1 === 'number') {
|
|
473
|
+
p.y1 = (0, canvas_draw_1.toFixedValue)(start.y1 + deltaY, 4);
|
|
474
|
+
}
|
|
475
|
+
if (typeof p.y2 === 'number') {
|
|
476
|
+
p.y2 = (0, canvas_draw_1.toFixedValue)(start.y2 + deltaY, 4);
|
|
477
|
+
}
|
|
478
|
+
p.x = (0, canvas_draw_1.toFixedValue)(x + d.x, 4);
|
|
479
|
+
p.y = (0, canvas_draw_1.toFixedValue)(y + d.y, 4);
|
|
480
|
+
});
|
|
481
|
+
this.updateNodeData();
|
|
482
|
+
},
|
|
213
483
|
});
|
|
214
|
-
|
|
484
|
+
this.draw();
|
|
485
|
+
}
|
|
486
|
+
onPathAddPoint(i, e) {
|
|
487
|
+
if (!this.currentPathNode || !this.document) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
const { path, position } = this.currentPathNode;
|
|
491
|
+
const { paths = [] } = path;
|
|
492
|
+
const p = this.getPosFromMouseEvent(e);
|
|
493
|
+
const pos = {
|
|
494
|
+
x: p.x - position.x,
|
|
495
|
+
y: p.y - position.y,
|
|
496
|
+
};
|
|
497
|
+
const point = paths[i];
|
|
498
|
+
const nextPoint = paths[i + 1] ? paths[i + 1] : paths[0];
|
|
499
|
+
const newPoint = (0, path_edit_1.getNewPoint)(point, nextPoint, pos);
|
|
500
|
+
paths.splice(i + 1, 0, newPoint);
|
|
501
|
+
this.pathPointSelection.enterPathMode([
|
|
502
|
+
{
|
|
503
|
+
pointId: newPoint.id,
|
|
504
|
+
},
|
|
505
|
+
]);
|
|
506
|
+
this.updateNodeData();
|
|
507
|
+
}
|
|
508
|
+
onClosePath() {
|
|
509
|
+
if (!this.currentPathNode) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
this.currentPathNode.path.closed = true;
|
|
513
|
+
this.pathPointSelection.enterSelectBezierMode([
|
|
514
|
+
{
|
|
515
|
+
pointId: this.currentPathNode.path.paths[0].id,
|
|
516
|
+
},
|
|
517
|
+
]);
|
|
518
|
+
this.updateNodeData();
|
|
215
519
|
}
|
|
216
520
|
draw() {
|
|
217
|
-
var _a, _b, _c;
|
|
521
|
+
var _a, _b, _c, _d, _e;
|
|
218
522
|
const selectNodes = ((_a = this.document) === null || _a === void 0 ? void 0 : _a.getSelectedNodes()) || [];
|
|
219
523
|
if (selectNodes.length > 1 ||
|
|
220
524
|
(selectNodes[0] && selectNodes[0].displayType !== 'path') ||
|
|
@@ -223,32 +527,42 @@ class PathEditLayer extends playground_1.Layer {
|
|
|
223
527
|
// this.editorState.toDefaultState();
|
|
224
528
|
return React.createElement(React.Fragment, null);
|
|
225
529
|
}
|
|
226
|
-
const
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
530
|
+
const { path = {}, position = { x: 0, y: 0 }, } = this.currentPathNode || {};
|
|
531
|
+
const { paths: p = [], closed = false } = path;
|
|
532
|
+
const paths = [...p].map(c => {
|
|
533
|
+
const item = Object.assign(Object.assign({}, c), { x: c.x + position.x, y: c.y + position.y });
|
|
534
|
+
if (typeof c.x1 === 'number') {
|
|
535
|
+
item.x1 = c.x1 + position.x;
|
|
536
|
+
}
|
|
537
|
+
if (typeof c.x2 === 'number') {
|
|
538
|
+
item.x2 = c.x2 + position.x;
|
|
539
|
+
}
|
|
540
|
+
if (typeof c.y1 === 'number') {
|
|
541
|
+
item.y1 = c.y1 + position.y;
|
|
542
|
+
}
|
|
543
|
+
if (typeof c.y2 === 'number') {
|
|
544
|
+
item.y2 = c.y2 + position.y;
|
|
545
|
+
}
|
|
546
|
+
return item;
|
|
237
547
|
});
|
|
238
|
-
return (React.createElement(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
548
|
+
return (React.createElement(exports.PathEditLayerEventContext.Provider, { value: {
|
|
549
|
+
onPointMouseDown: this.onPointMouseDown.bind(this),
|
|
550
|
+
onSceneAddEvent: this.onSceneAddEvent.bind(this),
|
|
551
|
+
onBezierPointMouseDown: this.onBezierPointMouseDown.bind(this),
|
|
552
|
+
onClosePath: this.onClosePath.bind(this),
|
|
553
|
+
onPathAddPoint: this.onPathAddPoint.bind(this),
|
|
554
|
+
} },
|
|
555
|
+
React.createElement(path_edit_1.SvgPath, { getPosFromMouseEvent: this.getPosFromMouseEvent.bind(this), width: ((_b = this.config.config.pageBounds) === null || _b === void 0 ? void 0 : _b.width) || 300, height: ((_c = this.config.config.pageBounds) === null || _c === void 0 ? void 0 : _c.height) || 300, paths: paths, closed: closed, selection: (_d = this.pathPointSelection) === null || _d === void 0 ? void 0 : _d.selection, selectMode: (_e = this.pathPointSelection) === null || _e === void 0 ? void 0 : _e.selectMode, getPointIsStartOrEnd: this.getPointIsStartOrEnd.bind(this), scale: this.config.finalScale })));
|
|
246
556
|
}
|
|
247
557
|
}
|
|
248
558
|
__decorate([
|
|
249
559
|
(0, playground_1.entity)(playground_1.EditorStateConfigEntity),
|
|
250
560
|
__metadata("design:type", playground_1.EditorStateConfigEntity)
|
|
251
561
|
], PathEditLayer.prototype, "editorState", void 0);
|
|
562
|
+
__decorate([
|
|
563
|
+
(0, playground_1.entity)(playground_1.SelectorBoxConfigEntity),
|
|
564
|
+
__metadata("design:type", playground_1.SelectorBoxConfigEntity)
|
|
565
|
+
], PathEditLayer.prototype, "selectorConfig", void 0);
|
|
252
566
|
__decorate([
|
|
253
567
|
(0, playground_1.entity)(document_entity_1.DocumentEntity),
|
|
254
568
|
__metadata("design:type", document_entity_1.DocumentEntity)
|