@@ -105,6 +105,7 @@ export const PURE_STYLE_KEY = [
105105
106106export const GRAPHIC_UPDATE_TAG_KEY = [
107107 'lineWidth' ,
108+ 'pathProxy' ,
108109 // 'lineCap',
109110 // 'lineJoin',
110111 // 'miterLimit',
@@ -321,7 +322,7 @@ export abstract class Graphic<T extends Partial<IGraphicAttribute> = Partial<IGr
321322 // declare prevAttrs?: T;
322323 // declare finalAttrs?: T;
323324
324- declare pathProxy ?: ICustomPath2D ;
325+ declare pathProxy ?: string | ICustomPath2D | ( ( attrs : T ) => string | ICustomPath2D ) ;
325326 // 依附于某个theme,如果该节点不存在parent,那么这个Theme就作为节点的Theme,避免添加到节点前计算属性
326327 declare attachedThemeGraphic ?: IGraphic ;
327328 protected updateAABBBoundsStamp : number ;
@@ -555,7 +556,7 @@ export abstract class Graphic<T extends Partial<IGraphicAttribute> = Partial<IGr
555556 }
556557
557558 updatePathProxyAABBBounds ( aabbBounds : IAABBBounds ) : boolean {
558- const path = typeof this . pathProxy === 'function' ? ( this . pathProxy as any ) ( this . attribute ) : this . pathProxy ;
559+ const path = this . getPathProxy ( ) ;
559560 if ( ! path ) {
560561 return false ;
561562 }
@@ -1492,13 +1493,35 @@ export abstract class Graphic<T extends Partial<IGraphicAttribute> = Partial<IGr
14921493 }
14931494
14941495 createPathProxy ( path ?: string ) {
1495- if ( isString ( path , true ) ) {
1496- this . pathProxy = new CustomPath2D ( ) . fromString ( path as string ) ;
1497- } else {
1498- this . pathProxy = new CustomPath2D ( ) ;
1496+ const proxy = isString ( path , true ) ? new CustomPath2D ( ) . fromString ( path as string ) : new CustomPath2D ( ) ;
1497+ // 兼容:保留运行时字段,同时将能力下沉到attribute配置
1498+ this . pathProxy = proxy ;
1499+ ( this . attribute as any ) . pathProxy = proxy ;
1500+ this . addUpdateShapeAndBoundsTag ( ) ;
1501+ this . onAttributeUpdate ( ) ;
1502+ return proxy ;
1503+ }
1504+
1505+ getPathProxy ( ) : ICustomPath2D | null {
1506+ const attributePathProxy = ( this . attribute as any ) ?. pathProxy ;
1507+ const rawPathProxy = attributePathProxy ?? this . pathProxy ;
1508+ if ( ! rawPathProxy ) {
1509+ return null ;
1510+ }
1511+
1512+ const resolvedPathProxy =
1513+ typeof rawPathProxy === 'function'
1514+ ? ( rawPathProxy as ( attrs : T ) => string | ICustomPath2D ) ( this . attribute )
1515+ : rawPathProxy ;
1516+ if ( ! resolvedPathProxy ) {
1517+ return null ;
1518+ }
1519+
1520+ if ( isString ( resolvedPathProxy , true ) ) {
1521+ return new CustomPath2D ( ) . fromString ( resolvedPathProxy as string ) ;
14991522 }
15001523
1501- return this . pathProxy ;
1524+ return resolvedPathProxy as ICustomPath2D ;
15021525 }
15031526
15041527 loadImage ( image : any , background : boolean = false ) {
@@ -1632,6 +1655,10 @@ export abstract class Graphic<T extends Partial<IGraphicAttribute> = Partial<IGr
16321655 abstract clone ( ) : IGraphic < any > ;
16331656
16341657 toCustomPath ( ) : ICustomPath2D {
1658+ const pathProxy = this . getPathProxy ( ) ;
1659+ if ( pathProxy ) {
1660+ return pathProxy ;
1661+ }
16351662 // throw new Error('暂不支持');
16361663 const renderer = ( this . stage ?. renderService || application . renderService ) ?. drawContribution ?. getRenderContribution (
16371664 this
0 commit comments