@visactor/vrender-core 1.0.0-alpha.11 → 1.0.0-alpha.13

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.
@@ -258,7 +258,7 @@ export interface IGraphic<T extends Partial<IGraphicAttribute> = Partial<IGraphi
258
258
  stateProxy?: (stateName: string, targetStates?: string[]) => Partial<T>;
259
259
  findFace?: () => IFace3d;
260
260
  toggleState: (stateName: string, hasAnimation?: boolean) => void;
261
- removeState: (stateName: string, hasAnimation?: boolean) => void;
261
+ removeState: (stateName: string | string[], hasAnimation?: boolean) => void;
262
262
  clearStates: (hasAnimation?: boolean) => void;
263
263
  useStates: (states: string[], hasAnimation?: boolean) => void;
264
264
  addState: (stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean) => void;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interface/graphic.ts"],"names":[],"mappings":"","file":"graphic.js","sourcesContent":["import type { IAABBBounds, IMatrix, IPointLike, IPoint, BoundsAnchorType, IOBBBounds } from '@visactor/vutils';\nimport type { IAnimate, IStep, EasingType, IAnimateTarget, ITimeline } from './animation';\nimport type { IColor } from './color';\nimport type { IGroup } from './graphic/group';\nimport type { IShadowRoot } from './graphic/shadow-root';\nimport type { ILayer } from './layer';\nimport type { INode } from './node-tree';\nimport type { ICustomPath2D } from './path';\nimport type { IStage } from './stage';\nimport type { IGlyphGraphicAttribute } from './graphic/glyph';\nimport type { IContainPointMode } from '../common/enums';\nimport type { IFace3d } from './graphic/face3d';\nimport type { IPickerService } from './picker';\nimport type { ISymbolClass } from './graphic/symbol';\n\ntype IStrokeSeg = {\n /**\n * 百分比\n */\n start: number;\n /**\n * 百分比\n * end和length二选一\n */\n end: number;\n /**\n * 像素长度\n */\n length: number;\n};\n\n// TODO 最后加一个any\nexport type GraphicType =\n | 'area'\n | 'circle'\n | 'ellipse'\n | 'line'\n | 'rect'\n | 'rect3d'\n | 'path'\n | 'richtext'\n | 'text'\n | 'arc'\n | 'arc3d'\n | 'image'\n | 'symbol'\n | 'group'\n | 'shadowroot'\n | 'polygon'\n | 'pyramid3d'\n | 'glyph'\n | string;\n\n// Cursor style\n// See: https://developer.mozilla.org/en-US/docs/Web/CSS/cursor\nexport type Cursor =\n | 'auto'\n | 'default'\n | 'none'\n | 'context-menu'\n | 'help'\n | 'pointer'\n | 'progress'\n | 'wait'\n | 'cell'\n | 'crosshair'\n | 'text'\n | 'vertical-text'\n | 'alias'\n | 'copy'\n | 'move'\n | 'no-drop'\n | 'not-allowed'\n | 'grab'\n | 'grabbing'\n | 'all-scroll'\n | 'col-resize'\n | 'row-resize'\n | 'n-resize'\n | 'e-resize'\n | 's-resize'\n | 'w-resize'\n | 'ne-resize'\n | 'nw-resize'\n | 'se-resize'\n | 'sw-resize'\n | 'ew-resize'\n | 'ns-resize'\n | 'nesw-resize'\n | 'nwse-resize'\n | 'zoom-in'\n | 'zoom-out';\n\nexport type ITransform = {\n /**\n * x坐标\n */\n x: number;\n /**\n * y坐标\n */\n y: number;\n /**\n * z坐标\n */\n z: number;\n /**\n * x方向偏移量\n */\n dx: number;\n /**\n * y方向偏移量\n */\n dy: number;\n /**\n * z方向偏移量\n */\n dz: number;\n /**\n * x方向的滚动值\n */\n scrollX: number;\n /**\n * y方向的滚动值\n */\n scrollY: number;\n /**\n * x方向的缩放值\n */\n scaleX: number;\n /**\n * y方向的缩放值\n */\n scaleY: number;\n /**\n * z方向的缩放值\n */\n scaleZ: number;\n /**\n * 绕z轴的转角,即xy平面上的旋转角度\n */\n angle: number;\n /**\n * 绕x轴的转角\n */\n alpha: number;\n /**\n * 绕y轴的转角\n */\n beta: number;\n /**\n * 应用缩放的中心\n */\n scaleCenter: [number | string, number | string];\n /**\n * 基于AABB的锚点位置,用于简单的定位某些path\n */\n anchor: [number | string, number | string];\n /**\n * 3d的锚点位置\n */\n anchor3d: [number | string, number | string, number] | [number | string, number | string];\n /**\n * 处理矩阵,在正常计算完变换矩阵之后,会将该矩阵乘到变换矩阵上得到最终的变换矩阵\n */\n postMatrix: IMatrix;\n};\n\nexport type IFillType = boolean | string | IColor;\nexport type IFillStyle = {\n /**\n * 图形的填充透明度\n */\n fillOpacity: number;\n /**\n * 图形模糊效果程度\n */\n shadowBlur: number;\n /**\n * 图形的阴影颜色\n */\n shadowColor: string;\n /**\n * 阴影水平偏移距离\n */\n shadowOffsetX: number;\n /**\n * 阴影垂直偏移距离\n */\n shadowOffsetY: number;\n /**\n * 图形的填充颜色\n */\n fill: IFillType;\n};\n\nexport type ILayout = {\n /**\n * 设置对齐方式\n */\n alignSelf: 'auto' | 'flex-start' | 'flex-end' | 'center';\n};\n\nexport type IBorderStyle = Omit<IStrokeStyle, 'outerBorder' | 'innerBorder'> & {\n /**\n * 边距离边缘的距离\n */\n distance: number | string;\n /**\n * 是否显示边框,默认是不显示的\n */\n visible?: boolean;\n};\n\nexport type IStrokeType = boolean | string | IColor | null;\nexport type IStrokeStyle = {\n /**\n * 外部边框的样式配置,默认不展示外部边框\n */\n outerBorder: Partial<IBorderStyle>;\n /**\n * 内部边框的样式配置\n */\n innerBorder: Partial<IBorderStyle>;\n /**\n * 描边的透明度\n */\n strokeOpacity: number;\n /**\n * 设置线条虚线样式的属性,它通过定义实线和空白的交替长度来创建虚线效果\n */\n lineDash: number[];\n\n /**\n * 设置虚线样式的起始偏移量\n */\n lineDashOffset: number;\n\n /**\n * 设置线条的宽度\n */\n lineWidth: number;\n\n /**\n * 设置线条末端的样式\n */\n lineCap: CanvasLineCap;\n\n /**\n * 设置线条拐角的样式\n */\n lineJoin: CanvasLineJoin;\n\n /**\n * 设置线条拐角处的斜接限制\n */\n miterLimit: number;\n /**\n * 描边的boundsBuffer,用于控制bounds的buffer\n */\n strokeBoundsBuffer: number;\n /**\n * stroke - true 全描边\n * stroke - false 不描边\n * stroke 为数值类型,适用于rect\\arc等图形,用于配置部分描边的场景,其中\n *\n * 0b00000 - 不描边\n * 0b000001 - top\n * 0b000010 - right\n * 0b000100 - bottom\n * 0b001000 - left\n * 相应的:\n * 0b000011 - top + right\n * 0b000111 - top + right + bottom\n * 0b001111 - 全描边\n *\n * stroke - boolean[],适用于rect\\arc等图形,用于配置部分描边的场景\n */\n stroke: IStrokeType[] | IStrokeType;\n};\n\ntype TextureType = 'circle' | 'diamond' | 'rect' | 'vertical-line' | 'horizontal-line' | 'bias-lr' | 'bias-rl' | 'grid';\n\nexport type IConnectedStyle = {\n /**\n * 连接,取零或者断开\n */\n connectedType: 'connect' | 'none';\n /**\n * 连接线的样式配置\n */\n connectedStyle: {\n stroke: IStrokeStyle['stroke'];\n strokeOpacity: IStrokeStyle['strokeOpacity'];\n lineDash: IStrokeStyle['lineDash'];\n lineDashOffset: IStrokeStyle['lineDashOffset'];\n lineCap: IStrokeStyle['lineCap'];\n lineJoin: IStrokeStyle['lineJoin'];\n lineWidth: IStrokeStyle['lineWidth'];\n fill: IFillStyle['fill'];\n fillOpacity: IFillStyle['fillOpacity'];\n };\n connectedX: number;\n connectedY: number;\n};\n\nexport type IBackgroundConfig = {\n stroke?: string | boolean;\n fill?: string | boolean;\n lineWidth?: number;\n cornerRadius?: number;\n expandX?: number;\n expandY?: number;\n};\n\ntype IBackgroundType = string | HTMLImageElement | HTMLCanvasElement | IBackgroundConfig;\n\nexport interface SimpleDomStyleOptions {\n /**\n * 容器的宽度\n */\n width: number;\n /**\n * 容器的高度\n */\n height: number;\n /**\n * 容器的样式设置\n */\n style?:\n | string\n | Record<string, any>\n | ((\n pos: { top: number; left: number; width: number; height: number },\n graphic: IGraphic,\n wrapContainer: HTMLElement\n ) => Record<string, any>); // 容器的样式\n}\n\nexport interface CommonDomOptions {\n /**\n * 全局唯一的id\n */\n id?: string;\n /**\n * 容器元素的id或者dom元素\n */\n container: string | HTMLElement | null;\n /**\n * 是否显示\n */\n visible?: boolean;\n /**\n * 是否支持事件冒泡\n */\n pointerEvents?: boolean | string;\n /**\n * 可穿透的事件列表\n * @since 0.21.2\n */\n penetrateEventList?: string[];\n /**\n * 定位类型\n * 'position' - 根据挂载图形节点的坐标也就是x,y进行定位\n * 'boundsLeftTop' - 定位到挂载图形节点bounds的左上角\n * 'left' - 定位到挂载图形节点bounds 的左侧\n * 'right' - 定位到挂载图形节点bounds 的右侧\n * 'bottom' - 定位到挂载图形节点bounds 的底部\n * 'top' - 定位到挂载图形节点bounds 的顶部\n * 'center' - 定位到挂载图形节点bounds 的中心\n * 'top-left' - 定位到挂载图形节点bounds 的左上角\n * 'top-right' - 定位到挂载图形节点bounds 的右上角\n * 'bottom-left' - 定位到挂载图形节点bounds 的左下角\n * 'bottom-right' - 定位到挂载图形节点bounds 的右下角\n */\n anchorType?: 'position' | 'boundsLeftTop' | BoundsAnchorType;\n}\n\nexport type IRoughStyle = {\n fillStyle: 'hachure' | 'solid' | 'zigzag' | 'cross-hatch' | 'dots' | 'sunburst' | 'dashed' | 'zigzag-line';\n roughness: number;\n bowing: number;\n};\n\nexport type IGraphicStyle = ILayout &\n IFillStyle &\n IStrokeStyle &\n IPickStyle & {\n /**\n * 强制设置的bounds宽度,主要用于使用html或者react展示图形的时候,设置一个固定的宽度\n */\n forceBoundsWidth: number | (() => number) | undefined;\n /**\n * 强制设置的bounds高度,主要用于使用html或者react展示图形的时候,设置一个固定的高度\n */\n forceBoundsHeight: number | (() => number) | undefined;\n /**\n * 透明度,会同时影响填充和描边\n */\n opacity: number;\n /**\n * 影子节点\n */\n shadowGraphic?: IGraphic | undefined;\n /**\n * 背景填充模式(与具体图元有关)\n */\n backgroundMode: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat';\n /**\n * 是否正好填充,只在repeat-x或者repeat-y以及no-repeat的时候生效\n */\n backgroundFit: boolean;\n /**\n * 是否保持背景图的宽高比\n */\n backgroundKeepAspectRatio: boolean;\n /**\n * 背景图缩放,只在no-repeat的时候生效\n */\n backgroundScale: number;\n /**\n * 背景图偏移,只在no-repeat的时候生效\n */\n backgroundOffsetX: number;\n /**\n * 背景图偏移,只在no-repeat的时候生效\n */\n backgroundOffsetY: number;\n /**\n * 背景图是否裁切,是否调用clip避免绘制到图元外部\n */\n backgroundClip: boolean;\n /**\n * 背景圆角半径\n */\n backgroundCornerRadius: number | number[];\n /**\n * 背景透明度\n */\n backgroundOpacity: number;\n /**\n * 背景,支持颜色字符串、html image元素、html canvas元素\n */\n // 纹理是否自动做动画\n autoAnimateTexture: boolean;\n // 如果做动画的话,这里代表ratio\n textureRatio: number;\n textureOptions: any;\n background:\n | IBackgroundType\n | {\n /**\n * 背景,支持颜色字符串、html image元素、html canvas元素\n */\n background: IBackgroundType;\n /**\n * 背景的x方向偏移量\n */\n dx?: number;\n /**\n * 背景的y方向偏移量\n */\n dy?: number;\n /**\n * 背景宽度\n */\n width?: number;\n /**\n * 背景高度\n */\n height?: number;\n /**\n * 背景的x坐标\n */\n x?: number;\n /**\n * 背景的y坐标\n */\n y?: number;\n }\n | null; // 背景,可以与fill同时存在\n /**\n * 纹理的类型\n */\n texture: TextureType | string;\n /**\n * 纹理的颜色\n */\n textureColor: string;\n /**\n * 纹理的大小\n */\n textureSize: number;\n /**\n * 纹理的间隙\n */\n texturePadding: number;\n\n blur: number;\n /**\n * 设置图形对应的鼠标样式\n */\n cursor: Cursor | null;\n // @deprecated 用处少废弃,后续考虑新设计API\n filter: string;\n renderStyle?: 'default' | 'rough' | any;\n roughStyle?: IRoughStyle | null;\n /**\n * HTML的dom或者string\n */\n html:\n | ({\n /**\n * dom字符串或者dom\n */\n dom: string | HTMLElement;\n } & SimpleDomStyleOptions &\n CommonDomOptions)\n | null;\n /**\n * 使用react元素渲染内容\n */\n react:\n | ({\n /**\n * react场景节点\n */\n element: any;\n } & SimpleDomStyleOptions &\n CommonDomOptions)\n | null;\n /**\n * 使用vue组件渲染内容\n */\n vue:\n | ({\n /**\n * vue 虚拟节点\n */\n element: any;\n } & SimpleDomStyleOptions &\n CommonDomOptions)\n | null;\n };\n\nexport type IPickStyle = {\n /**\n * 给stroke模式的pick额外加的buffer,用于外界控制stroke区域的pick范围\n */\n pickStrokeBuffer: number;\n};\n\nexport type IDebugType = {\n _debug_bounds: boolean | ((c: any, g: any) => void);\n};\nexport type IGraphicAttribute = IDebugType &\n IGraphicStyle &\n ITransform & {\n /**\n * stroke百分比\n */\n strokeSeg: IStrokeSeg | null;\n /**\n * 包围盒的padding\n */\n boundsPadding: number | number[];\n /**\n * 选择模式,精确模式,粗糙模式(包围盒模式),自定义模式\n */\n pickMode: 'accurate' | 'imprecise' | 'custom';\n boundsMode: 'accurate' | 'imprecise' | 'empty';\n customPickShape: () => boolean | null;\n /**\n * 是否支持事件拾取,默认为 true。\n * @default true\n */\n pickable: boolean;\n /**\n * 是否支持fill拾取,默认为 true。\n * @experimental\n * @default true\n */\n fillPickable: boolean;\n /**\n * 是否支持stroke拾取,默认为 true。\n * @experimental\n * @default true\n */\n strokePickable: boolean;\n /**\n * 对于 group 节点,是否支持其子元素的事件拾取,默认为 true。\n * 如果 group `pickable` 关闭,`childrenPickable` 开启,那么 group 的子节点仍参与事件拾取\n * @default true\n */\n childrenPickable: boolean;\n /**\n * 元素是否可见。\n * @default true\n */\n visible: boolean;\n /**\n * 分组下的层级,层级越小越先绘制\n */\n zIndex: number;\n layout: any;\n /**\n * 是否隐藏元素(只是绘制的时候不绘制)\n */\n renderable: boolean;\n /**\n * 是否在3d中控制方向\n * false: 不控制方向\n * true: 始终控制方向朝摄像机\n */\n keepDirIn3d?: boolean;\n shadowRootIdx: number;\n shadowPickMode?: 'full' | 'graphic';\n /**\n * 全局范围的层级,设置了这个属性的图形,会提取到交互层进行渲染\n */\n globalZIndex: number;\n /**\n * canvas 的合成方式\n */\n globalCompositeOperation: CanvasRenderingContext2D['globalCompositeOperation'] | '';\n /**\n * 完全支持滚动 | 完全不支持滚动 | 支持x方向的滚动 | 支持y方向的滚动\n */\n overflow: 'scroll' | 'hidden' | 'scroll-x' | 'scroll-y';\n /**\n * 绘制fill和stroke的顺序,为0表示fill先绘制,1表示stroke先绘制\n */\n fillStrokeOrder: number;\n /**\n * @since 0.20.15\n * 保持stroke的scale,默认为false,为true的话stroke显示的宽度会随着scale变化\n */\n keepStrokeScale: boolean;\n\n /**\n * @since 0.22.2\n * 裁剪路径,用于裁剪图形,用于普通图元的裁剪\n * 由于一般情况下普通图元只需要一个形状即可,所以这里不需要配置具体的位置和大小,强制中心在图元中心,宽高和图元Bounds宽高一致\n * 不考虑其他复杂情况,否则配置项就非常多了,比如多路径,或者配置位置大小等,如果配置大小那还得用户自己去拿图元的大小,目前没有这种需求\n */\n clipConfig: {\n shape: string;\n } | null;\n };\n\nexport interface IGraphicJson<T extends Partial<IGraphicAttribute> = Partial<IGraphicAttribute>> {\n attribute: Partial<T>;\n _uid: number;\n type: string;\n name: string;\n children: IGraphicJson<T>[];\n}\n\n/** the context of setAttribute */\nexport type ISetAttributeContext = {\n /** type of setAttribute */\n type?: number;\n animationState?: {\n step?: IStep;\n isFirstFrameOfStep?: boolean;\n /** ratio of animation */\n ratio?: number;\n /** is animation end? */\n end?: boolean;\n };\n skipUpdateCallback?: boolean;\n};\n\nexport type IGraphicAnimateParams = {\n slience?: boolean;\n id?: number | string;\n timeline?: ITimeline;\n onStart?: () => void;\n onFrame?: (step: IStep, ratio: number) => void;\n onEnd?: () => void;\n onRemove?: () => void;\n interpolate?: (key: string, ratio: number, from: any, to: any, nextAttributes: any) => boolean;\n};\n\nexport interface IGraphic<T extends Partial<IGraphicAttribute> = Partial<IGraphicAttribute>>\n extends INode,\n IAnimateTarget {\n type?: GraphicType;\n numberType?: number;\n stage?: IStage;\n layer?: ILayer;\n shadowRoot?: IShadowRoot;\n glyphHost?: IGraphic<IGlyphGraphicAttribute>;\n backgroundImg?: boolean;\n attachedThemeGraphic?: IGraphic<any>;\n /**\n * 保存语法上下文\n */\n context?: Record<string, any>;\n bindDom?: Map<\n string | HTMLElement,\n { container: HTMLElement | string; dom: HTMLElement | any; wrapGroup: HTMLDivElement | any; root?: any }\n >;\n\n valid: boolean;\n parent: IGroup | null;\n isContainer?: boolean;\n // 是否是3d模式(是否应用3d视角)\n in3dMode?: boolean;\n\n // 不考虑transform的宽高,特殊情况下会使用到\n widthWithoutTransform?: number;\n heightWithoutTransform?: number;\n\n // 上次更新的stamp\n stamp?: number;\n animationBackUps?: {\n from: Record<string, any>;\n to: Record<string, any>;\n };\n\n attribute: Partial<T>;\n\n /** 用于实现morph动画场景,转换成bezier曲线渲染 */\n pathProxy?: ICustomPath2D | ((attrs: T) => ICustomPath2D);\n incremental?: number;\n incrementalAt?: number;\n\n /** 记录state对应的图形属性 */\n states?: Record<string, Partial<T>>;\n normalAttrs?: Partial<T>;\n stateProxy?: (stateName: string, targetStates?: string[]) => Partial<T>;\n findFace?: () => IFace3d;\n toggleState: (stateName: string, hasAnimation?: boolean) => void;\n removeState: (stateName: string, hasAnimation?: boolean) => void;\n clearStates: (hasAnimation?: boolean) => void;\n useStates: (states: string[], hasAnimation?: boolean) => void;\n addState: (stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean) => void;\n hasState: (stateName?: string) => boolean;\n getState: (stateName: string) => Partial<T>;\n onBeforeAttributeUpdate?: (\n val: any,\n attributes: Partial<T>,\n key: null | string | string[],\n context?: ISetAttributeContext\n ) => T | undefined;\n applyStateAttrs: (attrs: Partial<T>, stateNames: string[], hasAnimation?: boolean, isClear?: boolean) => void;\n updateNormalAttrs: (stateAttrs: Partial<T>) => void;\n\n // get\n readonly AABBBounds: IAABBBounds; // 用于获取当前节点的AABB包围盒\n readonly OBBBounds: IOBBBounds; // 获取OBB包围盒,旋转防重叠需要用\n readonly globalAABBBounds: IAABBBounds; // 全局AABB包围盒\n readonly transMatrix: IMatrix; // 变换矩阵,动态计算\n readonly globalTransMatrix: IMatrix; // 变换矩阵,动态计算\n\n getOffsetXY: (attr?: ITransform) => IPoint;\n\n // function\n containsPoint: (x: number, y: number, mode?: IContainPointMode, picker?: IPickerService) => boolean;\n\n setMode: (mode: '3d' | '2d') => void;\n isValid: () => boolean;\n\n getClipPath: () => ISymbolClass | null;\n\n // TODO: transform API\n // 基于当前transform的变换,普通用户尽量别用,拿捏不住的~\n translate: (x: number, y: number) => this;\n translateTo: (x: number, y: number) => this;\n scale: (scaleX: number, scaleY: number, scaleCenter?: IPointLike) => this;\n scaleTo: (scaleX: number, scaleY: number) => this;\n rotate: (angle: number, rotateCenter?: IPointLike) => this;\n rotateTo: (angle: number) => this;\n skewTo: (b: number, c: number) => this;\n addUpdateBoundTag: () => void;\n addUpdateShapeAndBoundsTag: () => void;\n addUpdateLayoutTag: () => void;\n\n update: (d?: { bounds: boolean; trans: boolean }) => void;\n\n // animate\n animate?: (params?: IGraphicAnimateParams) => IAnimate;\n\n // 语法糖,可有可无,有的为了首屏性能考虑做成get方法,有的由外界直接托管,内部不赋值\n name?: string;\n\n // 供render处理shape缓存tag\n shouldUpdateShape: () => boolean;\n clearUpdateShapeTag: () => void;\n\n // // 供render缓存shape\n // cacheShape?: ICustomPath2D;\n // // 线段使用的path2D\n // cacheLine?: ISegPath2D | ISegPath2D[];\n // // 面积图使用的path2D\n // cacheArea?: IAreaCacheItem | IAreaCacheItem[];\n\n setAttributes: (params: Partial<T>, forceUpdateTag?: boolean, context?: ISetAttributeContext) => void;\n\n initAttributes: (params: Partial<T>) => void;\n\n setAttribute: (key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext) => void;\n\n setStage: (stage?: IStage, layer?: ILayer) => void;\n onSetStage: (cb: (g: IGraphic, stage: IStage) => void) => void;\n\n shouldUpdateAABBBounds: () => boolean;\n shouldSelfChangeUpdateAABBBounds: () => boolean;\n shouldUpdateGlobalMatrix: () => boolean;\n\n addUpdatePositionTag: () => void;\n addUpdateGlobalPositionTag: () => void;\n\n attachShadow: () => IShadowRoot;\n detachShadow: () => void;\n\n toJson: () => IGraphicJson;\n\n /** 创建pathProxy */\n createPathProxy: (path?: string) => void;\n /** 将图形转换成CustomPath2D */\n toCustomPath?: () => ICustomPath2D;\n\n resources?: Map<\n string | HTMLImageElement | HTMLCanvasElement | IBackgroundConfig,\n { state: 'init' | 'loading' | 'success' | 'fail'; data?: HTMLImageElement | HTMLCanvasElement }\n >;\n imageLoadSuccess: (url: string, data: HTMLImageElement) => void;\n imageLoadFail: (url: string) => void;\n\n clone: () => IGraphic;\n stopAnimates: (stopChildren?: boolean) => void;\n getNoWorkAnimateAttr: () => Record<string, number>;\n getGraphicTheme: () => T;\n\n getAttributes: (final?: boolean) => Partial<T>;\n}\n\nexport interface IRoot extends IGraphic {\n pick: (x: number, y: number) => IGraphic;\n}\n\n/**\n * 动画配置\n */\nexport type IAnimateConfig = {\n duration?: number;\n easing?: EasingType;\n};\n\nexport type GraphicReleaseStatus = 'released' | 'willRelease';\n"]}
