@gedit/editor-2d 0.3.10 → 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.
Files changed (52) hide show
  1. package/lib/browser/model/editor2d-document.d.ts +3 -1
  2. package/lib/browser/model/editor2d-document.d.ts.map +1 -1
  3. package/lib/browser/model/editor2d-document.js +18 -12
  4. package/lib/browser/model/editor2d-document.js.map +1 -1
  5. package/lib/browser/model/utils/anim.utils.d.ts +1 -0
  6. package/lib/browser/model/utils/anim.utils.d.ts.map +1 -1
  7. package/lib/browser/model/utils/anim.utils.js +22 -0
  8. package/lib/browser/model/utils/anim.utils.js.map +1 -1
  9. package/lib/browser/playground/anim-path-edit-layer.d.ts.map +1 -1
  10. package/lib/browser/playground/anim-path-edit-layer.js +5 -3
  11. package/lib/browser/playground/anim-path-edit-layer.js.map +1 -1
  12. package/lib/browser/playground/canvas-draw.d.ts.map +1 -1
  13. package/lib/browser/playground/canvas-draw.js +6 -3
  14. package/lib/browser/playground/canvas-draw.js.map +1 -1
  15. package/lib/browser/playground/canvas-layer.d.ts +1 -2
  16. package/lib/browser/playground/canvas-layer.d.ts.map +1 -1
  17. package/lib/browser/playground/canvas-layer.js +53 -44
  18. package/lib/browser/playground/canvas-layer.js.map +1 -1
  19. package/lib/browser/playground/extend-edit/gradient-conic-node.js +4 -4
  20. package/lib/browser/playground/extend-edit/gradient-conic-node.js.map +1 -1
  21. package/lib/browser/playground/extend-edit/gradient-node.d.ts.map +1 -1
  22. package/lib/browser/playground/extend-edit/gradient-node.js +3 -3
  23. package/lib/browser/playground/extend-edit/gradient-node.js.map +1 -1
  24. package/lib/browser/playground/path-edit/utils.d.ts +2 -2
  25. package/lib/browser/playground/path-edit/utils.d.ts.map +1 -1
  26. package/lib/browser/playground/path-edit/utils.js +55 -45
  27. package/lib/browser/playground/path-edit/utils.js.map +1 -1
  28. package/lib/browser/playground/path-edit-layer.d.ts +11 -1
  29. package/lib/browser/playground/path-edit-layer.d.ts.map +1 -1
  30. package/lib/browser/playground/path-edit-layer.js +242 -75
  31. package/lib/browser/playground/path-edit-layer.js.map +1 -1
  32. package/lib/browser/playground/selection-entity-manager.d.ts.map +1 -1
  33. package/lib/browser/playground/selection-entity-manager.js +60 -10
  34. package/lib/browser/playground/selection-entity-manager.js.map +1 -1
  35. package/lib/browser/utils/bounds.js +4 -4
  36. package/lib/browser/utils/snapshot.d.ts.map +1 -1
  37. package/lib/browser/utils/snapshot.js +2 -1
  38. package/lib/browser/utils/snapshot.js.map +1 -1
  39. package/package.json +9 -9
  40. package/src/browser/model/editor2d-document.ts +22 -12
  41. package/src/browser/model/utils/anim.utils.ts +24 -0
  42. package/src/browser/playground/anim-path-edit-layer.tsx +8 -4
  43. package/src/browser/playground/canvas-draw.ts +6 -3
  44. package/src/browser/playground/canvas-layer.ts +25 -14
  45. package/src/browser/playground/extend-edit/gradient-conic-node.tsx +4 -4
  46. package/src/browser/playground/extend-edit/gradient-node.tsx +3 -2
  47. package/src/browser/playground/path-edit/utils.tsx +56 -54
  48. package/src/browser/playground/path-edit-layer.tsx +310 -74
  49. package/src/browser/playground/selection-entity-manager.tsx +127 -30
  50. package/src/browser/utils/bounds.ts +4 -4
  51. package/src/browser/utils/snapshot.ts +1 -0
  52. package/LICENSE +0 -21
