@visactor/vrender-core 1.1.0-alpha.1 → 1.1.0-alpha.10

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.
@@ -40,6 +40,8 @@ export declare class Rect extends Graphic<IRectGraphicAttribute> implements IRec
40
40
  protected updateAABBBounds(attribute: IRectGraphicAttribute, rectTheme: Required<IRectGraphicAttribute>, aabbBounds: IAABBBounds): import("@visactor/vutils").IBounds;
41
41
  protected needUpdateTags(keys: string[]): boolean;
42
42
  protected needUpdateTag(key: string): boolean;
43
+ protected shouldSkipStateTransitionDefaultAttribute(key: string, targetAttrs?: Partial<IRectGraphicAttribute>): boolean;
44
+ protected getStateTransitionDefaultAttribute(key: string, targetAttrs?: Partial<IRectGraphicAttribute>): any;
43
45
  toCustomPath(): ICustomPath2D;
44
46
  clone(): Rect;
45
47
  getNoWorkAnimateAttr(): Record<string, number>;
@@ -38,6 +38,50 @@ class Rect extends graphic_1.Graphic {
38
38
  needUpdateTag(key) {
39
39
  return super.needUpdateTag(key, RECT_UPDATE_TAG_KEY);
40
40
  }
41
+ shouldSkipStateTransitionDefaultAttribute(key, targetAttrs) {
42
+ var _a;
43
+ const attrs = null !== (_a = null != targetAttrs ? targetAttrs : this.baseAttributes) && void 0 !== _a ? _a : this.attribute, hasValue = attrKey => null != attrs[attrKey], isNilValue = attrKey => null == attrs[attrKey];
44
+ switch (key) {
45
+ case "width":
46
+ return isNilValue("width") && hasValue("x") && hasValue("x1");
47
+
48
+ case "height":
49
+ return isNilValue("height") && hasValue("y") && hasValue("y1");
50
+
51
+ case "x1":
52
+ return isNilValue("x1") && hasValue("x") && hasValue("width");
53
+
54
+ case "y1":
55
+ return isNilValue("y1") && hasValue("y") && hasValue("height");
56
+
57
+ default:
58
+ return !1;
59
+ }
60
+ }
61
+ getStateTransitionDefaultAttribute(key, targetAttrs) {
62
+ var _a;
63
+ const attrs = null !== (_a = null != targetAttrs ? targetAttrs : this.baseAttributes) && void 0 !== _a ? _a : this.attribute, getNumber = attrKey => {
64
+ const value = attrs[attrKey];
65
+ return "number" == typeof value && Number.isFinite(value) ? value : void 0;
66
+ }, x = getNumber("x"), y = getNumber("y"), x1 = getNumber("x1"), y1 = getNumber("y1"), width = getNumber("width"), height = getNumber("height");
67
+ switch (key) {
68
+ case "width":
69
+ if (null == width && null != x && null != x1) return x1 - x;
70
+ break;
71
+
72
+ case "height":
73
+ if (null == height && null != y && null != y1) return y1 - y;
74
+ break;
75
+
76
+ case "x1":
77
+ if (null == x1 && null != x && null != width) return x + width;
78
+ break;
79
+
80
+ case "y1":
81
+ if (null == y1 && null != y && null != height) return y + height;
82
+ }
83
+ return super.getStateTransitionDefaultAttribute(key, targetAttrs);
84
+ }
41
85
  toCustomPath() {
42
86
  let path = super.toCustomPath();
43
87
  if (path) return path;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/rect.ts"],"names":[],"mappings":";;;AACA,uCAAiF;AAEjF,2DAAuD;AACvD,mCAAmC;AACnC,gDAA6C;AAC7C,2CAA+C;AAC/C,qDAA+D;AAC/D,2FAA8F;AAG9F,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,gCAAsB,CAAC,CAAC;AAEvG,MAAa,IAAK,SAAQ,iBAA8B;IAKtD,YAAY,MAA6B;QACvC,KAAK,CAAC,MAAM,CAAC,CAAC;QALhB,SAAI,GAAgB,MAAM,CAAC;QAMzB,IAAI,CAAC,UAAU,GAAG,4BAAgB,CAAC;IACrC,CAAC;IAED,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;IACO,QAAQ;QACd,OAAO,IAAI,CAAC;IAId,CAAC;IAED,eAAe;QACb,OAAO,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC,IAAI,CAAC;IAC7B,CAAC;IAES,gBAAgB,CACxB,SAA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port type { GraphicType, ICustomPath2D, IRect, IRectGraphicAttribute } from '../interface';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { RECT_NUMBER_TYPE } from './constants';\nimport { normalizeRectAttributes } from '../common/rect-utils';\nimport { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds';\nimport { EmptyContext2d } from '../canvas';\n\nconst RECT_UPDATE_TAG_KEY = ['width', 'x1', 'y1', 'height', 'cornerRadius', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Rect extends Graphic<IRectGraphicAttribute> implements IRect {\n type: GraphicType = 'rect';\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IRectGraphicAttribute) {\n super(params);\n this.numberType = RECT_NUMBER_TYPE;\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n return true;\n // 暂时不判断,理论上认为都是合法的,节省性能耗时\n // const { width, x1, y1, height } = this.attribute;\n // return (this._validNumber(width) || this._validNumber(x1)) && (this._validNumber(height) || this._validNumber(y1));\n }\n\n getGraphicTheme(): Required<IRectGraphicAttribute> {\n return getTheme(this).rect;\n }\n\n protected updateAABBBounds(\n attribute: IRectGraphicAttribute,\n rectTheme: Required<IRectGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n let { width, height } = attribute;\n const { x1, y1, x, y } = attribute;\n width = width ?? x1 - x;\n height = height ?? y1 - y;\n if (isFinite(width) || isFinite(height) || isFinite(x) || isFinite(y)) {\n aabbBounds.set(0, 0, width || 0, height || 0);\n }\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfCommonOuterBorder(attribute, rectTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n\n this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1;\n this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1;\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, rectTheme, false, this);\n return aabbBounds;\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, RECT_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, RECT_UPDATE_TAG_KEY);\n }\n\n toCustomPath(): ICustomPath2D {\n // throw new Error('暂不支持');\n let path = super.toCustomPath();\n if (path) {\n return path;\n }\n const attribute = this.attribute;\n const { x, y, width, height } = normalizeRectAttributes(attribute);\n\n path = new CustomPath2D();\n path.moveTo(x, y);\n path.rect(x, y, width, height);\n\n return path;\n }\n\n clone() {\n return new Rect({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Rect.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createRect(attributes: IRectGraphicAttribute): IRect {\n return new Rect(attributes);\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/rect.ts"],"names":[],"mappings":";;;AACA,uCAAiF;AAEjF,2DAAuD;AACvD,mCAAmC;AACnC,gDAA6C;AAC7C,2CAA+C;AAC/C,qDAA+D;AAC/D,2FAA8F;AAE9F,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,gCAAsB,CAAC,CAAC;AAEvG,MAAa,IAAK,SAAQ,iBAA8B;IAKtD,YAAY,MAA6B;QACvC,KAAK,CAAC,MAAM,CAAC,CAAC;QALhB,SAAI,GAAgB,MAAM,CAAC;QAMzB,IAAI,CAAC,UAAU,GAAG,4BAAgB,CAAC;IACrC,CAAC;IAED,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;IACO,QAAQ;QACd,OAAO,IAAI,CAAC;IAId,CAAC;IAED,eAAe;QACb,OA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PHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport type { GraphicType, ICustomPath2D, IRect, IRectGraphicAttribute } from '../interface';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { RECT_NUMBER_TYPE } from './constants';\nimport { normalizeRectAttributes } from '../common/rect-utils';\nimport { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds';\n\nconst RECT_UPDATE_TAG_KEY = ['width', 'x1', 'y1', 'height', 'cornerRadius', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Rect extends Graphic<IRectGraphicAttribute> implements IRect {\n type: GraphicType = 'rect';\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IRectGraphicAttribute) {\n super(params);\n this.numberType = RECT_NUMBER_TYPE;\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n return true;\n // 暂时不判断,理论上认为都是合法的,节省性能耗时\n // const { width, x1, y1, height } = this.attribute;\n // return (this._validNumber(width) || this._validNumber(x1)) && (this._validNumber(height) || this._validNumber(y1));\n }\n\n getGraphicTheme(): Required<IRectGraphicAttribute> {\n return getTheme(this).rect;\n }\n\n protected updateAABBBounds(\n attribute: IRectGraphicAttribute,\n rectTheme: Required<IRectGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n let { width, height } = attribute;\n const { x1, y1, x, y } = attribute;\n width = width ?? x1 - x;\n height = height ?? y1 - y;\n if (isFinite(width) || isFinite(height) || isFinite(x) || isFinite(y)) {\n aabbBounds.set(0, 0, width || 0, height || 0);\n }\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfCommonOuterBorder(attribute, rectTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n\n this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1;\n this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1;\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, rectTheme, false, this);\n return aabbBounds;\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, RECT_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, RECT_UPDATE_TAG_KEY);\n }\n\n protected shouldSkipStateTransitionDefaultAttribute(\n key: string,\n targetAttrs?: Partial<IRectGraphicAttribute>\n ): boolean {\n const attrs = (targetAttrs ?? this.baseAttributes ?? this.attribute) as Partial<IRectGraphicAttribute>;\n const hasValue = (attrKey: keyof IRectGraphicAttribute) => (attrs as any)[attrKey] != null;\n const isNilValue = (attrKey: keyof IRectGraphicAttribute) => (attrs as any)[attrKey] == null;\n\n switch (key) {\n case 'width':\n return isNilValue('width') && hasValue('x') && hasValue('x1');\n case 'height':\n return isNilValue('height') && hasValue('y') && hasValue('y1');\n case 'x1':\n return isNilValue('x1') && hasValue('x') && hasValue('width');\n case 'y1':\n return isNilValue('y1') && hasValue('y') && hasValue('height');\n default:\n return false;\n }\n }\n\n protected getStateTransitionDefaultAttribute(key: string, targetAttrs?: Partial<IRectGraphicAttribute>) {\n const attrs = (targetAttrs ?? this.baseAttributes ?? this.attribute) as Partial<IRectGraphicAttribute>;\n const getNumber = (attrKey: keyof IRectGraphicAttribute) => {\n const value = attrs[attrKey];\n return typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n };\n const x = getNumber('x');\n const y = getNumber('y');\n const x1 = getNumber('x1');\n const y1 = getNumber('y1');\n const width = getNumber('width');\n const height = getNumber('height');\n\n switch (key) {\n case 'width':\n if (width == null && x != null && x1 != null) {\n return x1 - x;\n }\n break;\n case 'height':\n if (height == null && y != null && y1 != null) {\n return y1 - y;\n }\n break;\n case 'x1':\n if (x1 == null && x != null && width != null) {\n return x + width;\n }\n break;\n case 'y1':\n if (y1 == null && y != null && height != null) {\n return y + height;\n }\n break;\n }\n\n return super.getStateTransitionDefaultAttribute(key, targetAttrs);\n }\n\n toCustomPath(): ICustomPath2D {\n // throw new Error('暂不支持');\n let path = super.toCustomPath();\n if (path) {\n return path;\n }\n const attribute = this.attribute;\n const { x, y, width, height } = normalizeRectAttributes(attribute);\n\n path = new CustomPath2D();\n path.moveTo(x, y);\n path.rect(x, y, width, height);\n\n return path;\n }\n\n clone() {\n return new Rect({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Rect.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createRect(attributes: IRectGraphicAttribute): IRect {\n return new Rect(attributes);\n}\n"]}
@@ -11,10 +11,14 @@ export interface IStateTransitionAnalysisOptions {
11
11
  noWorkAnimateAttr?: Record<string, number>;
12
12
  isClear?: boolean;
13
13
  getDefaultAttribute?: (key: string) => unknown;
14
+ shouldSkipDefaultAttribute?: (key: string, targetAttrs: Record<string, unknown>) => boolean;
14
15
  animateConfig?: IAnimateConfig;
16
+ extraAnimateAttrs?: Record<string, unknown>;
15
17
  }
16
18
  export interface IStateTransitionApplyOptions {
17
19
  animateConfig?: IAnimateConfig;
20
+ extraAnimateAttrs?: Record<string, unknown>;
21
+ shouldSkipDefaultAttribute?: (key: string, targetAttrs: Record<string, unknown>) => boolean;
18
22
  }
19
23
  export interface IStateTransitionGraphic<T> {
20
24
  finalAttribute?: Record<string, any>;
@@ -28,6 +32,7 @@ export interface IStateTransitionGraphic<T> {
28
32
  }) => void;
29
33
  getNoWorkAnimateAttr?: () => Record<string, number>;
30
34
  getDefaultAttribute?: (key: string) => unknown;
35
+ shouldSkipStateTransitionDefaultAttribute?: (key: string, targetAttrs?: Partial<T>) => boolean;
31
36
  }
32
37
  export interface IStateTransitionOrchestrator<T> {
33
38
  analyzeTransition: (currentAttrs: Partial<T>, targetAttrs: Partial<T>, stateNames?: string[], hasAnimation?: boolean, options?: IStateTransitionAnalysisOptions) => IStateTransitionPlan<T>;
@@ -27,11 +27,21 @@ class StateTransitionOrchestrator {
27
27
  noAnimateAttrs: {}
28
28
  };
29
29
  if (!hasAnimation) return plan;
30
- const noWorkAnimateAttr = Object.assign(Object.assign({}, null !== (_a = options.noWorkAnimateAttr) && void 0 !== _a ? _a : {}), normalizeNoAnimateAttrConfig(null === (_b = options.animateConfig) || void 0 === _b ? void 0 : _b.noAnimateAttrs)), isClear = !0 === options.isClear, getDefaultAttribute = options.getDefaultAttribute;
30
+ const noWorkAnimateAttr = Object.assign(Object.assign({}, null !== (_a = options.noWorkAnimateAttr) && void 0 !== _a ? _a : {}), normalizeNoAnimateAttrConfig(null === (_b = options.animateConfig) || void 0 === _b ? void 0 : _b.noAnimateAttrs)), isClear = !0 === options.isClear, getDefaultAttribute = options.getDefaultAttribute, shouldSkipDefaultAttribute = options.shouldSkipDefaultAttribute, assignTransitionAttr = (key, value) => {
31
+ if (noWorkAnimateAttr[key]) return plan.jumpAttrs[key] = value, void (plan.noAnimateAttrs[key] = value);
32
+ if (isClear && void 0 === value) {
33
+ if (null == shouldSkipDefaultAttribute ? void 0 : shouldSkipDefaultAttribute(key, targetAttrs)) return;
34
+ plan.animateAttrs[key] = getDefaultAttribute ? getDefaultAttribute(key) : value;
35
+ } else plan.animateAttrs[key] = value;
36
+ };
31
37
  for (const key in targetAttrs) {
32
38
  if (!Object.prototype.hasOwnProperty.call(targetAttrs, key)) continue;
33
- const value = targetAttrs[key];
34
- noWorkAnimateAttr[key] ? (plan.jumpAttrs[key] = value, plan.noAnimateAttrs[key] = value) : plan.animateAttrs[key] = isClear && void 0 === value && getDefaultAttribute ? getDefaultAttribute(key) : value;
39
+ assignTransitionAttr(key, targetAttrs[key]);
40
+ }
41
+ const extraAnimateAttrs = options.extraAnimateAttrs;
42
+ if (extraAnimateAttrs) for (const key in extraAnimateAttrs) {
43
+ const hasTargetAttr = Object.prototype.hasOwnProperty.call(targetAttrs, key);
44
+ !Object.prototype.hasOwnProperty.call(extraAnimateAttrs, key) || hasTargetAttr && void 0 !== targetAttrs[key] || assignTransitionAttr(key, extraAnimateAttrs[key]);
35
45
  }
36
46
  return plan;
37
47
  }
@@ -59,12 +69,14 @@ class StateTransitionOrchestrator {
59
69
  }), plan;
60
70
  }
61
71
  applyClearTransition(graphic, targetAttrs, hasAnimation, stateNames, options = {}) {
62
- var _a, _b;
72
+ var _a, _b, _c, _d;
63
73
  const plan = this.analyzeTransition({}, targetAttrs, stateNames, hasAnimation, {
64
74
  noWorkAnimateAttr: null === (_a = graphic.getNoWorkAnimateAttr) || void 0 === _a ? void 0 : _a.call(graphic),
65
75
  isClear: !0,
66
76
  getDefaultAttribute: null === (_b = graphic.getDefaultAttribute) || void 0 === _b ? void 0 : _b.bind(graphic),
67
- animateConfig: options.animateConfig
77
+ shouldSkipDefaultAttribute: null !== (_c = options.shouldSkipDefaultAttribute) && void 0 !== _c ? _c : null === (_d = graphic.shouldSkipStateTransitionDefaultAttribute) || void 0 === _d ? void 0 : _d.bind(graphic),
78
+ animateConfig: options.animateConfig,
79
+ extraAnimateAttrs: options.extraAnimateAttrs
68
80
  });
69
81
  return this.applyTransition(graphic, plan, hasAnimation, options);
70
82
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/state/state-transition-orchestrator.ts"],"names":[],"mappings":";;;AAAA,iDAAiE;AACjE,8CAAyD;AA2DzD,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,4BAA4B,CAAC,MAAyC;IAC7E,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzB,OAAO,MAAM,CAAC,MAAM,CAAyB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACxD,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACb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ACzD;QAED,OAAO,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,EAAE,IAAI,EAAE,2BAAmB,CAAC,KAAK,EAAE,CAAC,CAAC;QAElF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oBAAoB,CAClB,OAAmC,EACnC,WAAuB,EACvB,YAAsB,EACtB,UAAqB,EACrB,UAAwC,EAAE;;QAE1C,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE;YAC7E,iBAAiB,EAAE,MAAA,OAAO,CAAC,oBAAoB,uDAAI;YACnD,OAAO,EAAE,IAAI;YACb,mBAAmB,EAAE,MAAA,OAAO,CAAC,mBAAmB,0CAAE,IAAI,CAAC,OAAO,CAAC;YAC/D,aAAa,EAAE,OAAO,CAAC,aAAa;SACrC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;CACF;AAzGD,kEAyGC","file":"state-transition-orchestrator.js","sourcesContent":["import { DefaultStateAnimateConfig } from '../../animate/config';\nimport { AttributeUpdateType } from '../../common/enums';\nimport type { IAnimateConfig } from '../../interface/graphic';\n\nexport interface IStateTransitionPlan<T> {\n stateNames?: string[];\n targetAttrs: Partial<T>;\n animateAttrs: Partial<T>;\n jumpAttrs: Partial<T>;\n noAnimateAttrs: Partial<T>;\n}\n\nexport interface IStateTransitionAnalysisOptions {\n noWorkAnimateAttr?: Record<string, number>;\n isClear?: boolean;\n getDefaultAttribute?: (key: string) => unknown;\n animateConfig?: IAnimateConfig;\n}\n\nexport interface IStateTransitionApplyOptions {\n animateConfig?: IAnimateConfig;\n}\n\nexport interface IStateTransitionGraphic<T> {\n finalAttribute?: Record<string, any>;\n applyAnimationState?: (state: string[], animations: Array<Record<string, any>>) => void;\n setAttributesAndPreventAnimate: (\n attrs: Partial<T>,\n forceUpdateTag?: boolean,\n context?: { type: AttributeUpdateType }\n ) => void;\n stopStateAnimates: () => void;\n _emitCustomEvent: (type: string, context?: { type: AttributeUpdateType }) => void;\n getNoWorkAnimateAttr?: () => Record<string, number>;\n getDefaultAttribute?: (key: string) => unknown;\n}\n\nexport interface IStateTransitionOrchestrator<T> {\n analyzeTransition: (\n currentAttrs: Partial<T>,\n targetAttrs: Partial<T>,\n stateNames?: string[],\n hasAnimation?: boolean,\n options?: IStateTransitionAnalysisOptions\n ) => IStateTransitionPlan<T>;\n applyTransition: (\n graphic: IStateTransitionGraphic<T>,\n plan: IStateTransitionPlan<T>,\n hasAnimation?: boolean,\n options?: IStateTransitionApplyOptions\n ) => IStateTransitionPlan<T>;\n applyClearTransition: (\n graphic: IStateTransitionGraphic<T>,\n targetAttrs: Partial<T>,\n hasAnimation?: boolean,\n stateNames?: string[],\n options?: IStateTransitionApplyOptions\n ) => IStateTransitionPlan<T>;\n}\n\nfunction hasOwnKeys(value: object): boolean {\n return Object.keys(value).length > 0;\n}\n\nfunction normalizeNoAnimateAttrConfig(config?: IAnimateConfig['noAnimateAttrs']): Record<string, number> {\n if (!config) {\n return {};\n }\n\n if (Array.isArray(config)) {\n return config.reduce<Record<string, number>>((acc, key) => {\n acc[key] = 1;\n return acc;\n }, {});\n }\n\n return Object.keys(config).reduce<Record<string, number>>((acc, key) => {\n if ((config as Record<string, boolean | number>)[key]) {\n acc[key] = 1;\n }\n return acc;\n }, {});\n}\n\nexport class StateTransitionOrchestrator<T extends Record<string, any> = Record<string, any>>\n implements IStateTransitionOrchestrator<T>\n{\n analyzeTransition(\n _currentAttrs: Partial<T>,\n targetAttrs: Partial<T>,\n stateNames?: string[],\n hasAnimation?: boolean,\n options: IStateTransitionAnalysisOptions = {}\n ): IStateTransitionPlan<T> {\n const plan: IStateTransitionPlan<T> = {\n stateNames,\n targetAttrs: { ...targetAttrs },\n animateAttrs: {},\n jumpAttrs: {},\n noAnimateAttrs: {}\n };\n\n if (!hasAnimation) {\n return plan;\n }\n\n const noWorkAnimateAttr = {\n ...(options.noWorkAnimateAttr ?? {}),\n ...normalizeNoAnimateAttrConfig(options.animateConfig?.noAnimateAttrs)\n };\n const isClear = options.isClear === true;\n const getDefaultAttribute = options.getDefaultAttribute;\n\n for (const key in targetAttrs) {\n if (!Object.prototype.hasOwnProperty.call(targetAttrs, key)) {\n continue;\n }\n\n const value = (targetAttrs as Record<string, any>)[key];\n\n if (noWorkAnimateAttr[key]) {\n (plan.jumpAttrs as Record<string, any>)[key] = value;\n (plan.noAnimateAttrs as Record<string, any>)[key] = value;\n continue;\n }\n\n (plan.animateAttrs as Record<string, any>)[key] =\n isClear && value === undefined && getDefaultAttribute ? getDefaultAttribute(key) : value;\n }\n\n return plan;\n }\n\n applyTransition(\n graphic: IStateTransitionGraphic<T>,\n plan: IStateTransitionPlan<T>,\n hasAnimation?: boolean,\n options: IStateTransitionApplyOptions = {}\n ): IStateTransitionPlan<T> {\n if (hasAnimation) {\n const stateAnimateConfig = options.animateConfig ?? DefaultStateAnimateConfig;\n graphic.applyAnimationState?.(\n ['state'],\n [\n {\n name: 'state',\n animation: {\n type: 'state',\n to: plan.animateAttrs,\n duration: stateAnimateConfig.duration,\n easing: stateAnimateConfig.easing\n }\n }\n ]\n );\n\n if (hasOwnKeys(plan.noAnimateAttrs)) {\n graphic.setAttributesAndPreventAnimate(plan.noAnimateAttrs, false, { type: AttributeUpdateType.STATE });\n }\n } else {\n graphic.stopStateAnimates();\n graphic.setAttributesAndPreventAnimate(plan.targetAttrs, false, { type: AttributeUpdateType.STATE });\n }\n\n if (graphic.finalAttribute) {\n Object.assign(graphic.finalAttribute, plan.targetAttrs);\n }\n\n graphic._emitCustomEvent('afterStateUpdate', { type: AttributeUpdateType.STATE });\n\n return plan;\n }\n\n applyClearTransition(\n graphic: IStateTransitionGraphic<T>,\n targetAttrs: Partial<T>,\n hasAnimation?: boolean,\n stateNames?: string[],\n options: IStateTransitionApplyOptions = {}\n ): IStateTransitionPlan<T> {\n const plan = this.analyzeTransition({}, targetAttrs, stateNames, hasAnimation, {\n noWorkAnimateAttr: graphic.getNoWorkAnimateAttr?.(),\n isClear: true,\n getDefaultAttribute: graphic.getDefaultAttribute?.bind(graphic),\n animateConfig: options.animateConfig\n });\n\n return this.applyTransition(graphic, plan, hasAnimation, options);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/state/state-transition-orchestrator.ts"],"names":[],"mappings":";;;AAAA,iDAAiE;AACjE,8CAAyD;AAgEzD,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,4BAA4B,CAAC,MAAyC;IAC7E,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzB,OAAO,MAAM,CAAC,MAAM,CAAyB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACxD,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACb,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;KACR;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAyB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACrE,IAAK,MAA2C,CAAC,GAAG,CAAC,EAAE;YACrD,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SACd;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED,MAAa,2BAA2B;IAGtC,iBAAiB,CACf,aAAyB,EACzB,WAAuB,EACvB,UAAqB,EACrB,YAAsB,EACtB,UAA2C,EAAE;;QAE7C,MAAM,IAAI,GAA4B;YACpC,UAAU;YACV,WAAW,oBAAO,WAAW,CAAE;YAC/B,YAAY,EAAE,EAAE;YAChB,SAAS,EAAE,EAAE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AC,KAAK,EAAE,CAAC,CAAC;aACzG;SACF;aAAM;YACL,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAC5B,OAAO,CAAC,8BAA8B,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,2BAAmB,CAAC,KAAK,EAAE,CAAC,CAAC;SACtG;QAED,IAAI,OAAO,CAAC,cAAc,EAAE;YAC1B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;SACzD;QAED,OAAO,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,EAAE,IAAI,EAAE,2BAAmB,CAAC,KAAK,EAAE,CAAC,CAAC;QAElF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oBAAoB,CAClB,OAAmC,EACnC,WAAuB,EACvB,YAAsB,EACtB,UAAqB,EACrB,UAAwC,EAAE;;QAE1C,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE;YAC7E,iBAAiB,EAAE,MAAA,OAAO,CAAC,oBAAoB,uDAAI;YACnD,OAAO,EAAE,IAAI;YACb,mBAAmB,EAAE,MAAA,OAAO,CAAC,mBAAmB,0CAAE,IAAI,CAAC,OAAO,CAAC;YAC/D,0BAA0B,EACxB,MAAA,OAAO,CAAC,0BAA0B,mCAAI,MAAA,OAAO,CAAC,yCAAyC,0CAAE,IAAI,CAAC,OAAO,CAAC;YACxG,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;SAC7C,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;CACF;AArID,kEAqIC","file":"state-transition-orchestrator.js","sourcesContent":["import { DefaultStateAnimateConfig } from '../../animate/config';\nimport { AttributeUpdateType } from '../../common/enums';\nimport type { IAnimateConfig } from '../../interface/graphic';\n\nexport interface IStateTransitionPlan<T> {\n stateNames?: string[];\n targetAttrs: Partial<T>;\n animateAttrs: Partial<T>;\n jumpAttrs: Partial<T>;\n noAnimateAttrs: Partial<T>;\n}\n\nexport interface IStateTransitionAnalysisOptions {\n noWorkAnimateAttr?: Record<string, number>;\n isClear?: boolean;\n getDefaultAttribute?: (key: string) => unknown;\n shouldSkipDefaultAttribute?: (key: string, targetAttrs: Record<string, unknown>) => boolean;\n animateConfig?: IAnimateConfig;\n extraAnimateAttrs?: Record<string, unknown>;\n}\n\nexport interface IStateTransitionApplyOptions {\n animateConfig?: IAnimateConfig;\n extraAnimateAttrs?: Record<string, unknown>;\n shouldSkipDefaultAttribute?: (key: string, targetAttrs: Record<string, unknown>) => boolean;\n}\n\nexport interface IStateTransitionGraphic<T> {\n finalAttribute?: Record<string, any>;\n applyAnimationState?: (state: string[], animations: Array<Record<string, any>>) => void;\n setAttributesAndPreventAnimate: (\n attrs: Partial<T>,\n forceUpdateTag?: boolean,\n context?: { type: AttributeUpdateType }\n ) => void;\n stopStateAnimates: () => void;\n _emitCustomEvent: (type: string, context?: { type: AttributeUpdateType }) => void;\n getNoWorkAnimateAttr?: () => Record<string, number>;\n getDefaultAttribute?: (key: string) => unknown;\n shouldSkipStateTransitionDefaultAttribute?: (key: string, targetAttrs?: Partial<T>) => boolean;\n}\n\nexport interface IStateTransitionOrchestrator<T> {\n analyzeTransition: (\n currentAttrs: Partial<T>,\n targetAttrs: Partial<T>,\n stateNames?: string[],\n hasAnimation?: boolean,\n options?: IStateTransitionAnalysisOptions\n ) => IStateTransitionPlan<T>;\n applyTransition: (\n graphic: IStateTransitionGraphic<T>,\n plan: IStateTransitionPlan<T>,\n hasAnimation?: boolean,\n options?: IStateTransitionApplyOptions\n ) => IStateTransitionPlan<T>;\n applyClearTransition: (\n graphic: IStateTransitionGraphic<T>,\n targetAttrs: Partial<T>,\n hasAnimation?: boolean,\n stateNames?: string[],\n options?: IStateTransitionApplyOptions\n ) => IStateTransitionPlan<T>;\n}\n\nfunction hasOwnKeys(value: object): boolean {\n return Object.keys(value).length > 0;\n}\n\nfunction normalizeNoAnimateAttrConfig(config?: IAnimateConfig['noAnimateAttrs']): Record<string, number> {\n if (!config) {\n return {};\n }\n\n if (Array.isArray(config)) {\n return config.reduce<Record<string, number>>((acc, key) => {\n acc[key] = 1;\n return acc;\n }, {});\n }\n\n return Object.keys(config).reduce<Record<string, number>>((acc, key) => {\n if ((config as Record<string, boolean | number>)[key]) {\n acc[key] = 1;\n }\n return acc;\n }, {});\n}\n\nexport class StateTransitionOrchestrator<T extends Record<string, any> = Record<string, any>>\n implements IStateTransitionOrchestrator<T>\n{\n analyzeTransition(\n _currentAttrs: Partial<T>,\n targetAttrs: Partial<T>,\n stateNames?: string[],\n hasAnimation?: boolean,\n options: IStateTransitionAnalysisOptions = {}\n ): IStateTransitionPlan<T> {\n const plan: IStateTransitionPlan<T> = {\n stateNames,\n targetAttrs: { ...targetAttrs },\n animateAttrs: {},\n jumpAttrs: {},\n noAnimateAttrs: {}\n };\n\n if (!hasAnimation) {\n return plan;\n }\n\n const noWorkAnimateAttr = {\n ...(options.noWorkAnimateAttr ?? {}),\n ...normalizeNoAnimateAttrConfig(options.animateConfig?.noAnimateAttrs)\n };\n const isClear = options.isClear === true;\n const getDefaultAttribute = options.getDefaultAttribute;\n const shouldSkipDefaultAttribute = options.shouldSkipDefaultAttribute;\n\n const assignTransitionAttr = (key: string, value: any): void => {\n if (noWorkAnimateAttr[key]) {\n (plan.jumpAttrs as Record<string, any>)[key] = value;\n (plan.noAnimateAttrs as Record<string, any>)[key] = value;\n return;\n }\n\n if (isClear && value === undefined) {\n if (shouldSkipDefaultAttribute?.(key, targetAttrs as Record<string, unknown>)) {\n return;\n }\n (plan.animateAttrs as Record<string, any>)[key] = getDefaultAttribute ? getDefaultAttribute(key) : value;\n return;\n }\n\n (plan.animateAttrs as Record<string, any>)[key] = value;\n };\n\n for (const key in targetAttrs) {\n if (!Object.prototype.hasOwnProperty.call(targetAttrs, key)) {\n continue;\n }\n\n const value = (targetAttrs as Record<string, any>)[key];\n assignTransitionAttr(key, value);\n }\n\n const extraAnimateAttrs = options.extraAnimateAttrs;\n if (extraAnimateAttrs) {\n for (const key in extraAnimateAttrs) {\n const hasTargetAttr = Object.prototype.hasOwnProperty.call(targetAttrs, key);\n if (\n !Object.prototype.hasOwnProperty.call(extraAnimateAttrs, key) ||\n (hasTargetAttr && (targetAttrs as Record<string, any>)[key] !== undefined)\n ) {\n continue;\n }\n assignTransitionAttr(key, (extraAnimateAttrs as Record<string, any>)[key]);\n }\n }\n\n return plan;\n }\n\n applyTransition(\n graphic: IStateTransitionGraphic<T>,\n plan: IStateTransitionPlan<T>,\n hasAnimation?: boolean,\n options: IStateTransitionApplyOptions = {}\n ): IStateTransitionPlan<T> {\n if (hasAnimation) {\n const stateAnimateConfig = options.animateConfig ?? DefaultStateAnimateConfig;\n graphic.applyAnimationState?.(\n ['state'],\n [\n {\n name: 'state',\n animation: {\n type: 'state',\n to: plan.animateAttrs,\n duration: stateAnimateConfig.duration,\n easing: stateAnimateConfig.easing\n }\n }\n ]\n );\n\n if (hasOwnKeys(plan.noAnimateAttrs)) {\n graphic.setAttributesAndPreventAnimate(plan.noAnimateAttrs, false, { type: AttributeUpdateType.STATE });\n }\n } else {\n graphic.stopStateAnimates();\n graphic.setAttributesAndPreventAnimate(plan.targetAttrs, false, { type: AttributeUpdateType.STATE });\n }\n\n if (graphic.finalAttribute) {\n Object.assign(graphic.finalAttribute, plan.targetAttrs);\n }\n\n graphic._emitCustomEvent('afterStateUpdate', { type: AttributeUpdateType.STATE });\n\n return plan;\n }\n\n applyClearTransition(\n graphic: IStateTransitionGraphic<T>,\n targetAttrs: Partial<T>,\n hasAnimation?: boolean,\n stateNames?: string[],\n options: IStateTransitionApplyOptions = {}\n ): IStateTransitionPlan<T> {\n const plan = this.analyzeTransition({}, targetAttrs, stateNames, hasAnimation, {\n noWorkAnimateAttr: graphic.getNoWorkAnimateAttr?.(),\n isClear: true,\n getDefaultAttribute: graphic.getDefaultAttribute?.bind(graphic),\n shouldSkipDefaultAttribute:\n options.shouldSkipDefaultAttribute ?? graphic.shouldSkipStateTransitionDefaultAttribute?.bind(graphic),\n animateConfig: options.animateConfig,\n extraAnimateAttrs: options.extraAnimateAttrs\n });\n\n return this.applyTransition(graphic, plan, hasAnimation, options);\n }\n}\n"]}
package/dist/index.es.js CHANGED
@@ -10227,18 +10227,39 @@ class StateTransitionOrchestrator {
10227
10227
  const noWorkAnimateAttr = Object.assign(Object.assign({}, ((_a = options.noWorkAnimateAttr) !== null && _a !== void 0 ? _a : {})), normalizeNoAnimateAttrConfig((_b = options.animateConfig) === null || _b === void 0 ? void 0 : _b.noAnimateAttrs));
10228
10228
  const isClear = options.isClear === true;
10229
10229
  const getDefaultAttribute = options.getDefaultAttribute;
10230
+ const shouldSkipDefaultAttribute = options.shouldSkipDefaultAttribute;
10231
+ const assignTransitionAttr = (key, value) => {
10232
+ if (noWorkAnimateAttr[key]) {
10233
+ plan.jumpAttrs[key] = value;
10234
+ plan.noAnimateAttrs[key] = value;
10235
+ return;
10236
+ }
10237
+ if (isClear && value === undefined) {
10238
+ if (shouldSkipDefaultAttribute === null || shouldSkipDefaultAttribute === void 0 ? void 0 : shouldSkipDefaultAttribute(key, targetAttrs)) {
10239
+ return;
10240
+ }
10241
+ plan.animateAttrs[key] = getDefaultAttribute ? getDefaultAttribute(key) : value;
10242
+ return;
10243
+ }
10244
+ plan.animateAttrs[key] = value;
10245
+ };
10230
10246
  for (const key in targetAttrs) {
10231
10247
  if (!Object.prototype.hasOwnProperty.call(targetAttrs, key)) {
10232
10248
  continue;
10233
10249
  }
10234
10250
  const value = targetAttrs[key];
10235
- if (noWorkAnimateAttr[key]) {
10236
- plan.jumpAttrs[key] = value;
10237
- plan.noAnimateAttrs[key] = value;
10238
- continue;
10251
+ assignTransitionAttr(key, value);
10252
+ }
10253
+ const extraAnimateAttrs = options.extraAnimateAttrs;
10254
+ if (extraAnimateAttrs) {
10255
+ for (const key in extraAnimateAttrs) {
10256
+ const hasTargetAttr = Object.prototype.hasOwnProperty.call(targetAttrs, key);
10257
+ if (!Object.prototype.hasOwnProperty.call(extraAnimateAttrs, key) ||
10258
+ (hasTargetAttr && targetAttrs[key] !== undefined)) {
10259
+ continue;
10260
+ }
10261
+ assignTransitionAttr(key, extraAnimateAttrs[key]);
10239
10262
  }
10240
- plan.animateAttrs[key] =
10241
- isClear && value === undefined && getDefaultAttribute ? getDefaultAttribute(key) : value;
10242
10263
  }
10243
10264
  return plan;
10244
10265
  }
@@ -10272,12 +10293,14 @@ class StateTransitionOrchestrator {
10272
10293
  return plan;
10273
10294
  }
10274
10295
  applyClearTransition(graphic, targetAttrs, hasAnimation, stateNames, options = {}) {
10275
- var _a, _b;
10296
+ var _a, _b, _c, _d;
10276
10297
  const plan = this.analyzeTransition({}, targetAttrs, stateNames, hasAnimation, {
10277
10298
  noWorkAnimateAttr: (_a = graphic.getNoWorkAnimateAttr) === null || _a === void 0 ? void 0 : _a.call(graphic),
10278
10299
  isClear: true,
10279
10300
  getDefaultAttribute: (_b = graphic.getDefaultAttribute) === null || _b === void 0 ? void 0 : _b.bind(graphic),
10280
- animateConfig: options.animateConfig
10301
+ shouldSkipDefaultAttribute: (_c = options.shouldSkipDefaultAttribute) !== null && _c !== void 0 ? _c : (_d = graphic.shouldSkipStateTransitionDefaultAttribute) === null || _d === void 0 ? void 0 : _d.bind(graphic),
10302
+ animateConfig: options.animateConfig,
10303
+ extraAnimateAttrs: options.extraAnimateAttrs
10281
10304
  });
10282
10305
  return this.applyTransition(graphic, plan, hasAnimation, options);
10283
10306
  }
@@ -10778,12 +10801,16 @@ class Graphic extends Node {
10778
10801
  };
10779
10802
  }
10780
10803
  const sharedCompiledDefinitions = boundScope.effectiveCompiledDefinitions;
10804
+ const sharedStateProxyModeKey = this.stateProxy ? 'shared-missing-only' : 'none';
10805
+ const sharedStateProxyEligibility = this.stateProxy
10806
+ ? (stateName) => !sharedCompiledDefinitions.has(stateName)
10807
+ : undefined;
10781
10808
  if (!hasStates) {
10782
10809
  this.localFallbackCompiledDefinitions = undefined;
10783
10810
  return {
10784
10811
  compiledDefinitions: sharedCompiledDefinitions,
10785
- stateProxyModeKey: this.stateProxy ? 'shared-disabled' : 'none',
10786
- stateProxyEligibility: this.stateProxy ? () => false : undefined
10812
+ stateProxyModeKey: sharedStateProxyModeKey,
10813
+ stateProxyEligibility: sharedStateProxyEligibility
10787
10814
  };
10788
10815
  }
10789
10816
  const localStates = this.states;
@@ -10800,8 +10827,8 @@ class Graphic extends Node {
10800
10827
  this.localFallbackCompiledDefinitions = undefined;
10801
10828
  return {
10802
10829
  compiledDefinitions: sharedCompiledDefinitions,
10803
- stateProxyModeKey: this.stateProxy ? 'shared-disabled' : 'none',
10804
- stateProxyEligibility: this.stateProxy ? () => false : undefined
10830
+ stateProxyModeKey: sharedStateProxyModeKey,
10831
+ stateProxyEligibility: sharedStateProxyEligibility
10805
10832
  };
10806
10833
  }
10807
10834
  const localStatesVersion = this.getLocalStatesVersion();
@@ -10814,9 +10841,7 @@ class Graphic extends Node {
10814
10841
  return {
10815
10842
  compiledDefinitions: this.localFallbackCompiledDefinitions,
10816
10843
  stateProxyModeKey,
10817
- stateProxyEligibility: this.stateProxy
10818
- ? (stateName) => !sharedCompiledDefinitions.has(stateName)
10819
- : undefined
10844
+ stateProxyEligibility: sharedStateProxyEligibility
10820
10845
  };
10821
10846
  }
10822
10847
  recomputeCurrentStatePatch() {
@@ -10857,6 +10882,37 @@ class Graphic extends Node {
10857
10882
  });
10858
10883
  return snapshot;
10859
10884
  }
10885
+ buildRemovedStateAnimationAttrs(targetStateAttrs, previousResolvedStatePatch) {
10886
+ const extraAttrs = {};
10887
+ if (!previousResolvedStatePatch) {
10888
+ return extraAttrs;
10889
+ }
10890
+ const snapshot = this.buildStaticAttributeSnapshot();
10891
+ const staticTargetAttrs = snapshot;
10892
+ Object.keys(previousResolvedStatePatch).forEach(key => {
10893
+ const hasTargetAttr = Object.prototype.hasOwnProperty.call(targetStateAttrs, key);
10894
+ if (hasTargetAttr && targetStateAttrs[key] !== undefined) {
10895
+ return;
10896
+ }
10897
+ const assignFallbackAttr = (value) => {
10898
+ if (value === undefined && this.shouldSkipStateTransitionDefaultAttribute(key, staticTargetAttrs)) {
10899
+ return;
10900
+ }
10901
+ extraAttrs[key] = value === undefined ? value : cloneAttributeValue(value);
10902
+ };
10903
+ if (hasTargetAttr) {
10904
+ assignFallbackAttr(this.getStateTransitionDefaultAttribute(key, staticTargetAttrs));
10905
+ return;
10906
+ }
10907
+ if (Object.prototype.hasOwnProperty.call(snapshot, key)) {
10908
+ const snapshotValue = snapshot[key];
10909
+ assignFallbackAttr(snapshotValue === undefined ? this.getStateTransitionDefaultAttribute(key, staticTargetAttrs) : snapshotValue);
10910
+ return;
10911
+ }
10912
+ assignFallbackAttr(this.getStateTransitionDefaultAttribute(key, staticTargetAttrs));
10913
+ });
10914
+ return extraAttrs;
10915
+ }
10860
10916
  syncObjectToSnapshot(target, snapshot) {
10861
10917
  const delta = new Map();
10862
10918
  const keySet = new Set([...Object.keys(target), ...Object.keys(snapshot)]);
@@ -11565,22 +11621,36 @@ class Graphic extends Node {
11565
11621
  var _a, _b, _c;
11566
11622
  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;
11567
11623
  }
11568
- applyStateAttrs(attrs, stateNames, hasAnimation, isClear, animateConfig) {
11624
+ applyStateAttrs(attrs, stateNames, hasAnimation, isClear, animateConfig, extraAnimateAttrs) {
11569
11625
  const resolvedAnimateConfig = hasAnimation ? this.resolveStateAnimateConfig(animateConfig) : undefined;
11570
- const transitionOptions = resolvedAnimateConfig ? { animateConfig: resolvedAnimateConfig } : undefined;
11626
+ const transitionOptions = resolvedAnimateConfig
11627
+ ? {
11628
+ animateConfig: resolvedAnimateConfig,
11629
+ extraAnimateAttrs: extraAnimateAttrs,
11630
+ shouldSkipDefaultAttribute: this.shouldSkipStateTransitionDefaultAttribute.bind(this)
11631
+ }
11632
+ : undefined;
11571
11633
  if (isClear) {
11572
11634
  this.getStateTransitionOrchestrator().applyClearTransition(this, attrs, hasAnimation, stateNames, transitionOptions);
11573
11635
  return;
11574
11636
  }
11575
11637
  const plan = this.getStateTransitionOrchestrator().analyzeTransition({}, attrs, stateNames, hasAnimation, {
11576
11638
  noWorkAnimateAttr: this.getNoWorkAnimateAttr(),
11577
- animateConfig: resolvedAnimateConfig
11639
+ animateConfig: resolvedAnimateConfig,
11640
+ extraAnimateAttrs: extraAnimateAttrs,
11641
+ shouldSkipDefaultAttribute: this.shouldSkipStateTransitionDefaultAttribute.bind(this)
11578
11642
  });
11579
11643
  this.getStateTransitionOrchestrator().applyTransition(this, plan, hasAnimation, transitionOptions);
11580
11644
  }
11581
11645
  updateNormalAttrs(stateAttrs) {
11582
11646
  this._deprecatedNormalAttrsView = cloneAttributeValue(this.baseAttributes);
11583
11647
  }
11648
+ getStateTransitionDefaultAttribute(key, targetAttrs) {
11649
+ return this.getDefaultAttribute(key);
11650
+ }
11651
+ shouldSkipStateTransitionDefaultAttribute(_key, _targetAttrs) {
11652
+ return false;
11653
+ }
11584
11654
  stopStateAnimates(type = 'end') {
11585
11655
  const stopAnimationState = this.stopAnimationState;
11586
11656
  if (typeof stopAnimationState === 'function') {
@@ -11606,6 +11676,9 @@ class Graphic extends Node {
11606
11676
  clearStates(hasAnimation) {
11607
11677
  var _a, _b, _c;
11608
11678
  const previousStates = this.currentStates ? this.currentStates.slice() : [];
11679
+ const previousResolvedStatePatch = this.resolvedStatePatch
11680
+ ? cloneAttributeValue(this.resolvedStatePatch)
11681
+ : undefined;
11609
11682
  const transition = this.createStateModel().clearStates();
11610
11683
  if (!transition.changed && previousStates.length === 0) {
11611
11684
  this.currentStates = [];
@@ -11632,7 +11705,7 @@ class Graphic extends Node {
11632
11705
  });
11633
11706
  if (hasAnimation) {
11634
11707
  this._syncFinalAttributeFromStaticTruth();
11635
- this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, true);
11708
+ this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, true, undefined, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch));
11636
11709
  }
11637
11710
  else {
11638
11711
  this.stopStateAnimates();
@@ -11666,6 +11739,9 @@ class Graphic extends Node {
11666
11739
  return;
11667
11740
  }
11668
11741
  const previousStates = this.currentStates ? this.currentStates.slice() : [];
11742
+ const previousResolvedStatePatch = this.resolvedStatePatch
11743
+ ? cloneAttributeValue(this.resolvedStatePatch)
11744
+ : undefined;
11669
11745
  const stateResolveBaseAttrs = ((_a = this.baseAttributes) !== null && _a !== void 0 ? _a : this.attribute);
11670
11746
  const stateModel = this.createStateModel();
11671
11747
  (_b = this.stateEngine) === null || _b === void 0 ? void 0 : _b.setResolveContext(this, stateResolveBaseAttrs);
@@ -11691,7 +11767,7 @@ class Graphic extends Node {
11691
11767
  });
11692
11768
  if (hasAnimation) {
11693
11769
  this._syncFinalAttributeFromStaticTruth();
11694
- this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation);
11770
+ this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, false, undefined, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch));
11695
11771
  }
11696
11772
  else {
11697
11773
  this.stopStateAnimates();
@@ -13600,6 +13676,61 @@ class Rect extends Graphic {
13600
13676
  needUpdateTag(key) {
13601
13677
  return super.needUpdateTag(key, RECT_UPDATE_TAG_KEY);
13602
13678
  }
13679
+ shouldSkipStateTransitionDefaultAttribute(key, targetAttrs) {
13680
+ var _a;
13681
+ const attrs = ((_a = targetAttrs !== null && targetAttrs !== void 0 ? targetAttrs : this.baseAttributes) !== null && _a !== void 0 ? _a : this.attribute);
13682
+ const hasValue = (attrKey) => attrs[attrKey] != null;
13683
+ const isNilValue = (attrKey) => attrs[attrKey] == null;
13684
+ switch (key) {
13685
+ case 'width':
13686
+ return isNilValue('width') && hasValue('x') && hasValue('x1');
13687
+ case 'height':
13688
+ return isNilValue('height') && hasValue('y') && hasValue('y1');
13689
+ case 'x1':
13690
+ return isNilValue('x1') && hasValue('x') && hasValue('width');
13691
+ case 'y1':
13692
+ return isNilValue('y1') && hasValue('y') && hasValue('height');
13693
+ default:
13694
+ return false;
13695
+ }
13696
+ }
13697
+ getStateTransitionDefaultAttribute(key, targetAttrs) {
13698
+ var _a;
13699
+ const attrs = ((_a = targetAttrs !== null && targetAttrs !== void 0 ? targetAttrs : this.baseAttributes) !== null && _a !== void 0 ? _a : this.attribute);
13700
+ const getNumber = (attrKey) => {
13701
+ const value = attrs[attrKey];
13702
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
13703
+ };
13704
+ const x = getNumber('x');
13705
+ const y = getNumber('y');
13706
+ const x1 = getNumber('x1');
13707
+ const y1 = getNumber('y1');
13708
+ const width = getNumber('width');
13709
+ const height = getNumber('height');
13710
+ switch (key) {
13711
+ case 'width':
13712
+ if (width == null && x != null && x1 != null) {
13713
+ return x1 - x;
13714
+ }
13715
+ break;
13716
+ case 'height':
13717
+ if (height == null && y != null && y1 != null) {
13718
+ return y1 - y;
13719
+ }
13720
+ break;
13721
+ case 'x1':
13722
+ if (x1 == null && x != null && width != null) {
13723
+ return x + width;
13724
+ }
13725
+ break;
13726
+ case 'y1':
13727
+ if (y1 == null && y != null && height != null) {
13728
+ return y + height;
13729
+ }
13730
+ break;
13731
+ }
13732
+ return super.getStateTransitionDefaultAttribute(key, targetAttrs);
13733
+ }
13603
13734
  toCustomPath() {
13604
13735
  let path = super.toCustomPath();
13605
13736
  if (path) {
@@ -205,4 +205,5 @@ export class EmptyContext2d {
205
205
  release(...params) {
206
206
  this.stack.forEach((m => matrixAllocate.free(m))), this.stack.length = 0;
207
207
  }
208
- }
208
+ }
209
+ //# sourceMappingURL=empty-context.js.map
@@ -2,5 +2,4 @@ export * from "./interpolate";
2
2
 
3
3
  export * from "./store";
4
4
 
5
- export * from "./colorName";
6
- //# sourceMappingURL=index.js.map
5
+ export * from "./colorName";
@@ -1,2 +1,2 @@
1
1
  export const ApplicationContribution = Symbol("ApplicationContribution");
2
- //# sourceMappingURL=application.js.map
2
+ //# sourceMappingURL=application.js.map
@@ -83,4 +83,4 @@ export class AppContext {
83
83
  };
84
84
  }
85
85
  }
86
- //# sourceMappingURL=app-context.js.map
86
+ //# sourceMappingURL=app-context.js.map
@@ -149,6 +149,7 @@ export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Par
149
149
  };
150
150
  protected recomputeCurrentStatePatch(): void;
151
151
  protected buildStaticAttributeSnapshot(): Partial<T>;
152
+ protected buildRemovedStateAnimationAttrs(targetStateAttrs: Partial<T>, previousResolvedStatePatch?: Partial<T>): Partial<T>;
152
153
  protected syncObjectToSnapshot(target: Record<string, any>, snapshot: Record<string, any>): AttributeDelta;
153
154
  protected _syncAttribute(): AttributeDelta;
154
155
  protected _syncFinalAttributeFromStaticTruth(): void;
@@ -210,8 +211,10 @@ export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Par
210
211
  getState(stateName: string): Partial<T> | StateDefinition<T> | undefined;
211
212
  protected createStateModel(): StateModel<T>;
212
213
  protected resolveStateAnimateConfig(animateConfig?: IAnimateConfig): any;
213
- applyStateAttrs(attrs: Partial<T>, stateNames: string[], hasAnimation?: boolean, isClear?: boolean, animateConfig?: IAnimateConfig): void;
214
+ applyStateAttrs(attrs: Partial<T>, stateNames: string[], hasAnimation?: boolean, isClear?: boolean, animateConfig?: IAnimateConfig, extraAnimateAttrs?: Partial<T>): void;
214
215
  updateNormalAttrs(stateAttrs: Partial<T>): void;
216
+ protected getStateTransitionDefaultAttribute(key: string, targetAttrs?: Partial<T>): any;
217
+ protected shouldSkipStateTransitionDefaultAttribute(_key: string, _targetAttrs?: Partial<T>): boolean;
215
218
  protected stopStateAnimates(type?: 'start' | 'end'): void;
216
219
  private getNormalAttribute;
217
220
  clearStates(hasAnimation?: boolean): void;