1
+ {"version":3,"sources":["../src/interface/graphic.ts"],"names":[],"mappings":"","file":"graphic.js","sourcesContent":["import type { IAABBBounds, IMatrix, IPointLike, IPoint, BoundsAnchorType, IOBBBounds } from '@visactor/vutils';\nimport type { IAnimate, IStep, EasingType, IAnimateTarget, ITimeline } from './animation';\nimport type { IColor } from './color';\nimport type { IGroup } from './graphic/group';\nimport type { IShadowRoot } from './graphic/shadow-root';\nimport type { ILayer } from './layer';\nimport type { INode } from './node-tree';\nimport type { ICustomPath2D } from './path';\nimport type { IStage } from './stage';\nimport type { IGlyphGraphicAttribute } from './graphic/glyph';\nimport type { IContainPointMode } from '../common/enums';\nimport type { IFace3d } from './graphic/face3d';\nimport type { IPickerService } from './picker';\nimport type { ISymbolClass } from './graphic/symbol';\n\ntype IStrokeSeg = {\n /**\n * 百分比\n */\n start: number;\n /**\n * 百分比\n * end和length二选一\n */\n end: number;\n /**\n * 像素长度\n */\n length: number;\n};\n\n// TODO 最后加一个any\nexport type GraphicType =\n | 'area'\n | 'circle'\n | 'ellipse'\n | 'line'\n | 'rect'\n | 'rect3d'\n | 'path'\n | 'richtext'\n | 'text'\n | 'arc'\n | 'arc3d'\n | 'image'\n | 'symbol'\n | 'group'\n | 'shadowroot'\n | 'polygon'\n | 'pyramid3d'\n | 'glyph'\n | string;\n\n// Cursor style\n// See: https://developer.mozilla.org/en-US/docs/Web/CSS/cursor\nexport type Cursor =\n | 'auto'\n | 'default'\n | 'none'\n | 'context-menu'\n | 'help'\n | 'pointer'\n | 'progress'\n | 'wait'\n | 'cell'\n | 'crosshair'\n | 'text'\n | 'vertical-text'\n | 'alias'\n | 'copy'\n | 'move'\n | 'no-drop'\n | 'not-allowed'\n | 'grab'\n | 'grabbing'\n | 'all-scroll'\n | 'col-resize'\n | 'row-resize'\n | 'n-resize'\n | 'e-resize'\n | 's-resize'\n | 'w-resize'\n | 'ne-resize'\n | 'nw-resize'\n | 'se-resize'\n | 'sw-resize'\n | 'ew-resize'\n | 'ns-resize'\n | 'nesw-resize'\n | 'nwse-resize'\n | 'zoom-in'\n | 'zoom-out';\n\nexport type ITransform = {\n /**\n * x坐标\n */\n x: number;\n /**\n * y坐标\n */\n y: number;\n /**\n * z坐标\n */\n z: number;\n /**\n * x方向偏移量\n */\n dx: number;\n /**\n * y方向偏移量\n */\n dy: number;\n /**\n * z方向偏移量\n */\n dz: number;\n /**\n * x方向的滚动值\n */\n scrollX: number;\n /**\n * y方向的滚动值\n */\n scrollY: number;\n /**\n * x方向的缩放值\n */\n scaleX: number;\n /**\n * y方向的缩放值\n */\n scaleY: number;\n /**\n * z方向的缩放值\n */\n scaleZ: number;\n /**\n * 绕z轴的转角,即xy平面上的旋转角度\n */\n angle: number;\n /**\n * 绕x轴的转角\n */\n alpha: number;\n /**\n * 绕y轴的转角\n */\n beta: number;\n /**\n * 应用缩放的中心\n */\n scaleCenter: [number | string, number | string];\n /**\n * 基于AABB的锚点位置,用于简单的定位某些path\n */\n anchor: [number | string, number | string];\n /**\n * 3d的锚点位置\n */\n anchor3d: [number | string, number | string, number] | [number | string, number | string];\n /**\n * 处理矩阵,在正常计算完变换矩阵之后,会将该矩阵乘到变换矩阵上得到最终的变换矩阵\n */\n postMatrix: IMatrix;\n};\n\nexport type IFillType = boolean | string | IColor;\nexport type IFillStyle = {\n /**\n * 图形的填充透明度\n */\n fillOpacity: number;\n /**\n * 图形模糊效果程度\n */\n shadowBlur: number;\n /**\n * 图形的阴影颜色\n */\n shadowColor: string;\n /**\n * 阴影水平偏移距离\n */\n shadowOffsetX: number;\n /**\n * 阴影垂直偏移距离\n */\n shadowOffsetY: number;\n /**\n * 图形的填充颜色\n */\n fill: IFillType;\n};\n\nexport type ILayout = {\n /**\n * 设置对齐方式\n */\n alignSelf: 'auto' | 'flex-start' | 'flex-end' | 'center';\n};\n\nexport type IBorderStyle = Omit<IStrokeStyle, 'outerBorder' | 'innerBorder'> & {\n /**\n * 边距离边缘的距离\n */\n distance: number | string;\n /**\n * 是否显示边框,默认是不显示的\n */\n visible?: boolean;\n};\n\nexport type IStrokeType = boolean | string | IColor | null;\nexport type IStrokeStyle = {\n /**\n * 外部边框的样式配置,默认不展示外部边框\n */\n outerBorder: Partial<IBorderStyle>;\n /**\n * 内部边框的样式配置\n */\n innerBorder: Partial<IBorderStyle>;\n /**\n * 描边的透明度\n */\n strokeOpacity: number;\n /**\n * 设置线条虚线样式的属性,它通过定义实线和空白的交替长度来创建虚线效果\n */\n lineDash: number[];\n\n /**\n * 设置虚线样式的起始偏移量\n */\n lineDashOffset: number;\n\n /**\n * 设置线条的宽度\n */\n lineWidth: number;\n\n /**\n * 设置线条末端的样式\n */\n lineCap: CanvasLineCap;\n\n /**\n * 设置线条拐角的样式\n */\n lineJoin: CanvasLineJoin;\n\n /**\n * 设置线条拐角处的斜接限制\n */\n miterLimit: number;\n /**\n * 描边的boundsBuffer,用于控制bounds的buffer\n */\n strokeBoundsBuffer: number;\n /**\n * stroke - true 全描边\n * stroke - false 不描边\n * stroke 为数值类型,适用于rect\\arc等图形,用于配置部分描边的场景,其中\n *\n * 0b00000 - 不描边\n * 0b000001 - top\n * 0b000010 - right\n * 0b000100 - bottom\n * 0b001000 - left\n * 相应的:\n * 0b000011 - top + right\n * 0b000111 - top + right + bottom\n * 0b001111 - 全描边\n *\n * stroke - boolean[],适用于rect\\arc等图形,用于配置部分描边的场景\n */\n stroke: IStrokeType[] | IStrokeType;\n};\n\ntype TextureType = 'circle' | 'diamond' | 'rect' | 'vertical-line' | 'horizontal-line' | 'bias-lr' | 'bias-rl' | 'grid';\n\nexport type IConnectedStyle = {\n /**\n * 连接,取零或者断开\n */\n connectedType: 'connect' | 'none';\n /**\n * 连接线的样式配置\n */\n connectedStyle: {\n stroke: IStrokeStyle['stroke'];\n strokeOpacity: IStrokeStyle['strokeOpacity'];\n lineDash: IStrokeStyle['lineDash'];\n lineDashOffset: IStrokeStyle['lineDashOffset'];\n lineCap: IStrokeStyle['lineCap'];\n lineJoin: IStrokeStyle['lineJoin'];\n lineWidth: IStrokeStyle['lineWidth'];\n fill: IFillStyle['fill'];\n fillOpacity: IFillStyle['fillOpacity'];\n };\n connectedX: number;\n connectedY: number;\n};\n\nexport type IBackgroundConfig = {\n stroke?: string | boolean;\n fill?: string | boolean;\n lineWidth?: number;\n cornerRadius?: number;\n expandX?: number;\n expandY?: number;\n};\n\ntype IBackgroundType = string | HTMLImageElement | HTMLCanvasElement | IBackgroundConfig;\n\nexport interface SimpleDomStyleOptions {\n /**\n * 容器的宽度\n */\n width: number;\n /**\n * 容器的高度\n */\n height: number;\n /**\n * 容器的样式设置\n */\n style?:\n | string\n | Record<string, any>\n | ((\n pos: { top: number; left: number; width: number; height: number },\n graphic: IGraphic,\n wrapContainer: HTMLElement\n ) => Record<string, any>); // 容器的样式\n}\n\nexport interface CommonDomOptions {\n /**\n * 全局唯一的id\n */\n id?: string;\n /**\n * 容器元素的id或者dom元素\n */\n container: string | HTMLElement | null;\n /**\n * 是否显示\n */\n visible?: boolean;\n /**\n * 是否支持事件冒泡\n */\n pointerEvents?: boolean | string;\n /**\n * 可穿透的事件列表\n * @since 0.21.2\n */\n penetrateEventList?: string[];\n /**\n * 定位类型\n * 'position' - 根据挂载图形节点的坐标也就是x,y进行定位\n * 'boundsLeftTop' - 定位到挂载图形节点bounds的左上角\n * 'left' - 定位到挂载图形节点bounds 的左侧\n * 'right' - 定位到挂载图形节点bounds 的右侧\n * 'bottom' - 定位到挂载图形节点bounds 的底部\n * 'top' - 定位到挂载图形节点bounds 的顶部\n * 'center' - 定位到挂载图形节点bounds 的中心\n * 'top-left' - 定位到挂载图形节点bounds 的左上角\n * 'top-right' - 定位到挂载图形节点bounds 的右上角\n * 'bottom-left' - 定位到挂载图形节点bounds 的左下角\n * 'bottom-right' - 定位到挂载图形节点bounds 的右下角\n */\n anchorType?: 'position' | 'boundsLeftTop' | BoundsAnchorType;\n}\n\nexport type IRoughStyle = {\n fillStyle: 'hachure' | 'solid' | 'zigzag' | 'cross-hatch' | 'dots' | 'sunburst' | 'dashed' | 'zigzag-line';\n roughness: number;\n bowing: number;\n};\n\nexport type IGraphicStyle = ILayout &\n IFillStyle &\n IStrokeStyle &\n IPickStyle & {\n /**\n * 强制设置的bounds宽度,主要用于使用html或者react展示图形的时候,设置一个固定的宽度\n */\n forceBoundsWidth: number | (() => number) | undefined;\n /**\n * 强制设置的bounds高度,主要用于使用html或者react展示图形的时候,设置一个固定的高度\n */\n forceBoundsHeight: number | (() => number) | undefined;\n /**\n * 透明度,会同时影响填充和描边\n */\n opacity: number;\n /**\n * 影子节点\n */\n shadowGraphic?: IGraphic | undefined;\n /**\n * 背景填充模式(与具体图元有关)\n */\n backgroundMode: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat';\n /**\n * 是否正好填充,只在repeat-x或者repeat-y以及no-repeat的时候生效\n */\n backgroundFit: boolean;\n /**\n * 是否保持背景图的宽高比\n */\n backgroundKeepAspectRatio: boolean;\n /**\n * 背景图缩放,只在no-repeat的时候生效\n */\n backgroundScale: number;\n /**\n * 背景图偏移,只在no-repeat的时候生效\n */\n backgroundOffsetX: number;\n /**\n * 背景图偏移,只在no-repeat的时候生效\n */\n backgroundOffsetY: number;\n /**\n * 背景图是否裁切,是否调用clip避免绘制到图元外部\n */\n backgroundClip: boolean;\n /**\n * 背景圆角半径\n */\n backgroundCornerRadius: number | number[];\n /**\n * 背景透明度\n */\n backgroundOpacity: number;\n /**\n * 背景,支持颜色字符串、html image元素、html canvas元素\n */\n // 纹理是否自动做动画\n autoAnimateTexture: boolean;\n // 如果做动画的话,这里代表ratio\n textureRatio: number;\n textureOptions: any;\n background:\n | IBackgroundType\n | {\n /**\n * 背景,支持颜色字符串、html image元素、html canvas元素\n */\n background: IBackgroundType;\n /**\n * 背景的x方向偏移量\n */\n dx?: number;\n /**\n * 背景的y方向偏移量\n */\n dy?: number;\n /**\n * 背景宽度\n */\n width?: number;\n /**\n * 背景高度\n */\n height?: number;\n /**\n * 背景的x坐标\n */\n x?: number;\n /**\n * 背景的y坐标\n */\n y?: number;\n }\n | null; // 背景,可以与fill同时存在\n /**\n * 纹理的类型\n */\n texture: TextureType | string;\n /**\n * 纹理的颜色\n */\n textureColor: string;\n /**\n * 纹理的大小\n */\n textureSize: number;\n /**\n * 纹理的间隙\n */\n texturePadding: number;\n\n blur: number;\n /**\n * 设置图形对应的鼠标样式\n */\n cursor: Cursor | null;\n // @deprecated 用处少废弃,后续考虑新设计API\n filter: string;\n renderStyle?: 'default' | 'rough' | any;\n roughStyle?: IRoughStyle | null;\n /**\n * HTML的dom或者string\n */\n html:\n | ({\n /**\n * dom字符串或者dom\n */\n dom: string | HTMLElement;\n } & SimpleDomStyleOptions &\n CommonDomOptions)\n | null;\n /**\n * 使用react元素渲染内容\n */\n react:\n | ({\n /**\n * react场景节点\n */\n element: any;\n } & SimpleDomStyleOptions &\n CommonDomOptions)\n | null;\n /**\n * 使用vue组件渲染内容\n */\n vue:\n | ({\n /**\n * vue 虚拟节点\n */\n element: any;\n } & SimpleDomStyleOptions &\n CommonDomOptions)\n | null;\n };\n\nexport type IPickStyle = {\n /**\n * 给stroke模式的pick额外加的buffer,用于外界控制stroke区域的pick范围\n */\n pickStrokeBuffer: number;\n};\n\nexport type IDebugType = {\n _debug_bounds: boolean | ((c: any, g: any) => void);\n};\nexport type IGraphicAttribute = IDebugType &\n IGraphicStyle &\n ITransform & {\n /**\n * stroke百分比\n */\n strokeSeg: IStrokeSeg | null;\n /**\n * 包围盒的padding\n */\n boundsPadding: number | number[];\n /**\n * 选择模式,精确模式,粗糙模式(包围盒模式),自定义模式\n */\n pickMode: 'accurate' | 'imprecise' | 'custom';\n boundsMode: 'accurate' | 'imprecise' | 'empty';\n customPickShape: () => boolean | null;\n /**\n * 是否支持事件拾取,默认为 true。\n * @default true\n */\n pickable: boolean;\n /**\n * 是否支持fill拾取,默认为 true。\n * @experimental\n * @default true\n */\n fillPickable: boolean;\n /**\n * 是否支持stroke拾取,默认为 true。\n * @experimental\n * @default true\n */\n strokePickable: boolean;\n /**\n * 对于 group 节点,是否支持其子元素的事件拾取,默认为 true。\n * 如果 group `pickable` 关闭,`childrenPickable` 开启,那么 group 的子节点仍参与事件拾取\n * @default true\n */\n childrenPickable: boolean;\n /**\n * 元素是否可见。\n * @default true\n */\n visible: boolean;\n /**\n * 分组下的层级,层级越小越先绘制\n */\n zIndex: number;\n layout: any;\n /**\n * 是否隐藏元素(只是绘制的时候不绘制)\n */\n renderable: boolean;\n /**\n * 是否在3d中控制方向\n * false: 不控制方向\n * true: 始终控制方向朝摄像机\n */\n keepDirIn3d?: boolean;\n shadowRootIdx: number;\n shadowPickMode?: 'full' | 'graphic';\n /**\n * 全局范围的层级,设置了这个属性的图形,会提取到交互层进行渲染\n */\n globalZIndex: number;\n /**\n * canvas 的合成方式\n */\n globalCompositeOperation: CanvasRenderingContext2D['globalCompositeOperation'] | '';\n /**\n * 完全支持滚动 | 完全不支持滚动 | 支持x方向的滚动 | 支持y方向的滚动\n */\n overflow: 'scroll' | 'hidden' | 'scroll-x' | 'scroll-y';\n /**\n * 绘制fill和stroke的顺序,为0表示fill先绘制,1表示stroke先绘制\n */\n fillStrokeOrder: number;\n /**\n * @since 0.20.15\n * 保持stroke的scale,默认为false,为true的话stroke显示的宽度会随着scale变化\n */\n keepStrokeScale: boolean;\n\n /**\n * @since 0.22.2\n * 裁剪路径,用于裁剪图形,用于普通图元的裁剪\n * 由于一般情况下普通图元只需要一个形状即可,所以这里不需要配置具体的位置和大小,强制中心在图元中心,宽高和图元Bounds宽高一致\n * 不考虑其他复杂情况,否则配置项就非常多了,比如多路径,或者配置位置大小等,如果配置大小那还得用户自己去拿图元的大小,目前没有这种需求\n */\n clipConfig: {\n shape: string;\n } | null;\n };\n\nexport interface IGraphicJson<T extends Partial<IGraphicAttribute> = Partial<IGraphicAttribute>> {\n attribute: Partial<T>;\n _uid: number;\n type: string;\n name: string;\n children: IGraphicJson<T>[];\n}\n\n/** the context of setAttribute */\nexport type ISetAttributeContext = {\n /** type of setAttribute */\n type?: number;\n animationState?: {\n step?: IStep;\n isFirstFrameOfStep?: boolean;\n /** ratio of animation */\n ratio?: number;\n /** is animation end? */\n end?: boolean;\n };\n skipUpdateCallback?: boolean;\n};\n\nexport type IGraphicAnimateParams = {\n slience?: boolean;\n id?: number | string;\n timeline?: ITimeline;\n onStart?: () => void;\n onFrame?: (step: IStep, ratio: number) => void;\n onEnd?: () => void;\n onRemove?: () => void;\n interpolate?: (key: string, ratio: number, from: any, to: any, nextAttributes: any) => boolean;\n};\n\nexport interface IGraphic<T extends Partial<IGraphicAttribute> = Partial<IGraphicAttribute>>\n extends INode,\n IAnimateTarget {\n type?: GraphicType;\n numberType?: number;\n stage?: IStage;\n layer?: ILayer;\n shadowRoot?: IShadowRoot;\n glyphHost?: IGraphic<IGlyphGraphicAttribute>;\n backgroundImg?: boolean;\n attachedThemeGraphic?: IGraphic<any>;\n /**\n * 保存语法上下文\n */\n context?: Record<string, any>;\n bindDom?: Map<\n string | HTMLElement,\n { container: HTMLElement | string; dom: HTMLElement | any; wrapGroup: HTMLDivElement | any; root?: any }\n >;\n\n valid: boolean;\n parent: IGroup | null;\n isContainer?: boolean;\n // 是否是3d模式(是否应用3d视角)\n in3dMode?: boolean;\n\n // 不考虑transform的宽高,特殊情况下会使用到\n widthWithoutTransform?: number;\n heightWithoutTransform?: number;\n\n // 上次更新的stamp\n stamp?: number;\n animationBackUps?: {\n from: Record<string, any>;\n to: Record<string, any>;\n };\n\n attribute: Partial<T>;\n\n /** 用于实现morph动画场景,转换成bezier曲线渲染 */\n pathProxy?: ICustomPath2D | ((attrs: T) => ICustomPath2D);\n incremental?: number;\n incrementalAt?: number;\n\n /** 记录state对应的图形属性 */\n states?: Record<string, Partial<T>>;\n normalAttrs?: Partial<T>;\n stateProxy?: (stateName: string, targetStates?: string[]) => Partial<T>;\n findFace?: () => IFace3d;\n toggleState: (stateName: string, hasAnimation?: boolean) => void;\n removeState: (stateName: string | string[], hasAnimation?: boolean) => void;\n clearStates: (hasAnimation?: boolean) => void;\n useStates: (states: string[], hasAnimation?: boolean) => void;\n addState: (stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean) => void;\n hasState: (stateName?: string) => boolean;\n getState: (stateName: string) => Partial<T>;\n onBeforeAttributeUpdate?: (\n val: any,\n attributes: Partial<T>,\n key: null | string | string[],\n context?: ISetAttributeContext\n ) => T | undefined;\n applyStateAttrs: (attrs: Partial<T>, stateNames: string[], hasAnimation?: boolean, isClear?: boolean) => void;\n updateNormalAttrs: (stateAttrs: Partial<T>) => void;\n\n // get\n readonly AABBBounds: IAABBBounds; // 用于获取当前节点的AABB包围盒\n readonly OBBBounds: IOBBBounds; // 获取OBB包围盒,旋转防重叠需要用\n readonly globalAABBBounds: IAABBBounds; // 全局AABB包围盒\n readonly transMatrix: IMatrix; // 变换矩阵,动态计算\n readonly globalTransMatrix: IMatrix; // 变换矩阵,动态计算\n\n getOffsetXY: (attr?: ITransform) => IPoint;\n\n // function\n containsPoint: (x: number, y: number, mode?: IContainPointMode, picker?: IPickerService) => boolean;\n\n setMode: (mode: '3d' | '2d') => void;\n isValid: () => boolean;\n\n getClipPath: () => ISymbolClass | null;\n\n // TODO: transform API\n // 基于当前transform的变换,普通用户尽量别用,拿捏不住的~\n translate: (x: number, y: number) => this;\n translateTo: (x: number, y: number) => this;\n scale: (scaleX: number, scaleY: number, scaleCenter?: IPointLike) => this;\n scaleTo: (scaleX: number, scaleY: number) => this;\n rotate: (angle: number, rotateCenter?: IPointLike) => this;\n rotateTo: (angle: number) => this;\n skewTo: (b: number, c: number) => this;\n addUpdateBoundTag: () => void;\n addUpdateShapeAndBoundsTag: () => void;\n addUpdateLayoutTag: () => void;\n\n update: (d?: { bounds: boolean; trans: boolean }) => void;\n\n // animate\n animate?: (params?: IGraphicAnimateParams) => IAnimate;\n\n // 语法糖,可有可无,有的为了首屏性能考虑做成get方法,有的由外界直接托管,内部不赋值\n name?: string;\n\n // 供render处理shape缓存tag\n shouldUpdateShape: () => boolean;\n clearUpdateShapeTag: () => void;\n\n // // 供render缓存shape\n // cacheShape?: ICustomPath2D;\n // // 线段使用的path2D\n // cacheLine?: ISegPath2D | ISegPath2D[];\n // // 面积图使用的path2D\n // cacheArea?: IAreaCacheItem | IAreaCacheItem[];\n\n setAttributes: (params: Partial<T>, forceUpdateTag?: boolean, context?: ISetAttributeContext) => void;\n\n initAttributes: (params: Partial<T>) => void;\n\n setAttribute: (key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext) => void;\n\n setStage: (stage?: IStage, layer?: ILayer) => void;\n onSetStage: (cb: (g: IGraphic, stage: IStage) => void) => void;\n\n shouldUpdateAABBBounds: () => boolean;\n shouldSelfChangeUpdateAABBBounds: () => boolean;\n shouldUpdateGlobalMatrix: () => boolean;\n\n addUpdatePositionTag: () => void;\n addUpdateGlobalPositionTag: () => void;\n\n attachShadow: () => IShadowRoot;\n detachShadow: () => void;\n\n toJson: () => IGraphicJson;\n\n /** 创建pathProxy */\n createPathProxy: (path?: string) => void;\n /** 将图形转换成CustomPath2D */\n toCustomPath?: () => ICustomPath2D;\n\n resources?: Map<\n string | HTMLImageElement | HTMLCanvasElement | IBackgroundConfig,\n { state: 'init' | 'loading' | 'success' | 'fail'; data?: HTMLImageElement | HTMLCanvasElement }\n >;\n imageLoadSuccess: (url: string, data: HTMLImageElement) => void;\n imageLoadFail: (url: string) => void;\n\n clone: () => IGraphic;\n stopAnimates: (stopChildren?: boolean) => void;\n getNoWorkAnimateAttr: () => Record<string, number>;\n getGraphicTheme: () => T;\n\n getAttributes: (final?: boolean) => Partial<T>;\n}\n\nexport interface IRoot extends IGraphic {\n pick: (x: number, y: number) => IGraphic;\n}\n\n/**\n * 动画配置\n */\nexport type IAnimateConfig = {\n duration?: number;\n easing?: EasingType;\n};\n\nexport type GraphicReleaseStatus = 'released' | 'willRelease';\n"]}
package/dist/index.es.js CHANGED
@@ -10919,6 +10919,10 @@ class Graphic extends Node {
10919
10919
  this.setShadowGraphic(params.shadowGraphic);
10920
10920
  }
