@visactor/vrender-core 1.1.0-alpha.17 → 1.1.0-alpha.19
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.
- package/cjs/graphic/graphic.d.ts +23 -2
- package/cjs/graphic/graphic.js +84 -28
- package/cjs/graphic/graphic.js.map +1 -1
- package/cjs/graphic/state/shared-state-refresh.js +1 -0
- package/cjs/graphic/state/shared-state-refresh.js.map +1 -1
- package/cjs/interface/graphic.d.ts +8 -1
- package/cjs/interface/graphic.js.map +1 -1
- package/dist/index.es.js +131 -33
- package/es/graphic/graphic.d.ts +23 -2
- package/es/graphic/graphic.js +84 -28
- package/es/graphic/graphic.js.map +1 -1
- package/es/graphic/state/shared-state-refresh.js +1 -0
- package/es/graphic/state/shared-state-refresh.js.map +1 -1
- package/es/interface/graphic.d.ts +8 -1
- package/es/interface/graphic.js.map +1 -1
- package/package.json +3 -3
|
@@ -41,6 +41,7 @@ function flushStageSharedStateRefresh(stage) {
|
|
|
41
41
|
graphics.forEach((graphic => {
|
|
42
42
|
if ("released" === graphic.releaseStatus) return;
|
|
43
43
|
if (graphic.stage !== stage) return;
|
|
44
|
+
if (!graphic.sharedStateDirty) return;
|
|
44
45
|
const refresh = graphic.refreshSharedStateBeforeRender;
|
|
45
46
|
"function" == typeof refresh && (refresh.call(graphic), null == perfMonitor || perfMonitor.incrementCounter("sharedRefreshCommits"));
|
|
46
47
|
})), perfMonitor && (perfMonitor.recordCost("sharedRefresh", performance.now() - start),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/state/shared-state-refresh.ts"],"names":[],"mappings":";;;AAEA,6DAAsE;AAEtE,SAAgB,+BAA+B,CAAC,KAAyB;;IACvE,IAAI,CAAC,KAAK,IAAK,KAAa,CAAC,aAAa,KAAK,UAAU,EAAE;QACzD,OAAO;KACR;IAED,MAAA,IAAA,mDAA8B,EAAC,KAAK,CAAC,0CAAE,aAAa,CAAC,iBAAiB,C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AC,CAAC;SACvD;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,WAAW,EAAE;QACf,WAAW,CAAC,UAAU,CAAC,eAAe,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;QACnE,WAAW,CAAC,WAAW,CAAC,sBAAsB,EAAE;YAC9C,OAAO,EAAG,KAAa,CAAC,IAAI;YAC5B,eAAe,EAAE,QAAQ,CAAC,MAAM;SACjC,CAAC,CAAC;KACJ;AACH,CAAC;AArCD,oEAqCC","file":"shared-state-refresh.js","sourcesContent":["import type { IGraphic, IStage } from '../../interface';\nimport type { SharedStateScope } from './shared-state-scope';\nimport { getActiveStageStatePerfMonitor } from './state-perf-monitor';\n\nexport function scheduleStageSharedStateRefresh(stage: IStage | undefined): void {\n if (!stage || (stage as any).releaseStatus === 'released') {\n return;\n }\n\n getActiveStageStatePerfMonitor(stage)?.recordRefresh('renderScheduled');\n stage.renderNextFrame();\n}\n\nexport function enqueueGraphicSharedStateRefresh(stage: IStage | undefined, graphic: IGraphic): void {\n if (!stage) {\n return;\n }\n\n const pending =\n ((stage as any)._pendingSharedStateRefreshGraphics as Set<IGraphic> | undefined) ??\n (((stage as any)._pendingSharedStateRefreshGraphics = new Set<IGraphic>()) as Set<IGraphic>);\n\n if (!pending.has(graphic)) {\n pending.add(graphic);\n const perfMonitor = getActiveStageStatePerfMonitor(stage);\n perfMonitor?.recordRefresh('queuedGraphics');\n perfMonitor?.recordAllocation('refreshQueuePushes');\n }\n}\n\nexport function markScopeActiveDescendantsDirty<T extends Record<string, any> = Record<string, any>>(\n scope: SharedStateScope<T>,\n stage?: IStage\n): void {\n let marked = false;\n scope.subtreeActiveDescendants.forEach(graphic => {\n (graphic as any).sharedStateDirty = true;\n const ownerStage = stage ?? graphic.stage ?? scope.ownerStage;\n enqueueGraphicSharedStateRefresh(ownerStage, graphic);\n marked = true;\n });\n\n if (marked) {\n scheduleStageSharedStateRefresh(stage ?? scope.ownerStage);\n }\n}\n\nexport function flushStageSharedStateRefresh(stage: IStage): void {\n const pending = (stage as any)._pendingSharedStateRefreshGraphics as Set<IGraphic> | undefined;\n if (!pending || !pending.size) {\n return;\n }\n\n const perfMonitor = getActiveStageStatePerfMonitor(stage);\n const start = perfMonitor ? performance.now() : 0;\n const graphics = Array.from(pending.values());\n pending.clear();\n perfMonitor?.recordRefresh('flushedGraphics', graphics.length);\n\n graphics.forEach(graphic => {\n if ((graphic as any).releaseStatus === 'released') {\n return;\n }\n if (graphic.stage !== stage) {\n return;\n }\n if (!(graphic as any).sharedStateDirty) {\n return;\n }\n\n const refresh = (graphic as any).refreshSharedStateBeforeRender;\n if (typeof refresh === 'function') {\n refresh.call(graphic);\n perfMonitor?.incrementCounter('sharedRefreshCommits');\n }\n });\n\n if (perfMonitor) {\n perfMonitor.recordCost('sharedRefresh', performance.now() - start);\n perfMonitor.recordEvent('shared-refresh-flush', {\n stageId: (stage as any)._uid,\n flushedGraphics: graphics.length\n });\n }\n}\n"]}
|
|
@@ -286,7 +286,10 @@ export interface IGraphic<T extends Partial<IGraphicAttribute> = Partial<IGraphi
|
|
|
286
286
|
toggleState: (stateName: string, hasAnimation?: boolean) => void;
|
|
287
287
|
removeState: (stateName: string | string[], hasAnimation?: boolean) => void;
|
|
288
288
|
clearStates: (hasAnimation?: boolean) => void;
|
|
289
|
-
setStates:
|
|
289
|
+
setStates: {
|
|
290
|
+
(states?: string[] | null, hasAnimation?: boolean): void;
|
|
291
|
+
(states?: string[] | null, options?: ISetStatesOptions): void;
|
|
292
|
+
};
|
|
290
293
|
useStates: (states: string[], hasAnimation?: boolean) => void;
|
|
291
294
|
addState: (stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean) => void;
|
|
292
295
|
invalidateResolver: () => void;
|
|
@@ -364,5 +367,9 @@ export type IAnimateConfig = {
|
|
|
364
367
|
easing?: EasingType;
|
|
365
368
|
noAnimateAttrs?: string[] | Record<string, boolean | number>;
|
|
366
369
|
};
|
|
370
|
+
export type ISetStatesOptions = {
|
|
371
|
+
animate?: boolean;
|
|
372
|
+
animateSameStatePatchChange?: boolean;
|
|
373
|
+
};
|
|
367
374
|
export type GraphicReleaseStatus = 'released' | 'willRelease';
|
|
368
375
|
export {};
|
|
@@ -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';\nimport type {\n CompiledStateDefinition,\n StateDefinition,\n StateDefinitionsInput\n} from '../graphic/state/state-definition';\nimport type { StateMergeMode } from '../graphic/state/state-style-resolver';\nimport type { SharedStateScope } from '../graphic/state/shared-state-scope';\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\nexport type BackgroundSizing = 'cover' | 'contain' | 'fill' | 'auto';\nexport type BackgroundRepeatMode = 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat';\nexport type BackgroundSizingShorthand = 'no-repeat-cover' | 'no-repeat-contain' | 'no-repeat-fill' | 'no-repeat-auto';\nexport type BackgroundMode = BackgroundRepeatMode | BackgroundSizingShorthand;\nexport type BackgroundPositionHorizontalKeyword = 'left' | 'center' | 'right';\nexport type BackgroundPositionVerticalKeyword = 'top' | 'center' | 'bottom';\nexport type BackgroundPositionKeyword = BackgroundPositionHorizontalKeyword | BackgroundPositionVerticalKeyword;\nexport type BackgroundPositionPercent = `${number}%`;\nexport type BackgroundPositionValue = number | BackgroundPositionKeyword | BackgroundPositionPercent;\nexport type BackgroundPositionPreset =\n | 'top-left'\n | 'top-center'\n | 'top-right'\n | 'center-left'\n | 'center'\n | 'center-right'\n | 'bottom-left'\n | 'bottom-center'\n | 'bottom-right';\nexport type BackgroundPosition =\n | BackgroundPositionKeyword\n | BackgroundPositionPreset\n | [BackgroundPositionValue, BackgroundPositionValue];\n\nexport type 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: BackgroundMode;\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 * 背景图锚定位置(类似 CSS background-position),仅在 no-repeat 的图片背景下生效。\n */\n backgroundPosition: BackgroundPosition;\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 baseAttributes?: 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?: StateDefinitionsInput<T>;\n effectiveStates?: string[];\n resolvedStatePatch?: Partial<T>;\n normalAttrs?: Partial<T>;\n baseAttributes?: Partial<T>;\n boundSharedStateScope?: SharedStateScope<T>;\n boundSharedStateRevision?: number;\n sharedStateDirty?: boolean;\n registeredActiveScopes?: Set<SharedStateScope<T>>;\n localFallbackCompiledDefinitions?: Map<string, CompiledStateDefinition<T>>;\n localFallbackVersion?: number;\n stateProxy?: (stateName: string, targetStates?: string[]) => Partial<T>;\n stateMergeMode?: StateMergeMode;\n findFace?: () => IFace3d;\n toggleState: (stateName: string, hasAnimation?: boolean) => void;\n removeState: (stateName: string | string[], hasAnimation?: boolean) => void;\n clearStates: (hasAnimation?: boolean) => void;\n setStates: (states?: string[] | null, hasAnimation?: boolean) => void;\n useStates: (states: string[], hasAnimation?: boolean) => void;\n addState: (stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean) => void;\n invalidateResolver: () => void;\n hasState: (stateName?: string) => boolean;\n getState: (stateName: string) => Partial<T> | StateDefinition<T>;\n onBeforeAttributeUpdate?: (\n val: any,\n attributes: Partial<T>,\n key: null | string | string[],\n context?: ISetAttributeContext\n ) => T | undefined;\n applyStateAttrs: (\n attrs: Partial<T>,\n stateNames: string[],\n hasAnimation?: boolean,\n isClear?: boolean,\n animateConfig?: IAnimateConfig\n ) => 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 addUpdatePaintTag: () => 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 detachStageForRelease: () => 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 pauseAnimation?: (deep?: boolean) => void;\n resumeAnimation?: (deep?: boolean) => void;\n stopAnimation?: (deep?: boolean) => void;\n reApplyAnimationState?: (state: string, deep?: boolean) => this;\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 noAnimateAttrs?: string[] | Record<string, boolean | number>;\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';\nimport type {\n CompiledStateDefinition,\n StateDefinition,\n StateDefinitionsInput\n} from '../graphic/state/state-definition';\nimport type { StateMergeMode } from '../graphic/state/state-style-resolver';\nimport type { SharedStateScope } from '../graphic/state/shared-state-scope';\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\nexport type BackgroundSizing = 'cover' | 'contain' | 'fill' | 'auto';\nexport type BackgroundRepeatMode = 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat';\nexport type BackgroundSizingShorthand = 'no-repeat-cover' | 'no-repeat-contain' | 'no-repeat-fill' | 'no-repeat-auto';\nexport type BackgroundMode = BackgroundRepeatMode | BackgroundSizingShorthand;\nexport type BackgroundPositionHorizontalKeyword = 'left' | 'center' | 'right';\nexport type BackgroundPositionVerticalKeyword = 'top' | 'center' | 'bottom';\nexport type BackgroundPositionKeyword = BackgroundPositionHorizontalKeyword | BackgroundPositionVerticalKeyword;\nexport type BackgroundPositionPercent = `${number}%`;\nexport type BackgroundPositionValue = number | BackgroundPositionKeyword | BackgroundPositionPercent;\nexport type BackgroundPositionPreset =\n | 'top-left'\n | 'top-center'\n | 'top-right'\n | 'center-left'\n | 'center'\n | 'center-right'\n | 'bottom-left'\n | 'bottom-center'\n | 'bottom-right';\nexport type BackgroundPosition =\n | BackgroundPositionKeyword\n | BackgroundPositionPreset\n | [BackgroundPositionValue, BackgroundPositionValue];\n\nexport type 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: BackgroundMode;\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 * 背景图锚定位置(类似 CSS background-position),仅在 no-repeat 的图片背景下生效。\n */\n backgroundPosition: BackgroundPosition;\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 baseAttributes?: 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?: StateDefinitionsInput<T>;\n effectiveStates?: string[];\n resolvedStatePatch?: Partial<T>;\n normalAttrs?: Partial<T>;\n baseAttributes?: Partial<T>;\n boundSharedStateScope?: SharedStateScope<T>;\n boundSharedStateRevision?: number;\n sharedStateDirty?: boolean;\n registeredActiveScopes?: Set<SharedStateScope<T>>;\n localFallbackCompiledDefinitions?: Map<string, CompiledStateDefinition<T>>;\n localFallbackVersion?: number;\n stateProxy?: (stateName: string, targetStates?: string[]) => Partial<T>;\n stateMergeMode?: StateMergeMode;\n findFace?: () => IFace3d;\n toggleState: (stateName: string, hasAnimation?: boolean) => void;\n removeState: (stateName: string | string[], hasAnimation?: boolean) => void;\n clearStates: (hasAnimation?: boolean) => void;\n setStates: {\n (states?: string[] | null, hasAnimation?: boolean): void;\n (states?: string[] | null, options?: ISetStatesOptions): void;\n };\n useStates: (states: string[], hasAnimation?: boolean) => void;\n addState: (stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean) => void;\n invalidateResolver: () => void;\n hasState: (stateName?: string) => boolean;\n getState: (stateName: string) => Partial<T> | StateDefinition<T>;\n onBeforeAttributeUpdate?: (\n val: any,\n attributes: Partial<T>,\n key: null | string | string[],\n context?: ISetAttributeContext\n ) => T | undefined;\n applyStateAttrs: (\n attrs: Partial<T>,\n stateNames: string[],\n hasAnimation?: boolean,\n isClear?: boolean,\n animateConfig?: IAnimateConfig\n ) => 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 addUpdatePaintTag: () => 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 detachStageForRelease: () => 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 pauseAnimation?: (deep?: boolean) => void;\n resumeAnimation?: (deep?: boolean) => void;\n stopAnimation?: (deep?: boolean) => void;\n reApplyAnimationState?: (state: string, deep?: boolean) => this;\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 noAnimateAttrs?: string[] | Record<string, boolean | number>;\n};\n\nexport type ISetStatesOptions = {\n animate?: boolean;\n animateSameStatePatchChange?: boolean;\n};\n\nexport type GraphicReleaseStatus = 'released' | 'willRelease';\n"]}
|
package/dist/index.es.js
CHANGED
|
@@ -10421,6 +10421,9 @@ function flushStageSharedStateRefresh(stage) {
|
|
|
10421
10421
|
if (graphic.stage !== stage) {
|
|
10422
10422
|
return;
|
|
10423
10423
|
}
|
|
10424
|
+
if (!graphic.sharedStateDirty) {
|
|
10425
|
+
return;
|
|
10426
|
+
}
|
|
10424
10427
|
const refresh = graphic.refreshSharedStateBeforeRender;
|
|
10425
10428
|
if (typeof refresh === 'function') {
|
|
10426
10429
|
refresh.call(graphic);
|
|
@@ -10838,18 +10841,17 @@ class Graphic extends Node {
|
|
|
10838
10841
|
};
|
|
10839
10842
|
}
|
|
10840
10843
|
recomputeCurrentStatePatch() {
|
|
10841
|
-
var _a, _b
|
|
10844
|
+
var _a, _b;
|
|
10842
10845
|
if (!((_a = this.currentStates) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
10843
10846
|
this.effectiveStates = [];
|
|
10844
10847
|
this.resolvedStatePatch = undefined;
|
|
10845
10848
|
this.syncSharedStateActiveRegistrations();
|
|
10846
10849
|
return;
|
|
10847
10850
|
}
|
|
10848
|
-
const stateResolveBaseAttrs =
|
|
10849
|
-
const stateModel = this.createStateModel();
|
|
10850
|
-
(_c = this.stateEngine) === null || _c === void 0 ? void 0 : _c.setResolveContext(this, stateResolveBaseAttrs);
|
|
10851
|
+
const stateResolveBaseAttrs = this.getStateResolveBaseAttrs();
|
|
10852
|
+
const stateModel = this.createStateModel(stateResolveBaseAttrs);
|
|
10851
10853
|
const transition = stateModel.useStates(this.currentStates);
|
|
10852
|
-
const effectiveStates = (
|
|
10854
|
+
const effectiveStates = (_b = transition.effectiveStates) !== null && _b !== void 0 ? _b : transition.states;
|
|
10853
10855
|
const resolvedStateAttrs = this.stateEngine && this.compiledStateDefinitions
|
|
10854
10856
|
? Object.assign({}, this.stateEngine.resolvedPatch) : this.getStateStyleResolver(this.stateMergeMode).resolve(stateResolveBaseAttrs, this.states, this.stateProxy, transition.states, this.stateSort);
|
|
10855
10857
|
this.currentStates = transition.states;
|
|
@@ -11900,7 +11902,16 @@ class Graphic extends Node {
|
|
|
11900
11902
|
var _a;
|
|
11901
11903
|
return (_a = this.states) === null || _a === void 0 ? void 0 : _a[stateName];
|
|
11902
11904
|
}
|
|
11903
|
-
|
|
11905
|
+
getStateResolveBaseAttrs() {
|
|
11906
|
+
var _a;
|
|
11907
|
+
return ((_a = this.baseAttributes) !== null && _a !== void 0 ? _a : this.attribute);
|
|
11908
|
+
}
|
|
11909
|
+
syncStateResolveContext(stateResolveBaseAttrs = this.getStateResolveBaseAttrs()) {
|
|
11910
|
+
var _a;
|
|
11911
|
+
(_a = this.stateEngine) === null || _a === void 0 ? void 0 : _a.setResolveContext(this, stateResolveBaseAttrs);
|
|
11912
|
+
return stateResolveBaseAttrs;
|
|
11913
|
+
}
|
|
11914
|
+
createStateModel(stateResolveBaseAttrs = this.getStateResolveBaseAttrs()) {
|
|
11904
11915
|
const { compiledDefinitions, stateProxyEligibility, stateProxyModeKey } = this.resolveEffectiveCompiledDefinitions();
|
|
11905
11916
|
this.compiledStateDefinitions = compiledDefinitions;
|
|
11906
11917
|
if (!compiledDefinitions) {
|
|
@@ -11928,6 +11939,7 @@ class Graphic extends Node {
|
|
|
11928
11939
|
this.stateEngineMergeMode = this.stateMergeMode;
|
|
11929
11940
|
this.stateEngineStateProxyModeKey = stateProxyModeKey;
|
|
11930
11941
|
}
|
|
11942
|
+
this.syncStateResolveContext(stateResolveBaseAttrs);
|
|
11931
11943
|
return new StateModel({
|
|
11932
11944
|
states: this.states,
|
|
11933
11945
|
currentStates: this.currentStates,
|
|
@@ -12027,6 +12039,106 @@ class Graphic extends Node {
|
|
|
12027
12039
|
resolvedStateAttrs
|
|
12028
12040
|
};
|
|
12029
12041
|
}
|
|
12042
|
+
resolveGraphicStateTransition(states, previousStates, forceResolverRefresh = false) {
|
|
12043
|
+
var _a, _b;
|
|
12044
|
+
let transition = this.resolveSimpleLocalStateTransition(states, previousStates);
|
|
12045
|
+
const isSimpleLocalTransition = !!transition;
|
|
12046
|
+
let resolvedStateAttrs;
|
|
12047
|
+
if (transition) {
|
|
12048
|
+
resolvedStateAttrs = transition.resolvedStateAttrs;
|
|
12049
|
+
}
|
|
12050
|
+
else {
|
|
12051
|
+
const stateResolveBaseAttrs = this.getStateResolveBaseAttrs();
|
|
12052
|
+
const stateModel = this.createStateModel(stateResolveBaseAttrs);
|
|
12053
|
+
if (forceResolverRefresh) {
|
|
12054
|
+
(_a = this.stateEngine) === null || _a === void 0 ? void 0 : _a.invalidateResolverCache();
|
|
12055
|
+
}
|
|
12056
|
+
transition = stateModel.useStates(states);
|
|
12057
|
+
resolvedStateAttrs =
|
|
12058
|
+
this.stateEngine && this.compiledStateDefinitions
|
|
12059
|
+
? Object.assign({}, this.stateEngine.resolvedPatch) : this.getStateStyleResolver(this.stateMergeMode).resolve(stateResolveBaseAttrs, this.states, this.stateProxy, transition.states, this.stateSort);
|
|
12060
|
+
}
|
|
12061
|
+
const effectiveStates = (_b = transition.effectiveStates) !== null && _b !== void 0 ? _b : transition.states;
|
|
12062
|
+
return {
|
|
12063
|
+
transition,
|
|
12064
|
+
effectiveStates: effectiveStates,
|
|
12065
|
+
resolvedStateAttrs,
|
|
12066
|
+
isSimpleLocalTransition
|
|
12067
|
+
};
|
|
12068
|
+
}
|
|
12069
|
+
normalizeSetStatesOptions(options) {
|
|
12070
|
+
if (options && typeof options === 'object') {
|
|
12071
|
+
return {
|
|
12072
|
+
hasAnimation: options.animate,
|
|
12073
|
+
animateSameStatePatchChange: options.animateSameStatePatchChange === true,
|
|
12074
|
+
shouldRefreshSameStatePatch: true
|
|
12075
|
+
};
|
|
12076
|
+
}
|
|
12077
|
+
return {
|
|
12078
|
+
hasAnimation: typeof options === 'boolean' ? options : undefined,
|
|
12079
|
+
animateSameStatePatchChange: false,
|
|
12080
|
+
shouldRefreshSameStatePatch: false
|
|
12081
|
+
};
|
|
12082
|
+
}
|
|
12083
|
+
sameStatePatches(left, right) {
|
|
12084
|
+
const leftRecord = (left !== null && left !== void 0 ? left : {});
|
|
12085
|
+
const rightRecord = (right !== null && right !== void 0 ? right : {});
|
|
12086
|
+
const keys = new Set([...Object.keys(leftRecord), ...Object.keys(rightRecord)]);
|
|
12087
|
+
for (const key of keys) {
|
|
12088
|
+
const hasLeft = Object.prototype.hasOwnProperty.call(leftRecord, key);
|
|
12089
|
+
const hasRight = Object.prototype.hasOwnProperty.call(rightRecord, key);
|
|
12090
|
+
if (hasLeft !== hasRight) {
|
|
12091
|
+
return false;
|
|
12092
|
+
}
|
|
12093
|
+
if (!areAttributeValuesEqual(leftRecord[key], rightRecord[key])) {
|
|
12094
|
+
return false;
|
|
12095
|
+
}
|
|
12096
|
+
}
|
|
12097
|
+
return true;
|
|
12098
|
+
}
|
|
12099
|
+
commitSameStatePatchRefresh(states, hasAnimation, animateSameStatePatchChange = false) {
|
|
12100
|
+
var _a;
|
|
12101
|
+
const previousStates = (_a = this.currentStates) !== null && _a !== void 0 ? _a : EMPTY_STATE_NAMES;
|
|
12102
|
+
const previousResolvedStatePatch = this.resolvedStatePatch;
|
|
12103
|
+
const { transition, effectiveStates, resolvedStateAttrs, isSimpleLocalTransition } = this.resolveGraphicStateTransition(states, previousStates, true);
|
|
12104
|
+
const patchChanged = !this.sameStatePatches(previousResolvedStatePatch, resolvedStateAttrs);
|
|
12105
|
+
if (patchChanged &&
|
|
12106
|
+
!this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, false)) {
|
|
12107
|
+
return;
|
|
12108
|
+
}
|
|
12109
|
+
this.currentStates = transition.states;
|
|
12110
|
+
this.effectiveStates = isSimpleLocalTransition ? effectiveStates : [...effectiveStates];
|
|
12111
|
+
this.resolvedStatePatch = resolvedStateAttrs;
|
|
12112
|
+
this.sharedStateDirty = false;
|
|
12113
|
+
this.syncSharedStateActiveRegistrations();
|
|
12114
|
+
if (!patchChanged) {
|
|
12115
|
+
return;
|
|
12116
|
+
}
|
|
12117
|
+
if (this.stage) {
|
|
12118
|
+
const perfMonitor = getActiveStageStatePerfMonitor(this.stage);
|
|
12119
|
+
perfMonitor === null || perfMonitor === void 0 ? void 0 : perfMonitor.incrementCounter('stateCommits');
|
|
12120
|
+
perfMonitor === null || perfMonitor === void 0 ? void 0 : perfMonitor.recordEvent('state-commit', {
|
|
12121
|
+
graphicId: this._uid,
|
|
12122
|
+
targetStates: [...transition.states]
|
|
12123
|
+
});
|
|
12124
|
+
}
|
|
12125
|
+
if (hasAnimation && animateSameStatePatchChange) {
|
|
12126
|
+
this._syncFinalAttributeFromStaticTruth();
|
|
12127
|
+
this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, false, undefined, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch));
|
|
12128
|
+
}
|
|
12129
|
+
else {
|
|
12130
|
+
this.stopStateAnimates();
|
|
12131
|
+
if (this.attributeMayContainTransientAttrs) {
|
|
12132
|
+
this._restoreAttributeFromStaticTruth({ type: AttributeUpdateType.STATE });
|
|
12133
|
+
}
|
|
12134
|
+
else {
|
|
12135
|
+
this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, this.resolvedStatePatch, {
|
|
12136
|
+
type: AttributeUpdateType.STATE
|
|
12137
|
+
});
|
|
12138
|
+
}
|
|
12139
|
+
this.emitStateUpdateEvent();
|
|
12140
|
+
}
|
|
12141
|
+
}
|
|
12030
12142
|
resolveStateAnimateConfig(animateConfig) {
|
|
12031
12143
|
var _a, _b, _c;
|
|
12032
12144
|
return (_c = (_a = animateConfig !== null && animateConfig !== void 0 ? animateConfig : this.stateAnimateConfig) !== null && _a !== void 0 ? _a : (_b = this.context) === null || _b === void 0 ? void 0 : _b.stateAnimateConfig) !== null && _c !== void 0 ? _c : DefaultStateAnimateConfig;
|
|
@@ -12154,8 +12266,9 @@ class Graphic extends Node {
|
|
|
12154
12266
|
}
|
|
12155
12267
|
this.useStates(transition.states, hasAnimation);
|
|
12156
12268
|
}
|
|
12157
|
-
setStates(states,
|
|
12269
|
+
setStates(states, options) {
|
|
12158
12270
|
var _a, _b, _c;
|
|
12271
|
+
const { hasAnimation, animateSameStatePatchChange, shouldRefreshSameStatePatch } = this.normalizeSetStatesOptions(options);
|
|
12159
12272
|
const nextStates = (states === null || states === void 0 ? void 0 : states.length) ? states : EMPTY_STATE_NAMES;
|
|
12160
12273
|
const hasCurrentState = !!((_a = this.currentStates) === null || _a === void 0 ? void 0 : _a.length) ||
|
|
12161
12274
|
!!((_b = this.effectiveStates) === null || _b === void 0 ? void 0 : _b.length) ||
|
|
@@ -12169,6 +12282,10 @@ class Graphic extends Node {
|
|
|
12169
12282
|
return;
|
|
12170
12283
|
}
|
|
12171
12284
|
if (this.sameStateNames(this.currentStates, nextStates)) {
|
|
12285
|
+
if (shouldRefreshSameStatePatch) {
|
|
12286
|
+
this.commitSameStatePatchRefresh(nextStates, hasAnimation, animateSameStatePatchChange);
|
|
12287
|
+
return;
|
|
12288
|
+
}
|
|
12172
12289
|
if (this.sharedStateDirty) {
|
|
12173
12290
|
this.refreshSharedStateBeforeRender();
|
|
12174
12291
|
}
|
|
@@ -12177,35 +12294,17 @@ class Graphic extends Node {
|
|
|
12177
12294
|
this.useStates(nextStates, hasAnimation);
|
|
12178
12295
|
}
|
|
12179
12296
|
useStates(states, hasAnimation) {
|
|
12180
|
-
var _a
|
|
12297
|
+
var _a;
|
|
12181
12298
|
if (!states.length) {
|
|
12182
12299
|
this.clearStates(hasAnimation);
|
|
12183
12300
|
return;
|
|
12184
12301
|
}
|
|
12185
12302
|
const previousStates = (_a = this.currentStates) !== null && _a !== void 0 ? _a : EMPTY_STATE_NAMES;
|
|
12186
12303
|
const previousResolvedStatePatch = this.resolvedStatePatch;
|
|
12187
|
-
|
|
12188
|
-
|
|
12189
|
-
|
|
12190
|
-
if (transition) {
|
|
12191
|
-
if (!transition.changed) {
|
|
12192
|
-
return;
|
|
12193
|
-
}
|
|
12194
|
-
resolvedStateAttrs = transition.resolvedStateAttrs;
|
|
12195
|
-
}
|
|
12196
|
-
else {
|
|
12197
|
-
const stateResolveBaseAttrs = ((_b = this.baseAttributes) !== null && _b !== void 0 ? _b : this.attribute);
|
|
12198
|
-
const stateModel = this.createStateModel();
|
|
12199
|
-
(_c = this.stateEngine) === null || _c === void 0 ? void 0 : _c.setResolveContext(this, stateResolveBaseAttrs);
|
|
12200
|
-
transition = stateModel.useStates(states);
|
|
12201
|
-
if (!transition.changed && this.sameStateNames(previousStates, transition.states)) {
|
|
12202
|
-
return;
|
|
12203
|
-
}
|
|
12204
|
-
resolvedStateAttrs =
|
|
12205
|
-
this.stateEngine && this.compiledStateDefinitions
|
|
12206
|
-
? Object.assign({}, this.stateEngine.resolvedPatch) : this.getStateStyleResolver(this.stateMergeMode).resolve(stateResolveBaseAttrs, this.states, this.stateProxy, transition.states, this.stateSort);
|
|
12304
|
+
const { transition, effectiveStates, resolvedStateAttrs, isSimpleLocalTransition } = this.resolveGraphicStateTransition(states, previousStates);
|
|
12305
|
+
if (!transition.changed && this.sameStateNames(previousStates, transition.states)) {
|
|
12306
|
+
return;
|
|
12207
12307
|
}
|
|
12208
|
-
const effectiveStates = (_d = transition.effectiveStates) !== null && _d !== void 0 ? _d : transition.states;
|
|
12209
12308
|
if (!this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, false)) {
|
|
12210
12309
|
return;
|
|
12211
12310
|
}
|
|
@@ -12240,13 +12339,12 @@ class Graphic extends Node {
|
|
|
12240
12339
|
}
|
|
12241
12340
|
}
|
|
12242
12341
|
invalidateResolver() {
|
|
12243
|
-
var _a, _b
|
|
12342
|
+
var _a, _b;
|
|
12244
12343
|
if (!this.stateEngine || !((_a = this.currentStates) === null || _a === void 0 ? void 0 : _a.length) || !this.compiledStateDefinitions) {
|
|
12245
12344
|
return;
|
|
12246
12345
|
}
|
|
12247
|
-
|
|
12248
|
-
this.
|
|
12249
|
-
this.resolverEpoch = ((_c = this.resolverEpoch) !== null && _c !== void 0 ? _c : 0) + 1;
|
|
12346
|
+
this.syncStateResolveContext();
|
|
12347
|
+
this.resolverEpoch = ((_b = this.resolverEpoch) !== null && _b !== void 0 ? _b : 0) + 1;
|
|
12250
12348
|
this.stateEngine.invalidateResolverCache();
|
|
12251
12349
|
const transition = this.stateEngine.applyStates(this.currentStates);
|
|
12252
12350
|
const resolvedStateAttrs = Object.assign({}, this.stateEngine.resolvedPatch);
|
package/es/graphic/graphic.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ICustomPath2D } from './../interface/path';
|
|
2
2
|
import { Matrix, Point, type Dict, type IAABBBounds, type IOBBBounds, type IPointLike } from '@visactor/vutils';
|
|
3
|
-
import type { GraphicType, IAnimateConfig, IGraphicAttribute, IGraphic, IGraphicJson, ISetAttributeContext, ITransform, GraphicReleaseStatus } from '../interface/graphic';
|
|
3
|
+
import type { GraphicType, IAnimateConfig, IGraphicAttribute, IGraphic, IGraphicJson, ISetAttributeContext, ISetStatesOptions, ITransform, GraphicReleaseStatus } from '../interface/graphic';
|
|
4
4
|
import { Node } from './node-tree';
|
|
5
5
|
import type { IAnimate, IAnimateTarget, IGlyphGraphicAttribute, ILayer, IPickerService, IShadowRoot, IStage, IStep, ISymbolClass } from '../interface';
|
|
6
6
|
import { IContainPointMode } from '../common/enums';
|
|
@@ -18,6 +18,16 @@ type AttributeDelta = Map<string, {
|
|
|
18
18
|
prev: unknown;
|
|
19
19
|
next: unknown;
|
|
20
20
|
}>;
|
|
21
|
+
type ResolvedGraphicStateTransition<T> = {
|
|
22
|
+
transition: {
|
|
23
|
+
changed: boolean;
|
|
24
|
+
states: string[];
|
|
25
|
+
effectiveStates?: string[];
|
|
26
|
+
};
|
|
27
|
+
effectiveStates: string[];
|
|
28
|
+
resolvedStateAttrs: Partial<T>;
|
|
29
|
+
isSimpleLocalTransition: boolean;
|
|
30
|
+
};
|
|
21
31
|
export declare const NOWORK_ANIMATE_ATTR: {
|
|
22
32
|
strokeSeg: number;
|
|
23
33
|
boundsPadding: number;
|
|
@@ -235,13 +245,23 @@ export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Par
|
|
|
235
245
|
}): void;
|
|
236
246
|
hasState(stateName?: string): boolean;
|
|
237
247
|
getState(stateName: string): Partial<T> | StateDefinition<T> | undefined;
|
|
238
|
-
protected
|
|
248
|
+
protected getStateResolveBaseAttrs(): Partial<T>;
|
|
249
|
+
protected syncStateResolveContext(stateResolveBaseAttrs?: Partial<T>): Partial<T>;
|
|
250
|
+
protected createStateModel(stateResolveBaseAttrs?: Partial<T>): StateModel<T>;
|
|
239
251
|
protected resolveSimpleLocalStateTransition(states: string[], previousStates: readonly string[]): {
|
|
240
252
|
changed: boolean;
|
|
241
253
|
states: string[];
|
|
242
254
|
effectiveStates: string[];
|
|
243
255
|
resolvedStateAttrs: Partial<T>;
|
|
244
256
|
} | null;
|
|
257
|
+
protected resolveGraphicStateTransition(states: string[], previousStates: readonly string[], forceResolverRefresh?: boolean): ResolvedGraphicStateTransition<T>;
|
|
258
|
+
protected normalizeSetStatesOptions(options?: boolean | ISetStatesOptions): {
|
|
259
|
+
hasAnimation?: boolean;
|
|
260
|
+
animateSameStatePatchChange: boolean;
|
|
261
|
+
shouldRefreshSameStatePatch: boolean;
|
|
262
|
+
};
|
|
263
|
+
protected sameStatePatches(left?: Partial<T>, right?: Partial<T>): boolean;
|
|
264
|
+
protected commitSameStatePatchRefresh(states: string[], hasAnimation?: boolean, animateSameStatePatchChange?: boolean): void;
|
|
245
265
|
protected resolveStateAnimateConfig(animateConfig?: IAnimateConfig): any;
|
|
246
266
|
applyStateAttrs(attrs: Partial<T>, stateNames: string[], hasAnimation?: boolean, isClear?: boolean, animateConfig?: IAnimateConfig, extraAnimateAttrs?: Partial<T>): void;
|
|
247
267
|
updateNormalAttrs(_stateAttrs: Partial<T>): void;
|
|
@@ -254,6 +274,7 @@ export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Par
|
|
|
254
274
|
toggleState(stateName: string, hasAnimation?: boolean): void;
|
|
255
275
|
addState(stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean): void;
|
|
256
276
|
setStates(states?: string[] | null, hasAnimation?: boolean): void;
|
|
277
|
+
setStates(states?: string[] | null, options?: ISetStatesOptions): void;
|
|
257
278
|
useStates(states: string[], hasAnimation?: boolean): void;
|
|
258
279
|
invalidateResolver(): void;
|
|
259
280
|
private sameStateNames;
|