@leafer-game/worker 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.
package/dist/worker.js CHANGED
@@ -46,7 +46,7 @@ var LeaferUI = (function (exports) {
46
46
  };
47
47
  const I$2 = IncrementId;
48
48
 
49
- const { round: round$6, pow: pow$2, PI: PI$5 } = Math;
49
+ const { round: round$6, pow: pow$2, PI: PI$4 } = Math;
50
50
  const MathHelper = {
51
51
  within(value, min, max) {
52
52
  if (typeof min === 'object')
@@ -142,9 +142,9 @@ var LeaferUI = (function (exports) {
142
142
  function randInt(num) {
143
143
  return Math.round(Math.random() * num);
144
144
  }
145
- const OneRadian = PI$5 / 180;
146
- const PI2 = PI$5 * 2;
147
- const PI_2 = PI$5 / 2;
145
+ const OneRadian = PI$4 / 180;
146
+ const PI2 = PI$4 * 2;
147
+ const PI_2 = PI$4 / 2;
148
148
  function getPointData() { return { x: 0, y: 0 }; }
149
149
  function getBoundsData() { return { x: 0, y: 0, width: 0, height: 0 }; }
150
150
  function getMatrixData() { return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }; }
@@ -439,7 +439,7 @@ var LeaferUI = (function (exports) {
439
439
  const M$7 = MatrixHelper;
440
440
 
441
441
  const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
442
- const { sin: sin$5, cos: cos$5, abs: abs$5, sqrt: sqrt$4, atan2: atan2$2, min: min$1, round: round$5, PI: PI$4 } = Math;
442
+ const { sin: sin$5, cos: cos$5, abs: abs$5, sqrt: sqrt$4, atan2: atan2$2, min: min$1, round: round$5 } = Math;
443
443
  const PointHelper = {
444
444
  defaultPoint: getPointData(),
445
445
  tempPoint: {},
@@ -552,10 +552,11 @@ var LeaferUI = (function (exports) {
552
552
  getRadianFrom(fromX, fromY, originX, originY, toX, toY, toOriginX, toOriginY) {
553
553
  if (toOriginX === undefined)
554
554
  toOriginX = originX, toOriginY = originY;
555
- let fromAngle = atan2$2(fromY - originY, fromX - originX);
556
- let toAngle = atan2$2(toY - toOriginY, toX - toOriginX);
557
- const radian = toAngle - fromAngle;
558
- return radian < -PI$4 ? radian + PI2 : radian;
555
+ const a = fromX - originX;
556
+ const b = fromY - originY;
557
+ const c = toX - toOriginX;
558
+ const d = toY - toOriginY;
559
+ return Math.atan2(a * d - b * c, a * c + b * d);
559
560
  },
560
561
  getAtan2(t, to) {
561
562
  return atan2$2(to.y - t.y, to.x - t.x);
@@ -3342,7 +3343,7 @@ var LeaferUI = (function (exports) {
3342
3343
  const { arcTo } = PathCommandDataHelper;
3343
3344
  const PathCorner = {
3344
3345
  smooth(data, cornerRadius, _cornerSmoothing) {
3345
- let command, commandLen;
3346
+ let command, lastCommand, commandLen;
3346
3347
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0;
3347
3348
  const len = data.length;
3348
3349
  const smooth = [];
@@ -3380,8 +3381,10 @@ var LeaferUI = (function (exports) {
3380
3381
  lastY = y;
3381
3382
  break;
3382
3383
  case Z$1:
3383
- arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3384
- smooth.push(Z$1);
3384
+ if (lastCommand !== Z$1) {
3385
+ arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3386
+ smooth.push(Z$1);
3387
+ }
3385
3388
  i += 1;
3386
3389
  break;
3387
3390
  default:
@@ -3390,6 +3393,7 @@ var LeaferUI = (function (exports) {
3390
3393
  smooth.push(data[i + j]);
3391
3394
  i += commandLen;
3392
3395
  }
3396
+ lastCommand = command;
3393
3397
  }
3394
3398
  if (command !== Z$1) {
3395
3399
  smooth[1] = startX;
@@ -3886,12 +3890,12 @@ var LeaferUI = (function (exports) {
3886
3890
  try {
3887
3891
  if (transform && pattern.setTransform) {
3888
3892
  pattern.setTransform(transform);
3889
- transform = null;
3893
+ transform = undefined;
3890
3894
  }
3891
3895
  }
3892
3896
  catch (_a) { }
3893
3897
  if (paint)
3894
- paint.transform = transform;
3898
+ DataHelper.stintSet(paint, 'transform', transform);
3895
3899
  return pattern;
3896
3900
  }
3897
3901
  destroy() {
@@ -3996,10 +4000,14 @@ var LeaferUI = (function (exports) {
3996
4000
  }));
3997
4001
  }
3998
4002
  const pathType = boundsType;
3999
- function affectStrokeBoundsType(defaultValue) {
4003
+ function affectStrokeBoundsType(defaultValue, useStroke) {
4000
4004
  return decorateLeafAttr(defaultValue, (key) => attr({
4001
4005
  set(value) {
4002
- this.__setAttr(key, value) && doStrokeType(this);
4006
+ if (this.__setAttr(key, value)) {
4007
+ doStrokeType(this);
4008
+ if (useStroke)
4009
+ this.__.__useStroke = true;
4010
+ }
4003
4011
  }
4004
4012
  }));
4005
4013
  }
@@ -5425,6 +5433,8 @@ var LeaferUI = (function (exports) {
5425
5433
 
5426
5434
  const LeafRender = {
5427
5435
  __render(canvas, options) {
5436
+ if (options.shape)
5437
+ return this.__renderShape(canvas, options);
5428
5438
  if (this.__worldOpacity) {
5429
5439
  const data = this.__;
5430
5440
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
@@ -5434,12 +5444,10 @@ var LeaferUI = (function (exports) {
5434
5444
  return this.__renderEraser(canvas, options);
5435
5445
  const tempCanvas = canvas.getSameCanvas(true, true);
5436
5446
  this.__draw(tempCanvas, options, canvas);
5437
- if (this.__worldFlipped) {
5447
+ if (this.__worldFlipped)
5438
5448
  canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, data.__blendMode, true);
5439
- }
5440
- else {
5449
+ else
5441
5450
  canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, data.__blendMode);
5442
- }
5443
5451
  tempCanvas.recycle(this.__nowWorld);
5444
5452
  }
5445
5453
  else {
@@ -5449,6 +5457,12 @@ var LeaferUI = (function (exports) {
5449
5457
  Debug.drawBounds(this, canvas, options);
5450
5458
  }
5451
5459
  },
5460
+ __renderShape(canvas, options) {
5461
+ if (this.__worldOpacity) {
5462
+ canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5463
+ this.__drawShape(canvas, options);
5464
+ }
5465
+ },
5452
5466
  __clip(canvas, options) {
5453
5467
  if (this.__worldOpacity) {
5454
5468
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
@@ -5868,7 +5882,8 @@ var LeaferUI = (function (exports) {
5868
5882
  __drawFast(_canvas, _options) { }
5869
5883
  __draw(_canvas, _options, _originCanvas) { }
5870
5884
  __clip(_canvas, _options) { }
5871
- __renderShape(_canvas, _options, _ignoreFill, _ignoreStroke) { }
5885
+ __renderShape(_canvas, _options) { }
5886
+ __drawShape(_canvas, _options) { }
5872
5887
  __updateWorldOpacity() { }
5873
5888
  __updateChange() { }
5874
5889
  __drawPath(_canvas) { }
@@ -6236,7 +6251,7 @@ var LeaferUI = (function (exports) {
6236
6251
  }
6237
6252
  }
6238
6253
 
6239
- const version = "1.6.7";
6254
+ const version = "1.7.0";
6240
6255
 
6241
6256
  class LeaferCanvas extends LeaferCanvasBase {
6242
6257
  get allowBackgroundColor() { return true; }
@@ -7153,13 +7168,9 @@ var LeaferUI = (function (exports) {
7153
7168
  else
7154
7169
  return strokeWidth;
7155
7170
  }
7156
- get __hasStroke() { return this.stroke && this.strokeWidth; }
7157
- get __hasHalf() { const t = this; return (t.stroke && t.strokeAlign === 'center' && t.strokeWidth % 2) || undefined; }
7158
7171
  get __hasMultiPaint() {
7159
7172
  const t = this;
7160
- if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
7161
- return true;
7162
- return t.fill && this.__hasStroke;
7173
+ return (t.fill && this.__useStroke) || (t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect;
7163
7174
  }
7164
7175
  get __clipAfterFill() { const t = this; return (t.cornerRadius || t.innerShadow || t.__pathInputed); }
7165
7176
  get __hasSurface() { const t = this; return (t.fill || t.stroke); }
@@ -7450,15 +7461,18 @@ var LeaferUI = (function (exports) {
7450
7461
  const UIRender = {
7451
7462
  __updateChange() {
7452
7463
  const data = this.__;
7464
+ if (data.__useStroke) {
7465
+ const useStroke = data.__useStroke = !!(data.stroke && data.strokeWidth);
7466
+ stintSet$1(this.__world, 'half', useStroke && data.strokeAlign === 'center' && data.strokeWidth % 2);
7467
+ stintSet$1(data, '__fillAfterStroke', useStroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
7468
+ }
7453
7469
  if (data.__useEffect) {
7454
7470
  const { shadow, fill, stroke } = data, otherEffect = data.innerShadow || data.blur || data.backgroundBlur || data.filter;
7455
7471
  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')));
7456
7472
  data.__useEffect = !!(shadow || otherEffect);
7457
7473
  }
7458
- stintSet$1(this.__world, 'half', data.__hasHalf);
7459
- stintSet$1(data, '__fillAfterStroke', data.stroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
7460
7474
  data.__checkSingle();
7461
- stintSet$1(data, '__complex', data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect);
7475
+ stintSet$1(data, '__complex', (data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect));
7462
7476
  },
7463
7477
  __drawFast(canvas, options) {
7464
7478
  drawFast(this, canvas, options);
@@ -7516,18 +7530,15 @@ var LeaferUI = (function (exports) {
7516
7530
  this.__drawFast(canvas, options);
7517
7531
  }
7518
7532
  },
7519
- __renderShape(canvas, options, ignoreFill, ignoreStroke) {
7520
- if (this.__worldOpacity) {
7521
- canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
7522
- const { fill, stroke } = this.__;
7523
- this.__drawRenderPath(canvas);
7524
- if (fill && !ignoreFill)
7525
- this.__.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7526
- if (this.__.__isCanvas)
7527
- this.__drawAfterFill(canvas, options);
7528
- if (stroke && !ignoreStroke)
7529
- this.__.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7530
- }
7533
+ __drawShape(canvas, options) {
7534
+ this.__drawRenderPath(canvas);
7535
+ const data = this.__, { fill, stroke } = data;
7536
+ if (fill && !options.ignoreFill)
7537
+ data.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7538
+ if (data.__isCanvas)
7539
+ this.__drawAfterFill(canvas, options);
7540
+ if (stroke && !options.ignoreStroke)
7541
+ data.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7531
7542
  },
7532
7543
  __drawAfterFill(canvas, options) {
7533
7544
  if (this.__.__clipAfterFill) {
@@ -7652,12 +7663,14 @@ var LeaferUI = (function (exports) {
7652
7663
  }
7653
7664
  }
7654
7665
  __updateRenderPath() {
7655
- if (this.__.path) {
7656
- const data = this.__;
7666
+ const data = this.__;
7667
+ if (data.path) {
7657
7668
  data.__pathForRender = data.cornerRadius ? PathCorner.smooth(data.path, data.cornerRadius, data.cornerSmoothing) : data.path;
7658
7669
  if (data.__useArrow)
7659
7670
  PathArrow.addArrows(this, !data.cornerRadius);
7660
7671
  }
7672
+ else
7673
+ data.__pathForRender && (data.__pathForRender = undefined);
7661
7674
  }
7662
7675
  __drawRenderPath(canvas) {
7663
7676
  canvas.beginPath();
@@ -7868,13 +7881,13 @@ var LeaferUI = (function (exports) {
7868
7881
  surfaceType()
7869
7882
  ], exports.UI.prototype, "fill", void 0);
7870
7883
  __decorate([
7871
- strokeType()
7884
+ strokeType(undefined, true)
7872
7885
  ], exports.UI.prototype, "stroke", void 0);
7873
7886
  __decorate([
7874
7887
  strokeType('inside')
7875
7888
  ], exports.UI.prototype, "strokeAlign", void 0);
7876
7889
  __decorate([
7877
- strokeType(1)
7890
+ strokeType(1, true)
7878
7891
  ], exports.UI.prototype, "strokeWidth", void 0);
7879
7892
  __decorate([
7880
7893
  strokeType(false)
@@ -8301,7 +8314,7 @@ var LeaferUI = (function (exports) {
8301
8314
  list.push(item);
8302
8315
  this.requestRender();
8303
8316
  }
8304
- zoom(_zoomType, _padding, _fixedScale, _transition) {
8317
+ zoom(_zoomType, _optionsOrPadding, _scroll, _transition) {
8305
8318
  return Plugin.need('view');
8306
8319
  }
8307
8320
  getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
@@ -8346,7 +8359,7 @@ var LeaferUI = (function (exports) {
8346
8359
  Leafer_1.list.remove(this);
8347
8360
  try {
8348
8361
  this.stop();
8349
- this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
8362
+ this.emitLeafer(LeaferEvent.END);
8350
8363
  this.__removeListenEvents();
8351
8364
  this.__controllers.forEach(item => !(this.parent && item === this.interaction) && item.destroy());
8352
8365
  this.__controllers.length = 0;
@@ -8474,7 +8487,7 @@ var LeaferUI = (function (exports) {
8474
8487
  }
8475
8488
  __drawContent(canvas, options) {
8476
8489
  this.__renderGroup(canvas, options);
8477
- if (this.__.__hasStroke) {
8490
+ if (this.__.__useStroke) {
8478
8491
  canvas.setWorld(this.__nowWorld);
8479
8492
  this.__drawRenderPath(canvas);
8480
8493
  }
@@ -8694,8 +8707,8 @@ var LeaferUI = (function (exports) {
8694
8707
  for (let i = 1; i < sides; i++) {
8695
8708
  lineTo$1(path, rx + rx * sin$2((i * 2 * PI$2) / sides), ry - ry * cos$2((i * 2 * PI$2) / sides));
8696
8709
  }
8710
+ closePath$1(path);
8697
8711
  }
8698
- closePath$1(path);
8699
8712
  }
8700
8713
  __updateRenderPath() { }
8701
8714
  __updateBoxBounds() { }
@@ -8933,6 +8946,11 @@ var LeaferUI = (function (exports) {
8933
8946
  return;
8934
8947
  super.__draw(canvas, options, originCanvas);
8935
8948
  }
8949
+ __drawShape(canvas, options) {
8950
+ if (options.shape)
8951
+ this.__box && this.__box.__drawShape(canvas, options);
8952
+ super.__drawShape(canvas, options);
8953
+ }
8936
8954
  destroy() {
8937
8955
  if (this.boxStyle)
8938
8956
  this.boxStyle = null;
@@ -9754,6 +9772,7 @@ var LeaferUI = (function (exports) {
9754
9772
  delta: { x: 80 / 4, y: 8.0 },
9755
9773
  },
9756
9774
  pointer: {
9775
+ type: 'pointer',
9757
9776
  snap: true,
9758
9777
  hitRadius: 5,
9759
9778
  tapTime: 120,
@@ -10297,7 +10316,7 @@ var LeaferUI = (function (exports) {
10297
10316
  h.resize({ width, height, pixelRatio: 1 });
10298
10317
  h.clear();
10299
10318
  ImageManager.patternLocked = true;
10300
- this.__renderShape(h, { matrix: matrix.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y) }, !isHitPixelFill, !isHitPixelStroke);
10319
+ this.__renderShape(h, { matrix: matrix.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y), ignoreFill: !isHitPixelFill, ignoreStroke: !isHitPixelStroke });
10301
10320
  ImageManager.patternLocked = false;
10302
10321
  h.resetTransform();
10303
10322
  data.__isHitPixel = true;
@@ -10701,7 +10720,7 @@ var LeaferUI = (function (exports) {
10701
10720
  };
10702
10721
 
10703
10722
  let origin = {};
10704
- const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate } = MatrixHelper;
10723
+ const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate, skew: skewHelper } = MatrixHelper;
10705
10724
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10706
10725
  const transform = get$3();
10707
10726
  translate$1(transform, box.x + x, box.y + y);
@@ -10710,13 +10729,15 @@ var LeaferUI = (function (exports) {
10710
10729
  rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10711
10730
  data.transform = transform;
10712
10731
  }
10713
- function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
10732
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew) {
10714
10733
  const transform = get$3();
10715
- translate$1(transform, box.x + x, box.y + y);
10716
- if (scaleX)
10717
- scaleHelper(transform, scaleX, scaleY);
10718
10734
  if (rotation)
10719
10735
  rotate(transform, rotation);
10736
+ if (skew)
10737
+ skewHelper(transform, skew.x, skew.y);
10738
+ if (scaleX)
10739
+ scaleHelper(transform, scaleX, scaleY);
10740
+ translate$1(transform, box.x + x, box.y + y);
10720
10741
  data.transform = transform;
10721
10742
  }
10722
10743
  function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
@@ -10753,11 +10774,13 @@ var LeaferUI = (function (exports) {
10753
10774
  const tempScaleData = {};
10754
10775
  const tempImage = {};
10755
10776
  function createData(leafPaint, image, paint, box) {
10756
- const { changeful, sync } = paint;
10777
+ const { changeful, sync, editing } = paint;
10757
10778
  if (changeful)
10758
10779
  leafPaint.changeful = changeful;
10759
10780
  if (sync)
10760
10781
  leafPaint.sync = sync;
10782
+ if (editing)
10783
+ leafPaint.editing = editing;
10761
10784
  leafPaint.data = getPatternData(paint, box, image);
10762
10785
  }
10763
10786
  function getPatternData(paint, box, image) {
@@ -10766,7 +10789,7 @@ var LeaferUI = (function (exports) {
10766
10789
  if (paint.mode === 'strench')
10767
10790
  paint.mode = 'stretch';
10768
10791
  let { width, height } = image;
10769
- const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint;
10792
+ const { opacity, mode, align, offset, scale, size, rotation, skew, repeat, filters } = paint;
10770
10793
  const sameBox = box.width === width && box.height === height;
10771
10794
  const data = { mode };
10772
10795
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
@@ -10800,8 +10823,8 @@ var LeaferUI = (function (exports) {
10800
10823
  break;
10801
10824
  case 'normal':
10802
10825
  case 'clip':
10803
- if (tempImage.x || tempImage.y || scaleX || rotation)
10804
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
10826
+ if (tempImage.x || tempImage.y || scaleX || rotation || skew)
10827
+ clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew);
10805
10828
  break;
10806
10829
  case 'repeat':
10807
10830
  if (!sameBox || scaleX || rotation)
@@ -10878,11 +10901,11 @@ var LeaferUI = (function (exports) {
10878
10901
  }
10879
10902
  onLoadSuccess(ui, event);
10880
10903
  }
10881
- leafPaint.loadId = null;
10904
+ leafPaint.loadId = undefined;
10882
10905
  }, (error) => {
10883
10906
  ignoreRender(ui, false);
10884
10907
  onLoadError(ui, event, error);
10885
- leafPaint.loadId = null;
10908
+ leafPaint.loadId = undefined;
10886
10909
  });
10887
10910
  if (ui.placeholderColor) {
10888
10911
  if (!ui.placeholderDelay)
@@ -10948,6 +10971,8 @@ var LeaferUI = (function (exports) {
10948
10971
  const { image, data } = paint;
10949
10972
  let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
10950
10973
  if (sx) {
10974
+ sx = abs$2(sx);
10975
+ sy = abs$2(sy);
10951
10976
  imageMatrix = get$1();
10952
10977
  copy$1(imageMatrix, transform);
10953
10978
  scale(imageMatrix, 1 / sx, 1 / sy);