10921
10921
  }
10922
+ getGraphicService() {
10923
+ var _a, _b;
10924
+ return (_b = (_a = this.stage) === null || _a === void 0 ? void 0 : _a.graphicService) !== null && _b !== void 0 ? _b : application.graphicService;
10925
+ }
10922
10926
  getAttributes() {
10923
10927
  return this.attribute;
10924
10928
  }
@@ -10949,7 +10953,6 @@ class Graphic extends Node {
10949
10953
  this._emitCustomEvent('animate-bind', animate);
10950
10954
  }
10951
10955
  tryUpdateAABBBounds() {
10952
- var _a, _b;
10953
10956
  const full = this.attribute.boundsMode === 'imprecise';
10954
10957
  if (!this.shouldUpdateAABBBounds()) {
10955
10958
  return this._AABBBounds;
@@ -10958,9 +10961,9 @@ class Graphic extends Node {
10958
10961
  this._AABBBounds.clear();
10959
10962
  return this._AABBBounds;
10960
10963
  }
10961
- (_a = this.stage) === null || _a === void 0 ? void 0 : _a.graphicService.beforeUpdateAABBBounds(this, this.stage, true, this._AABBBounds);
10964
+ this.getGraphicService().beforeUpdateAABBBounds(this, this.stage, true, this._AABBBounds);
10962
10965
  const bounds = this.doUpdateAABBBounds(full);
10963
- (_b = this.stage) === null || _b === void 0 ? void 0 : _b.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, true);
10966
+ this.getGraphicService().afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, true);
10964
10967
  if (this.attribute.boundsMode === 'empty') {
10965
10968
  bounds.clear();
10966
10969
  }
