@gedit/editor-2d 0.1.115 → 0.2.4
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/editor2d-context-key-service.js.map +1 -1
- package/lib/browser/editor2d-contribution.js.map +1 -1
- package/lib/browser/editor2d-label-provider.js.map +1 -1
- package/lib/browser/editor2d-model-provider.js.map +1 -1
- package/lib/browser/editor2d-ref-provider-contribution.d.ts +1 -1
- package/lib/browser/editor2d-ref-provider-contribution.d.ts.map +1 -1
- package/lib/browser/editor2d-ref-provider-contribution.js +8 -8
- package/lib/browser/editor2d-ref-provider-contribution.js.map +1 -1
- package/lib/browser/editor2d-service.js.map +1 -1
- package/lib/browser/model/editor2d-document.d.ts +45 -19
- package/lib/browser/model/editor2d-document.d.ts.map +1 -1
- package/lib/browser/model/editor2d-document.js +291 -70
- package/lib/browser/model/editor2d-document.js.map +1 -1
- package/lib/browser/model/editor2d-model.js.map +1 -1
- package/lib/browser/model/editor2d-selection.js.map +1 -1
- package/lib/browser/model/editor2d-widget.js.map +1 -1
- package/lib/browser/model/editor2d.d.ts +8 -4
- package/lib/browser/model/editor2d.d.ts.map +1 -1
- package/lib/browser/model/editor2d.js +23 -4
- package/lib/browser/model/editor2d.js.map +1 -1
- package/lib/browser/model/utils/anim.utils.d.ts +3 -0
- package/lib/browser/model/utils/anim.utils.d.ts.map +1 -1
- package/lib/browser/model/utils/anim.utils.js +10 -4
- package/lib/browser/model/utils/anim.utils.js.map +1 -1
- package/lib/browser/playground/canvas-draw.d.ts +8 -0
- package/lib/browser/playground/canvas-draw.d.ts.map +1 -1
- package/lib/browser/playground/canvas-draw.js +29 -15
- package/lib/browser/playground/canvas-draw.js.map +1 -1
- package/lib/browser/playground/canvas-layer.d.ts +10 -2
- package/lib/browser/playground/canvas-layer.d.ts.map +1 -1
- package/lib/browser/playground/canvas-layer.js +25 -2
- package/lib/browser/playground/canvas-layer.js.map +1 -1
- package/lib/browser/playground/entities/extend-entity.d.ts +10 -0
- package/lib/browser/playground/entities/extend-entity.d.ts.map +1 -0
- package/lib/browser/playground/entities/extend-entity.js +34 -0
- package/lib/browser/playground/entities/extend-entity.js.map +1 -0
- package/lib/browser/playground/entities/index.d.ts +1 -0
- package/lib/browser/playground/entities/index.d.ts.map +1 -1
- package/lib/browser/playground/entities/index.js +1 -0
- package/lib/browser/playground/entities/index.js.map +1 -1
- package/lib/browser/playground/extend-edit-layer-point-event.d.ts +30 -0
- package/lib/browser/playground/extend-edit-layer-point-event.d.ts.map +1 -0
- package/lib/browser/playground/extend-edit-layer-point-event.js +50 -0
- package/lib/browser/playground/extend-edit-layer-point-event.js.map +1 -0
- package/lib/browser/playground/extend-edit-layer.d.ts +38 -0
- package/lib/browser/playground/extend-edit-layer.d.ts.map +1 -0
- package/lib/browser/playground/extend-edit-layer.js +335 -0
- package/lib/browser/playground/extend-edit-layer.js.map +1 -0
- package/lib/browser/playground/index.d.ts +1 -0
- package/lib/browser/playground/index.d.ts.map +1 -1
- package/lib/browser/playground/index.js +1 -0
- package/lib/browser/playground/index.js.map +1 -1
- package/lib/browser/playground/path-edit-layer-move-point.d.ts +15 -0
- package/lib/browser/playground/path-edit-layer-move-point.d.ts.map +1 -0
- package/lib/browser/playground/path-edit-layer-move-point.js +47 -0
- package/lib/browser/playground/path-edit-layer-move-point.js.map +1 -0
- package/lib/browser/playground/path-edit-layer-svg-path.d.ts +11 -0
- package/lib/browser/playground/path-edit-layer-svg-path.d.ts.map +1 -0
- package/lib/browser/playground/path-edit-layer-svg-path.js +21 -0
- package/lib/browser/playground/path-edit-layer-svg-path.js.map +1 -0
- package/lib/browser/playground/path-edit-layer.d.ts +36 -0
- package/lib/browser/playground/path-edit-layer.d.ts.map +1 -0
- package/lib/browser/playground/path-edit-layer.js +257 -0
- package/lib/browser/playground/path-edit-layer.js.map +1 -0
- package/lib/browser/playground/playground-context.js.map +1 -1
- package/lib/browser/playground/playground-contribution.d.ts +2 -0
- package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
- package/lib/browser/playground/playground-contribution.js +40 -3
- package/lib/browser/playground/playground-contribution.js.map +1 -1
- package/lib/browser/utils/snapshot.d.ts.map +1 -1
- package/lib/browser/utils/snapshot.js +1 -1
- package/lib/browser/utils/snapshot.js.map +1 -1
- package/package.json +9 -7
- package/src/browser/editor2d-ref-provider-contribution.ts +8 -8
- package/src/browser/model/editor2d-document.ts +278 -49
- package/src/browser/model/editor2d.ts +22 -6
- package/src/browser/model/utils/anim.utils.ts +9 -2
- package/src/browser/playground/canvas-draw.ts +31 -17
- package/src/browser/playground/canvas-layer.ts +25 -3
- package/src/browser/playground/entities/extend-entity.ts +37 -0
- package/src/browser/playground/entities/index.ts +1 -0
- package/src/browser/playground/extend-edit-layer-point-event.tsx +71 -0
- package/src/browser/playground/extend-edit-layer.tsx +442 -0
- package/src/browser/playground/index.ts +1 -0
- package/src/browser/playground/path-edit-layer-move-point.tsx +71 -0
- package/src/browser/playground/path-edit-layer-svg-path.tsx +50 -0
- package/src/browser/playground/path-edit-layer.tsx +330 -0
- package/src/browser/playground/playground-contribution.ts +37 -3
- package/src/browser/style/canvas-layer.css +16 -0
- package/src/browser/style/extend-edit-layer.less +127 -0
- package/src/browser/style/index.less +2 -1
- package/src/browser/style/path-edit-layer.less +72 -0
- package/src/browser/svg/pen+.svg +24 -0
- package/src/browser/utils/snapshot.ts +1 -0
- package/lib/browser/playground/canvas-draw-layer.d.ts +0 -22
- package/lib/browser/playground/canvas-draw-layer.d.ts.map +0 -1
- package/lib/browser/playground/canvas-draw-layer.js +0 -102
- package/lib/browser/playground/canvas-draw-layer.js.map +0 -1
- package/src/browser/playground/canvas-draw-layer.tsx +0 -88
- package/src/browser/style/canvas-draw-layer.less +0 -24
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { EditorStateConfigEntity, entity, Layer } from '@gedit/playground';
|
|
3
|
+
import { DocumentEntity } from './entities/document-entity';
|
|
4
|
+
import { domUtils } from '@gedit/utils/lib/browser';
|
|
5
|
+
import { GameObjectBaseType } from '@gedit/render-engine';
|
|
6
|
+
import {
|
|
7
|
+
Editor2dDocument,
|
|
8
|
+
Editor2dPathNode,
|
|
9
|
+
} from '../model';
|
|
10
|
+
import { PlaygroundContext2d } from './playground-context';
|
|
11
|
+
import { SelectableTreeNode, TreeSelection } from '@gedit/tree';
|
|
12
|
+
import { asVec, getLineWidth, PathChild } from '@gedit/canvas-draw';
|
|
13
|
+
import { generateUuid } from '@gedit/utils';
|
|
14
|
+
import { PointDefault, PointSchema } from './path-edit-layer-move-point';
|
|
15
|
+
import { SvgPath } from './path-edit-layer-svg-path';
|
|
16
|
+
|
|
17
|
+
const EDIT_PATH_STATE = 'ADD_PATH';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 动态绘制层
|
|
21
|
+
*/
|
|
22
|
+
export class PathEditLayer extends Layer<PlaygroundContext2d> {
|
|
23
|
+
node = domUtils.createDivWithClass('gedit-path-edit-layer');
|
|
24
|
+
@entity(EditorStateConfigEntity)
|
|
25
|
+
protected editorState: EditorStateConfigEntity;
|
|
26
|
+
@entity(DocumentEntity) documentEntity: DocumentEntity;
|
|
27
|
+
protected hideMovePoint: boolean;
|
|
28
|
+
|
|
29
|
+
currentPathNode?: Editor2dPathNode;
|
|
30
|
+
currentPointId?: string;
|
|
31
|
+
startPos?: PathChild;
|
|
32
|
+
selectId?: string;
|
|
33
|
+
|
|
34
|
+
get isEnabled(): boolean {
|
|
35
|
+
return this.editorState.is(EDIT_PATH_STATE);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
onZoom(scale: number): void {
|
|
39
|
+
domUtils.setStyle(this.node, {
|
|
40
|
+
transform: `scale(${scale})`,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onReady(): void {
|
|
45
|
+
this.toDispose.pushAll([
|
|
46
|
+
// 退出路径编辑
|
|
47
|
+
this.editorState.onCancel(EDIT_PATH_STATE, () => {
|
|
48
|
+
if (!this.currentPathNode) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// 如果只有一个点代表绘制不成功,则删除
|
|
52
|
+
/* if (
|
|
53
|
+
!this.currentPathNode.path ||
|
|
54
|
+
(this.currentPathNode.path &&
|
|
55
|
+
this.currentPathNode.path.paths.length <= 1)
|
|
56
|
+
) {
|
|
57
|
+
this.document?.delNode(this.currentPathNode);
|
|
58
|
+
} */
|
|
59
|
+
this.selectId = undefined;
|
|
60
|
+
this.currentPathNode = undefined;
|
|
61
|
+
}),
|
|
62
|
+
this.listenPlaygroundEvent(
|
|
63
|
+
'mousedown',
|
|
64
|
+
(e: MouseEvent) => {
|
|
65
|
+
// 当前编辑模式为路径编辑
|
|
66
|
+
if (this.editorState.is(EDIT_PATH_STATE)) {
|
|
67
|
+
this.startPos = this.getPosFromMouseEvent(e);
|
|
68
|
+
this.startPos.id = generateUuid();
|
|
69
|
+
this.currentPointId = this.startPos.id;
|
|
70
|
+
this.drawPath(this.startPos);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
10
|
|
74
|
+
),
|
|
75
|
+
this.listenPlaygroundEvent('mousemove', (e: MouseEvent) => {
|
|
76
|
+
if (this.startPos) {
|
|
77
|
+
const pos = this.getPosFromMouseEvent(e);
|
|
78
|
+
const x1 = this.startPos.x * 2 - pos.x;
|
|
79
|
+
const y1 = this.startPos.y * 2 - pos.y;
|
|
80
|
+
this.startPos.x2 = pos.x;
|
|
81
|
+
this.startPos.y2 = pos.y;
|
|
82
|
+
this.startPos.x1 = x1;
|
|
83
|
+
this.startPos.y1 = y1;
|
|
84
|
+
this.document?.updateNode(this.currentPathNode!, {}, true);
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
this.listenPlaygroundEvent('mouseup', (e: MouseEvent) => {
|
|
88
|
+
this.startPos = undefined;
|
|
89
|
+
}),
|
|
90
|
+
// 图层发生变化时退出模式
|
|
91
|
+
this.selectionService?.onSelectionChanged(e => {
|
|
92
|
+
if (this.editorState.is(EDIT_PATH_STATE)) {
|
|
93
|
+
const selectNodes = this.document?.getSelectedNodes() || [];
|
|
94
|
+
if (
|
|
95
|
+
selectNodes.length &&
|
|
96
|
+
(selectNodes[0].displayType !== GameObjectBaseType.PATH ||
|
|
97
|
+
selectNodes.length !== 1)
|
|
98
|
+
) {
|
|
99
|
+
this.editorState.toDefaultState();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
})!,
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 创建路径
|
|
108
|
+
* @param pos - 当前鼠标点击的位置
|
|
109
|
+
*/
|
|
110
|
+
drawPath(pos: PointSchema): void {
|
|
111
|
+
if (!this.document) return;
|
|
112
|
+
// 判断当前 select 是否 path 路径
|
|
113
|
+
const selectedNodes = this.document?.getSelectedNodes() || [];
|
|
114
|
+
if (selectedNodes.length === 1 && selectedNodes[0].displayType === 'path') {
|
|
115
|
+
this.currentPathNode = selectedNodes[0] as Editor2dPathNode;
|
|
116
|
+
}
|
|
117
|
+
// 创建一个空的路径节点,用于存储数据
|
|
118
|
+
if (!this.currentPathNode) {
|
|
119
|
+
this.currentPathNode = this.document.createDisplayNode<Editor2dPathNode>(
|
|
120
|
+
GameObjectBaseType.PATH
|
|
121
|
+
);
|
|
122
|
+
this.currentPathNode.selected = true;
|
|
123
|
+
this.context.selection.addSelection({
|
|
124
|
+
node: this.currentPathNode as Readonly<SelectableTreeNode>,
|
|
125
|
+
type: TreeSelection.SelectionType.TOGGLE,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
this.selectId = this.currentPathNode.id;
|
|
129
|
+
this.currentPathNode.path.paths.push(pos);
|
|
130
|
+
this.document.updateNode(this.currentPathNode, {}, true);
|
|
131
|
+
/* this.document.updateNode(
|
|
132
|
+
this.currentPathNode,
|
|
133
|
+
{
|
|
134
|
+
path: {
|
|
135
|
+
...this.currentPathNode.path,
|
|
136
|
+
paths: (this.currentPathNode.path.paths || []).concat(pos),
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
true
|
|
140
|
+
); */
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
get document(): Editor2dDocument | undefined {
|
|
144
|
+
return this.documentEntity.config.document;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
protected onBezierPointMouseDown(e: React.MouseEvent, p: PathChild, key: string): void {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
e.stopPropagation();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
protected onPointMouseDown(
|
|
153
|
+
e: React.MouseEvent,
|
|
154
|
+
node: Editor2dPathNode,
|
|
155
|
+
p: PathChild
|
|
156
|
+
): void {
|
|
157
|
+
const document = this.document!;
|
|
158
|
+
this.startDrag(e.clientX, e.clientY, {
|
|
159
|
+
// 拖动
|
|
160
|
+
onDrag(dragEvent): void {
|
|
161
|
+
const pos = dragEvent.endPos;
|
|
162
|
+
const x = pos.x / (this.config?.finalScale || 1);
|
|
163
|
+
const y = pos.y / (this.config?.finalScale || 1);
|
|
164
|
+
if (typeof p.x1 === 'number') {
|
|
165
|
+
p.x1 = p.x1 - p.x + x;
|
|
166
|
+
}
|
|
167
|
+
if (typeof p.x2 === 'number') {
|
|
168
|
+
p.x2 = p.x2 - p.x + x;
|
|
169
|
+
}
|
|
170
|
+
if (typeof p.y1 === 'number') {
|
|
171
|
+
p.y1 = p.y1 - p.y + y;
|
|
172
|
+
}
|
|
173
|
+
if (typeof p.y2 === 'number') {
|
|
174
|
+
p.y2 = p.y2 - p.y + y;
|
|
175
|
+
}
|
|
176
|
+
p.x = x;
|
|
177
|
+
p.y = y;
|
|
178
|
+
|
|
179
|
+
document.updateNode(node, {}, true);
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
this.currentPointId = p.id;
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
e.stopPropagation();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
protected onHideMovePoint(): void {
|
|
188
|
+
this.hideMovePoint = true;
|
|
189
|
+
this.draw();
|
|
190
|
+
}
|
|
191
|
+
protected onShowMovePoint(): void {
|
|
192
|
+
this.hideMovePoint = false;
|
|
193
|
+
this.draw();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
protected getBezierPoint(node?: Editor2dPathNode): JSX.Element[] {
|
|
197
|
+
if (!node) {
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
const { paths } = node.path;
|
|
201
|
+
const children: JSX.Element[] = [];
|
|
202
|
+
const points: PathChild[] = [];
|
|
203
|
+
// 在最后点
|
|
204
|
+
if (!this.currentPointId) {
|
|
205
|
+
points.push(paths[paths.length - 1]);
|
|
206
|
+
} else {
|
|
207
|
+
const index = paths.findIndex(c => c.id === this.currentPointId);
|
|
208
|
+
points.push(...paths.filter((_, i) => i >= index - 1 && i <= index + 1));
|
|
209
|
+
}
|
|
210
|
+
points.forEach((p, i) => {
|
|
211
|
+
if ('x1' in p && 'y1' in p) {
|
|
212
|
+
children.push(
|
|
213
|
+
<div
|
|
214
|
+
key={`x1-line_${i}`}
|
|
215
|
+
className="gedit-path-edit-layer-point-bezier-line"
|
|
216
|
+
style={{
|
|
217
|
+
width: getLineWidth({ x: p.x1 || 0, y: p.y1 || 0 }, p),
|
|
218
|
+
transform: `translate(${p.x}px, ${p.y}px) rotate(${
|
|
219
|
+
(asVec({ x: p.x1 || 0, y: p.y1 || 0 }, p).ang / Math.PI) * 180
|
|
220
|
+
}deg)`,
|
|
221
|
+
}}
|
|
222
|
+
/>,
|
|
223
|
+
<div
|
|
224
|
+
key={`x1_${i}`}
|
|
225
|
+
className="gedit-path-edit-layer-point-bezier"
|
|
226
|
+
style={{
|
|
227
|
+
transform: `translate(${p.x1}px, ${p.y1}px) scale(${
|
|
228
|
+
1 / this.config.finalScale
|
|
229
|
+
})`,
|
|
230
|
+
}}
|
|
231
|
+
onMouseDown={e => {
|
|
232
|
+
this.onBezierPointMouseDown(e, p, '1');
|
|
233
|
+
}}
|
|
234
|
+
onMouseEnter={this.onHideMovePoint.bind(this)}
|
|
235
|
+
onMouseLeave={this.onShowMovePoint.bind(this)}
|
|
236
|
+
/>
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
if ('x2' in p && 'y2' in p) {
|
|
240
|
+
children.push(
|
|
241
|
+
<div
|
|
242
|
+
key={`x2-line_${i}`}
|
|
243
|
+
className="gedit-path-edit-layer-point-bezier-line"
|
|
244
|
+
style={{
|
|
245
|
+
width: getLineWidth({ x: p.x2 || 0, y: p.y2 || 0 }, p),
|
|
246
|
+
transform: `translate(${p.x}px, ${p.y}px) rotate(${
|
|
247
|
+
(asVec({ x: p.x2 || 0, y: p.y2 || 0 }, p).ang / Math.PI) * 180
|
|
248
|
+
}deg)`,
|
|
249
|
+
}}
|
|
250
|
+
/>,
|
|
251
|
+
<div
|
|
252
|
+
key={`x2_${i}`}
|
|
253
|
+
className="gedit-path-edit-layer-point-bezier"
|
|
254
|
+
style={{
|
|
255
|
+
transform: `translate(${p.x2}px, ${p.y2}px) scale(${
|
|
256
|
+
1 / this.config.finalScale
|
|
257
|
+
})`,
|
|
258
|
+
}}
|
|
259
|
+
onMouseEnter={this.onHideMovePoint.bind(this)}
|
|
260
|
+
onMouseLeave={this.onShowMovePoint.bind(this)}
|
|
261
|
+
/>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return children;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
draw(): JSX.Element {
|
|
269
|
+
const selectNodes = this.document?.getSelectedNodes() || [];
|
|
270
|
+
if (
|
|
271
|
+
selectNodes.length > 1 ||
|
|
272
|
+
(selectNodes[0] && selectNodes[0].displayType !== 'path') ||
|
|
273
|
+
!this.document ||
|
|
274
|
+
!this.isEnabled
|
|
275
|
+
) {
|
|
276
|
+
// this.editorState.toDefaultState();
|
|
277
|
+
return <></>;
|
|
278
|
+
}
|
|
279
|
+
const node: Editor2dPathNode | undefined = selectNodes[0] as
|
|
280
|
+
| Editor2dPathNode
|
|
281
|
+
| undefined;
|
|
282
|
+
|
|
283
|
+
const allPoints: JSX.Element[] = [];
|
|
284
|
+
// 只管当前点相邻的两个点的 bezier;
|
|
285
|
+
const bezierPoint: JSX.Element[] = this.getBezierPoint(node);
|
|
286
|
+
|
|
287
|
+
const { paths = [] } = node ? node.path : {};
|
|
288
|
+
paths.forEach((p, i) => {
|
|
289
|
+
allPoints.push(
|
|
290
|
+
<div
|
|
291
|
+
className="gedit-path-edit-layer-point"
|
|
292
|
+
key={`${node?.id}.${i}`}
|
|
293
|
+
style={{
|
|
294
|
+
transform: `translate(${p.x}px, ${p.y}px) scale(${
|
|
295
|
+
1 / this.config.finalScale
|
|
296
|
+
})`,
|
|
297
|
+
}}
|
|
298
|
+
onMouseDown={e => {
|
|
299
|
+
this.onPointMouseDown(e, node!, p);
|
|
300
|
+
}}
|
|
301
|
+
onMouseEnter={this.onHideMovePoint.bind(this)}
|
|
302
|
+
onMouseLeave={this.onShowMovePoint.bind(this)}
|
|
303
|
+
/>
|
|
304
|
+
);
|
|
305
|
+
});
|
|
306
|
+
return (
|
|
307
|
+
<>
|
|
308
|
+
{!this.hideMovePoint && (
|
|
309
|
+
<PointDefault
|
|
310
|
+
getPosFromMouseEvent={this.getPosFromMouseEvent.bind(this)}
|
|
311
|
+
paths={paths}
|
|
312
|
+
scale={this.config.finalScale}
|
|
313
|
+
/>
|
|
314
|
+
)}
|
|
315
|
+
<SvgPath
|
|
316
|
+
width={this.config.config.pageBounds?.width || 300}
|
|
317
|
+
height={this.config.config.pageBounds?.height || 300}
|
|
318
|
+
paths={paths}
|
|
319
|
+
scale={this.config.finalScale}
|
|
320
|
+
pathProps={{
|
|
321
|
+
onMouseEnter: this.onHideMovePoint.bind(this),
|
|
322
|
+
onMouseLeave: this.onShowMovePoint.bind(this),
|
|
323
|
+
}}
|
|
324
|
+
/>
|
|
325
|
+
{allPoints}
|
|
326
|
+
{bezierPoint}
|
|
327
|
+
</>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
ToolbarConfigEntity
|
|
11
11
|
} from '@gedit/playground';
|
|
12
12
|
import { CanvasLayer } from './canvas-layer';
|
|
13
|
-
import {
|
|
13
|
+
import { PathEditLayer } from './path-edit-layer';
|
|
14
14
|
// import { SelectionLayer } from './selection-layer';
|
|
15
15
|
import { AppConfigData, AppConfigService } from '@gedit/app-config';
|
|
16
16
|
import { HistoryService } from '@gedit/history';
|
|
@@ -18,6 +18,8 @@ import { Editor2dModelOptions, Editor2dNode } from '../model/editor2d';
|
|
|
18
18
|
import { ContextMenuRenderer } from '@gedit/layout';
|
|
19
19
|
import { CommandService } from '@gedit/command';
|
|
20
20
|
import { CommonCommands } from '@gedit/application-common/lib/browser';
|
|
21
|
+
import { ExtendEditLayer, EXTEND_EDIT_STATE } from './extend-edit-layer';
|
|
22
|
+
import { Editor2dSelection } from '../model/editor2d-selection';
|
|
21
23
|
|
|
22
24
|
@injectable()
|
|
23
25
|
export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
@@ -27,9 +29,11 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
|
27
29
|
@inject(PlaygroundConfig) readonly config: PlaygroundConfig;
|
|
28
30
|
@inject(CommandService) readonly commandService: CommandService;
|
|
29
31
|
@inject(ContextMenuRenderer) readonly menuRender: ContextMenuRenderer;
|
|
32
|
+
@inject(Editor2dSelection) readonly editor2dSelection: Editor2dSelection;
|
|
30
33
|
registerPlayground(registry: PlaygroundRegistry): void {
|
|
31
34
|
registry.registerLayer(CanvasLayer);
|
|
32
|
-
registry.registerLayer(
|
|
35
|
+
registry.registerLayer(PathEditLayer);
|
|
36
|
+
registry.registerLayer(ExtendEditLayer);
|
|
33
37
|
// registry.registerLayer(SelectionLayer);
|
|
34
38
|
}
|
|
35
39
|
onDispose(playground: Playground): void {
|
|
@@ -50,6 +54,7 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
|
50
54
|
gridVisible: false,
|
|
51
55
|
});
|
|
52
56
|
}
|
|
57
|
+
const isComponent = this.modelOpts.autoSaveService.resource.uri.path.ext === '.comp';
|
|
53
58
|
if (stateEntity) {
|
|
54
59
|
stateEntity.registerState({
|
|
55
60
|
id: 'FULL_SCREEN',
|
|
@@ -64,6 +69,14 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
|
64
69
|
}, 10);
|
|
65
70
|
}
|
|
66
71
|
});
|
|
72
|
+
stateEntity.registerState({
|
|
73
|
+
id: EXTEND_EDIT_STATE,
|
|
74
|
+
icon: '',
|
|
75
|
+
title: '扩展编辑',
|
|
76
|
+
hidden: true, // 该模式为内部模式
|
|
77
|
+
disableSelector: true,
|
|
78
|
+
cancelMode: 'hold'
|
|
79
|
+
});
|
|
67
80
|
stateEntity.registerState({
|
|
68
81
|
id: 'ADD_ELEMENT',
|
|
69
82
|
icon: 'gedit-toolbar-add',
|
|
@@ -83,6 +96,27 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
|
83
96
|
});
|
|
84
97
|
}
|
|
85
98
|
});
|
|
99
|
+
/* stateEntity.registerState({
|
|
100
|
+
id: 'ADD_PATH',
|
|
101
|
+
icon: 'gedit-toolbar-pen',
|
|
102
|
+
title: '失量',
|
|
103
|
+
shortcut: 'P',
|
|
104
|
+
// cursor: 'url(https://gw.alipayobjects.com/zos/bmw-prod/8dc2fcc4-279b-408c-886c-60fdba4c1f1e.svg), copy',
|
|
105
|
+
// shortcutAutoEsc: true,
|
|
106
|
+
disableSelector: true,
|
|
107
|
+
priority: 0,
|
|
108
|
+
order: 1,
|
|
109
|
+
cancelMode: 'esc',
|
|
110
|
+
handle: (a, b) => {
|
|
111
|
+
const currentSelectedNodes = this.editor2dSelection.selectedNodes;
|
|
112
|
+
console.log(currentSelectedNodes);
|
|
113
|
+
if (currentSelectedNodes.length !== 1 || currentSelectedNodes[0].displayType !== 'path') {
|
|
114
|
+
// 路径选中时先取消所有 selection;
|
|
115
|
+
this.editor2dSelection.clearSelection();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
}); */
|
|
86
120
|
}
|
|
87
121
|
// 模板编辑器模式
|
|
88
122
|
if (this.modelOpts.isTemplate) {
|
|
@@ -96,7 +130,7 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
|
|
|
96
130
|
});
|
|
97
131
|
}
|
|
98
132
|
playground.getConfigEntity<SnaplineConfigEntity>(SnaplineConfigEntity).updateConfig({
|
|
99
|
-
originlineVisible:
|
|
133
|
+
originlineVisible: isComponent, // 是否隐藏原点线条,如果是组件模式则显示
|
|
100
134
|
});
|
|
101
135
|
playground.toDispose.push(
|
|
102
136
|
// TODO 放在这里处理会增加复杂度
|
|
@@ -6,6 +6,22 @@
|
|
|
6
6
|
z-index: 10
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
.gedit-canvas-viewport {
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 100%;
|
|
12
|
+
overflow: hidden;
|
|
13
|
+
position: relative;
|
|
14
|
+
}
|
|
15
|
+
.gedit-canvas-viewport canvas {
|
|
16
|
+
position: absolute;
|
|
17
|
+
}
|
|
18
|
+
.gedit-viewport-mask, .gedit-viewport-bg {
|
|
19
|
+
position: absolute;
|
|
20
|
+
}
|
|
21
|
+
.gedit-viewport-mask {
|
|
22
|
+
background-color: var(--g-editor-background);;
|
|
23
|
+
opacity: 0.4;
|
|
24
|
+
}
|
|
9
25
|
.gedit-canvas-layer canvas {
|
|
10
26
|
position: absolute;
|
|
11
27
|
display: none;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
.gedit-extend-edit-layer {
|
|
2
|
+
z-index: 20;
|
|
3
|
+
.gedit-extend-edit-item {
|
|
4
|
+
position: absolute;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.gedit-extend-range-point {
|
|
9
|
+
position: absolute;
|
|
10
|
+
left: -5px;
|
|
11
|
+
top: -5px;
|
|
12
|
+
width: 10px;
|
|
13
|
+
height: 10px;
|
|
14
|
+
}
|
|
15
|
+
.gedit-extend-range-point,
|
|
16
|
+
.gedit-extend-color-point {
|
|
17
|
+
> div {
|
|
18
|
+
content: "";
|
|
19
|
+
display: block;
|
|
20
|
+
width: 10px;
|
|
21
|
+
height: 10px;
|
|
22
|
+
position: relative;
|
|
23
|
+
border: 1px solid #fff;
|
|
24
|
+
background-color: #ccc;
|
|
25
|
+
box-shadow: 0 0 4px fade(#262626, 50);
|
|
26
|
+
transition: transform 0.3s;
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
&:hover {
|
|
29
|
+
transform: scale(1.2);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.gedit-extend-center-point > div {
|
|
35
|
+
top: -5px;
|
|
36
|
+
}
|
|
37
|
+
.gedit-extend-radius-point {
|
|
38
|
+
> div {
|
|
39
|
+
top: 5px;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
.gedit-extend-color-point-active {
|
|
43
|
+
transform: scale(1.3);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.gedit-extend-color-point {
|
|
47
|
+
width: 8px;
|
|
48
|
+
height: 8px;
|
|
49
|
+
position: absolute;
|
|
50
|
+
left: -4px;
|
|
51
|
+
top: -4px;
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
> div {
|
|
54
|
+
width: 8px;
|
|
55
|
+
height: 8px;
|
|
56
|
+
border-radius: 100%;
|
|
57
|
+
top: 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.gedit-extend-range-line {
|
|
62
|
+
background-color: #fff;
|
|
63
|
+
background-clip: padding-box;
|
|
64
|
+
height: 5px;
|
|
65
|
+
position: absolute;
|
|
66
|
+
left: 0;
|
|
67
|
+
top: -2.5px;
|
|
68
|
+
border: 2px solid transparent;
|
|
69
|
+
border-left: none;
|
|
70
|
+
border-right: none;
|
|
71
|
+
transform-origin: 0 2.5px;
|
|
72
|
+
cursor: copy;
|
|
73
|
+
}
|
|
74
|
+
.gedit-extend-radial-box {
|
|
75
|
+
border: 1px solid #fff;
|
|
76
|
+
border-radius: 100%;
|
|
77
|
+
position: absolute;
|
|
78
|
+
box-shadow: 0 0 1px 0 fade(#262626, 50) inset;
|
|
79
|
+
}
|
|
80
|
+
.gedit-extend-radial-point {
|
|
81
|
+
width: 10px;
|
|
82
|
+
height: 10px;
|
|
83
|
+
left: -5px;
|
|
84
|
+
top: 50%;
|
|
85
|
+
margin-top: -5px;
|
|
86
|
+
position: absolute;
|
|
87
|
+
background-color: #ccc;
|
|
88
|
+
border-radius: 100%;
|
|
89
|
+
border: 1px solid #fff;
|
|
90
|
+
transition: transform 0.45s;
|
|
91
|
+
:hover {
|
|
92
|
+
transform: scale(1.2);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.gedit-extend-origin {
|
|
97
|
+
&-wrapper {
|
|
98
|
+
position: absolute;
|
|
99
|
+
margin-left: -7px;
|
|
100
|
+
margin-top: -7px;
|
|
101
|
+
width: 14px;
|
|
102
|
+
height: 14px;
|
|
103
|
+
}
|
|
104
|
+
background-color: #fff;
|
|
105
|
+
-webkit-mask: var(--g-playground-icon-origin);
|
|
106
|
+
mask: var(--g-playground-icon-origin);
|
|
107
|
+
width: 14px;
|
|
108
|
+
height: 14px;
|
|
109
|
+
cursor: move;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.gedit-extend-angle {
|
|
113
|
+
&-wrapper {
|
|
114
|
+
width: 14px;
|
|
115
|
+
height: 14px;
|
|
116
|
+
margin-left: -7px;
|
|
117
|
+
margin-top: -7px;
|
|
118
|
+
}
|
|
119
|
+
width: 14px;
|
|
120
|
+
height: 14px;
|
|
121
|
+
margin-left: 7px;
|
|
122
|
+
border: 1px solid #fff;
|
|
123
|
+
background-color: #ccc;
|
|
124
|
+
box-shadow: 0 0 4px #262626;
|
|
125
|
+
clip-path: path("M0 7 L14 0 L14 14z");
|
|
126
|
+
cursor: pointer;
|
|
127
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
@import './engine2d.css';
|
|
2
2
|
@import './canvas-layer.css';
|
|
3
|
-
@import './
|
|
3
|
+
@import './path-edit-layer.less';
|
|
4
4
|
@import './selector-extend.less';
|
|
5
|
+
@import './extend-edit-layer.less';
|
|
5
6
|
|
|
6
7
|
:root {
|
|
7
8
|
--g-mask-transparent: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAADKADAAQAAAABAAAADAAAAAATDPpdAAAAfUlEQVQoFbVQQQ7AIAgD7Sf8/8s8+gd1s0vIptMlHkZiUGyBVmOMRwux4B2AhBDEOWflK6uqgICRYLVn3Zh9C6t+5G3CcqXVkKYPnQYCvfdSSpFaa8ejaM05N223S0QQmFJ6NeIfaN1I4JtnNmFb9L8Ergm6MWrg7jP36NIJC0BbmAiDWGoAAAAASUVORK5CYII=');;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
.gedit-path-edit-layer {
|
|
2
|
+
position: absolute;
|
|
3
|
+
left: 0;
|
|
4
|
+
top: 0;
|
|
5
|
+
overflow: visible;
|
|
6
|
+
z-index: 20;
|
|
7
|
+
&-point {
|
|
8
|
+
position: absolute;
|
|
9
|
+
width: 8px;
|
|
10
|
+
height: 8px;
|
|
11
|
+
border-radius: 100%;
|
|
12
|
+
top: -4px;
|
|
13
|
+
left: -4px;
|
|
14
|
+
background-color: #fff; //var(--g-playground-select);
|
|
15
|
+
border: 1px solid #ccc;
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
z-index: 50;
|
|
18
|
+
&-move {
|
|
19
|
+
z-index: 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
&-point-bezier {
|
|
23
|
+
position: absolute;
|
|
24
|
+
width: 6px;
|
|
25
|
+
height: 6px;
|
|
26
|
+
top: -3px;
|
|
27
|
+
left: -3px;
|
|
28
|
+
background-color: #fff;//var(--g-playground-select);
|
|
29
|
+
border: 1px solid #ccc;
|
|
30
|
+
border-radius: 100%;
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
z-index: 50;
|
|
33
|
+
&-line {
|
|
34
|
+
height: 1px;
|
|
35
|
+
position: absolute;
|
|
36
|
+
top: 0;
|
|
37
|
+
left: 0;
|
|
38
|
+
transform-origin: 0% 50%;
|
|
39
|
+
background-color: #bbb;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
&-pen {
|
|
43
|
+
// 移出画布
|
|
44
|
+
cursor: url(../svg/pen+.svg), copy;
|
|
45
|
+
}
|
|
46
|
+
&-line {
|
|
47
|
+
height: 1px;
|
|
48
|
+
background-color: #ccc;
|
|
49
|
+
position: absolute;
|
|
50
|
+
top: 0;
|
|
51
|
+
left: 0;
|
|
52
|
+
transform-origin: 0% 50%;
|
|
53
|
+
z-index: 0;
|
|
54
|
+
}
|
|
55
|
+
&-svg {
|
|
56
|
+
position: absolute;
|
|
57
|
+
overflow: visible;
|
|
58
|
+
left: 0;
|
|
59
|
+
top: 0;
|
|
60
|
+
cursor: url(../svg/pen+.svg), copy;
|
|
61
|
+
z-index: 1;
|
|
62
|
+
}
|
|
63
|
+
&-path {
|
|
64
|
+
stroke: #fff000;
|
|
65
|
+
fill: none;
|
|
66
|
+
// stroke-width: 1px;
|
|
67
|
+
pointer-events: auto;
|
|
68
|
+
&:hover {
|
|
69
|
+
stroke: var(--g-playground-select);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg width="20px" height="20px" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
+
<title>编组 2</title>
|
|
4
|
+
<defs>
|
|
5
|
+
<rect id="path-1" x="0" y="0" width="20" height="20"></rect>
|
|
6
|
+
</defs>
|
|
7
|
+
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
8
|
+
<g id="3-Pen-+-形状结合-蒙版">
|
|
9
|
+
<mask id="mask-2" fill="white">
|
|
10
|
+
<use xlink:href="#path-1"></use>
|
|
11
|
+
</mask>
|
|
12
|
+
<g id="蒙版"></g>
|
|
13
|
+
<g id="3-Pen" mask="url(#mask-2)">
|
|
14
|
+
<g transform="translate(-8.950265, -5.827689)">
|
|
15
|
+
<g id="编组-3" stroke="none" fill="none" fill-rule="evenodd" transform="translate(15.908060, 15.908060) rotate(-33.000000) translate(-15.908060, -15.908060) translate(4.408060, 4.408060)">
|
|
16
|
+
<path d="M15.2636045,3.54128301 C15.1463591,3.42389369 14.9824898,3.36270075 14.8080946,3.37118409 C14.6336994,3.37966742 14.4630852,3.45713108 14.3338359,3.58651099 L11.6470455,6.26392495 C11.5176657,6.39317434 11.440202,6.5637885 11.4317187,6.73818372 C11.4232353,6.91257893 11.4844283,7.07644824 11.6018176,7.1936937 L11.8768691,7.46874527 C10.5668432,8.45506005 9.02084742,9.03767617 7.45291352,9.13593476 C7.17991393,9.16129804 6.93457934,9.35190929 6.83636102,9.61496155 L3.41043657,18.7950899 C3.33416882,18.998745 3.35731687,19.2172739 3.47265178,19.3824321 C3.58798669,19.5475903 3.78145241,19.6392496 3.9926312,19.6287856 C4.06292863,19.6255581 4.13335027,19.6110664 4.20120966,19.5858632 L13.3818161,16.1500821 C13.6415844,16.0533232 13.8312241,15.8129004 13.8603634,15.5433857 C13.9604921,13.9787315 14.5428258,12.4364838 15.5270733,11.1292857 L15.8021248,11.4043373 C15.9193778,11.5205354 16.0825735,11.5809356 16.2560971,11.5723565 C16.4307018,11.5648704 16.6019069,11.488138 16.7318934,11.3591093 L19.4089874,8.67888942 C19.5435052,8.54879031 19.6244033,8.37447287 19.6330845,8.19600994 C19.6417657,8.01754702 19.5774832,7.8502918 19.4550144,7.73269363 L15.2636045,3.54128301 Z" id="路径" stroke="#FFFFFF" fill="#000000" fill-rule="nonzero" transform="translate(11.500000, 11.500000) rotate(-225.000000) translate(-11.500000, -11.500000) "></path>
|
|
17
|
+
<path d="M14.0272692,11.6425806 L7.59746366,14.049758 L10.7844497,10.8596464 C11.2245552,10.9666111 11.7106572,10.7537469 11.9661762,10.3421679 C12.2216953,9.93058893 12.1818754,9.42460131 11.869373,9.11209895 C11.5568707,8.79959659 11.050883,8.75977669 10.6393041,9.01529573 C10.2277251,9.27081477 10.0148608,9.7569168 10.1218256,10.1970223 L6.93171401,13.3840083 L9.33889138,6.9542028 C11.0769116,6.75281121 12.7662565,6.04449073 14.1937478,4.91862422 L16.0690989,6.79397534 C14.9422125,8.21892537 14.2317635,9.90598413 14.0272692,11.6425806 L14.0272692,11.6425806 Z" id="路径" fill="#FFFFFF" fill-rule="nonzero" transform="translate(11.500406, 9.484191) rotate(-225.000000) translate(-11.500406, -9.484191) "></path>
|
|
18
|
+
</g>
|
|
19
|
+
<path d="M23.1879258,6.71185268 C24.3227683,6.31096118 24.4529395,6.56265282 24.6021394,6.71185268 C24.7831038,6.89281709 24.8950326,7.14281709 24.8950326,7.41915954 L24.8950326,7.41915954 L24.8942326,9.41815943 L26.8950326,9.41895946 C27.171175,9.41895946 27.421175,9.53088827 27.6021394,9.71185268 C27.7831038,9.89281709 27.8950326,10.1428171 27.8950326,10.4189595 C27.8950326,10.6951018 27.7831038,10.9451018 27.6021394,11.1260662 C27.421175,11.3070306 27.171175,11.4189595 26.8948327,11.4189594 L26.8948327,11.4189594 L24.8942326,11.4181595 L24.8950326,13.4189595 C24.8950326,13.6951018 24.7831038,13.9451018 24.6021394,14.1260662 C24.421175,14.3070306 24.171175,14.4189595 23.8950326,14.4189595 C23.6188902,14.4189595 23.3688902,14.3070306 23.1879258,14.1260662 C23.0069614,13.9451018 22.8950326,13.6951018 22.8950326,13.4191594 L22.8950326,13.4191594 L22.8942326,11.4181595 L20.8950326,11.4189595 C20.6188902,11.4189595 20.3688902,11.3070306 20.1879258,11.1260662 C20.0069614,10.9451018 19.8950326,10.6951018 19.8950326,10.4189595 C19.8950326,10.1428171 20.0069614,9.89281709 20.1879258,9.71185268 C20.3688902,9.53088827 20.6188902,9.41895946 20.8948325,9.4189595 L20.8948325,9.4189595 L22.8942326,9.41815942 L22.8950326,7.41895946 C22.8950326,7.14281709 23.0069614,6.89281709 23.1879258,6.71185268 Z" id="形状结合" stroke="#FFFFFF" fill="#000000" fill-rule="nonzero"></path>
|
|
20
|
+
</g>
|
|
21
|
+
</g>
|
|
22
|
+
</g>
|
|
23
|
+
</g>
|
|
24
|
+
</svg>
|