@didaoktv/didaoui-uniapp 1.2.2 → 1.2.3

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.
@@ -355,6 +355,8 @@
355
355
  expWidth = this.expWidth,
356
356
  expHeight = this.expHeight;
357
357
 
358
+ // 立即模式画布:清掉裁剪大图再画导出小图,防止透明像素透出底图
359
+ ctxCanvas.clearRect(0, 0, this.windowWidth, this.windowHeight);
358
360
  await ctxCanvas.drawImage(r, 0, 0, expWidth, expHeight);
359
361
  ctxCanvas.draw(false, () => {
360
362
  ctxCanvas.toTempFilePath({
@@ -444,6 +446,8 @@
444
446
  expWidth = this.expWidth,
445
447
  expHeight = this.expHeight;
446
448
 
449
+ // 立即模式画布:清掉裁剪大图再画导出小图,防止透明像素透出底图
450
+ ctxCanvas.clearRect(0, 0, this.windowWidth, this.windowHeight);
447
451
  await ctxCanvas.drawImage(r, 0, 0, expWidth, expHeight);
448
452
  ctxCanvas.draw(false, () => {
449
453
  ctxCanvas.toTempFilePath({
@@ -570,14 +574,17 @@
570
574
  this.useHeight = useHeight;
571
575
 
572
576
  let style = this.selStyle,
573
- left = parseInt(style.left),
574
- top = parseInt(style.top),
575
- width = parseInt(style.width),
576
- height = parseInt(style.height),
577
- ctxCanvas = this.ctxCanvas,
578
- ctxCanvasOper = this.ctxCanvasOper;
577
+ left = parseInt(style.left),
578
+ top = parseInt(style.top),
579
+ width = parseInt(style.width),
580
+ height = parseInt(style.height),
581
+ ctxCanvas = this.ctxCanvas,
582
+ ctxCanvasOper = this.ctxCanvasOper;
579
583
 
580
- ctxCanvasOper.setLineWidth(3);
584
+ // H5/小程序 type=2d 为立即模式画布,重绘遮罩前须清掉上一帧,否则拖控制点时遮罩残留
585
+ ctxCanvasOper.clearRect(0, 0, this.windowWidth, this.windowHeight);
586
+
587
+ ctxCanvasOper.setLineWidth(3);
581
588
  ctxCanvasOper.setStrokeStyle('grey');
582
589
  ctxCanvasOper.setGlobalAlpha(0.4);
583
590
  ctxCanvasOper.setFillStyle('black');
@@ -627,22 +634,30 @@
627
634
  this.$emit("avtinit");
628
635
  },
629
636
  async drawImage() {
630
- await this.initCanvasRefs();
631
- let tm_now = Date.now();
632
- if (tm_now - this.drawTm < 20) return;
633
- this.drawTm = tm_now;
634
- let ctxCanvas = this.ctxCanvas;
635
- if (this.fillColor && this.fillColor !== 'transparent') {
636
- ctxCanvas.fillRect(0, 0, this.windowWidth, this.windowHeight - tabHeight);
637
- }
638
- ctxCanvas.save();
639
- ctxCanvas.translate(this.posWidth + this.useWidth / 2, this.posHeight + this.useHeight / 2);
640
- ctxCanvas.scale(this.scaleSize, this.scaleSize);
641
- ctxCanvas.rotate(this.rotateDeg * Math.PI / 180);
642
- await ctxCanvas.drawImage(this.imgPath, -this.useWidth / 2, -this.useHeight / 2, this.useWidth, this.useHeight);
643
- ctxCanvas.restore();
644
- ctxCanvas.draw(false);
645
- },
637
+ await this.initCanvasRefs();
638
+ let tm_now = Date.now();
639
+ if (tm_now - this.drawTm < 20) return;
640
+ this.drawTm = tm_now;
641
+ let ctxCanvas = this.ctxCanvas;
642
+ // 图片对象先取回(dd-canvas 内部有缓存,二次绘制走同步路径);
643
+ // 加载期间若新帧已触发(token 失配)则丢弃本帧,避免旧帧续体把图片画回旧位置
644
+ const token = this._drawToken = (this._drawToken || 0) + 1;
645
+ const image = await ctxCanvas.loadImage(this.imgPath).catch(() => null);
646
+ if (!image || token !== this._drawToken) return;
647
+ // H5/小程序 type=2d 为立即模式画布,ctx.draw() 在 dd-canvas 内是 no-op,
648
+ // 上一帧像素不会自动清空——拖动残影的根因,每帧必须先 clearRect
649
+ ctxCanvas.clearRect(0, 0, this.windowWidth, this.windowHeight);
650
+ if (this.fillColor && this.fillColor !== 'transparent') {
651
+ ctxCanvas.fillRect(0, 0, this.windowWidth, this.windowHeight - tabHeight);
652
+ }
653
+ ctxCanvas.save();
654
+ ctxCanvas.translate(this.posWidth + this.useWidth / 2, this.posHeight + this.useHeight / 2);
655
+ ctxCanvas.scale(this.scaleSize, this.scaleSize);
656
+ ctxCanvas.rotate(this.rotateDeg * Math.PI / 180);
657
+ ctxCanvas.drawImage(image, -this.useWidth / 2, -this.useHeight / 2, this.useWidth, this.useHeight);
658
+ ctxCanvas.restore();
659
+ ctxCanvas.draw(false);
660
+ },
646
661
  hideImg() {
647
662
  this.prvImg = '';
648
663
  this.prvTop = '-10000px';
@@ -681,23 +696,25 @@
681
696
  this.prvImgTmp = r = r.tempFilePath;
682
697
 
683
698
  let ctxCanvasPrv = this.ctxCanvasPrv,
684
- prvX = this.windowWidth,
685
- prvY = parseInt(this.cvsStyleHeight),
686
- prvWidth = parseInt(this.selStyle.width),
687
- prvHeight = parseInt(this.selStyle.height),
688
- useWidth = prvX - 40,
689
- useHeight = prvY - 80,
690
- radio = useWidth / prvWidth,
691
- rHeight = prvHeight * radio;
692
- if (rHeight < useHeight) {
693
- prvWidth = useWidth;
694
- prvHeight = rHeight;
695
- } else {
696
- radio = useHeight / prvHeight;
697
- prvWidth *= radio;
698
- prvHeight = useHeight;
699
- }
700
- if (this.fillColor && this.fillColor !== 'transparent') {
699
+ prvX = this.windowWidth,
700
+ prvY = parseInt(this.cvsStyleHeight),
701
+ prvWidth = parseInt(this.selStyle.width),
702
+ prvHeight = parseInt(this.selStyle.height),
703
+ useWidth = prvX - 40,
704
+ useHeight = prvY - 80,
705
+ radio = useWidth / prvWidth,
706
+ rHeight = prvHeight * radio;
707
+ // 立即模式画布:清掉上一次预览的残影再画新帧
708
+ ctxCanvasPrv.clearRect(0, 0, this.windowWidth, this.windowHeight);
709
+ if (rHeight < useHeight) {
710
+ prvWidth = useWidth;
711
+ prvHeight = rHeight;
712
+ } else {
713
+ radio = useHeight / prvHeight;
714
+ prvWidth *= radio;
715
+ prvHeight = useHeight;
716
+ }
717
+ if (this.fillColor && this.fillColor !== 'transparent') {
701
718
  ctxCanvasPrv.setFillStyle(this.fillColor);
702
719
  ctxCanvasPrv.fillRect(0, 0, prvX, prvY);
703
720
  ctxCanvasPrv.fillRect(x, y, width, height);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@didaoktv/didaoui-uniapp",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "帝到KTV UniApp 组件库",
5
5
  "main": "index.ts",
6
6
  "types": "index.ts",