@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
@@ -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] = parseFloat(x.toFixed(4));
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] = parseFloat(y.toFixed(4));
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, 4);
214
- point.y2 = toFixedValue(hull[0].y, 4);
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, 4);
219
- newPoint.y1 = toFixedValue(pCenter.y, 4);
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, 4);
224
- nextPoint.y1 = toFixedValue(hull[2].y, 4);
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, 4);
228
- newPoint.y2 = toFixedValue(pCenter.y, 4);
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, 4);
246
- path[y] = toFixedValue(pos.y, 4);
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, 4);
265
- path[y1] = toFixedValue(p2.y, 4);
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 }, { x: 0, y: 0 }, rotation);
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 }, { x: 0, y: 0 }, -rotation);
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
- const item = {
329
- ...c,
330
- x: toFixedValue(c.x - x, 4),
331
- y: toFixedValue(c.y - y, 4),
332
- };
333
- if (typeof c.x1 === 'number') {
334
- item.x1 = toFixedValue(c.x1 - x, 4);
335
- }
336
- if (typeof c.x2 === 'number') {
337
- item.x2 = toFixedValue(c.x2 - x, 4);
338
- }
339
- if (typeof c.y1 === 'number') {
340
- item.y1 = toFixedValue(c.y1 - y, 4);
341
- }
342
- if (typeof c.y2 === 'number') {
343
- item.y2 = toFixedValue(c.y2 - y, 4);
344
- }
345
- return item;
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 += position.x;
352
- y += position.y;
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: { ...path, paths: newPath, origin },
357
+ path,
356
358
  size: {
357
359
  ...size,
358
360
  width: contentWidth,
359
361
  height: contentHeight,
360
362
  },
361
- position: {
362
- x,
363
- y,
364
- },
363
+ // position: {
364
+ // x,
365
+ // y,
366
+ // },
365
367
  };
366
368
  };