@@ -11137,10 +11140,10 @@ class Graphic extends Node {
11137
11140
  shouldUpdateAABBBounds() {
11138
11141
  if (this.shadowRoot) {
11139
11142
  return ((!!(this._updateTag & UpdateTag.UPDATE_BOUNDS) || this.shadowRoot.shouldUpdateAABBBounds()) &&
11140
- application.graphicService.validCheck(this.attribute, this.getGraphicTheme(), this._AABBBounds, this));
11143
+ this.getGraphicService().validCheck(this.attribute, this.getGraphicTheme(), this._AABBBounds, this));
11141
11144
  }
11142
11145
  return (!!(this._updateTag & UpdateTag.UPDATE_BOUNDS) &&
11143
- application.graphicService.validCheck(this.attribute, this.getGraphicTheme(), this._AABBBounds, this));
11146
+ this.getGraphicService().validCheck(this.attribute, this.getGraphicTheme(), this._AABBBounds, this));
11144
11147
  }
11145
11148
  shouldSelfChangeUpdateAABBBounds() {
11146
11149
  if (this.shadowRoot) {
@@ -11451,11 +11454,10 @@ class Graphic extends Node {
11451
11454
  return this;
11452
11455
  }
11453
11456
  onAttributeUpdate(context) {
11454
- var _a;
11455
11457
  if (context && context.skipUpdateCallback) {
11456
11458
  return;
11457
11459
  }
11458
- (_a = this.stage) === null || _a === void 0 ? void 0 : _a.graphicService.onAttributeUpdate(this);
11460
+ this.getGraphicService().onAttributeUpdate(this);
11459
11461
  this._emitCustomEvent('afterAttributeUpdate', context);
11460
11462
  }
11461
11463
  update(d) {
@@ -11748,7 +11750,6 @@ class Graphic extends Node {
11748
11750
  }
11749
11751
  }
11750
11752
  setStage(stage, layer) {
11751
- var _a;
11752
11753
  if (this.stage !== stage) {
11753
11754
  this.stage = stage;
11754
11755
  this.layer = layer;
@@ -11763,7 +11764,7 @@ class Graphic extends Node {
11763
11764
  });
11764
11765
  }
11765
11766
  this._onSetStage && this._onSetStage(this, stage, layer);
11766
- (_a = this.stage) === null || _a === void 0 ? void 0 : _a.graphicService.onSetStage(this, stage);
11767
+ this.getGraphicService().onSetStage(this, stage);
11767
11768
  }
11768
11769
  }
