@leafer-draw/miniapp 1.6.7 → 1.7.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.
@@ -43,7 +43,7 @@ const IncrementId = {
43
43
  };
44
44
  const I$1 = IncrementId;
45
45
 
46
- const { round: round$3, pow: pow$1, PI: PI$4 } = Math;
46
+ const { round: round$3, pow: pow$1, PI: PI$3 } = Math;
47
47
  const MathHelper = {
48
48
  within(value, min, max) {
49
49
  if (typeof min === 'object')
@@ -139,9 +139,9 @@ const MathHelper = {
139
139
  function randInt(num) {
140
140
  return Math.round(Math.random() * num);
141
141
  }
142
- const OneRadian = PI$4 / 180;
143
- const PI2 = PI$4 * 2;
144
- const PI_2 = PI$4 / 2;
142
+ const OneRadian = PI$3 / 180;
143
+ const PI2 = PI$3 * 2;
144
+ const PI_2 = PI$3 / 2;
145
145
  function getPointData() { return { x: 0, y: 0 }; }
146
146
  function getBoundsData() { return { x: 0, y: 0, width: 0, height: 0 }; }
147
147
  function getMatrixData() { return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }; }
@@ -436,7 +436,7 @@ const MatrixHelper = {
436
436
  const M$6 = MatrixHelper;
437
437
 
438
438
  const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
439
- const { sin: sin$4, cos: cos$4, abs: abs$4, sqrt: sqrt$2, atan2: atan2$2, min: min$1, round: round$2, PI: PI$3 } = Math;
439
+ const { sin: sin$4, cos: cos$4, abs: abs$4, sqrt: sqrt$2, atan2: atan2$2, min: min$1, round: round$2 } = Math;
440
440
  const PointHelper = {
441
441
  defaultPoint: getPointData(),
442
442
  tempPoint: {},
@@ -549,10 +549,11 @@ const PointHelper = {
549
549
  getRadianFrom(fromX, fromY, originX, originY, toX, toY, toOriginX, toOriginY) {
550
550
  if (toOriginX === undefined)
551
551
  toOriginX = originX, toOriginY = originY;
552
- let fromAngle = atan2$2(fromY - originY, fromX - originX);
553
- let toAngle = atan2$2(toY - toOriginY, toX - toOriginX);
554
- const radian = toAngle - fromAngle;
555
- return radian < -PI$3 ? radian + PI2 : radian;
552
+ const a = fromX - originX;
553
+ const b = fromY - originY;
554
+ const c = toX - toOriginX;
555
+ const d = toY - toOriginY;
556
+ return Math.atan2(a * d - b * c, a * c + b * d);
556
557
  },
557
558
  getAtan2(t, to) {
558
559
  return atan2$2(to.y - t.y, to.x - t.x);
@@ -3339,7 +3340,7 @@ const { getCenterX, getCenterY } = PointHelper;
3339
3340
  const { arcTo } = PathCommandDataHelper;
3340
3341
  const PathCorner = {
3341
3342
  smooth(data, cornerRadius, _cornerSmoothing) {
3342
- let command, commandLen;
3343
+ let command, lastCommand, commandLen;
3343
3344
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0;
3344
3345
  const len = data.length;
3345
3346
  const smooth = [];
@@ -3377,8 +3378,10 @@ const PathCorner = {
3377
3378
  lastY = y;
3378
3379
  break;
3379
3380
  case Z:
3380
- arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3381
- smooth.push(Z);
3381
+ if (lastCommand !== Z) {
3382
+ arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3383
+ smooth.push(Z);
3384
+ }
3382
3385
  i += 1;
3383
3386
  break;
3384
3387
  default:
@@ -3387,6 +3390,7 @@ const PathCorner = {
3387
3390
  smooth.push(data[i + j]);
3388
3391
  i += commandLen;
3389
3392
  }
3393
+ lastCommand = command;
3390
3394
  }
3391
3395
  if (command !== Z) {
3392
3396
  smooth[1] = startX;
@@ -3883,12 +3887,12 @@ class LeaferImage {
3883
3887
  try {
3884
3888
  if (transform && pattern.setTransform) {
3885
3889
  pattern.setTransform(transform);
3886
- transform = null;
3890
+ transform = undefined;
3887
3891
  }
3888
3892
  }
3889
3893
  catch (_a) { }
3890
3894
  if (paint)
3891
- paint.transform = transform;
3895
+ DataHelper.stintSet(paint, 'transform', transform);
3892
3896
  return pattern;
3893
3897
  }
3894
3898
  destroy() {
@@ -3993,10 +3997,14 @@ function pathInputType(defaultValue) {
3993
3997
  }));
3994
3998
  }
3995
3999
  const pathType = boundsType;
3996
- function affectStrokeBoundsType(defaultValue) {
4000
+ function affectStrokeBoundsType(defaultValue, useStroke) {
3997
4001
  return decorateLeafAttr(defaultValue, (key) => attr({
3998
4002
  set(value) {
3999
- this.__setAttr(key, value) && doStrokeType(this);
4003
+ if (this.__setAttr(key, value)) {
4004
+ doStrokeType(this);
4005
+ if (useStroke)
4006
+ this.__.__useStroke = true;
4007
+ }
4000
4008
  }
4001
4009
  }));
4002
4010
  }
@@ -5422,6 +5430,8 @@ const LeafBounds = {
5422
5430
 
5423
5431
  const LeafRender = {
5424
5432
  __render(canvas, options) {
5433
+ if (options.shape)
5434
+ return this.__renderShape(canvas, options);
5425
5435
  if (this.__worldOpacity) {
5426
5436
  const data = this.__;
5427
5437
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
@@ -5431,12 +5441,10 @@ const LeafRender = {
5431
5441
  return this.__renderEraser(canvas, options);
5432
5442
  const tempCanvas = canvas.getSameCanvas(true, true);
5433
5443
  this.__draw(tempCanvas, options, canvas);
5434
- if (this.__worldFlipped) {
5444
+ if (this.__worldFlipped)
5435
5445
  canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, data.__blendMode, true);
5436
- }
5437
- else {
5446
+ else
5438
5447
  canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, data.__blendMode);
5439
- }
5440
5448
  tempCanvas.recycle(this.__nowWorld);
5441
5449
  }
5442
5450
  else {
@@ -5446,6 +5454,12 @@ const LeafRender = {
5446
5454
  Debug.drawBounds(this, canvas, options);
5447
5455
  }
5448
5456
  },
5457
+ __renderShape(canvas, options) {
5458
+ if (this.__worldOpacity) {
5459
+ canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5460
+ this.__drawShape(canvas, options);
5461
+ }
5462
+ },
5449
5463
  __clip(canvas, options) {
5450
5464
  if (this.__worldOpacity) {
5451
5465
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
@@ -5865,7 +5879,8 @@ let Leaf = class Leaf {
5865
5879
  __drawFast(_canvas, _options) { }
5866
5880
  __draw(_canvas, _options, _originCanvas) { }
5867
5881
  __clip(_canvas, _options) { }
5868
- __renderShape(_canvas, _options, _ignoreFill, _ignoreStroke) { }
5882
+ __renderShape(_canvas, _options) { }
5883
+ __drawShape(_canvas, _options) { }
5869
5884
  __updateWorldOpacity() { }
5870
5885
  __updateChange() { }
5871
5886
  __drawPath(_canvas) { }
@@ -6233,7 +6248,7 @@ class LeafLevelList {
6233
6248
  }
6234
6249
  }
6235
6250
 
6236
- const version = "1.6.7";
6251
+ const version = "1.7.0";
6237
6252
 
6238
6253
  class LeaferCanvas extends LeaferCanvasBase {
6239
6254
  get allowBackgroundColor() { return false; }
@@ -7132,13 +7147,9 @@ class UIData extends LeafData {
7132
7147
  else
7133
7148
  return strokeWidth;
7134
7149
  }
7135
- get __hasStroke() { return this.stroke && this.strokeWidth; }
7136
- get __hasHalf() { const t = this; return (t.stroke && t.strokeAlign === 'center' && t.strokeWidth % 2) || undefined; }
7137
7150
  get __hasMultiPaint() {
7138
7151
  const t = this;
7139
- if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
7140
- return true;
7141
- return t.fill && this.__hasStroke;
7152
+ return (t.fill && this.__useStroke) || (t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect;
7142
7153
  }
7143
7154
  get __clipAfterFill() { const t = this; return (t.cornerRadius || t.innerShadow || t.__pathInputed); }
7144
7155
  get __hasSurface() { const t = this; return (t.fill || t.stroke); }
@@ -7429,15 +7440,18 @@ const { stintSet: stintSet$1 } = DataHelper;
7429
7440
  const UIRender = {
7430
7441
  __updateChange() {
7431
7442
  const data = this.__;
7443
+ if (data.__useStroke) {
7444
+ const useStroke = data.__useStroke = !!(data.stroke && data.strokeWidth);
7445
+ stintSet$1(this.__world, 'half', useStroke && data.strokeAlign === 'center' && data.strokeWidth % 2);
7446
+ stintSet$1(data, '__fillAfterStroke', useStroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
7447
+ }
7432
7448
  if (data.__useEffect) {
7433
7449
  const { shadow, fill, stroke } = data, otherEffect = data.innerShadow || data.blur || data.backgroundBlur || data.filter;
7434
7450
  stintSet$1(data, '__isFastShadow', shadow && !otherEffect && shadow.length < 2 && !shadow[0].spread && !(shadow[0].box && data.__isTransparentFill) && fill && !(fill instanceof Array && fill.length > 1) && (this.useFastShadow || !stroke || (stroke && data.strokeAlign === 'inside')));
7435
7451
  data.__useEffect = !!(shadow || otherEffect);
7436
7452
  }
7437
- stintSet$1(this.__world, 'half', data.__hasHalf);
7438
- stintSet$1(data, '__fillAfterStroke', data.stroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
7439
7453
  data.__checkSingle();
7440
- stintSet$1(data, '__complex', data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect);
7454
+ stintSet$1(data, '__complex', (data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect));
7441
7455
  },
7442
7456
  __drawFast(canvas, options) {
7443
7457
  drawFast(this, canvas, options);
@@ -7495,18 +7509,15 @@ const UIRender = {
7495
7509
  this.__drawFast(canvas, options);
7496
7510
  }
7497
7511
  },
7498
- __renderShape(canvas, options, ignoreFill, ignoreStroke) {
7499
- if (this.__worldOpacity) {
7500
- canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
7501
- const { fill, stroke } = this.__;
7502
- this.__drawRenderPath(canvas);
7503
- if (fill && !ignoreFill)
7504
- this.__.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7505
- if (this.__.__isCanvas)
7506
- this.__drawAfterFill(canvas, options);
7507
- if (stroke && !ignoreStroke)
7508
- this.__.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7509
- }
7512
+ __drawShape(canvas, options) {
7513
+ this.__drawRenderPath(canvas);
7514
+ const data = this.__, { fill, stroke } = data;
7515
+ if (fill && !options.ignoreFill)
7516
+ data.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7517
+ if (data.__isCanvas)
7518
+ this.__drawAfterFill(canvas, options);
7519
+ if (stroke && !options.ignoreStroke)
7520
+ data.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7510
7521
  },
7511
7522
  __drawAfterFill(canvas, options) {
7512
7523
  if (this.__.__clipAfterFill) {
@@ -7631,12 +7642,14 @@ let UI = UI_1 = class UI extends Leaf {
7631
7642
  }
7632
7643
  }
7633
7644
  __updateRenderPath() {
7634
- if (this.__.path) {
7635
- const data = this.__;
7645
+ const data = this.__;
7646
+ if (data.path) {
7636
7647
  data.__pathForRender = data.cornerRadius ? PathCorner.smooth(data.path, data.cornerRadius, data.cornerSmoothing) : data.path;
7637
7648
  if (data.__useArrow)
7638
7649
  PathArrow.addArrows(this, !data.cornerRadius);
7639
7650
  }
7651
+ else
7652
+ data.__pathForRender && (data.__pathForRender = undefined);
7640
7653
  }
7641
7654
  __drawRenderPath(canvas) {
7642
7655
  canvas.beginPath();
@@ -7847,13 +7860,13 @@ __decorate([
7847
7860
  surfaceType()
7848
7861
  ], UI.prototype, "fill", void 0);
7849
7862
  __decorate([
7850
- strokeType()
7863
+ strokeType(undefined, true)
7851
7864
  ], UI.prototype, "stroke", void 0);
7852
7865
  __decorate([
7853
7866
  strokeType('inside')
7854
7867
  ], UI.prototype, "strokeAlign", void 0);
7855
7868
  __decorate([
7856
- strokeType(1)
7869
+ strokeType(1, true)
7857
7870
  ], UI.prototype, "strokeWidth", void 0);
7858
7871
  __decorate([
7859
7872
  strokeType(false)
@@ -8280,7 +8293,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8280
8293
  list.push(item);
8281
8294
  this.requestRender();
8282
8295
  }
8283
- zoom(_zoomType, _padding, _fixedScale, _transition) {
8296
+ zoom(_zoomType, _optionsOrPadding, _scroll, _transition) {
8284
8297
  return Plugin.need('view');
8285
8298
  }
8286
8299
  getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
@@ -8325,7 +8338,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8325
8338
  Leafer_1.list.remove(this);
8326
8339
  try {
8327
8340
  this.stop();
8328
- this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
8341
+ this.emitLeafer(LeaferEvent.END);
8329
8342
  this.__removeListenEvents();
8330
8343
  this.__controllers.forEach(item => !(this.parent && item === this.interaction) && item.destroy());
8331
8344
  this.__controllers.length = 0;
@@ -8453,7 +8466,7 @@ let Box = class Box extends Group {
8453
8466
  }
8454
8467
  __drawContent(canvas, options) {
8455
8468
  this.__renderGroup(canvas, options);
8456
- if (this.__.__hasStroke) {
8469
+ if (this.__.__useStroke) {
8457
8470
  canvas.setWorld(this.__nowWorld);
8458
8471
  this.__drawRenderPath(canvas);
8459
8472
  }
@@ -8673,8 +8686,8 @@ let Polygon = class Polygon extends UI {
8673
8686
  for (let i = 1; i < sides; i++) {
8674
8687
  lineTo$1(path, rx + rx * sin$1((i * 2 * PI$1) / sides), ry - ry * cos$1((i * 2 * PI$1) / sides));
8675
8688
  }
8689
+ closePath$1(path);
8676
8690
  }
8677
- closePath$1(path);
8678
8691
  }
8679
8692
  __updateRenderPath() { }
8680
8693
  __updateBoxBounds() { }
@@ -8912,6 +8925,11 @@ let Text = class Text extends UI {
8912
8925
  return;
8913
8926
  super.__draw(canvas, options, originCanvas);
8914
8927
  }
8928
+ __drawShape(canvas, options) {
8929
+ if (options.shape)
8930
+ this.__box && this.__box.__drawShape(canvas, options);
8931
+ super.__drawShape(canvas, options);
8932
+ }
8915
8933
  destroy() {
8916
8934
  if (this.boxStyle)
8917
8935
  this.boxStyle = null;
@@ -9372,7 +9390,7 @@ const PaintModule = {
9372
9390
  };
9373
9391
 
9374
9392
  let origin = {};
9375
- const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate } = MatrixHelper;
9393
+ const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate, skew: skewHelper } = MatrixHelper;
9376
9394
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
9377
9395
  const transform = get$3();
9378
9396
  translate$1(transform, box.x + x, box.y + y);
@@ -9381,13 +9399,15 @@ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
9381
9399
  rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
9382
9400
  data.transform = transform;
9383
9401
  }
9384
- function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
9402
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew) {
9385
9403
  const transform = get$3();
9386
- translate$1(transform, box.x + x, box.y + y);
9387
- if (scaleX)
9388
- scaleHelper(transform, scaleX, scaleY);
9389
9404
  if (rotation)
9390
9405
  rotate(transform, rotation);
9406
+ if (skew)
9407
+ skewHelper(transform, skew.x, skew.y);
9408
+ if (scaleX)
9409
+ scaleHelper(transform, scaleX, scaleY);
9410
+ translate$1(transform, box.x + x, box.y + y);
9391
9411
  data.transform = transform;
9392
9412
  }
9393
9413
  function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
@@ -9424,11 +9444,13 @@ const tempBox = new Bounds();
9424
9444
  const tempScaleData = {};
9425
9445
  const tempImage = {};
9426
9446
  function createData(leafPaint, image, paint, box) {
9427
- const { changeful, sync } = paint;
9447
+ const { changeful, sync, editing } = paint;
9428
9448
  if (changeful)
9429
9449
  leafPaint.changeful = changeful;
9430
9450
  if (sync)
9431
9451
  leafPaint.sync = sync;
9452
+ if (editing)
9453
+ leafPaint.editing = editing;
9432
9454
  leafPaint.data = getPatternData(paint, box, image);
9433
9455
  }
9434
9456
  function getPatternData(paint, box, image) {
@@ -9437,7 +9459,7 @@ function getPatternData(paint, box, image) {
9437
9459
  if (paint.mode === 'strench')
9438
9460
  paint.mode = 'stretch';
9439
9461
  let { width, height } = image;
9440
- const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint;
9462
+ const { opacity, mode, align, offset, scale, size, rotation, skew, repeat, filters } = paint;
9441
9463
  const sameBox = box.width === width && box.height === height;
9442
9464
  const data = { mode };
9443
9465
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
@@ -9471,8 +9493,8 @@ function getPatternData(paint, box, image) {
9471
9493
  break;
9472
9494
  case 'normal':
9473
9495
  case 'clip':
9474
- if (tempImage.x || tempImage.y || scaleX || rotation)
9475
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
9496
+ if (tempImage.x || tempImage.y || scaleX || rotation || skew)
9497
+ clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew);
9476
9498
  break;
9477
9499
  case 'repeat':
9478
9500
  if (!sameBox || scaleX || rotation)
@@ -9549,11 +9571,11 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
9549
9571
  }
9550
9572
  onLoadSuccess(ui, event);
9551
9573
  }
9552
- leafPaint.loadId = null;
9574
+ leafPaint.loadId = undefined;
9553
9575
  }, (error) => {
9554
9576
  ignoreRender(ui, false);
9555
9577
  onLoadError(ui, event, error);
9556
- leafPaint.loadId = null;
9578
+ leafPaint.loadId = undefined;
9557
9579
  });
9558
9580
  if (ui.placeholderColor) {
9559
9581
  if (!ui.placeholderDelay)
@@ -9619,6 +9641,8 @@ function createPattern(ui, paint, pixelRatio) {
9619
9641
  const { image, data } = paint;
9620
9642
  let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
9621
9643
  if (sx) {
9644
+ sx = abs$1(sx);
9645
+ sy = abs$1(sy);
9622
9646
  imageMatrix = get$1();
9623
9647
  copy$1(imageMatrix, transform);
9624
9648
  scale(imageMatrix, 1 / sx, 1 / sy);