@@ -1367,6 +1367,8 @@ export class Canvas {
1367
1367
! pen . parentId && this . randomCombineId ( pen , pens ) ;
1368
1368
}
1369
1369
if ( Object . keys ( this . randomIdObj ) . length !== 0 ) {
1370
+ const keys = Object . keys ( this . randomIdObj ) . join ( '|' ) ;
1371
+ const regex = new RegExp ( `(${ keys } )` , "g" ) ;
1370
1372
for ( const pen of pens ) {
1371
1373
if ( pen . type ) {
1372
1374
pen . anchors [ 0 ] . connectTo = this . randomIdObj [ pen . anchors [ 0 ] . connectTo ] ;
@@ -1378,6 +1380,20 @@ export class Canvas {
1378
1380
item . lineId = this . randomIdObj [ item . lineId ] ;
1379
1381
} ) ;
1380
1382
}
1383
+
1384
+ //动画、事件和状态
1385
+ if ( pen . animations ?. length ) {
1386
+ const str = JSON . stringify ( pen . animations ) . replace ( regex , match => this . randomIdObj [ match ] ) ;
1387
+ pen . animations = JSON . parse ( str ) ;
1388
+ }
1389
+ if ( pen . triggers ?. length ) {
1390
+ const str = JSON . stringify ( pen . triggers ) . replace ( regex , match => this . randomIdObj [ match ] ) ;
1391
+ pen . triggers = JSON . parse ( str ) ;
1392
+ }
1393
+ if ( pen . events ?. length ) {
1394
+ const str = JSON . stringify ( pen . events ) . replace ( regex , match => this . randomIdObj [ match ] ) ;
1395
+ pen . events = JSON . parse ( str ) ;
1396
+ }
1381
1397
}
1382
1398
}
1383
1399
for ( const pen of pens ) {
@@ -1490,14 +1506,18 @@ export class Canvas {
1490
1506
pen . anchors [ 0 ] . id ,
1491
1507
pen . anchors [ pen . anchors . length - 1 ] . id ,
1492
1508
] ;
1509
+ } else {
1510
+ beforeIds = [ pen . id ] ;
1493
1511
}
1494
1512
} else {
1495
- if ( pen . connectedLines && pen . connectedLines . length ) {
1513
+ if ( pens . length > 1 ) {
1514
+ // if (pen.connectedLines && pen.connectedLines.length) {
1496
1515
beforeIds = [ pen . id ] ;
1497
1516
}
1498
1517
}
1499
1518
randomId ( pen ) ;
1500
- if ( beforeIds ) {
1519
+ if ( pens . length > 1 ) {
1520
+ // if (beforeIds) {
1501
1521
if ( beforeIds . length === 1 ) {
1502
1522
this . randomIdObj [ beforeIds [ 0 ] ] = pen . id ;
1503
1523
} else {
@@ -2842,7 +2862,7 @@ export class Canvas {
2842
2862
const gridSize = this . store . data . gridSize || this . store . options . gridSize ;
2843
2863
const { origin, scale } = this . store . data ;
2844
2864
const autoAlignGrid =
2845
- this . store . options . autoAlignGrid && this . store . data . grid ;
2865
+ this . store . options . autoAlignGrid && ( this . store . data . grid || this . store . options . grid ) ;
2846
2866
movedPens . forEach ( ( pen ) => {
2847
2867
const i = this . movingPens . findIndex ( ( item ) => item . id === pen . id + movingSuffix ) ;
2848
2868
if ( i < 0 ) {
@@ -3767,6 +3787,7 @@ export class Canvas {
3767
3787
} else if ( ! pen . height ) {
3768
3788
pen . width = this . width ;
3769
3789
}
3790
+ this . updatePenRect ( pen ) ;
3770
3791
}
3771
3792
calcInView ( pen ) ;
3772
3793
}
@@ -4203,6 +4224,12 @@ export class Canvas {
4203
4224
} ) ;
4204
4225
}
4205
4226
! pen . rotate && ( pen . rotate = 0 ) ;
4227
+ pen . lineAnimateImages ??= [ ]
4228
+ if ( pen . lineAnimateImages ) {
4229
+ pen . lineAnimateImages . forEach ( ( src ) => {
4230
+ this . __loadImage ( src )
4231
+ } )
4232
+ }
4206
4233
this . loadImage ( pen ) ;
4207
4234
this . parent . penNetwork ( pen ) ;
4208
4235
}
@@ -4572,6 +4599,33 @@ export class Canvas {
4572
4599
pen . calculative . strokeImage = pen . strokeImage ;
4573
4600
}
4574
4601
}
4602
+
4603
+ // 加载图片到全局缓存
4604
+ __loadImage ( src :string ) {
4605
+ return new Promise ( resolve => {
4606
+ if ( ! globalStore . htmlElements [ src ] ) {
4607
+ const img = new Image ( ) ;
4608
+ img . crossOrigin = 'anonymous' ;
4609
+ img . src = src ;
4610
+ if (
4611
+ this . store . options . cdn &&
4612
+ ! (
4613
+ src . startsWith ( 'http' ) ||
4614
+ src . startsWith ( '//' ) ||
4615
+ src . startsWith ( 'data:image' )
4616
+ )
4617
+ ) {
4618
+ img . src = this . store . options . cdn + src ;
4619
+ }
4620
+ img . onload = ( ) => {
4621
+ globalStore . htmlElements [ src ] = img ;
4622
+ resolve ( img ) ;
4623
+ } ;
4624
+ } else {
4625
+ resolve ( globalStore . htmlElements [ src ] ) ;
4626
+ }
4627
+ } )
4628
+ }
4575
4629
private imageTimer : any ;
4576
4630
// 避免初始化图片加载重复调用 render,此处防抖
4577
4631
imageLoaded ( ) {
@@ -5217,11 +5271,11 @@ export class Canvas {
5217
5271
}
5218
5272
scalePoint ( this . store . data . origin , s , center ) ;
5219
5273
this . store . data . pens . forEach ( ( pen ) => {
5274
+ pen . onScale && pen . onScale ( pen ) ;
5220
5275
if ( pen . parentId ) {
5221
5276
return ;
5222
5277
}
5223
5278
scalePen ( pen , s , center ) ;
5224
- pen . onScale && pen . onScale ( pen ) ;
5225
5279
if ( pen . isRuleLine ) {
5226
5280
// 扩大线的比例,若是放大,即不缩小,若是缩小,会放大
5227
5281
const lineScale = 1 / s ; //s > 1 ? 1 : 1 / s / s;
@@ -6713,8 +6767,19 @@ export class Canvas {
6713
6767
const curPage = sessionStorage . getItem ( 'page' ) ;
6714
6768
const scale = this . store . data . scale ;
6715
6769
if ( this . store . clipboard . mousePos && ( Math . abs ( this . store . clipboard . mousePos . x - this . mousePos . x ) > 100 * scale || Math . abs ( this . store . clipboard . mousePos . y - this . mousePos . y ) > 100 * scale ) ) {
6716
- const offsetX = ( scale - this . store . clipboard . scale ) * this . store . clipboard . initRect . width / 2 ;
6717
- const offsetY = ( scale - this . store . clipboard . scale ) * this . store . clipboard . initRect . height / 2 ;
6770
+ let _x = - this . store . clipboard . initRect . width / this . store . clipboard . scale / 10 / ( scale ) ;
6771
+ let _y = - this . store . clipboard . initRect . height / this . store . clipboard . scale / 10 / ( scale ) ;
6772
+ let offsetX = ( scale - this . store . clipboard . scale ) * this . store . clipboard . initRect . width / 2 + _x ;
6773
+ let offsetY = ( scale - this . store . clipboard . scale ) * this . store . clipboard . initRect . height / 2 + _y ;
6774
+ if ( scale < this . store . clipboard . scale ) {
6775
+ // 减小粘贴偏移量
6776
+ offsetX = ( scale - this . store . clipboard . scale ) / ( ( this . store . clipboard . scale - scale ) * 100 ) * this . store . clipboard . initRect . width / 2 + _x ;
6777
+ offsetY = ( scale - this . store . clipboard . scale ) / ( ( this . store . clipboard . scale - scale ) * 100 ) * this . store . clipboard . initRect . height / 2 + _y ;
6778
+ }
6779
+ if ( this . store . clipboard . pens . length > 1 ) {
6780
+ offsetX = ( scale - 1 ) * this . store . clipboard . initRect . width / this . store . clipboard . scale / 2 ;
6781
+ offsetY = ( scale - 1 ) * this . store . clipboard . initRect . height / this . store . clipboard . scale / 2 ;
6782
+ }
6718
6783
this . store . clipboard . pos = { x : this . mousePos . x - offsetX , y : this . mousePos . y - offsetY } ;
6719
6784
this . store . clipboard . offset = 0 ;
6720
6785
} else if ( curPage !== clipboard . page ) {
@@ -7119,7 +7184,7 @@ export class Canvas {
7119
7184
id = _id ;
7120
7185
}
7121
7186
}
7122
-
7187
+
7123
7188
} ) ;
7124
7189
this . store . hover = this . store . pens [ id ] ;
7125
7190
this . store . pens [ id ] . calculative . hover = true ;
@@ -7846,7 +7911,7 @@ export class Canvas {
7846
7911
if ( needCalcIconRectProps . includes ( k ) ) {
7847
7912
willCalcIconRect = true ;
7848
7913
}
7849
- if ( pen . image && pen . name !== 'gif' && [ 'globalAlpha' , 'flipY' , 'flipX' , 'x' , 'y' , 'width' , 'height' , 'iconWidth' , 'iconHeight' , 'imageRatio' , 'iconLeft' , 'iconTop' , 'iconAlign' , 'rotate' ] . includes ( k ) ) {
7914
+ if ( pen . image && pen . name !== 'gif' && [ 'globalAlpha' , 'flipY' , 'flipX' , 'x' , 'y' , 'width' , 'height' , 'iconWidth' , 'iconHeight' , 'imageRatio' , 'iconLeft' , 'iconTop' , 'iconAlign' , 'rotate' , 'visible' ] . includes ( k ) ) {
7850
7915
willRenderImage = true ;
7851
7916
}
7852
7917
} else {
@@ -8442,6 +8507,7 @@ export class Canvas {
8442
8507
this . externalElements . style . zIndex = '5' ;
8443
8508
this . magnifierCanvas . magnifier = false ;
8444
8509
this . externalElements . style . cursor = 'default' ;
8510
+ this . magnifierCanvas . render ( ) ;
8445
8511
this . render ( ) ;
8446
8512
}
8447
8513
0 commit comments