@@ -13,17 +13,22 @@ import {
13
13
  } from '@gedit/playground';
14
14
  import type { PlaygroundContext2d } from './playground-context';
15
15
  import { Rectangle } from '@gedit/math';
16
- import { GameObject } from '@gedit/render-engine';
16
+ import { GameObject, GameObjectBaseType } from '@gedit/render-engine';
17
17
  import { SelectorExtendRender } from './selector-extend-renderer';
18
18
  import { followKeyType } from '@gedit/render-engine-pixi';
19
+ import {
20
+ getPathBounds,
21
+ PathGameObjectData,
22
+ toFixedValue,
23
+ } from '@gedit/canvas-draw';
19
24
 
20
- const numberToFixed4 = (data: {[key: string]: any}) => {
25
+ const numberToFixed4 = (data: { [key: string]: any }) => {
21
26
  const d: any = {};
22
27
  Object.keys(data).forEach(key => {
23
28
  const value = data[key];
24
29
  // 旋转不能四舍五入,不然属性面板旋转角度误差很大
25
30
  if (typeof value === 'number' && key !== 'rotation') {
26
- d[key] = parseFloat(value.toFixed(6));
31
+ d[key] = toFixedValue(value, 2);
27
32
  } else if (typeof value === 'object') {
28
33
  d[key] = numberToFixed4(value);
29
34
  } else {
@@ -43,13 +48,18 @@ export class SelectionEntityManager {
43
48
  protected context: PlaygroundContext2d,
44
49
  protected loading: () => boolean,
45
50
  protected getDocument: () => Editor2dDocument | undefined,
46
- protected isVisible: () => boolean,
51
+ protected isVisible: () => boolean
47
52
  ) {
48
- const editorStateConfigEntity = entityManager.getEntity<EditorStateConfigEntity>(EditorStateConfigEntity);
49
- const selectionConfigEntity = entityManager.getEntity<SelectorConfigEntity>(SelectorConfigEntity);
53
+ const editorStateConfigEntity = entityManager.getEntity<EditorStateConfigEntity>(
54
+ EditorStateConfigEntity
55
+ );
56
+ const selectionConfigEntity = entityManager.getEntity<SelectorConfigEntity>(
57
+ SelectorConfigEntity
58
+ );
50
59
  selectionConfigEntity?.customSelectorEntityRenderer(props => {
51
-
52
- const showSceneRangeRuler = editorStateConfigEntity?.getCurrentState?.() === EditorState.SHOW_SCENE_RANGE_RULER;
60
+ const showSceneRangeRuler =
61
+ editorStateConfigEntity?.getCurrentState?.() ===
62
+ EditorState.SHOW_SCENE_RANGE_RULER;
53
63
  const newProps: SelectorEntityRendererProps = {
54
64
  ...props,
55
65
  // editorStateConfigEntity, // 当前菜单状态, "SHOW_SCENE_RANGE_RULER" 显示场景范围标尺
@@ -57,7 +67,10 @@ export class SelectionEntityManager {
57
67
  };
58
68
  const entity = newProps.entity as Editor2dEntity;
59
69
  const register = entity.node
60
- ? this.context.renderEngine.getGameObjectIDERegister(entity.gameObject.scene.config.engine, entity.node.displayType)
70
+ ? this.context.renderEngine.getGameObjectIDERegister(
71
+ entity.gameObject.scene.config.engine,
72
+ entity.node.displayType
73
+ )
61
74
  : undefined;
62
75
  const deco = register?.decoration;
63
76
  newProps.extendRenderer = () => (
@@ -80,7 +93,11 @@ export class SelectionEntityManager {
80
93
  });
81
94
  }
82
95
 
83
- setTransformMask(entity: Editor2dEntity, nodePath: string, node?: Editor2dNode): void {
96
+ setTransformMask(
97
+ entity: Editor2dEntity,
98
+ nodePath: string,
99
+ node?: Editor2dNode
100
+ ): void {
84
101
  let maskEntity;
85
102
  if (node) {
86
103
  entity.transform.isMask = node.isMask;
@@ -107,15 +124,29 @@ export class SelectionEntityManager {
107
124
  * @param selectable
108
125
  * @param adsorbable
109
126
  */
110
- createEntity(nodePath: string, node: Editor2dNode, gameObject: GameObject, selectable: boolean, adsorbable: boolean): Editor2dEntity | undefined {
111
- const register = this.context.renderEngine.getGameObjectIDERegister(gameObject.scene.config.engine, node.displayType);
127
+ createEntity(
128
+ nodePath: string,
129
+ node: Editor2dNode,
130
+ gameObject: GameObject,
131
+ selectable: boolean,
132
+ adsorbable: boolean
133
+ ): Editor2dEntity | undefined {
134
+ const register = this.context.renderEngine.getGameObjectIDERegister(
135
+ gameObject.scene.config.engine,
136
+ node.displayType
137
+ );
112
138
  const deco = register.decoration;
113
139
  if (!register.getSelectionData || Editor2dNode.isRootNode(node)) return;
114
- const entity = this.entityManager.createEntity<Editor2dEntity>(Editor2dEntity, { id: nodePath });
140
+ const entity = this.entityManager.createEntity<Editor2dEntity>(
141
+ Editor2dEntity,
142
+ { id: nodePath }
143
+ );
115
144
  entity.selectableInit = selectable;
116
145
  entity.adsorbableInit = adsorbable;
117
- entity.mouseSelect = selectable && (deco.mouseSelect === undefined ? true : deco.mouseSelect);
118
- entity.adsorbable = adsorbable && (deco.adsorbable === undefined ? true : deco.adsorbable);
146
+ entity.mouseSelect =
147
+ selectable && (deco.mouseSelect === undefined ? true : deco.mouseSelect);
148
+ entity.adsorbable =
149
+ adsorbable && (deco.adsorbable === undefined ? true : deco.adsorbable);
119
150
  entity.gameObject = gameObject;
120
151
  entity.document = this.getDocument()!;
121
152
  entity.nodeId = node.id;
@@ -128,11 +159,15 @@ export class SelectionEntityManager {
128
159
  };
129
160
  }
130
161
 
162
+ if (gameObject.type === GameObjectBaseType.PATH) {
163
+ entity.transform.isPath = true;
164
+ }
165
+
131
166
  this.setTransformMask(entity, nodePath, node);
132
167
  // 切换选择框的类型,如圆形、矩形, 默认矩形
133
168
  if (deco.selectDisplayType) {
134
169
  entity.selectState.update({
135
- displayType: deco.selectDisplayType
170
+ displayType: deco.selectDisplayType,
136
171
  });
137
172
  }
138
173
  // 实体选中状态改变
@@ -186,18 +221,59 @@ export class SelectionEntityManager {
186
221
  const selectionNodes = document.getSelectedNodes();
187
222
  if (selectionNodes.some(c => c.id === node.id)) {
188
223
  document.message.warn(
189
- `元素开启了跟随,${type
190
- ?.map(c => followKeyType[c])
191
- .join(',') || 'x'} 被锁定`,
192
- {timeout: 2000 }
224
+ `元素开启了跟随,${
225
+ type?.map(c => followKeyType[c]).join(',') || 'x'
226
+ } 被锁定`,
227
+ { timeout: 2000 }
193
228
  );
194
229
  }
195
230
  }
196
231
  }
232
+ // 减掉根据 bounds 计算的 origin
233
+ if (gameObject.type === GameObjectBaseType.PATH) {
234
+ const { bounds: pathBounds } = (gameObject as GameObject & {
235
+ getBounds: () => { bounds: ReturnType<typeof getPathBounds> };
236
+ }).getBounds();
237
+ const { path } = gameObject.data as PathGameObjectData;
238
+ const {
239
+ origin = { x: 0, y: 0 },
240
+ } = node;
241
+ const { originChangeBeforeSize } = path;
242
+ const offset = {
243
+ x: 0,
244
+ y: 0,
245
+ };
246
+ if (originChangeBeforeSize) {
247
+ if (originChangeBeforeSize.width !== pathBounds.width) {
248
+ offset.x +=
249
+ ((pathBounds.width - originChangeBeforeSize.width) * origin.x) /
250
+ pathBounds.width;
251
+ }
252
+ if (originChangeBeforeSize.height !== pathBounds.height) {
253
+ offset.y +=
254
+ ((pathBounds.height - originChangeBeforeSize.height) * origin.y) /
255
+ pathBounds.height;
256
+ }
257
+ }
258
+ newTransform.origin.x = toFixedValue(
259
+ newTransform.origin.x +
260
+ (pathBounds ? pathBounds.minX / pathBounds.width : 0) +
261
+ offset.x,
262
+ 2
263
+ );
264
+ newTransform.origin.y = toFixedValue(
265
+ newTransform.origin.y +
266
+ (pathBounds ? pathBounds.minY / pathBounds.height : 0) +
267
+ offset.y,
268
+ 2
269
+ );
270
+ }
197
271
  let oldTransform: TransformSchema = {} as TransformSchema;
198
- Object.keys(entity.transform.data).forEach((key: keyof typeof entity.transform.data) => {
199
- oldTransform[key] = node[key]! as any;
200
- });
272
+ Object.keys(entity.transform.data).forEach(
273
+ (key: keyof typeof entity.transform.data) => {
274
+ oldTransform[key] = node[key]! as any;
275
+ }
276
+ );
201
277
  oldTransform = numberToFixed4(oldTransform);
202
278
  if (JSON.stringify(oldTransform) !== JSON.stringify(newTransform)) {
203
279
  document.updateNode(node, newTransform, true);
@@ -229,7 +305,10 @@ export class SelectionEntityManager {
229
305
  }
230
306
  }
231
307
  updateEntity(nodePath: string, gameObject: GameObject, scale?: number): void {
232
- const register = this.context.renderEngine.getGameObjectIDERegister(gameObject.scene.config.engine, gameObject.type);
308
+ const register = this.context.renderEngine.getGameObjectIDERegister(
309
+ gameObject.scene.config.engine,
310
+ gameObject.type
311
+ );
233
312
  const deco = register.decoration;
234
313
  const entity = this.nodeEntitiesCache.get(nodePath);
235
314
  if (!entity || !register.getSelectionData) {
@@ -238,7 +317,9 @@ export class SelectionEntityManager {
238
317
  const node = entity.node;
239
318
  entity.ignoreTransformChanged = true;
240
319
  if (gameObject.parent) {
241
- const parentEntity = this.nodeEntitiesCache.get(gameObject.parent.id as string);
320
+ const parentEntity = this.nodeEntitiesCache.get(
321
+ gameObject.parent.id as string
322
+ );
242
323
  if (parentEntity) {
243
324
  entity.transform.setParent(parentEntity.transform);
244
325
  }
@@ -250,6 +331,9 @@ export class SelectionEntityManager {
250
331
  height: gameObject.data.scene?.height || 400,
251
332
  };
252
333
  }
334
+ if (gameObject.type === GameObjectBaseType.PATH) {
335
+ entity.transform.isPath = true;
336
+ }
253
337
  entity.update(register.getSelectionData(gameObject, scale));
254
338
  entity.ignoreTransformChanged = false;
255
339
  const sizeVisible = !this.isHidden(entity.node); // && (entity.transform.size.width > 0 && entity.transform.size.height > 0 || !!deco.isContainer);
@@ -257,9 +341,16 @@ export class SelectionEntityManager {
257
341
  // 图层节点无法被选中
258
342
  entity.selectable = entity.selectableInit && sizeVisible;
259
343
  // 锁定状态的节点无法通过鼠标点击
260
- entity.mouseSelect = (deco.mouseSelect === undefined ? true : deco.mouseSelect) && !opacityZero && !this.isLocked(node);
344
+ entity.mouseSelect =
345
+ (deco.mouseSelect === undefined ? true : deco.mouseSelect) &&
346
+ !opacityZero &&
347
+ !this.isLocked(node);
261
348
  // 是否支持吸附
262
- entity.adsorbable = entity.adsorbableInit && sizeVisible && !opacityZero && (deco.adsorbable === undefined ? true : deco.adsorbable);
349
+ entity.adsorbable =
350
+ entity.adsorbableInit &&
351
+ sizeVisible &&
352
+ !opacityZero &&
353
+ (deco.adsorbable === undefined ? true : deco.adsorbable);
263
354
  // 同步选中状态
264
355
  entity.selected = !!node?.selected;
265
356
  // 更新zIndex, 每次都要更新,因为节点拖拽会导致所有的zIndex顺序错乱
@@ -284,7 +375,11 @@ export class SelectionEntityManager {
284
375
  scrollToSelectedNodes(): void {
285
376
  const entitiesScrollTo: Editor2dEntity[] = [];
286
377
  for (const entity of this.nodeEntitiesCache.values()) {
287
- if (!Editor2dNode.isRootNode(entity.node) && entity.node && entity.selectable) {
378
+ if (
379
+ !Editor2dNode.isRootNode(entity.node) &&
380
+ entity.node &&
381
+ entity.selectable
382
+ ) {
288
383
  if (!entity.selected && entity.node.selected) {
289
384
  entitiesScrollTo.push(entity);
290
385
  }
@@ -295,9 +390,11 @@ export class SelectionEntityManager {
295
390
  // this.context.syncToSelectionService(this);
296
391
  if (entitiesScrollTo.length > 0) {
297
392
  // 滚动画布到选中的节点
298
- this.entityManager.getEntity<PlaygroundConfigEntity>(PlaygroundConfigEntity)!.scrollToView({entities: entitiesScrollTo});
393
+ this.entityManager
394
+ .getEntity<PlaygroundConfigEntity>(PlaygroundConfigEntity)!
395
+ .scrollToView({ entities: entitiesScrollTo });
299
396
  }
300
- };
397
+ }
301
398
 
302
399
  /**
303
400
  * 获取所有实体的外围最大矩形
@@ -100,10 +100,10 @@ export const getPIXILocalBoundsByNode = (obj: GameObjectData): ChildBounds => {
100
100
  ? { x: 0, y: 0, height: 0, width: 0 }
101
101
  : Bounds.getBounds(data as any, transformData);
102
102
  return {
103
- x: toFixedValue(bounds.x, 6),
104
- y: toFixedValue(bounds.y, 6),
105
- maxX: toFixedValue(bounds.x + bounds.width, 6),
106
- maxY: toFixedValue(bounds.y + bounds.height, 6),
103
+ x: toFixedValue(bounds.x, 2),
104
+ y: toFixedValue(bounds.y, 2),
105
+ maxX: toFixedValue(bounds.x + bounds.width, 2),
106
+ maxY: toFixedValue(bounds.y + bounds.height, 2),
107
107
  isMask: c.isMask,
108
108
  mask: c.mask,
109
109
  id: c.id,
@@ -133,6 +133,7 @@ export class SnapshotCreator extends DisposableImpl {
133
133
  this.current = undefined;
134
134
  this.processing = undefined;
135
135
  this.drawer.renderWidget?.currentScene?.dispose();
136
+ this.drawer.renderWidget?.dispose();
136
137
  }));
137
138
  dispose.push(
138
139
  drawer!.onLoading(e => {
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 GEdit
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.