11769
11770
  setStageToShadowRoot(stage, layer) {
@@ -12015,15 +12016,14 @@ class Group extends Graphic {
12015
12016
  return false;
12016
12017
  }
12017
12018
  tryUpdateAABBBounds() {
12018
- var _a, _b;
12019
12019
  if (!this.shouldUpdateAABBBounds()) {
12020
12020
  return this._AABBBounds;
12021
12021
  }
12022
- (_a = this.stage) === null || _a === void 0 ? void 0 : _a.graphicService.beforeUpdateAABBBounds(this, this.stage, true, this._AABBBounds);
12022
+ this.getGraphicService().beforeUpdateAABBBounds(this, this.stage, true, this._AABBBounds);
12023
12023
  const selfChange = this.shouldSelfChangeUpdateAABBBounds();
12024
12024
  const bounds = this.doUpdateAABBBounds();
12025
12025
  this.addUpdateLayoutTag();
12026
- (_b = this.stage) === null || _b === void 0 ? void 0 : _b.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange);
12026
+ this.getGraphicService().afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange);
12027
12027
  if (this.attribute.boundsMode === 'empty') {
12028
12028
  bounds.clear();
12029
12029
  }
@@ -12092,21 +12092,19 @@ class Group extends Graphic {
12092
12092
  return this.theme.getTheme(this);
12093
12093
  }
12094
12094
  incrementalAppendChild(node) {
12095
- var _a;
12096
12095
  const data = super.appendChild(node);
12097
12096
  if (this.stage && data) {
12098
12097
  data.stage = this.stage;
12099
12098
  data.layer = this.layer;
12100
12099
  }
12101
12100
  this.addUpdateBoundTag();
12102
- (_a = this.stage) === null || _a === void 0 ? void 0 : _a.graphicService.onAddIncremental(node, this, this.stage);
12101
+ this.getGraphicService().onAddIncremental(node, this, this.stage);
12103
12102
  return data;
12104
12103
  }
12105
12104
  incrementalClearChild() {
12106
- var _a;
12107
12105
  super.removeAllChild();
12108
12106
  this.addUpdateBoundTag();
12109
- (_a = this.stage) === null || _a === void 0 ? void 0 : _a.graphicService.onClearIncremental(this, this.stage);
12107
+ this.getGraphicService().onClearIncremental(this, this.stage);
12110
12108
  return;
12111
12109
  }
