@gedit/editor-2d 0.3.9 → 0.3.11
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 +3 -1
- package/lib/browser/model/editor2d-document.d.ts.map +1 -1
- package/lib/browser/model/editor2d-document.js +18 -12
- package/lib/browser/model/editor2d-document.js.map +1 -1
- package/lib/browser/model/utils/anim.utils.d.ts +1 -0
- package/lib/browser/model/utils/anim.utils.d.ts.map +1 -1
- package/lib/browser/model/utils/anim.utils.js +22 -0
- package/lib/browser/model/utils/anim.utils.js.map +1 -1
- package/lib/browser/playground/anim-path-edit-layer.d.ts.map +1 -1
- package/lib/browser/playground/anim-path-edit-layer.js +5 -3
- package/lib/browser/playground/anim-path-edit-layer.js.map +1 -1
- package/lib/browser/playground/canvas-draw.d.ts +1 -0
- package/lib/browser/playground/canvas-draw.d.ts.map +1 -1
- package/lib/browser/playground/canvas-draw.js +26 -11
- package/lib/browser/playground/canvas-draw.js.map +1 -1
- package/lib/browser/playground/canvas-layer.d.ts +1 -2
- package/lib/browser/playground/canvas-layer.d.ts.map +1 -1
- package/lib/browser/playground/canvas-layer.js +53 -44
- package/lib/browser/playground/canvas-layer.js.map +1 -1
- package/lib/browser/playground/extend-edit/gradient-conic-node.js +4 -4
- package/lib/browser/playground/extend-edit/gradient-conic-node.js.map +1 -1
- package/lib/browser/playground/extend-edit/gradient-node.d.ts.map +1 -1
- package/lib/browser/playground/extend-edit/gradient-node.js +3 -3
- package/lib/browser/playground/extend-edit/gradient-node.js.map +1 -1
- package/lib/browser/playground/path-edit/utils.d.ts +2 -2
- package/lib/browser/playground/path-edit/utils.d.ts.map +1 -1
- package/lib/browser/playground/path-edit/utils.js +55 -45
- package/lib/browser/playground/path-edit/utils.js.map +1 -1
- package/lib/browser/playground/path-edit-layer.d.ts +11 -1
- package/lib/browser/playground/path-edit-layer.d.ts.map +1 -1
- package/lib/browser/playground/path-edit-layer.js +242 -75
- package/lib/browser/playground/path-edit-layer.js.map +1 -1
- package/lib/browser/playground/selection-entity-manager.d.ts.map +1 -1
- package/lib/browser/playground/selection-entity-manager.js +60 -10
- package/lib/browser/playground/selection-entity-manager.js.map +1 -1
- package/lib/browser/utils/bounds.js +4 -4
- package/lib/browser/utils/snapshot.d.ts.map +1 -1
- package/lib/browser/utils/snapshot.js +2 -1
- package/lib/browser/utils/snapshot.js.map +1 -1
- package/package.json +9 -9
- package/src/browser/model/editor2d-document.ts +22 -12
- package/src/browser/model/utils/anim.utils.ts +24 -0
- package/src/browser/playground/anim-path-edit-layer.tsx +8 -4
- package/src/browser/playground/canvas-draw.ts +24 -6
- package/src/browser/playground/canvas-layer.ts +25 -14
- package/src/browser/playground/extend-edit/gradient-conic-node.tsx +4 -4
- package/src/browser/playground/extend-edit/gradient-node.tsx +3 -2
- package/src/browser/playground/path-edit/utils.tsx +56 -54
- package/src/browser/playground/path-edit-layer.tsx +310 -74
- package/src/browser/playground/selection-entity-manager.tsx +127 -30
- package/src/browser/utils/bounds.ts +4 -4
- package/src/browser/utils/snapshot.ts +1 -0
- package/LICENSE +0 -21
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { entity, Layer, PipelineDimension } from '@gedit/playground';
|
|
2
|
-
import { DocumentEntity
|
|
2
|
+
import { DocumentEntity /* Editor2dEntity */ } from './entities';
|
|
3
3
|
import { domUtils } from '@gedit/utils/lib/browser';
|
|
4
4
|
import { PlaygroundContext2d } from './playground-context';
|
|
5
5
|
import { Editor2dDocument, Editor2dNode } from '../model';
|
|
@@ -11,13 +11,13 @@ import {
|
|
|
11
11
|
GameObjectChangeEvent,
|
|
12
12
|
GameObjectEventType,
|
|
13
13
|
} from './canvas-draw';
|
|
14
|
-
import { debounce
|
|
14
|
+
import { debounce /* OriginSchema */ } from '@gedit/utils';
|
|
15
15
|
import {
|
|
16
16
|
GameObject,
|
|
17
|
-
GameObjectBaseType,
|
|
17
|
+
// GameObjectBaseType,
|
|
18
18
|
GameWidgetIDE,
|
|
19
19
|
} from '@gedit/render-engine-ide';
|
|
20
|
-
import { toFixedValue } from '@gedit/canvas-draw';
|
|
20
|
+
// import { toFixedValue } from '@gedit/canvas-draw';
|
|
21
21
|
|
|
22
22
|
const childrenMap = (list: GameObject[], c: GameObject) => {
|
|
23
23
|
if (c.disposed) {
|
|
@@ -128,9 +128,15 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
|
|
|
128
128
|
);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
+
// pixi 和 galacean 的画布会被立即杀掉,这块初始化逻辑不需要了
|
|
132
|
+
/* originTimeout: NodeJS.Timeout;
|
|
131
133
|
onContainerInitOrigin(entity?: Editor2dEntity, update?: boolean): void {
|
|
132
134
|
const config = this.documentEntity.config;
|
|
133
|
-
if (
|
|
135
|
+
if (
|
|
136
|
+
(config.appConfig?.engine !== 'pixi' &&
|
|
137
|
+
config.appConfig?.engine !== 'galacean') ||
|
|
138
|
+
!entity
|
|
139
|
+
) {
|
|
134
140
|
return;
|
|
135
141
|
}
|
|
136
142
|
const node = this.nodeCache.get(entity.id);
|
|
@@ -142,8 +148,8 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
|
|
|
142
148
|
// console.log(localBounds, entity.gameObject.rendererObject._localBoundsRect);
|
|
143
149
|
const { x: minX, y: minY, width, height } = localBounds; // entity.gameObject.rendererObject._localBoundsRect;
|
|
144
150
|
// 算出组件与组的 0 点位置;
|
|
145
|
-
const x = toFixedValue(-minX / width || 0,
|
|
146
|
-
const y = toFixedValue(-minY / height || 0,
|
|
151
|
+
const x = toFixedValue(-minX / width || 0, 2);
|
|
152
|
+
const y = toFixedValue(-minY / height || 0, 2);
|
|
147
153
|
const initOrigin = { x, y };
|
|
148
154
|
const o: OriginSchema = update ? org : initOrigin;
|
|
149
155
|
if (update || typeof o.initX === 'undefined') {
|
|
@@ -156,15 +162,20 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
|
|
|
156
162
|
};
|
|
157
163
|
// group origin 始终为 0;
|
|
158
164
|
// transform.update({ origin });
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
165
|
+
// node.origin = origin;
|
|
166
|
+
// 加 timeout 是为了防止拖动时多次触发;
|
|
167
|
+
clearTimeout(this.originTimeout);
|
|
168
|
+
this.originTimeout = setTimeout(() => {
|
|
169
|
+
this.document?.updateNode(node, {
|
|
170
|
+
origin,
|
|
171
|
+
});
|
|
172
|
+
}, 33);
|
|
173
|
+
// console.log('--------------origin--------------', origin, node.size);
|
|
163
174
|
// obj.data.origin = origin;
|
|
164
175
|
// this.selectionEntityManager.updateEntity(obj.id, obj);
|
|
165
176
|
}
|
|
166
177
|
}
|
|
167
|
-
}
|
|
178
|
+
} */
|
|
168
179
|
onUpdateEntity = debounce((update: boolean) => {
|
|
169
180
|
const updateList = getListData(this.updateList);
|
|
170
181
|
updateList.forEach(item => {
|
|
@@ -177,8 +188,8 @@ export class CanvasLayer extends Layer<PlaygroundContext2d> {
|
|
|
177
188
|
item,
|
|
178
189
|
this.config.config.zoom
|
|
179
190
|
);
|
|
180
|
-
const entity = this.selectionEntityManager.nodeEntitiesCache.get(item.id);
|
|
181
|
-
this.onContainerInitOrigin(entity, update);
|
|
191
|
+
// const entity = this.selectionEntityManager.nodeEntitiesCache.get(item.id);
|
|
192
|
+
// this.onContainerInitOrigin(entity, update);
|
|
182
193
|
});
|
|
183
194
|
this.updateList = [];
|
|
184
195
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import { asVec, defaultGradientRange } from '@gedit/canvas-draw';
|
|
3
|
+
import { asVec, defaultGradientRange, toFixedValue } from '@gedit/canvas-draw';
|
|
4
4
|
import PointEvent from './gradient-edit-layer-point-event';
|
|
5
5
|
import { GradientNodeProps } from './gradient-node';
|
|
6
6
|
|
|
@@ -40,7 +40,7 @@ export const GradientConicNode = (props: GradientNodeProps): JSX.Element => {
|
|
|
40
40
|
const newVec = asVec({ x: r, y: r }, { x: nx, y: ny });
|
|
41
41
|
const newAngle = ((newVec.ang / Math.PI) * 180 + 360) % 360;
|
|
42
42
|
const newRange = data.range || {};
|
|
43
|
-
newRange.angle =
|
|
43
|
+
newRange.angle = toFixedValue(newAngle, 2);
|
|
44
44
|
data.range = newRange;
|
|
45
45
|
onChange(data);
|
|
46
46
|
}}
|
|
@@ -95,8 +95,8 @@ export const GradientConicNode = (props: GradientNodeProps): JSX.Element => {
|
|
|
95
95
|
pointClassName="gedit-extend-origin"
|
|
96
96
|
onChange={d => {
|
|
97
97
|
const newRange = data.range || {};
|
|
98
|
-
newRange.cx =
|
|
99
|
-
newRange.cy =
|
|
98
|
+
newRange.cx = toFixedValue(cx + d.x / width, 2);
|
|
99
|
+
newRange.cy = toFixedValue(cy + d.y / height, 2);
|
|
100
100
|
data.range = newRange;
|
|
101
101
|
onChange(data);
|
|
102
102
|
}}
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
ColorSchema,
|
|
7
7
|
defaultGradientRange,
|
|
8
8
|
getLineWidth,
|
|
9
|
+
toFixedValue,
|
|
9
10
|
} from '@gedit/canvas-draw';
|
|
10
11
|
import PointEvent, { DifferProps } from './gradient-edit-layer-point-event';
|
|
11
12
|
import { ExtendEntity } from '../entities';
|
|
@@ -40,13 +41,13 @@ export const GradientNode = (props: GradientNodeProps): JSX.Element => {
|
|
|
40
41
|
const range = data.range || {};
|
|
41
42
|
if (typeof p.x === 'number' && typeof c.x === 'number' && keyP.x) {
|
|
42
43
|
const x = c.x + p.x / width;
|
|
43
|
-
range[keyP.x] =
|
|
44
|
+
range[keyP.x] = toFixedValue(x, 2);
|
|
44
45
|
} else if (keyP.x) {
|
|
45
46
|
range[keyP.x] = lx;
|
|
46
47
|
}
|
|
47
48
|
if (typeof p.y === 'number' && typeof c.y === 'number' && keyP.y) {
|
|
48
49
|
const y = c.y + p.y / height;
|
|
49
|
-
range[keyP.y] =
|
|
50
|
+
range[keyP.y] = toFixedValue(y, 2);
|
|
50
51
|
} else if (keyP.y) {
|
|
51
52
|
range[keyP.y] = ly;
|
|
52
53
|
}
|
|
@@ -210,22 +210,22 @@ export const getNewPoint = (
|
|
|
210
210
|
let pCenter;
|
|
211
211
|
if (point.type !== PATH_FUNC_TYPE.STRAIGHT) {
|
|
212
212
|
point.type = PATH_FUNC_TYPE.UNEQUAL;
|
|
213
|
-
point.x2 = toFixedValue(hull[0].x,
|
|
214
|
-
point.y2 = toFixedValue(hull[0].y,
|
|
213
|
+
point.x2 = toFixedValue(hull[0].x, 2);
|
|
214
|
+
point.y2 = toFixedValue(hull[0].y, 2);
|
|
215
215
|
} else {
|
|
216
216
|
// 不是贝赛尔时,转换回二次贝赛尔点;
|
|
217
217
|
pCenter = cubicToQuadratic(hull[5], hull[3]);
|
|
218
|
-
newPoint.x1 = toFixedValue(pCenter.x,
|
|
219
|
-
newPoint.y1 = toFixedValue(pCenter.y,
|
|
218
|
+
newPoint.x1 = toFixedValue(pCenter.x, 2);
|
|
219
|
+
newPoint.y1 = toFixedValue(pCenter.y, 2);
|
|
220
220
|
}
|
|
221
221
|
if (nextPoint.type !== PATH_FUNC_TYPE.STRAIGHT) {
|
|
222
222
|
nextPoint.type = PATH_FUNC_TYPE.UNEQUAL;
|
|
223
|
-
nextPoint.x1 = toFixedValue(hull[2].x,
|
|
224
|
-
nextPoint.y1 = toFixedValue(hull[2].y,
|
|
223
|
+
nextPoint.x1 = toFixedValue(hull[2].x, 2);
|
|
224
|
+
nextPoint.y1 = toFixedValue(hull[2].y, 2);
|
|
225
225
|
} else {
|
|
226
226
|
pCenter = cubicToQuadratic(hull[5], hull[4]);
|
|
227
|
-
newPoint.x2 = toFixedValue(pCenter.x,
|
|
228
|
-
newPoint.y2 = toFixedValue(pCenter.y,
|
|
227
|
+
newPoint.x2 = toFixedValue(pCenter.x, 2);
|
|
228
|
+
newPoint.y2 = toFixedValue(pCenter.y, 2);
|
|
229
229
|
}
|
|
230
230
|
return newPoint;
|
|
231
231
|
};
|
|
@@ -242,8 +242,8 @@ export const setBezierMovePoint = (
|
|
|
242
242
|
const y1 = key === 'left' ? 'y2' : 'y1';
|
|
243
243
|
const center = { x: path.x, y: path.y };
|
|
244
244
|
const currentPoint = { x: pos.x, y: pos.y };
|
|
245
|
-
path[x] = toFixedValue(pos.x,
|
|
246
|
-
path[y] = toFixedValue(pos.y,
|
|
245
|
+
path[x] = toFixedValue(pos.x, 2);
|
|
246
|
+
path[y] = toFixedValue(pos.y, 2);
|
|
247
247
|
let p2: PointSchema | false = false;
|
|
248
248
|
const isOnly =
|
|
249
249
|
typeof path[x1] === 'undefined' && typeof path[y1] === 'undefined';
|
|
@@ -261,8 +261,8 @@ export const setBezierMovePoint = (
|
|
|
261
261
|
break;
|
|
262
262
|
}
|
|
263
263
|
if (p2) {
|
|
264
|
-
path[x1] = toFixedValue(p2.x,
|
|
265
|
-
path[y1] = toFixedValue(p2.y,
|
|
264
|
+
path[x1] = toFixedValue(p2.x, 2);
|
|
265
|
+
path[y1] = toFixedValue(p2.y, 2);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
return path;
|
|
@@ -270,13 +270,14 @@ export const setBezierMovePoint = (
|
|
|
270
270
|
|
|
271
271
|
export const transformToData = (
|
|
272
272
|
point: PointSchema,
|
|
273
|
-
transform: { scale?: ScaleSchema; rotation?: number }
|
|
273
|
+
transform: { scale?: ScaleSchema; rotation?: number },
|
|
274
|
+
center: PointSchema
|
|
274
275
|
) => {
|
|
275
|
-
const { scale = { x: 1, y: 1}, rotation = 0 } = transform;
|
|
276
|
+
const { scale = { x: 1, y: 1 }, rotation = 0 } = transform;
|
|
276
277
|
let { x, y } = point;
|
|
277
278
|
x *= scale.x;
|
|
278
279
|
y *= scale.y;
|
|
279
|
-
const rx = transformRotation({ x, y },
|
|
280
|
+
const rx = transformRotation({ x, y }, center, rotation);
|
|
280
281
|
x = rx.x;
|
|
281
282
|
y = rx.y;
|
|
282
283
|
return {
|
|
@@ -287,11 +288,12 @@ export const transformToData = (
|
|
|
287
288
|
|
|
288
289
|
export const inverseTransformToData = (
|
|
289
290
|
point: PointSchema,
|
|
290
|
-
transform: { scale: ScaleSchema; rotation: number }
|
|
291
|
+
transform: { scale: ScaleSchema; rotation: number },
|
|
292
|
+
center: PointSchema
|
|
291
293
|
) => {
|
|
292
294
|
const { scale, rotation } = transform;
|
|
293
295
|
let { x, y } = point;
|
|
294
|
-
const r = transformRotation({ x, y },
|
|
296
|
+
const r = transformRotation({ x, y }, center, -rotation);
|
|
295
297
|
x = r.x;
|
|
296
298
|
y = r.y;
|
|
297
299
|
x /= scale.x;
|
|
@@ -303,13 +305,13 @@ export const updatePathNodeData = (
|
|
|
303
305
|
node: Editor2dPathNode
|
|
304
306
|
): { path: PathSchema; position?: PositionSchema; size: SizeSchema } => {
|
|
305
307
|
const {
|
|
306
|
-
position = { x: 0, y: 0 },
|
|
307
|
-
origin = { x: 0.5, y: 0.5 },
|
|
308
|
+
// position = { x: 0, y: 0 },
|
|
309
|
+
// origin = { x: 0.5, y: 0.5 },
|
|
308
310
|
path,
|
|
309
311
|
style,
|
|
310
|
-
size,
|
|
311
|
-
rotation = 0,
|
|
312
|
-
scale = { x: 1, y: 1 },
|
|
312
|
+
size = { width: 0, height: 0},
|
|
313
|
+
// rotation = 0,
|
|
314
|
+
// scale = { x: 1, y: 1 },
|
|
313
315
|
} = node;
|
|
314
316
|
const { paths: p = [], closed } = path;
|
|
315
317
|
const paths = cloneDeep(p);
|
|
@@ -321,46 +323,46 @@ export const updatePathNodeData = (
|
|
|
321
323
|
style!.line,
|
|
322
324
|
bounds
|
|
323
325
|
);
|
|
324
|
-
let x = bounds.minX + bounds.width * origin!.x;
|
|
325
|
-
let y = bounds.minY + bounds.height * origin!.y;
|
|
326
|
+
// let x = bounds.minX + bounds.width * origin!.x;
|
|
327
|
+
// let y = bounds.minY + bounds.height * origin!.y;
|
|
326
328
|
|
|
327
|
-
const newPath = p.map(c => {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
});
|
|
347
|
-
const t = transformToData({ x, y }, { scale, rotation });
|
|
348
|
-
x = t.x;
|
|
349
|
-
y = t.y;
|
|
329
|
+
// const newPath = p.map(c => {
|
|
330
|
+
// const item = {
|
|
331
|
+
// ...c,
|
|
332
|
+
// x: toFixedValue(c.x - x, 4),
|
|
333
|
+
// y: toFixedValue(c.y - y, 4),
|
|
334
|
+
// };
|
|
335
|
+
// if (typeof c.x1 === 'number') {
|
|
336
|
+
// item.x1 = toFixedValue(c.x1 - x, 4);
|
|
337
|
+
// }
|
|
338
|
+
// if (typeof c.x2 === 'number') {
|
|
339
|
+
// item.x2 = toFixedValue(c.x2 - x, 4);
|
|
340
|
+
// }
|
|
341
|
+
// if (typeof c.y1 === 'number') {
|
|
342
|
+
// item.y1 = toFixedValue(c.y1 - y, 4);
|
|
343
|
+
// }
|
|
344
|
+
// if (typeof c.y2 === 'number') {
|
|
345
|
+
// item.y2 = toFixedValue(c.y2 - y, 4);
|
|
346
|
+
// }
|
|
347
|
+
// return item;
|
|
348
|
+
// });
|
|
350
349
|
|
|
351
|
-
x
|
|
352
|
-
|
|
350
|
+
// const t = transformToData({ x, y }, { scale, rotation });
|
|
351
|
+
// x = t.x;
|
|
352
|
+
// y = t.y;
|
|
353
353
|
|
|
354
|
+
// x += position.x;
|
|
355
|
+
// y += position.y;
|
|
354
356
|
return {
|
|
355
|
-
path
|
|
357
|
+
path,
|
|
356
358
|
size: {
|
|
357
359
|
...size,
|
|
358
360
|
width: contentWidth,
|
|
359
361
|
height: contentHeight,
|
|
360
362
|
},
|
|
361
|
-
position: {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
},
|
|
363
|
+
// position: {
|
|
364
|
+
// x,
|
|
365
|
+
// y,
|
|
366
|
+
// },
|
|
365
367
|
};
|
|
366
368
|
};
|