@leafer-editor/worker 1.0.10 → 1.1.0

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.
@@ -108,7 +108,7 @@ const MathHelper = {
108
108
  return rotation - oldRotation;
109
109
  },
110
110
  float(num, maxLength) {
111
- const a = maxLength ? pow$1(10, maxLength) : 1000000000000;
111
+ const a = maxLength !== undefined ? pow$1(10, maxLength) : 1000000000000;
112
112
  num = round(num * a) / a;
113
113
  return num === -0 ? 0 : num;
114
114
  },
@@ -4165,20 +4165,17 @@ const LeafHelper = {
4165
4165
  }
4166
4166
  return true;
4167
4167
  },
4168
- moveWorld(t, x, y = 0, isInnerPoint) {
4168
+ moveWorld(t, x, y = 0, isInnerPoint, transition) {
4169
4169
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4170
4170
  isInnerPoint ? toOuterPoint$1(t.localTransform, local, local, true) : (t.parent && toInnerPoint$1(t.parent.worldTransform, local, local, true));
4171
- L$3.moveLocal(t, local.x, local.y);
4171
+ L$3.moveLocal(t, local.x, local.y, transition);
4172
4172
  },
4173
- moveLocal(t, x, y = 0) {
4174
- if (typeof x === 'object') {
4175
- t.x += x.x;
4176
- t.y += x.y;
4177
- }
4178
- else {
4179
- t.x += x;
4180
- t.y += y;
4181
- }
4173
+ moveLocal(t, x, y = 0, transition) {
4174
+ if (typeof x === 'object')
4175
+ y = x.y, x = x.x;
4176
+ x += t.x;
4177
+ y += t.y;
4178
+ transition ? t.animate({ x, y }, transition) : (t.x = x, t.y = y);
4182
4179
  },
4183
4180
  zoomOfWorld(t, origin, scaleX, scaleY, resize) {
4184
4181
  L$3.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
@@ -5558,11 +5555,11 @@ let Leaf = class Leaf {
5558
5555
  transform(matrix, resize) {
5559
5556
  transform(this, matrix, resize);
5560
5557
  }
5561
- move(x, y) {
5562
- moveLocal(this, x, y);
5558
+ move(x, y, transition) {
5559
+ moveLocal(this, x, y, transition);
5563
5560
  }
5564
- moveInner(x, y) {
5565
- moveWorld(this, x, y, true);
5561
+ moveInner(x, y, transition) {
5562
+ moveWorld(this, x, y, true, transition);
5566
5563
  }
5567
5564
  scaleOf(origin, scaleX, scaleY, resize) {
5568
5565
  zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
@@ -5576,8 +5573,8 @@ let Leaf = class Leaf {
5576
5573
  transformWorld(worldTransform, resize) {
5577
5574
  transformWorld(this, worldTransform, resize);
5578
5575
  }
5579
- moveWorld(x, y) {
5580
- moveWorld(this, x, y);
5576
+ moveWorld(x, y, transition) {
5577
+ moveWorld(this, x, y, false, transition);
5581
5578
  }
5582
5579
  scaleOfWorld(worldOrigin, scaleX, scaleY, resize) {
5583
5580
  zoomOfWorld(this, worldOrigin, scaleX, scaleY, resize);
@@ -5975,7 +5972,7 @@ class LeafLevelList {
5975
5972
  }
5976
5973
  }
5977
5974
 
5978
- const version = "1.0.10";
5975
+ const version = "1.1.0";
5979
5976
 
5980
5977
  class LeaferCanvas extends LeaferCanvasBase {
5981
5978
  get allowBackgroundColor() { return true; }
@@ -7405,11 +7402,15 @@ let UI = UI_1 = class UI extends Leaf {
7405
7402
  super(data);
7406
7403
  }
7407
7404
  reset(_data) { }
7408
- set(data, isTemp) {
7409
- if (isTemp) {
7410
- this.lockNormalStyle = true;
7411
- Object.assign(this, data);
7412
- this.lockNormalStyle = false;
7405
+ set(data, transition) {
7406
+ if (transition) {
7407
+ if (transition === 'temp') {
7408
+ this.lockNormalStyle = true;
7409
+ Object.assign(this, data);
7410
+ this.lockNormalStyle = false;
7411
+ }
7412
+ else
7413
+ this.animate(data, transition);
7413
7414
  }
7414
7415
  else
7415
7416
  Object.assign(this, data);
@@ -7719,17 +7720,17 @@ let Group = class Group extends UI {
7719
7720
  if (!this.children)
7720
7721
  this.children = [];
7721
7722
  }
7722
- set(data, isTemp) {
7723
+ set(data, transition) {
7723
7724
  if (data.children) {
7724
7725
  const { children } = data;
7725
7726
  delete data.children;
7726
7727
  this.children ? this.clear() : this.__setBranch();
7727
- super.set(data, isTemp);
7728
+ super.set(data, transition);
7728
7729
  children.forEach(child => this.add(child));
7729
7730
  data.children = children;
7730
7731
  }
7731
7732
  else
7732
- super.set(data, isTemp);
7733
+ super.set(data, transition);
7733
7734
  }
7734
7735
  toJSON(options) {
7735
7736
  const data = super.toJSON(options);
@@ -7842,8 +7843,8 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7842
7843
  }
7843
7844
  onInit() { }
7844
7845
  initType(_type) { }
7845
- set(data) {
7846
- this.waitInit(() => { super.set(data); });
7846
+ set(data, transition) {
7847
+ this.waitInit(() => { super.set(data, transition); });
7847
7848
  }
7848
7849
  start() {
7849
7850
  clearTimeout(this.__startTimer);
@@ -9032,10 +9033,8 @@ let DragEvent = class DragEvent extends PointerEvent {
9032
9033
  this.data = data;
9033
9034
  }
9034
9035
  static getValidMove(leaf, start, total) {
9035
- const { draggable, dragBounds, x, y } = leaf;
9036
- const move = leaf.getLocalPoint(total, null, true);
9037
- move.x += start.x - x;
9038
- move.y += start.y - y;
9036
+ const { draggable, dragBounds } = leaf, move = leaf.getLocalPoint(total, null, true);
9037
+ PointHelper.move(move, start.x - leaf.x, start.y - leaf.y);
9039
9038
  if (dragBounds)
9040
9039
  this.getMoveInDragBounds(leaf.__local, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true);
9041
9040
  if (draggable === 'x')
@@ -9045,8 +9044,7 @@ let DragEvent = class DragEvent extends PointerEvent {
9045
9044
  return move;
9046
9045
  }
9047
9046
  static getMoveInDragBounds(childBox, dragBounds, move, change) {
9048
- const x = childBox.x + move.x, y = childBox.y + move.y;
9049
- const right = x + childBox.width, bottom = y + childBox.height;
9047
+ const x = childBox.x + move.x, y = childBox.y + move.y, right = x + childBox.width, bottom = y + childBox.height;
9050
9048
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
9051
9049
  if (!change)
9052
9050
  move = Object.assign({}, move);
@@ -9098,9 +9096,7 @@ let DragEvent = class DragEvent extends PointerEvent {
9098
9096
  return this.getLocalMove(relative, true);
9099
9097
  }
9100
9098
  getPageBounds() {
9101
- const total = this.getPageTotal();
9102
- const start = this.getPagePoint();
9103
- const bounds = {};
9099
+ const total = this.getPageTotal(), start = this.getPagePoint(), bounds = {};
9104
9100
  BoundsHelper.set(bounds, start.x - total.x, start.y - total.y, total.x, total.y);
9105
9101
  BoundsHelper.unsign(bounds);
9106
9102
  return bounds;
@@ -10488,6 +10484,8 @@ function stroke(stroke, ui, canvas) {
10488
10484
  case 'center':
10489
10485
  canvas.setStroke(stroke, __strokeWidth, options);
10490
10486
  canvas.stroke();
10487
+ if (options.__useArrow)
10488
+ strokeArrow(ui, canvas);
10491
10489
  break;
10492
10490
  case 'inside':
10493
10491
  canvas.save();
@@ -10525,6 +10523,8 @@ function strokes(strokes, ui, canvas) {
10525
10523
  case 'center':
10526
10524
  canvas.setStroke(undefined, __strokeWidth, options);
10527
10525
  drawStrokesStyle(strokes, false, ui, canvas);
10526
+ if (options.__useArrow)
10527
+ strokeArrow(ui, canvas);
10528
10528
  break;
10529
10529
  case 'inside':
10530
10530
  canvas.save();
@@ -10550,6 +10550,14 @@ function strokes(strokes, ui, canvas) {
10550
10550
  }
10551
10551
  }
10552
10552
  }
10553
+ function strokeArrow(ui, canvas) {
10554
+ if (ui.__.dashPattern) {
10555
+ canvas.beginPath();
10556
+ ui.__drawPathByData(canvas, ui.__.__pathForArrow);
10557
+ canvas.dashPattern = null;
10558
+ canvas.stroke();
10559
+ }
10560
+ }
10553
10561
 
10554
10562
  const { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper;
10555
10563
  function shape(ui, current, options) {
@@ -14375,13 +14383,13 @@ const half = { x: -0.5 };
14375
14383
  const angle = { connect: half, offset: { x: -0.71, bevelJoin: 0.36, roundJoin: 0.22 }, path: [1, -3, -3, 2, 0, 0, 2, -3, 3] };
14376
14384
  const angleSide = { connect: half, offset: { x: -1.207, bevelJoin: 0.854, roundJoin: 0.707 }, path: [1, -3, -3, 2, 0, 0, 2, -1, 0] };
14377
14385
  const triangleLinePath = [1, -3, 0, 2, -3, -2, 2, 0, 0, 2, -3, 2, 2, -3, 0];
14378
- const triangle = { connect: half, offset: { x: -0.9, bevelJoin: 0.624, roundJoin: 0.4 }, path: [...triangleLinePath, 1, -2.05, 1.1, 2, -2.05, -1.1] };
14386
+ const triangle = { connect: half, offset: { x: -0.9, bevelJoin: 0.624, roundJoin: 0.4 }, path: [...triangleLinePath, 1, -2.05, 1.1, 2, -2.05, -1.1], dashPath: [1, -2, 0, 2, -0.5, 0] };
14379
14387
  const arrowLinePath = [1, -3, 0, 2, -3.5, -1.8, 2, 0, 0, 2, -3.5, 1.8, 2, -3, 0];
14380
- const arrow = { connect: half, offset: { x: -1.1, bevelJoin: 0.872, roundJoin: 0.6 }, path: [...arrowLinePath, 1, -2.25, 0.95, 2, -2.25, -0.95] };
14381
- const triangleFlip = { offset: half, path: [...triangle.path], };
14388
+ const arrow = { connect: half, offset: { x: -1.1, bevelJoin: 0.872, roundJoin: 0.6 }, path: [...arrowLinePath, 1, -2.25, 0.95, 2, -2.25, -0.95], dashPath: [1, -3, 0, 2, -0.5, 0] };
14389
+ const triangleFlip = { offset: half, path: [...triangle.path], dashPath: [1, -2.5, 0, 2, -1, 0] };
14382
14390
  rotate(triangleFlip.path, 180, { x: -1.5, y: 0 });
14383
14391
  const circleLine = { connect: { x: -1.3 }, path: [1, 1.8, -0.1, 2, 1.8, 0, 26, 0, 0, 1.8, 0, 359, 0], };
14384
- const circle = { connect: { x: 0.5 }, path: [...circleLine.path, 1, 0, 0, 26, 0, 0, 1, 0, 360, 0] };
14392
+ const circle = { connect: { x: 0.5 }, path: [...circleLine.path, 1, 0, 0, 26, 0, 0, 1, 0, 360, 0], dashPath: [1, -0.5, 0, 2, 0.5, 0] };
14385
14393
  const squareLine = { connect: { x: -1.3 }, path: [1, -1.4, 0, 2, -1.4, -1.4, 2, 1.4, -1.4, 2, 1.4, 1.4, 2, -1.4, 1.4, 2, -1.4, 0] };
14386
14394
  const square = { path: [...squareLine.path, 2, -1.4, -0.49, 2, 1, -0.49, 1, -1.4, 0.49, 2, 1, 0.49] };
14387
14395
  const diamondLine = DataHelper.clone(squareLine);
@@ -14403,12 +14411,14 @@ const arrows = {
14403
14411
  'diamond-line': diamondLine,
14404
14412
  mark,
14405
14413
  };
14406
- function getArrowPath(ui, arrow, from, to, scale, connectOffset) {
14414
+ function getArrowPath(ui, arrow, from, to, scale, connectOffset, hasDashPattern) {
14407
14415
  const { strokeCap, strokeJoin } = ui.__;
14408
- const { offset, connect, path } = (typeof arrow === 'object' ? arrow : arrows[arrow]);
14416
+ const { offset, connect, path, dashPath } = (typeof arrow === 'object' ? arrow : arrows[arrow]);
14409
14417
  let connectX = connect ? connect.x : 0;
14410
14418
  let offsetX = offset ? offset.x : 0;
14411
14419
  const data = [...path];
14420
+ if (hasDashPattern && dashPath)
14421
+ data.push(...dashPath);
14412
14422
  if (strokeCap !== 'none')
14413
14423
  connectX -= 0.5;
14414
14424
  if (offset) {
@@ -14432,7 +14442,7 @@ const last = {}, now = {};
14432
14442
  const PathArrowModule = {
14433
14443
  list: arrows,
14434
14444
  addArrows(ui, changeRenderPath) {
14435
- const { startArrow, endArrow, strokeWidth, __pathForRender: data } = ui.__;
14445
+ const { startArrow, endArrow, strokeWidth, dashPattern, __pathForRender: data } = ui.__;
14436
14446
  let command, i = 0, len = data.length, count = 0, useStartArrow = startArrow && startArrow !== 'none';
14437
14447
  while (i < len) {
14438
14448
  command = data[i];
@@ -14491,17 +14501,20 @@ const PathArrowModule = {
14491
14501
  if (count === 2 && useStartArrow)
14492
14502
  copy(second, command === L ? now : last);
14493
14503
  if (i === len) {
14494
- const p = ui.__.__pathForRender = changeRenderPath ? [...data] : data;
14504
+ const path = ui.__.__pathForRender = changeRenderPath ? [...data] : data;
14505
+ const pathForArrow = ui.__.__pathForArrow = [];
14495
14506
  if (useStartArrow) {
14496
- p.push(...getArrowPath(ui, startArrow, second, first, strokeWidth, connectPoint));
14507
+ const startArrowPath = getArrowPath(ui, startArrow, second, first, strokeWidth, connectPoint, !!dashPattern);
14508
+ dashPattern ? pathForArrow.push(...startArrowPath) : path.push(...startArrowPath);
14497
14509
  if (connectPoint.x) {
14498
14510
  getDistancePoint(first, second, -connectPoint.x, true);
14499
- p[1] = second.x;
14500
- p[2] = second.y;
14511
+ path[1] = second.x;
14512
+ path[2] = second.y;
14501
14513
  }
14502
14514
  }
14503
14515
  if (endArrow && endArrow !== 'none') {
14504
- p.push(...getArrowPath(ui, endArrow, last, now, strokeWidth, connectPoint));
14516
+ const endArrowPath = getArrowPath(ui, endArrow, last, now, strokeWidth, connectPoint, !!dashPattern);
14517
+ dashPattern ? pathForArrow.push(...endArrowPath) : path.push(...endArrowPath);
14505
14518
  if (connectPoint.x) {
14506
14519
  getDistancePoint(now, last, -connectPoint.x, true);
14507
14520
  let index;
@@ -14520,7 +14533,7 @@ const PathArrowModule = {
14520
14533
  break;
14521
14534
  }
14522
14535
  if (index)
14523
- setPoint(p, last, index);
14536
+ setPoint(path, last, index);
14524
14537
  }
14525
14538
  }
14526
14539
  }
@@ -14645,7 +14658,7 @@ let TextEditor = class TextEditor extends InnerEditor {
14645
14658
  style.position = 'fixed';
14646
14659
  style.transformOrigin = 'left top';
14647
14660
  style.boxSizing = 'border-box';
14648
- this.isHTMLText ? div.innerHTML = text.text : div.innerText = text.text;
14661
+ this.isHTMLText ? div.innerHTML = String(text.text) : div.innerText = String(text.text);
14649
14662
  const { view } = editor.app;
14650
14663
  (this.inBody = view instanceof HTMLCanvasElement) ? document.body.appendChild(div) : view.appendChild(div);
14651
14664
  this.eventIds = [