12112
12110
  _updateChildToStage(child) {
@@ -12134,17 +12132,15 @@ class Group extends Graphic {
12134
12132
  return this._updateChildToStage(super.insertInto(newNode, idx));
12135
12133
  }
12136
12134
  removeChild(child) {
12137
- var _a;
12138
12135
  const data = super.removeChild(child);
12139
12136
  child.stage = null;
12140
- (_a = this.stage) === null || _a === void 0 ? void 0 : _a.graphicService.onRemove(child);
12137
+ this.getGraphicService().onRemove(child);
12141
12138
  this.addUpdateBoundTag();
12142
12139
  return data;
12143
12140
  }
12144
12141
  removeAllChild(deep = false) {
12145
12142
  this.forEachChildren((child) => {
12146
- var _a;
12147
- (_a = this.stage) === null || _a === void 0 ? void 0 : _a.graphicService.onRemove(child);
12143
+ this.getGraphicService().onRemove(child);
12148
12144
  if (deep && child.isContainer) {
12149
12145
  child.removeAllChild(deep);
12150
12146
  }
@@ -12153,13 +12149,12 @@ class Group extends Graphic {
12153
12149
  this.addUpdateBoundTag();
12154
12150
  }
12155
12151
  setStage(stage, layer) {
12156
- var _a;
12157
12152
  if (this.stage !== stage) {
12158
12153
  this.stage = stage;
12159
12154
  this.layer = layer;
12160
12155
  this.setStageToShadowRoot(stage, layer);
12161
12156
  this._onSetStage && this._onSetStage(this, stage, layer);
12162
- (_a = this.stage) === null || _a === void 0 ? void 0 : _a.graphicService.onSetStage(this, stage);
12157
+ this.getGraphicService().onSetStage(this, stage);
12163
12158
  this.forEachChildren(item => {
12164
12159
  item.setStage(stage, this.layer);
12165
12160
  });
@@ -13109,7 +13104,7 @@ let DefaultGraphicService = class DefaultGraphicService {
13109
13104
  if (!(graphic.valid && visible)) {
13110
13105
  if (!aabbBounds.empty()) {
13111
13106
  graphic.parent && aabbBounds.transformWithMatrix(graphic.parent.globalTransMatrix);
13112
- application.graphicService.clearAABBBounds(graphic, graphic.stage, aabbBounds);
13107
+ this.clearAABBBounds(graphic, graphic.stage, aabbBounds);
13113
13108
  aabbBounds.clear();
13114
13109
  }
13115
13110
  return false;
@@ -30,8 +30,6 @@ import { GraphicCreator } from "../constants";
30
30
 
31
31
  import { identityMat4, multiplyMat4Mat4, rotateX, rotateY, rotateZ, scaleMat4, translate } from "../../common/matrix";
32
32
 
33
- import { application } from "../../application";
34
-
35
33
  export function getExtraModelMatrix(dx, dy, graphic) {
36
34
  const {alpha: alpha, beta: beta} = graphic.attribute;
37
35
  if (!alpha && !beta) return null;
@@ -185,8 +183,7 @@ let DefaultGraphicService = class {
185
183
  if (graphic.shadowRoot || graphic.isContainer) return !0;
186
184
  const {visible: visible = theme.visible} = attribute;
187
185
  return !(!graphic.valid || !visible) || (aabbBounds.empty() || (graphic.parent && aabbBounds.transformWithMatrix(graphic.parent.globalTransMatrix),
188
- application.graphicService.clearAABBBounds(graphic, graphic.stage, aabbBounds),
189
- aabbBounds.clear()), !1);
186
+ this.clearAABBBounds(graphic, graphic.stage, aabbBounds), aabbBounds.clear()), !1);
190
187
  }
191
188
  updateTempAABBBounds(aabbBounds) {
192
189
  const tb1 = this.tempAABBBounds1, tb2 = this.tempAABBBounds2;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/graphic-service/graphic-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAczC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,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E,UAAU,CAAC,KAAK,EAAE,CAAC;aACpB;YACD,OAAO,KAAK,CAAC;SACd;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oBAAoB,CAAC,UAAuB;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC;QACjC,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC;QACjC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;QACzE,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;QAEzE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IACtB,CAAC;CACF,CAAA;AAvOY,qBAAqB;IADjC,UAAU,EAAE;IAiBE,WAAA,MAAM,CAAC,cAAc,CAAC,CAAA;;GAhBxB,qBAAqB,CAuOjC;SAvOY,qBAAqB","file":"graphic-service.js","sourcesContent":["import { inject, injectable } from '../../common/inversify-lite';\nimport type { IAABBBounds } from '@visactor/vutils';\nimport { AABBBounds, isNumber, transformBoundsWithMatrix } from '@visactor/vutils';\nimport { SyncHook } from '../../tapable';\nimport type {\n mat4,\n IGraphicAttribute,\n IGraphic,\n IGroup,\n IStage,\n IText,\n ITextGraphicAttribute,\n ITransform,\n IGraphicService,\n IGraphicCreator,\n ISyncHook\n} from '../../interface';\nimport { textDrawOffsetX, textLayoutOffsetY } from '../../common/text';\nimport { boundStroke } from '../tools';\nimport { mat4Allocate } from '../../allocator/matrix-allocate';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { BoundsContext } from '../../common/bounds-context';\nimport { renderCommandList } from '../../common/render-command-list';\nimport { GraphicCreator } from '../constants';\nimport { identityMat4, multiplyMat4Mat4, rotateX, rotateY, rotateZ, scaleMat4, translate } from '../../common/matrix';\nimport { application } from '../../application';\n\nexport function getExtraModelMatrix(dx: number, dy: number, graphic: IGraphic): mat4 | null {\n const { alpha, beta } = graphic.attribute;\n if (!alpha && !beta) {\n return null;\n }\n const { anchor3d = graphic.attribute.anchor } = graphic.attribute;\n\n const _anchor: [number, number] = [0, 0];\n if (anchor3d) {\n if (typeof anchor3d[0] === 'string') {\n const ratio = parseFloat(anchor3d[0]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[0] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[0] = anchor3d[0];\n }\n if (typeof anchor3d[1] === 'string') {\n const ratio = parseFloat(anchor3d[1]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[1] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[1] = anchor3d[1];\n }\n }\n\n if (graphic.type === 'text') {\n const { textAlign } = graphic.attribute as ITextGraphicAttribute;\n // 计算偏移\n _anchor[0] += textDrawOffsetX(textAlign, (graphic as IText).clipedWidth);\n }\n\n // 应用偏移,计算全局的偏移\n _anchor[0] += dx;\n _anchor[1] += dy;\n // matrix.scale(dpr, dpr);\n\n const modelMatrix = mat4Allocate.allocate();\n translate(modelMatrix, modelMatrix, [_anchor[0], _anchor[1], 0]);\n if (beta) {\n rotateX(modelMatrix, modelMatrix, beta);\n }\n if (alpha) {\n rotateY(modelMatrix, modelMatrix, alpha);\n }\n translate(modelMatrix, modelMatrix, [-_anchor[0], -_anchor[1], 0]);\n\n return modelMatrix;\n}\n\n// 计算3d下的模型矩阵\nexport function getModelMatrix(out: mat4, graphic: IGraphic, theme: ITransform) {\n const {\n x = theme.x,\n y = theme.y,\n z = theme.z,\n dx = theme.dx,\n dy = theme.dy,\n dz = theme.dz,\n scaleX = theme.scaleX,\n scaleY = theme.scaleY,\n scaleZ = theme.scaleZ,\n alpha = theme.alpha,\n beta = theme.beta,\n angle = theme.angle,\n anchor3d = graphic.attribute.anchor,\n anchor\n } = graphic.attribute;\n\n const _anchor: [number, number, number] = [0, 0, 0];\n if (anchor3d) {\n if (typeof anchor3d[0] === 'string') {\n const ratio = parseFloat(anchor3d[0]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[0] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[0] = anchor3d[0];\n }\n if (typeof anchor3d[1] === 'string') {\n const ratio = parseFloat(anchor3d[1]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[1] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[1] = anchor3d[1];\n }\n _anchor[2] = anchor3d[2] ?? 0;\n }\n\n // if (graphic.type === 'text') {\n // const { textAlign } = graphic.attribute as ITextGraphicAttribute;\n // // 计算偏移\n // _anchor[0] += textDrawOffsetX(textAlign, (graphic as IText).clipedWidth);\n // }\n\n identityMat4(out);\n // 平移\n translate(out, out, [x + dx, y + dy, z + dz]);\n translate(out, out, [_anchor[0], _anchor[1], _anchor[2]]);\n rotateX(out, out, beta);\n rotateY(out, out, alpha);\n // 基于z轴的偏移基于anchor计算\n // rotateZ(out, out, angle);\n translate(out, out, [-_anchor[0], -_anchor[1], _anchor[2]]);\n scaleMat4(out, out, [scaleX, scaleY, scaleZ]);\n\n // 计算基于z轴的偏移\n if (angle) {\n const m = mat4Allocate.allocate();\n const _anchor: [number, number] = [0, 0];\n if (anchor) {\n if (typeof anchor3d[0] === 'string') {\n const ratio = parseFloat(anchor3d[0]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[0] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[0] = anchor3d[0];\n }\n if (typeof anchor3d[1] === 'string') {\n const ratio = parseFloat(anchor3d[1]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[1] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[1] = anchor3d[1];\n }\n }\n\n translate(m, m, [_anchor[0], _anchor[1], 0]);\n // 基于z轴的偏移基于anchor计算\n rotateZ(m, m, angle);\n translate(m, m, [-_anchor[0], -_anchor[1], 0]);\n\n multiplyMat4Mat4(out, out, m);\n }\n}\n\nexport function shouldUseMat4(graphic: IGraphic) {\n const { alpha, beta } = graphic.attribute;\n return alpha || beta;\n}\n\n// 管理graphic\n@injectable()\nexport class DefaultGraphicService implements IGraphicService {\n declare hooks: {\n onAttributeUpdate: ISyncHook<[IGraphic]>;\n onSetStage: ISyncHook<[IGraphic, IStage]>;\n onRemove: ISyncHook<[IGraphic]>;\n onRelease: ISyncHook<[IGraphic]>;\n onAddIncremental: ISyncHook<[IGraphic, IGroup, IStage]>;\n onClearIncremental: ISyncHook<[IGroup, IStage]>;\n beforeUpdateAABBBounds: ISyncHook<[IGraphic, IStage, boolean, IAABBBounds]>;\n afterUpdateAABBBounds: ISyncHook<[IGraphic, IStage, IAABBBounds, { globalAABBBounds: IAABBBounds }, boolean]>;\n clearAABBBounds: ISyncHook<[IGraphic, IStage, IAABBBounds]>;\n };\n\n // 临时bounds,用作缓存\n protected tempAABBBounds1: AABBBounds;\n protected tempAABBBounds2: AABBBounds;\n constructor(@inject(GraphicCreator) public readonly creator: IGraphicCreator) {\n this.hooks = {\n onAttributeUpdate: new SyncHook<[IGraphic]>(['graphic']),\n onSetStage: new SyncHook<[IGraphic, IStage]>(['graphic', 'stage']),\n onRemove: new SyncHook<[IGraphic]>(['graphic']),\n onRelease: new SyncHook<[IGraphic]>(['graphic']),\n onAddIncremental: new SyncHook<[IGraphic, IGroup, IStage]>(['graphic', 'group', 'stage']),\n onClearIncremental: new SyncHook<[IGroup, IStage]>(['graphic', 'group', 'stage']),\n beforeUpdateAABBBounds: new SyncHook<[IGraphic, IStage, boolean, IAABBBounds]>([\n 'graphic',\n 'stage',\n 'willUpdate',\n 'aabbBounds'\n ]),\n afterUpdateAABBBounds: new SyncHook<[IGraphic, IStage, IAABBBounds, { globalAABBBounds: IAABBBounds }, boolean]>([\n 'graphic',\n 'stage',\n 'aabbBounds',\n 'globalAABBBounds',\n 'selfChange'\n ]),\n clearAABBBounds: new SyncHook<[IGraphic, IStage, IAABBBounds]>(['graphic', 'stage', 'aabbBounds'])\n };\n this.tempAABBBounds1 = new AABBBounds();\n this.tempAABBBounds2 = new AABBBounds();\n }\n onAttributeUpdate(graphic: IGraphic) {\n if (this.hooks.onAttributeUpdate.taps.length) {\n this.hooks.onAttributeUpdate.call(graphic);\n }\n }\n onSetStage(graphic: IGraphic, stage: IStage): void {\n if (this.hooks.onSetStage.taps.length) {\n this.hooks.onSetStage.call(graphic, stage);\n }\n }\n onRemove(graphic: IGraphic<Partial<IGraphicAttribute>>): void {\n if (this.hooks.onRemove.taps.length) {\n this.hooks.onRemove.call(graphic);\n }\n }\n onRelease(graphic: IGraphic<Partial<IGraphicAttribute>>): void {\n if (this.hooks.onRelease.taps.length) {\n this.hooks.onRelease.call(graphic);\n }\n }\n onAddIncremental(graphic: IGraphic, group: IGroup, stage: IStage): void {\n if (this.hooks.onAddIncremental.taps.length) {\n this.hooks.onAddIncremental.call(graphic, group, stage);\n }\n }\n onClearIncremental(group: IGroup, stage: IStage): void {\n if (this.hooks.onClearIncremental.taps.length) {\n this.hooks.onClearIncremental.call(group, stage);\n }\n }\n beforeUpdateAABBBounds(graphic: IGraphic, stage: IStage, willUpdate: boolean, bounds: IAABBBounds) {\n if (this.hooks.beforeUpdateAABBBounds.taps.length) {\n this.hooks.beforeUpdateAABBBounds.call(graphic, stage, willUpdate, bounds);\n }\n }\n afterUpdateAABBBounds(\n graphic: IGraphic,\n stage: IStage,\n bounds: IAABBBounds,\n params: { globalAABBBounds: IAABBBounds },\n selfChange: boolean\n ) {\n if (this.hooks.afterUpdateAABBBounds.taps.length) {\n this.hooks.afterUpdateAABBBounds.call(graphic, stage, bounds, params, selfChange);\n }\n }\n clearAABBBounds(graphic: IGraphic, stage: IStage, b: IAABBBounds) {\n if (this.hooks.clearAABBBounds.taps.length) {\n this.hooks.clearAABBBounds.call(graphic, stage, b);\n }\n }\n // TODO delete\n updatePathProxyAABBBounds(aabbBounds: IAABBBounds, graphic?: IGraphic): boolean {\n const path = typeof graphic.pathProxy === 'function' ? graphic.pathProxy(graphic.attribute) : graphic.pathProxy;\n if (!path) {\n return false;\n }\n const boundsContext = new BoundsContext(aabbBounds);\n renderCommandList(path.commandList, boundsContext, 0, 0);\n return true;\n }\n\n updateHTMLTextAABBBounds(\n attribute: ITextGraphicAttribute,\n textTheme: Required<ITextGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: IText\n ) {\n const { textAlign, textBaseline } = attribute;\n if (attribute.forceBoundsHeight != null) {\n const h = isNumber(attribute.forceBoundsHeight) ? attribute.forceBoundsHeight : attribute.forceBoundsHeight();\n const dy = textLayoutOffsetY(textBaseline, h, h);\n aabbBounds.set(aabbBounds.x1, dy, aabbBounds.x2, dy + h);\n }\n if (attribute.forceBoundsWidth != null) {\n const w = isNumber(attribute.forceBoundsWidth) ? attribute.forceBoundsWidth : attribute.forceBoundsWidth();\n const dx = textDrawOffsetX(textAlign, w);\n aabbBounds.set(dx, aabbBounds.y1, dx + w, aabbBounds.y2);\n }\n }\n\n combindShadowAABBBounds(bounds: IAABBBounds, graphic?: IGraphic) {\n // 合并shadowRoot的Bounds\n if (graphic && graphic.shadowRoot) {\n const b = graphic.shadowRoot.AABBBounds;\n bounds.union(b);\n }\n }\n\n transformAABBBounds(\n attribute: Partial<IGraphicAttribute>,\n aabbBounds: IAABBBounds,\n theme: Required<IGraphicAttribute>,\n miter: boolean,\n graphic?: IGraphic\n ) {\n if (!aabbBounds.empty()) {\n const {\n scaleX = theme.scaleX,\n scaleY = theme.scaleY,\n stroke = theme.stroke,\n shadowBlur = theme.shadowBlur,\n lineWidth = theme.lineWidth,\n pickStrokeBuffer = theme.pickStrokeBuffer,\n strokeBoundsBuffer = theme.strokeBoundsBuffer\n } = attribute;\n const tb1 = this.tempAABBBounds1;\n const tb2 = this.tempAABBBounds2;\n if (stroke && lineWidth) {\n const scaledHalfLineWidth = (lineWidth + pickStrokeBuffer) / Math.abs(scaleX + scaleY);\n boundStroke(tb1, scaledHalfLineWidth, miter, strokeBoundsBuffer);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n }\n if (shadowBlur) {\n const { shadowOffsetX = theme.shadowOffsetX, shadowOffsetY = theme.shadowOffsetY } = attribute;\n const shadowBlurWidth = (shadowBlur / Math.abs(scaleX + scaleY)) * 2;\n boundStroke(tb1, shadowBlurWidth, false, strokeBoundsBuffer + 1);\n tb1.translate(shadowOffsetX, shadowOffsetY);\n aabbBounds.union(tb1);\n // tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n }\n }\n\n // 合并shadowRoot的bounds\n this.combindShadowAABBBounds(aabbBounds, graphic);\n if (aabbBounds.empty()) {\n return;\n }\n\n // 性能优化逻辑,group类型变换较少,不需要矩阵变换\n let updateMatrix = true;\n const m = graphic.transMatrix;\n if (graphic && graphic.isContainer) {\n updateMatrix = !(m.a === 1 && m.b === 0 && m.c === 0 && m.d === 1 && m.e === 0 && m.f === 0);\n }\n updateMatrix && transformBoundsWithMatrix(aabbBounds, aabbBounds, m);\n\n // TODO 加上锚点\n // transformBounds(aabbBounds, x, y, scaleX, scaleY, angle);\n // if (graphic.attribute.postMatrix) {\n // console.log('aaa');\n // transformBoundsWithMatrix(aabbBounds, graphic.attribute.postMatrix);\n // }\n // aabbBounds.translate(dx, dy);\n }\n\n validCheck(\n attribute: Partial<IGraphicAttribute>,\n theme: Required<IGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: IGraphic\n ): boolean {\n if (!graphic) {\n return true;\n }\n\n // 设置了强制wh,那就直接认为是合法的\n if (attribute.forceBoundsHeight != null || attribute.forceBoundsWidth != null) {\n return true;\n }\n\n // 是Group或者有影子节点的话,就直接认为是合法的\n if (graphic.shadowRoot || graphic.isContainer) {\n return true;\n }\n\n const { visible = theme.visible } = attribute;\n\n if (!(graphic.valid && visible)) {\n // application.graphicService.beforeUpdateAABBBounds(graphic, graphic.stage, true, aabbBounds);\n if (!aabbBounds.empty()) {\n graphic.parent && aabbBounds.transformWithMatrix((graphic.parent as IGroup).globalTransMatrix);\n application.graphicService.clearAABBBounds(graphic, graphic.stage, aabbBounds);\n aabbBounds.clear();\n }\n return false;\n }\n return true;\n }\n\n updateTempAABBBounds(aabbBounds: IAABBBounds) {\n const tb1 = this.tempAABBBounds1;\n const tb2 = this.tempAABBBounds2;\n tb1.setValue(aabbBounds.x1, aabbBounds.y1, aabbBounds.x2, aabbBounds.y2);\n tb2.setValue(aabbBounds.x1, aabbBounds.y1, aabbBounds.x2, aabbBounds.y2);\n\n return { tb1, tb2 };\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/graphic-service/graphic-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAczC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEtH,MAAM,UAAU,mBAAmB,CAAC,EAAU,EAAE,EAAU,EAAE,OAAiB;IAC3E,MAAM,EAAE,KAA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U,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;QACzE,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;QAEzE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IACtB,CAAC;CACF,CAAA;AAvOY,qBAAqB;IADjC,UAAU,EAAE;IAiBE,WAAA,MAAM,CAAC,cAAc,CAAC,CAAA;;GAhBxB,qBAAqB,CAuOjC;SAvOY,qBAAqB","file":"graphic-service.js","sourcesContent":["import { inject, injectable } from '../../common/inversify-lite';\nimport type { IAABBBounds } from '@visactor/vutils';\nimport { AABBBounds, isNumber, transformBoundsWithMatrix } from '@visactor/vutils';\nimport { SyncHook } from '../../tapable';\nimport type {\n mat4,\n IGraphicAttribute,\n IGraphic,\n IGroup,\n IStage,\n IText,\n ITextGraphicAttribute,\n ITransform,\n IGraphicService,\n IGraphicCreator,\n ISyncHook\n} from '../../interface';\nimport { textDrawOffsetX, textLayoutOffsetY } from '../../common/text';\nimport { boundStroke } from '../tools';\nimport { mat4Allocate } from '../../allocator/matrix-allocate';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { BoundsContext } from '../../common/bounds-context';\nimport { renderCommandList } from '../../common/render-command-list';\nimport { GraphicCreator } from '../constants';\nimport { identityMat4, multiplyMat4Mat4, rotateX, rotateY, rotateZ, scaleMat4, translate } from '../../common/matrix';\n\nexport function getExtraModelMatrix(dx: number, dy: number, graphic: IGraphic): mat4 | null {\n const { alpha, beta } = graphic.attribute;\n if (!alpha && !beta) {\n return null;\n }\n const { anchor3d = graphic.attribute.anchor } = graphic.attribute;\n\n const _anchor: [number, number] = [0, 0];\n if (anchor3d) {\n if (typeof anchor3d[0] === 'string') {\n const ratio = parseFloat(anchor3d[0]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[0] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[0] = anchor3d[0];\n }\n if (typeof anchor3d[1] === 'string') {\n const ratio = parseFloat(anchor3d[1]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[1] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[1] = anchor3d[1];\n }\n }\n\n if (graphic.type === 'text') {\n const { textAlign } = graphic.attribute as ITextGraphicAttribute;\n // 计算偏移\n _anchor[0] += textDrawOffsetX(textAlign, (graphic as IText).clipedWidth);\n }\n\n // 应用偏移,计算全局的偏移\n _anchor[0] += dx;\n _anchor[1] += dy;\n // matrix.scale(dpr, dpr);\n\n const modelMatrix = mat4Allocate.allocate();\n translate(modelMatrix, modelMatrix, [_anchor[0], _anchor[1], 0]);\n if (beta) {\n rotateX(modelMatrix, modelMatrix, beta);\n }\n if (alpha) {\n rotateY(modelMatrix, modelMatrix, alpha);\n }\n translate(modelMatrix, modelMatrix, [-_anchor[0], -_anchor[1], 0]);\n\n return modelMatrix;\n}\n\n// 计算3d下的模型矩阵\nexport function getModelMatrix(out: mat4, graphic: IGraphic, theme: ITransform) {\n const {\n x = theme.x,\n y = theme.y,\n z = theme.z,\n dx = theme.dx,\n dy = theme.dy,\n dz = theme.dz,\n scaleX = theme.scaleX,\n scaleY = theme.scaleY,\n scaleZ = theme.scaleZ,\n alpha = theme.alpha,\n beta = theme.beta,\n angle = theme.angle,\n anchor3d = graphic.attribute.anchor,\n anchor\n } = graphic.attribute;\n\n const _anchor: [number, number, number] = [0, 0, 0];\n if (anchor3d) {\n if (typeof anchor3d[0] === 'string') {\n const ratio = parseFloat(anchor3d[0]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[0] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[0] = anchor3d[0];\n }\n if (typeof anchor3d[1] === 'string') {\n const ratio = parseFloat(anchor3d[1]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[1] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[1] = anchor3d[1];\n }\n _anchor[2] = anchor3d[2] ?? 0;\n }\n\n // if (graphic.type === 'text') {\n // const { textAlign } = graphic.attribute as ITextGraphicAttribute;\n // // 计算偏移\n // _anchor[0] += textDrawOffsetX(textAlign, (graphic as IText).clipedWidth);\n // }\n\n identityMat4(out);\n // 平移\n translate(out, out, [x + dx, y + dy, z + dz]);\n translate(out, out, [_anchor[0], _anchor[1], _anchor[2]]);\n rotateX(out, out, beta);\n rotateY(out, out, alpha);\n // 基于z轴的偏移基于anchor计算\n // rotateZ(out, out, angle);\n translate(out, out, [-_anchor[0], -_anchor[1], _anchor[2]]);\n scaleMat4(out, out, [scaleX, scaleY, scaleZ]);\n\n // 计算基于z轴的偏移\n if (angle) {\n const m = mat4Allocate.allocate();\n const _anchor: [number, number] = [0, 0];\n if (anchor) {\n if (typeof anchor3d[0] === 'string') {\n const ratio = parseFloat(anchor3d[0]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[0] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[0] = anchor3d[0];\n }\n if (typeof anchor3d[1] === 'string') {\n const ratio = parseFloat(anchor3d[1]) / 100;\n const bounds = graphic.AABBBounds;\n _anchor[1] = bounds.x1 + (bounds.x2 - bounds.x1) * ratio;\n } else {\n _anchor[1] = anchor3d[1];\n }\n }\n\n translate(m, m, [_anchor[0], _anchor[1], 0]);\n // 基于z轴的偏移基于anchor计算\n rotateZ(m, m, angle);\n translate(m, m, [-_anchor[0], -_anchor[1], 0]);\n\n multiplyMat4Mat4(out, out, m);\n }\n}\n\nexport function shouldUseMat4(graphic: IGraphic) {\n const { alpha, beta } = graphic.attribute;\n return alpha || beta;\n}\n\n// 管理graphic\n@injectable()\nexport class DefaultGraphicService implements IGraphicService {\n declare hooks: {\n onAttributeUpdate: ISyncHook<[IGraphic]>;\n onSetStage: ISyncHook<[IGraphic, IStage]>;\n onRemove: ISyncHook<[IGraphic]>;\n onRelease: ISyncHook<[IGraphic]>;\n onAddIncremental: ISyncHook<[IGraphic, IGroup, IStage]>;\n onClearIncremental: ISyncHook<[IGroup, IStage]>;\n beforeUpdateAABBBounds: ISyncHook<[IGraphic, IStage, boolean, IAABBBounds]>;\n afterUpdateAABBBounds: ISyncHook<[IGraphic, IStage, IAABBBounds, { globalAABBBounds: IAABBBounds }, boolean]>;\n clearAABBBounds: ISyncHook<[IGraphic, IStage, IAABBBounds]>;\n };\n\n // 临时bounds,用作缓存\n protected tempAABBBounds1: AABBBounds;\n protected tempAABBBounds2: AABBBounds;\n constructor(@inject(GraphicCreator) public readonly creator: IGraphicCreator) {\n this.hooks = {\n onAttributeUpdate: new SyncHook<[IGraphic]>(['graphic']),\n onSetStage: new SyncHook<[IGraphic, IStage]>(['graphic', 'stage']),\n onRemove: new SyncHook<[IGraphic]>(['graphic']),\n onRelease: new SyncHook<[IGraphic]>(['graphic']),\n onAddIncremental: new SyncHook<[IGraphic, IGroup, IStage]>(['graphic', 'group', 'stage']),\n onClearIncremental: new SyncHook<[IGroup, IStage]>(['graphic', 'group', 'stage']),\n beforeUpdateAABBBounds: new SyncHook<[IGraphic, IStage, boolean, IAABBBounds]>([\n 'graphic',\n 'stage',\n 'willUpdate',\n 'aabbBounds'\n ]),\n afterUpdateAABBBounds: new SyncHook<[IGraphic, IStage, IAABBBounds, { globalAABBBounds: IAABBBounds }, boolean]>([\n 'graphic',\n 'stage',\n 'aabbBounds',\n 'globalAABBBounds',\n 'selfChange'\n ]),\n clearAABBBounds: new SyncHook<[IGraphic, IStage, IAABBBounds]>(['graphic', 'stage', 'aabbBounds'])\n };\n this.tempAABBBounds1 = new AABBBounds();\n this.tempAABBBounds2 = new AABBBounds();\n }\n onAttributeUpdate(graphic: IGraphic) {\n if (this.hooks.onAttributeUpdate.taps.length) {\n this.hooks.onAttributeUpdate.call(graphic);\n }\n }\n onSetStage(graphic: IGraphic, stage: IStage): void {\n if (this.hooks.onSetStage.taps.length) {\n this.hooks.onSetStage.call(graphic, stage);\n }\n }\n onRemove(graphic: IGraphic<Partial<IGraphicAttribute>>): void {\n if (this.hooks.onRemove.taps.length) {\n this.hooks.onRemove.call(graphic);\n }\n }\n onRelease(graphic: IGraphic<Partial<IGraphicAttribute>>): void {\n if (this.hooks.onRelease.taps.length) {\n this.hooks.onRelease.call(graphic);\n }\n }\n onAddIncremental(graphic: IGraphic, group: IGroup, stage: IStage): void {\n if (this.hooks.onAddIncremental.taps.length) {\n this.hooks.onAddIncremental.call(graphic, group, stage);\n }\n }\n onClearIncremental(group: IGroup, stage: IStage): void {\n if (this.hooks.onClearIncremental.taps.length) {\n this.hooks.onClearIncremental.call(group, stage);\n }\n }\n beforeUpdateAABBBounds(graphic: IGraphic, stage: IStage, willUpdate: boolean, bounds: IAABBBounds) {\n if (this.hooks.beforeUpdateAABBBounds.taps.length) {\n this.hooks.beforeUpdateAABBBounds.call(graphic, stage, willUpdate, bounds);\n }\n }\n afterUpdateAABBBounds(\n graphic: IGraphic,\n stage: IStage,\n bounds: IAABBBounds,\n params: { globalAABBBounds: IAABBBounds },\n selfChange: boolean\n ) {\n if (this.hooks.afterUpdateAABBBounds.taps.length) {\n this.hooks.afterUpdateAABBBounds.call(graphic, stage, bounds, params, selfChange);\n }\n }\n clearAABBBounds(graphic: IGraphic, stage: IStage, b: IAABBBounds) {\n if (this.hooks.clearAABBBounds.taps.length) {\n this.hooks.clearAABBBounds.call(graphic, stage, b);\n }\n }\n // TODO delete\n updatePathProxyAABBBounds(aabbBounds: IAABBBounds, graphic?: IGraphic): boolean {\n const path = typeof graphic.pathProxy === 'function' ? graphic.pathProxy(graphic.attribute) : graphic.pathProxy;\n if (!path) {\n return false;\n }\n const boundsContext = new BoundsContext(aabbBounds);\n renderCommandList(path.commandList, boundsContext, 0, 0);\n return true;\n }\n\n updateHTMLTextAABBBounds(\n attribute: ITextGraphicAttribute,\n textTheme: Required<ITextGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: IText\n ) {\n const { textAlign, textBaseline } = attribute;\n if (attribute.forceBoundsHeight != null) {\n const h = isNumber(attribute.forceBoundsHeight) ? attribute.forceBoundsHeight : attribute.forceBoundsHeight();\n const dy = textLayoutOffsetY(textBaseline, h, h);\n aabbBounds.set(aabbBounds.x1, dy, aabbBounds.x2, dy + h);\n }\n if (attribute.forceBoundsWidth != null) {\n const w = isNumber(attribute.forceBoundsWidth) ? attribute.forceBoundsWidth : attribute.forceBoundsWidth();\n const dx = textDrawOffsetX(textAlign, w);\n aabbBounds.set(dx, aabbBounds.y1, dx + w, aabbBounds.y2);\n }\n }\n\n combindShadowAABBBounds(bounds: IAABBBounds, graphic?: IGraphic) {\n // 合并shadowRoot的Bounds\n if (graphic && graphic.shadowRoot) {\n const b = graphic.shadowRoot.AABBBounds;\n bounds.union(b);\n }\n }\n\n transformAABBBounds(\n attribute: Partial<IGraphicAttribute>,\n aabbBounds: IAABBBounds,\n theme: Required<IGraphicAttribute>,\n miter: boolean,\n graphic?: IGraphic\n ) {\n if (!aabbBounds.empty()) {\n const {\n scaleX = theme.scaleX,\n scaleY = theme.scaleY,\n stroke = theme.stroke,\n shadowBlur = theme.shadowBlur,\n lineWidth = theme.lineWidth,\n pickStrokeBuffer = theme.pickStrokeBuffer,\n strokeBoundsBuffer = theme.strokeBoundsBuffer\n } = attribute;\n const tb1 = this.tempAABBBounds1;\n const tb2 = this.tempAABBBounds2;\n if (stroke && lineWidth) {\n const scaledHalfLineWidth = (lineWidth + pickStrokeBuffer) / Math.abs(scaleX + scaleY);\n boundStroke(tb1, scaledHalfLineWidth, miter, strokeBoundsBuffer);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n }\n if (shadowBlur) {\n const { shadowOffsetX = theme.shadowOffsetX, shadowOffsetY = theme.shadowOffsetY } = attribute;\n const shadowBlurWidth = (shadowBlur / Math.abs(scaleX + scaleY)) * 2;\n boundStroke(tb1, shadowBlurWidth, false, strokeBoundsBuffer + 1);\n tb1.translate(shadowOffsetX, shadowOffsetY);\n aabbBounds.union(tb1);\n // tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n }\n }\n\n // 合并shadowRoot的bounds\n this.combindShadowAABBBounds(aabbBounds, graphic);\n if (aabbBounds.empty()) {\n return;\n }\n\n // 性能优化逻辑,group类型变换较少,不需要矩阵变换\n let updateMatrix = true;\n const m = graphic.transMatrix;\n if (graphic && graphic.isContainer) {\n updateMatrix = !(m.a === 1 && m.b === 0 && m.c === 0 && m.d === 1 && m.e === 0 && m.f === 0);\n }\n updateMatrix && transformBoundsWithMatrix(aabbBounds, aabbBounds, m);\n\n // TODO 加上锚点\n // transformBounds(aabbBounds, x, y, scaleX, scaleY, angle);\n // if (graphic.attribute.postMatrix) {\n // console.log('aaa');\n // transformBoundsWithMatrix(aabbBounds, graphic.attribute.postMatrix);\n // }\n // aabbBounds.translate(dx, dy);\n }\n\n validCheck(\n attribute: Partial<IGraphicAttribute>,\n theme: Required<IGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: IGraphic\n ): boolean {\n if (!graphic) {\n return true;\n }\n\n // 设置了强制wh,那就直接认为是合法的\n if (attribute.forceBoundsHeight != null || attribute.forceBoundsWidth != null) {\n return true;\n }\n\n // 是Group或者有影子节点的话,就直接认为是合法的\n if (graphic.shadowRoot || graphic.isContainer) {\n return true;\n }\n\n const { visible = theme.visible } = attribute;\n\n if (!(graphic.valid && visible)) {\n // application.graphicService.beforeUpdateAABBBounds(graphic, graphic.stage, true, aabbBounds);\n if (!aabbBounds.empty()) {\n graphic.parent && aabbBounds.transformWithMatrix((graphic.parent as IGroup).globalTransMatrix);\n this.clearAABBBounds(graphic, graphic.stage, aabbBounds);\n aabbBounds.clear();\n }\n return false;\n }\n return true;\n }\n\n updateTempAABBBounds(aabbBounds: IAABBBounds) {\n const tb1 = this.tempAABBBounds1;\n const tb2 = this.tempAABBBounds2;\n tb1.setValue(aabbBounds.x1, aabbBounds.y1, aabbBounds.x2, aabbBounds.y2);\n tb2.setValue(aabbBounds.x1, aabbBounds.y1, aabbBounds.x2, aabbBounds.y2);\n\n return { tb1, tb2 };\n }\n}\n"]}
@@ -93,6 +93,7 @@ export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Par
93
93
  protected updateOBBBoundsStamp?: number;
94
94
  clipPathMap?: Map<string, ISymbolClass>;
95
95
  constructor(params?: T);
96
+ getGraphicService(): import("../interface").IGraphicService;
96
97
  getAttributes(): T;
97
98
  setMode(mode: '2d' | '3d'): void;
98
99
  set3dMode(): void;
@@ -99,6 +99,10 @@ export class Graphic extends Node {
99
99
  super(), this._AABBBounds = new AABBBounds, this._updateTag = UpdateTag.INIT, this.attribute = params,
100
100
  this.valid = this.isValid(), this.updateAABBBoundsStamp = 0, params.background ? this.loadImage(null !== (_a = params.background.background) && void 0 !== _a ? _a : params.background, !0) : params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic);
101
101
  }
102
+ getGraphicService() {
103
+ var _a, _b;
104
+ return null !== (_b = null === (_a = this.stage) || void 0 === _a ? void 0 : _a.graphicService) && void 0 !== _b ? _b : application.graphicService;
105
+ }
102
106
  getAttributes() {
103
107
  return this.attribute;
104
108
  }
@@ -124,13 +128,12 @@ export class Graphic extends Node {
124
128
  this._emitCustomEvent("animate-bind", animate);
125
129
  }
126
130
  tryUpdateAABBBounds() {
127
- var _a, _b;
128
131
  const full = "imprecise" === this.attribute.boundsMode;
129
132
  if (!this.shouldUpdateAABBBounds()) return this._AABBBounds;
130
133
  if (!this.valid) return this._AABBBounds.clear(), this._AABBBounds;
131
- null === (_a = this.stage) || void 0 === _a || _a.graphicService.beforeUpdateAABBBounds(this, this.stage, !0, this._AABBBounds);
134
+ this.getGraphicService().beforeUpdateAABBBounds(this, this.stage, !0, this._AABBBounds);
132
135
  const bounds = this.doUpdateAABBBounds(full);
133
- return null === (_b = this.stage) || void 0 === _b || _b.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, !0),
136
+ return this.getGraphicService().afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, !0),
134
137
  "empty" === this.attribute.boundsMode && bounds.clear(), bounds;
135
138
  }
136
139
  tryUpdateOBBBounds() {
@@ -226,7 +229,7 @@ export class Graphic extends Node {
226
229
  clearTag && this.clearUpdateLocalPositionTag()), this._transMatrix;
227
230
  }
228
231
  shouldUpdateAABBBounds() {
229
- return this.shadowRoot ? (!!(this._updateTag & UpdateTag.UPDATE_BOUNDS) || this.shadowRoot.shouldUpdateAABBBounds()) && application.graphicService.validCheck(this.attribute, this.getGraphicTheme(), this._AABBBounds, this) : !!(this._updateTag & UpdateTag.UPDATE_BOUNDS) && application.graphicService.validCheck(this.attribute, this.getGraphicTheme(), this._AABBBounds, this);
232
+ return this.shadowRoot ? (!!(this._updateTag & UpdateTag.UPDATE_BOUNDS) || this.shadowRoot.shouldUpdateAABBBounds()) && this.getGraphicService().validCheck(this.attribute, this.getGraphicTheme(), this._AABBBounds, this) : !!(this._updateTag & UpdateTag.UPDATE_BOUNDS) && this.getGraphicService().validCheck(this.attribute, this.getGraphicTheme(), this._AABBBounds, this);
230
233
  }
231
234
  shouldSelfChangeUpdateAABBBounds() {
232
235
  return this.shadowRoot ? !!(this._updateTag & UpdateTag.UPDATE_BOUNDS) || this.shadowRoot.shouldUpdateAABBBounds() : !!(this._updateTag & UpdateTag.UPDATE_BOUNDS);
@@ -409,8 +412,7 @@ export class Graphic extends Node {
409
412
  return this;
410
413
  }
411
414
  onAttributeUpdate(context) {
412
- var _a;
413
- context && context.skipUpdateCallback || (null === (_a = this.stage) || void 0 === _a || _a.graphicService.onAttributeUpdate(this),
415
+ context && context.skipUpdateCallback || (this.getGraphicService().onAttributeUpdate(this),
414
416
  this._emitCustomEvent("afterAttributeUpdate", context));
415
417
  }
416
418
  update(d) {
@@ -587,7 +589,6 @@ export class Graphic extends Node {
587
589
  }
588
590
  }
589
591
  setStage(stage, layer) {
590
- var _a;
591
592
  if (this.stage !== stage) {
592
593
  if (this.stage = stage, this.layer = layer, this.setStageToShadowRoot(stage, layer),
593
594
  this.animates && this.animates.size) {
@@ -596,7 +597,7 @@ export class Graphic extends Node {
596
597
  a.timeline.isGlobal && (a.setTimeline(timeline), timeline.addAnimate(a));
597
598
  }));
598
599
  }
599
- this._onSetStage && this._onSetStage(this, stage, layer), null === (_a = this.stage) || void 0 === _a || _a.graphicService.onSetStage(this, stage);
600
+ this._onSetStage && this._onSetStage(this, stage, layer), this.getGraphicService().onSetStage(this, stage);
600
601
  }
601
602
  }
602
603
  setStageToShadowRoot(stage, layer) {