leafer-ui 1.0.0-rc.3 → 1.0.0-rc.4

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.
@@ -647,7 +647,7 @@ const BoundsHelper = {
647
647
  },
648
648
  getFitMatrix(t, put) {
649
649
  const scale = Math.min(1, Math.min(t.width / put.width, t.height / put.height));
650
- return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
650
+ return new Matrix(scale, 0, 0, scale, -Math.ceil(put.x * scale), -Math.ceil(put.y * scale));
651
651
  },
652
652
  getSpread(t, spreadX, spreadY) {
653
653
  const n = {};
@@ -4591,7 +4591,8 @@ class InteractionBase {
4591
4591
  dragDistance: 2,
4592
4592
  swipeDistance: 20,
4593
4593
  ignoreMove: false
4594
- }
4594
+ },
4595
+ cursor: {}
4595
4596
  };
4596
4597
  this.tapCount = 0;
4597
4598
  this.downKeyMap = {};
@@ -4817,6 +4818,8 @@ class InteractionBase {
4817
4818
  this.hoverData = data;
4818
4819
  }
4819
4820
  updateCursor(data) {
4821
+ if (this.config.cursor.stop)
4822
+ return;
4820
4823
  if (!data) {
4821
4824
  this.updateHoverData();
4822
4825
  data = this.hoverData;
@@ -4829,17 +4832,16 @@ class InteractionBase {
4829
4832
  }
4830
4833
  else if (!data || this.dragger.dragging)
4831
4834
  return;
4832
- const path = data.path;
4833
4835
  let leaf;
4836
+ let cursor;
4837
+ const { path } = data;
4834
4838
  for (let i = 0, len = path.length; i < len; i++) {
4835
4839
  leaf = path.list[i];
4836
- if (leaf.cursor) {
4837
- const { cursor } = leaf;
4838
- this.setCursor(cursor === 'grab' ? (this.downData ? 'grabbing' : cursor) : cursor);
4839
- return;
4840
- }
4840
+ cursor = leaf.cursor;
4841
+ if (cursor)
4842
+ break;
4841
4843
  }
4842
- this.setCursor('default');
4844
+ this.setCursor(cursor);
4843
4845
  }
4844
4846
  setCursor(cursor) {
4845
4847
  this.cursor = cursor;
@@ -5457,7 +5459,7 @@ const LeafRender = {
5457
5459
  const tempCanvas = canvas.getSameCanvas(true);
5458
5460
  this.__draw(tempCanvas, options);
5459
5461
  const blendMode = this.__.isEraser ? 'destination-out' : this.__.blendMode;
5460
- if (options.matrix || this.__hasMirror) {
5462
+ if (this.__hasMirror || options.matrix) {
5461
5463
  canvas.copyWorldByReset(tempCanvas, null, null, blendMode);
5462
5464
  }
5463
5465
  else {
@@ -5526,7 +5528,12 @@ const BranchRender = {
5526
5528
  this.__renderBranch(tempCanvas, options);
5527
5529
  canvas.opacity = this.__worldOpacity;
5528
5530
  const blendMode = this.__.isEraser ? 'destination-out' : this.__.blendMode;
5529
- options.matrix ? canvas.copyWorld(tempCanvas, null, null, blendMode) : canvas.copyWorld(tempCanvas, this.__world, this.__world, blendMode);
5531
+ if (this.__hasMirror || options.matrix) {
5532
+ canvas.copyWorld(tempCanvas, null, null, blendMode);
5533
+ }
5534
+ else {
5535
+ canvas.copyWorld(tempCanvas, this.__world, this.__world, blendMode);
5536
+ }
5530
5537
  tempCanvas.recycle();
5531
5538
  }
5532
5539
  else {
@@ -7425,7 +7432,7 @@ class UIData extends LeafData {
7425
7432
  if (typeof value === 'string' || !value) {
7426
7433
  if (this.__isFills) {
7427
7434
  this.__removeInput('fill');
7428
- Paint.recycleImage(this, 'fill');
7435
+ Paint.recycleImage('fill', this);
7429
7436
  this.__isFills = false;
7430
7437
  }
7431
7438
  this._fill = value;
@@ -7441,7 +7448,7 @@ class UIData extends LeafData {
7441
7448
  if (typeof value === 'string' || !value) {
7442
7449
  if (this.__isStrokes) {
7443
7450
  this.__removeInput('stroke');
7444
- Paint.recycleImage(this, 'stroke');
7451
+ Paint.recycleImage('stroke', this);
7445
7452
  this.__isStrokes = false;
7446
7453
  }
7447
7454
  this._stroke = value;
@@ -7693,11 +7700,11 @@ const UIRender = {
7693
7700
  const { fill, stroke, __drawAfterFill } = this.__;
7694
7701
  this.__drawRenderPath(canvas);
7695
7702
  if (fill)
7696
- Paint.fill(this, canvas, fill);
7703
+ Paint.fill(fill, this, canvas);
7697
7704
  if (__drawAfterFill)
7698
7705
  this.__drawAfterFill(canvas, options);
7699
7706
  if (stroke)
7700
- Paint.stroke(this, canvas, stroke);
7707
+ Paint.stroke(stroke, this, canvas, options);
7701
7708
  },
7702
7709
  __draw(canvas, options) {
7703
7710
  if (this.__.__complex) {
@@ -7709,40 +7716,40 @@ const UIRender = {
7709
7716
  if (shadow)
7710
7717
  Effect.shadow(this, canvas, shape, options);
7711
7718
  if (fill)
7712
- this.__.__isFills ? Paint.fills(this, canvas, fill) : Paint.fill(this, canvas, fill);
7719
+ this.__.__isFills ? Paint.fills(fill, this, canvas) : Paint.fill(fill, this, canvas);
7713
7720
  if (__drawAfterFill)
7714
7721
  this.__drawAfterFill(canvas, options);
7715
7722
  if (innerShadow)
7716
7723
  Effect.innerShadow(this, canvas, shape, options);
7717
7724
  if (stroke)
7718
- this.__.__isStrokes ? Paint.strokes(this, canvas, stroke) : Paint.stroke(this, canvas, stroke);
7725
+ this.__.__isStrokes ? Paint.strokes(stroke, this, canvas, options) : Paint.stroke(stroke, this, canvas, options);
7719
7726
  if (shape.worldCanvas)
7720
7727
  shape.worldCanvas.recycle();
7721
7728
  shape.canvas.recycle();
7722
7729
  }
7723
7730
  else {
7724
7731
  if (fill)
7725
- this.__.__isFills ? Paint.fills(this, canvas, fill) : Paint.fill(this, canvas, fill);
7732
+ this.__.__isFills ? Paint.fills(fill, this, canvas) : Paint.fill(fill, this, canvas);
7726
7733
  if (__drawAfterFill)
7727
7734
  this.__drawAfterFill(canvas, options);
7728
7735
  if (stroke)
7729
- this.__.__isStrokes ? Paint.strokes(this, canvas, stroke) : Paint.stroke(this, canvas, stroke);
7736
+ this.__.__isStrokes ? Paint.strokes(stroke, this, canvas, options) : Paint.stroke(stroke, this, canvas, options);
7730
7737
  }
7731
7738
  }
7732
7739
  else {
7733
7740
  this.__drawFast(canvas, options);
7734
7741
  }
7735
7742
  },
7736
- __renderShape(canvas, options) {
7743
+ __renderShape(canvas, renderOptions) {
7737
7744
  if (!this.__worldOpacity)
7738
7745
  return;
7739
- canvas.setWorld(this.__world, options.matrix);
7746
+ canvas.setWorld(this.__world, renderOptions.matrix);
7740
7747
  const { fill, stroke } = this.__;
7741
7748
  this.__drawRenderPath(canvas);
7742
7749
  if (fill)
7743
- Paint.fill(this, canvas, '#000000');
7750
+ Paint.fill('#000000', this, canvas);
7744
7751
  if (stroke)
7745
- Paint.stroke(this, canvas, '#000000');
7752
+ Paint.stroke('#000000', this, canvas, renderOptions);
7746
7753
  }
7747
7754
  };
7748
7755
 
@@ -7811,9 +7818,9 @@ let UI = UI_1 = class UI extends Leaf {
7811
7818
  if (this.__.__input) {
7812
7819
  const { fill, stroke } = this.__.__input;
7813
7820
  if (fill)
7814
- Paint.compute(this, 'fill');
7821
+ Paint.compute('fill', this);
7815
7822
  if (stroke)
7816
- Paint.compute(this, 'stroke');
7823
+ Paint.compute('stroke', this);
7817
7824
  }
7818
7825
  }
7819
7826
  __updateRenderPath() {
@@ -7930,7 +7937,7 @@ __decorate([
7930
7937
  hitType()
7931
7938
  ], UI.prototype, "hitRadius", void 0);
7932
7939
  __decorate([
7933
- cursorType('default')
7940
+ cursorType('')
7934
7941
  ], UI.prototype, "cursor", void 0);
7935
7942
  __decorate([
7936
7943
  surfaceType()
@@ -9393,7 +9400,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
9393
9400
  }
9394
9401
  }
9395
9402
 
9396
- function recycleImage(data, attrName) {
9403
+ function recycleImage(attrName, data) {
9397
9404
  const paints = (attrName === 'fill' ? data._fill : data._stroke);
9398
9405
  if (paints instanceof Array) {
9399
9406
  let image, recycleMap, input, url;
@@ -9438,11 +9445,11 @@ function fillText(ui, canvas) {
9438
9445
  }
9439
9446
  }
9440
9447
 
9441
- function fill(ui, canvas, fill) {
9448
+ function fill(fill, ui, canvas) {
9442
9449
  canvas.fillStyle = fill;
9443
9450
  ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
9444
9451
  }
9445
- function fills(ui, canvas, fills) {
9452
+ function fills(fills, ui, canvas) {
9446
9453
  let item;
9447
9454
  const { windingRule, __font } = ui.__;
9448
9455
  for (let i = 0, len = fills.length; i < len; i++) {
@@ -9473,32 +9480,37 @@ function fills(ui, canvas, fills) {
9473
9480
  }
9474
9481
  }
9475
9482
 
9476
- function strokeText(ui, canvas, stroke) {
9483
+ function strokeText(stroke, ui, canvas, renderOptions) {
9477
9484
  const { strokeAlign } = ui.__;
9478
9485
  const isStrokes = typeof stroke !== 'string';
9479
9486
  switch (strokeAlign) {
9480
9487
  case 'center':
9481
9488
  canvas.setStroke(isStrokes ? undefined : stroke, ui.__.strokeWidth, ui.__);
9482
- isStrokes ? drawStrokesStyle(ui, stroke, canvas, true) : drawTextStroke(ui, canvas);
9489
+ isStrokes ? drawStrokesStyle(stroke, true, ui, canvas) : drawTextStroke(ui, canvas);
9483
9490
  break;
9484
9491
  case 'inside':
9485
- drawAlignStroke(ui, canvas, stroke, 'inside', isStrokes);
9492
+ drawAlignStroke('inside', stroke, isStrokes, ui, canvas, renderOptions);
9486
9493
  break;
9487
9494
  case 'outside':
9488
- drawAlignStroke(ui, canvas, stroke, 'outside', isStrokes);
9495
+ drawAlignStroke('outside', stroke, isStrokes, ui, canvas, renderOptions);
9489
9496
  break;
9490
9497
  }
9491
9498
  }
9492
- function drawAlignStroke(ui, canvas, stroke, align, isStrokes) {
9499
+ function drawAlignStroke(align, stroke, isStrokes, ui, canvas, renderOptions) {
9493
9500
  const { strokeWidth, __font } = ui.__;
9494
9501
  const out = canvas.getSameCanvas(true);
9495
9502
  out.setStroke(isStrokes ? undefined : stroke, strokeWidth * 2, ui.__);
9496
9503
  out.font = __font;
9497
- isStrokes ? drawStrokesStyle(ui, stroke, out, true) : drawTextStroke(ui, out);
9504
+ isStrokes ? drawStrokesStyle(stroke, true, ui, out) : drawTextStroke(ui, out);
9498
9505
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
9499
9506
  fillText(ui, out);
9500
9507
  out.blendMode = 'normal';
9501
- canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds);
9508
+ if (ui.__hasMirror || renderOptions.matrix) {
9509
+ canvas.copyWorldByReset(out);
9510
+ }
9511
+ else {
9512
+ canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds);
9513
+ }
9502
9514
  out.recycle();
9503
9515
  }
9504
9516
  function drawTextStroke(ui, canvas) {
@@ -9518,7 +9530,7 @@ function drawTextStroke(ui, canvas) {
9518
9530
  canvas.strokeRect(row.x, row.y + decorationY, row.width, decorationHeight);
9519
9531
  }
9520
9532
  }
9521
- function drawStrokesStyle(ui, strokes, canvas, isText) {
9533
+ function drawStrokesStyle(strokes, isText, ui, canvas) {
9522
9534
  let item;
9523
9535
  for (let i = 0, len = strokes.length; i < len; i++) {
9524
9536
  item = strokes[i];
@@ -9538,13 +9550,13 @@ function drawStrokesStyle(ui, strokes, canvas, isText) {
9538
9550
  }
9539
9551
  }
9540
9552
 
9541
- function stroke(ui, canvas, stroke) {
9553
+ function stroke(stroke, ui, canvas, renderOptions) {
9542
9554
  const options = ui.__;
9543
9555
  const { strokeWidth, strokeAlign, __font } = options;
9544
9556
  if (!strokeWidth)
9545
9557
  return;
9546
9558
  if (__font) {
9547
- strokeText(ui, canvas, stroke);
9559
+ strokeText(stroke, ui, canvas, renderOptions);
9548
9560
  }
9549
9561
  else {
9550
9562
  switch (strokeAlign) {
@@ -9566,31 +9578,36 @@ function stroke(ui, canvas, stroke) {
9566
9578
  out.stroke();
9567
9579
  options.windingRule ? out.clip(options.windingRule) : out.clip();
9568
9580
  out.clearWorld(ui.__layout.renderBounds);
9569
- canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds);
9581
+ if (ui.__hasMirror || renderOptions.matrix) {
9582
+ canvas.copyWorldByReset(out);
9583
+ }
9584
+ else {
9585
+ canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds);
9586
+ }
9570
9587
  out.recycle();
9571
9588
  break;
9572
9589
  }
9573
9590
  }
9574
9591
  }
9575
- function strokes(ui, canvas, strokes) {
9592
+ function strokes(strokes, ui, canvas, renderOptions) {
9576
9593
  const options = ui.__;
9577
9594
  const { strokeWidth, strokeAlign, __font } = options;
9578
9595
  if (!strokeWidth)
9579
9596
  return;
9580
9597
  if (__font) {
9581
- strokeText(ui, canvas, strokes);
9598
+ strokeText(strokes, ui, canvas, renderOptions);
9582
9599
  }
9583
9600
  else {
9584
9601
  switch (strokeAlign) {
9585
9602
  case 'center':
9586
9603
  canvas.setStroke(undefined, strokeWidth, options);
9587
- drawStrokesStyle(ui, strokes, canvas);
9604
+ drawStrokesStyle(strokes, false, ui, canvas);
9588
9605
  break;
9589
9606
  case 'inside':
9590
9607
  canvas.save();
9591
9608
  canvas.setStroke(undefined, strokeWidth * 2, options);
9592
9609
  options.windingRule ? canvas.clip(options.windingRule) : canvas.clip();
9593
- drawStrokesStyle(ui, strokes, canvas);
9610
+ drawStrokesStyle(strokes, false, ui, canvas);
9594
9611
  canvas.restore();
9595
9612
  break;
9596
9613
  case 'outside':
@@ -9598,10 +9615,15 @@ function strokes(ui, canvas, strokes) {
9598
9615
  const out = canvas.getSameCanvas(true);
9599
9616
  ui.__drawRenderPath(out);
9600
9617
  out.setStroke(undefined, strokeWidth * 2, ui.__);
9601
- drawStrokesStyle(ui, strokes, out);
9618
+ drawStrokesStyle(strokes, false, ui, out);
9602
9619
  options.windingRule ? out.clip(options.windingRule) : out.clip();
9603
9620
  out.clearWorld(renderBounds);
9604
- canvas.copyWorldToInner(out, ui.__world, renderBounds);
9621
+ if (ui.__hasMirror || renderOptions.matrix) {
9622
+ canvas.copyWorldByReset(out);
9623
+ }
9624
+ else {
9625
+ canvas.copyWorldToInner(out, ui.__world, renderBounds);
9626
+ }
9605
9627
  out.recycle();
9606
9628
  break;
9607
9629
  }
@@ -9733,21 +9755,21 @@ function conicGradient(paint, box) {
9733
9755
  }
9734
9756
 
9735
9757
  let recycleMap;
9736
- function compute(ui, attrName) {
9758
+ function compute(attrName, ui) {
9737
9759
  const value = [];
9738
9760
  let item;
9739
9761
  let paints = ui.__.__input[attrName];
9740
9762
  if (!(paints instanceof Array))
9741
9763
  paints = [paints];
9742
- recycleMap = recycleImage(ui.__, attrName);
9764
+ recycleMap = recycleImage(attrName, ui.__);
9743
9765
  for (let i = 0, len = paints.length; i < len; i++) {
9744
- item = getLeafPaint(ui, paints[i], attrName);
9766
+ item = getLeafPaint(attrName, paints[i], ui);
9745
9767
  if (item)
9746
9768
  value.push(item);
9747
9769
  }
9748
9770
  ui.__['_' + attrName] = value.length ? value : undefined;
9749
9771
  }
9750
- function getLeafPaint(ui, paint, attrName) {
9772
+ function getLeafPaint(attrName, paint, ui) {
9751
9773
  if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)
9752
9774
  return undefined;
9753
9775
  const { boxBounds } = ui.__layout;
@@ -9785,7 +9807,7 @@ var UIPaint = /*#__PURE__*/Object.freeze({
9785
9807
  const { copy, toOffsetOutBounds: toOffsetOutBounds$1 } = BoundsHelper;
9786
9808
  const tempBounds = {};
9787
9809
  const offsetOutBounds$1 = {};
9788
- function shadow(ui, current, shape, _options) {
9810
+ function shadow(ui, current, shape, renderOptions) {
9789
9811
  let copyBounds, spreadScale;
9790
9812
  const { __world, __layout } = ui;
9791
9813
  const { shadow } = ui.__;
@@ -9807,7 +9829,7 @@ function shadow(ui, current, shape, _options) {
9807
9829
  }
9808
9830
  worldCanvas ? other.copyWorld(worldCanvas, __world, __world, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
9809
9831
  }
9810
- if (ui.__hasMirror) {
9832
+ if (ui.__hasMirror || renderOptions.matrix) {
9811
9833
  current.copyWorldByReset(other, copyBounds, __world, item.blendMode);
9812
9834
  }
9813
9835
  else {
@@ -9847,7 +9869,7 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
9847
9869
 
9848
9870
  const { toOffsetOutBounds } = BoundsHelper;
9849
9871
  const offsetOutBounds = {};
9850
- function innerShadow(ui, current, shape, _options) {
9872
+ function innerShadow(ui, current, shape, renderOptions) {
9851
9873
  let copyBounds, spreadScale;
9852
9874
  const { __world, __layout: __layout } = ui;
9853
9875
  const { innerShadow } = ui.__;
@@ -9871,7 +9893,7 @@ function innerShadow(ui, current, shape, _options) {
9871
9893
  copyBounds = bounds;
9872
9894
  }
9873
9895
  other.fillWorld(copyBounds, item.color, 'source-in');
9874
- if (ui.__hasMirror) {
9896
+ if (ui.__hasMirror || renderOptions.matrix) {
9875
9897
  current.copyWorldByReset(other, copyBounds, __world, item.blendMode);
9876
9898
  }
9877
9899
  else {