@visactor/vrender-core 1.1.0-alpha.5 → 1.1.0-alpha.7

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.
Files changed (76) hide show
  1. package/cjs/canvas/constants.js +1 -2
  2. package/cjs/color-string/index.js +2 -1
  3. package/cjs/common/diff.js +1 -2
  4. package/cjs/common/event-transformer.js +2 -1
  5. package/cjs/common/rect-utils.js +1 -1
  6. package/cjs/common/render-area.js +1 -1
  7. package/cjs/common/render-command-list.js +1 -1
  8. package/cjs/common/render-curve.js +1 -1
  9. package/cjs/common/render-utils.js +1 -1
  10. package/cjs/common/seg-context.js +1 -2
  11. package/cjs/common/simplify.js +1 -1
  12. package/cjs/common/sort.js +1 -1
  13. package/cjs/common/split-path.js +1 -1
  14. package/cjs/common/store.js +1 -1
  15. package/cjs/common/text.js +1 -1
  16. package/cjs/common/utils.js +1 -1
  17. package/cjs/core/camera.js +1 -1
  18. package/cjs/core/constants.js +1 -1
  19. package/cjs/core/core-modules.js +1 -1
  20. package/cjs/core/global-module.js +2 -0
  21. package/cjs/core/global.js +1 -1
  22. package/cjs/core/graphic-utils.js +1 -1
  23. package/cjs/core/index.js +1 -1
  24. package/cjs/core/layer-service.js +2 -1
  25. package/cjs/core/layer.js +1 -1
  26. package/cjs/core/light.js +1 -1
  27. package/cjs/core/stage.js +1 -1
  28. package/cjs/core/window.js +1 -1
  29. package/cjs/graphic/graphic.d.ts +4 -1
  30. package/cjs/graphic/graphic.js +33 -7
  31. package/cjs/graphic/graphic.js.map +1 -1
  32. package/cjs/graphic/rect.d.ts +2 -0
  33. package/cjs/graphic/rect.js +44 -0
  34. package/cjs/graphic/rect.js.map +1 -1
  35. package/cjs/graphic/state/state-transition-orchestrator.d.ts +5 -0
  36. package/cjs/graphic/state/state-transition-orchestrator.js +17 -5
  37. package/cjs/graphic/state/state-transition-orchestrator.js.map +1 -1
  38. package/dist/index.es.js +142 -13
  39. package/es/canvas/constants.js +1 -2
  40. package/es/color-string/index.js +2 -1
  41. package/es/common/diff.js +1 -2
  42. package/es/common/event-transformer.js +2 -1
  43. package/es/common/rect-utils.js +1 -1
  44. package/es/common/render-area.js +1 -1
  45. package/es/common/render-command-list.js +1 -1
  46. package/es/common/render-curve.js +1 -1
  47. package/es/common/render-utils.js +1 -1
  48. package/es/common/seg-context.js +1 -2
  49. package/es/common/simplify.js +1 -1
  50. package/es/common/sort.js +1 -1
  51. package/es/common/split-path.js +1 -1
  52. package/es/common/store.js +1 -1
  53. package/es/common/text.js +1 -1
  54. package/es/common/utils.js +1 -1
  55. package/es/core/camera.js +1 -1
  56. package/es/core/constants.js +1 -1
  57. package/es/core/core-modules.js +1 -1
  58. package/es/core/global-module.js +2 -0
  59. package/es/core/global.js +1 -1
  60. package/es/core/graphic-utils.js +1 -1
  61. package/es/core/index.js +1 -1
  62. package/es/core/layer-service.js +2 -1
  63. package/es/core/layer.js +1 -1
  64. package/es/core/light.js +1 -1
  65. package/es/core/stage.js +1 -1
  66. package/es/core/window.js +1 -1
  67. package/es/graphic/graphic.d.ts +4 -1
  68. package/es/graphic/graphic.js +33 -7
  69. package/es/graphic/graphic.js.map +1 -1
  70. package/es/graphic/rect.d.ts +2 -0
  71. package/es/graphic/rect.js +44 -0
  72. package/es/graphic/rect.js.map +1 -1
  73. package/es/graphic/state/state-transition-orchestrator.d.ts +5 -0
  74. package/es/graphic/state/state-transition-orchestrator.js +17 -5
  75. package/es/graphic/state/state-transition-orchestrator.js.map +1 -1
  76. package/package.json +3 -3
@@ -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,SAAgC,EAChC,SAA0C,EAC1C,UAAuB;QAEvB,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,UAAU,CAAC,EAAE;YAC/C,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;YAClC,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC;YACnC,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,GAAG,CAAC,CAAC;YACxB,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,GAAG,CAAC,CAAC;YAC1B,IAAI,QAA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;SACb;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAA,oCAAuB,EAAC,SAAS,CAAC,CAAC;QAEnE,IAAI,GAAG,IAAI,4BAAY,EAAE,CAAC;QAC1B,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAE/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,IAAI,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IACzC,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AAjFH,oBAkFC;AA/EQ,wBAAmB,GAAG,6BAAmB,CAAC;AAiFnD,SAAgB,UAAU,CAAC,UAAiC;IAC1D,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC;AAFD,gCAEC","file":"rect.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport { Graphic, GRAPHIC_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';\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,OAAO,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC,IAAI,CAAC;IAC7B,CAAC;IAES,gBAAgB,CACxB,SAAgC,EAChC,SAA0C,EAC1C,UAAuB;QAEvB,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,UAAU,CAAC,EAAE;YAC/C,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;YAClC,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC;YACnC,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,GAAG,CAAC,CAAC;YACxB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AAE,CAAC;QAChC,IAAI,IAAI,EAAE;YACR,OAAO,IAAI,CAAC;SACb;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAA,oCAAuB,EAAC,SAAS,CAAC,CAAC;QAEnE,IAAI,GAAG,IAAI,4BAAY,EAAE,CAAC;QAC1B,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAE/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,IAAI,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IACzC,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AA9IH,oBA+IC;AA5IQ,wBAAmB,GAAG,6BAAmB,CAAC;AA8InD,SAAgB,UAAU,CAAC,UAAiC;IAC1D,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC;AAFD,gCAEC","file":"rect.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport { Graphic, GRAPHIC_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,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,E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BAAmB,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;A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AAC,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
  }
@@ -10859,6 +10882,37 @@ class Graphic extends Node {
10859
10882
  });
10860
10883
  return snapshot;
10861
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
+ }
10862
10916
  syncObjectToSnapshot(target, snapshot) {
10863
10917
  const delta = new Map();
10864
10918
  const keySet = new Set([...Object.keys(target), ...Object.keys(snapshot)]);
@@ -11567,22 +11621,36 @@ class Graphic extends Node {
11567
11621
  var _a, _b, _c;
11568
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;
11569
11623
  }
11570
- applyStateAttrs(attrs, stateNames, hasAnimation, isClear, animateConfig) {
11624
+ applyStateAttrs(attrs, stateNames, hasAnimation, isClear, animateConfig, extraAnimateAttrs) {
11571
11625
  const resolvedAnimateConfig = hasAnimation ? this.resolveStateAnimateConfig(animateConfig) : undefined;
11572
- 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;
11573
11633
  if (isClear) {
11574
11634
  this.getStateTransitionOrchestrator().applyClearTransition(this, attrs, hasAnimation, stateNames, transitionOptions);
11575
11635
  return;
11576
11636
  }
11577
11637
  const plan = this.getStateTransitionOrchestrator().analyzeTransition({}, attrs, stateNames, hasAnimation, {
11578
11638
  noWorkAnimateAttr: this.getNoWorkAnimateAttr(),
11579
- animateConfig: resolvedAnimateConfig
11639
+ animateConfig: resolvedAnimateConfig,
11640
+ extraAnimateAttrs: extraAnimateAttrs,
11641
+ shouldSkipDefaultAttribute: this.shouldSkipStateTransitionDefaultAttribute.bind(this)
11580
11642
  });
11581
11643
  this.getStateTransitionOrchestrator().applyTransition(this, plan, hasAnimation, transitionOptions);
11582
11644
  }
11583
11645
  updateNormalAttrs(stateAttrs) {
11584
11646
  this._deprecatedNormalAttrsView = cloneAttributeValue(this.baseAttributes);
11585
11647
  }
11648
+ getStateTransitionDefaultAttribute(key, targetAttrs) {
11649
+ return this.getDefaultAttribute(key);
11650
+ }
11651
+ shouldSkipStateTransitionDefaultAttribute(_key, _targetAttrs) {
11652
+ return false;
11653
+ }
11586
11654
  stopStateAnimates(type = 'end') {
11587
11655
  const stopAnimationState = this.stopAnimationState;
11588
11656
  if (typeof stopAnimationState === 'function') {
@@ -11608,6 +11676,9 @@ class Graphic extends Node {
11608
11676
  clearStates(hasAnimation) {
11609
11677
  var _a, _b, _c;
11610
11678
  const previousStates = this.currentStates ? this.currentStates.slice() : [];
11679
+ const previousResolvedStatePatch = this.resolvedStatePatch
11680
+ ? cloneAttributeValue(this.resolvedStatePatch)
11681
+ : undefined;
11611
11682
  const transition = this.createStateModel().clearStates();
11612
11683
  if (!transition.changed && previousStates.length === 0) {
11613
11684
  this.currentStates = [];
@@ -11634,7 +11705,7 @@ class Graphic extends Node {
11634
11705
  });
11635
11706
  if (hasAnimation) {
11636
11707
  this._syncFinalAttributeFromStaticTruth();
11637
- this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, true);
11708
+ this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, true, undefined, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch));
11638
11709
  }
11639
11710
  else {
11640
11711
  this.stopStateAnimates();
@@ -11668,6 +11739,9 @@ class Graphic extends Node {
11668
11739
  return;
11669
11740
  }
11670
11741
  const previousStates = this.currentStates ? this.currentStates.slice() : [];
11742
+ const previousResolvedStatePatch = this.resolvedStatePatch
11743
+ ? cloneAttributeValue(this.resolvedStatePatch)
11744
+ : undefined;
11671
11745
  const stateResolveBaseAttrs = ((_a = this.baseAttributes) !== null && _a !== void 0 ? _a : this.attribute);
11672
11746
  const stateModel = this.createStateModel();
11673
11747
  (_b = this.stateEngine) === null || _b === void 0 ? void 0 : _b.setResolveContext(this, stateResolveBaseAttrs);
@@ -11693,7 +11767,7 @@ class Graphic extends Node {
11693
11767
  });
11694
11768
  if (hasAnimation) {
11695
11769
  this._syncFinalAttributeFromStaticTruth();
11696
- this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation);
11770
+ this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, false, undefined, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch));
11697
11771
  }
11698
11772
  else {
11699
11773
  this.stopStateAnimates();
@@ -13602,6 +13676,61 @@ class Rect extends Graphic {
13602
13676
  needUpdateTag(key) {
13603
13677
  return super.needUpdateTag(key, RECT_UPDATE_TAG_KEY);
13604
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
+ }
13605
13734
  toCustomPath() {
13606
13735
  let path = super.toCustomPath();
13607
13736
  if (path) {
@@ -1,4 +1,3 @@
1
1
  export const CanvasFactory = Symbol.for("CanvasFactory");
2
2
 
3
- export const Context2dFactory = Symbol.for("Context2dFactory");
4
- //# sourceMappingURL=constants.js.map
3
+ export const Context2dFactory = Symbol.for("Context2dFactory");
@@ -2,4 +2,5 @@ export * from "./interpolate";
2
2
 
3
3
  export * from "./store";
4
4
 
5
- export * from "./colorName";
5
+ export * from "./colorName";
6
+ //# sourceMappingURL=index.js.map
package/es/common/diff.js CHANGED
@@ -8,5 +8,4 @@ export function diff(oldAttrs, newAttrs, getAttr) {
8
8
  void 0 !== value && (diffObj[key] = value);
9
9
  }
10
10
  return diffObj;
11
- }
12
- //# sourceMappingURL=diff.js.map
11
+ }
@@ -113,4 +113,5 @@ export function mapToCanvasPointForCanvas(nativeEvent) {
113
113
  x: nativeEvent._canvasX || 0,
114
114
  y: nativeEvent._canvasY || 0
115
115
  };
116
- }
116
+ }
117
+ //# sourceMappingURL=event-transformer.js.map
@@ -17,4 +17,4 @@ export const normalizeRectAttributes = attribute => {
17
17
  height: height
18
18
  };
19
19
  };
20
- //# sourceMappingURL=rect-utils.js.map
20
+ //# sourceMappingURL=rect-utils.js.map
@@ -61,4 +61,4 @@ function drawAreaBlock(path, topList, bottomList, params) {
61
61
  }
62
62
  path.closePath();
63
63
  }
64
- //# sourceMappingURL=render-area.js.map
64
+ //# sourceMappingURL=render-area.js.map
@@ -6,4 +6,4 @@ export function renderCommandList(commandList, context, x = 0, y = 0, sx = 1, sy
6
6
  commandFuncs[command[0]](command, context, x, y, sx, sy, z);
7
7
  }
8
8
  }
9
- //# sourceMappingURL=render-command-list.js.map
9
+ //# sourceMappingURL=render-command-list.js.map
@@ -93,4 +93,4 @@ export function drawIncrementalAreaSegments(path, lastSeg, segments, params) {
93
93
  path.closePath();
94
94
  }));
95
95
  }
96
- //# sourceMappingURL=render-curve.js.map
96
+ //# sourceMappingURL=render-curve.js.map
@@ -11,4 +11,4 @@ export function drawSegItem(ctx, curve, endPercent, params) {
11
11
  ctx.lineTo(offsetX + p.x, offsetY + p.y, offsetZ);
12
12
  }
13
13
  }
14
- //# sourceMappingURL=render-utils.js.map
14
+ //# sourceMappingURL=render-utils.js.map
@@ -90,5 +90,4 @@ export class ReflectSegContext extends SegContext {
90
90
  clear() {
91
91
  return super.clear();
92
92
  }
93
- }
94
- //# sourceMappingURL=seg-context.js.map
93
+ }
@@ -30,4 +30,4 @@ export function flatten_simplify(points, tolerance, highestQuality) {
30
30
  if (points.length <= 10) return points;
31
31
  return points = highestQuality ? points : simplifyRadialDist(points, void 0 !== tolerance ? tolerance * tolerance : 1);
32
32
  }
33
- //# sourceMappingURL=simplify.js.map
33
+ //# sourceMappingURL=simplify.js.map
package/es/common/sort.js CHANGED
@@ -94,4 +94,4 @@ export function findNextGraphic(graphic, id, defaultZIndex, reverse = !1) {
94
94
  !1)), reverse);
95
95
  return result;
96
96
  }
97
- //# sourceMappingURL=sort.js.map
97
+ //# sourceMappingURL=sort.js.map
@@ -248,4 +248,4 @@ export const splitPath = (path, count) => {
248
248
  }
249
249
  return res;
250
250
  };
251
- //# sourceMappingURL=split-path.js.map
251
+ //# sourceMappingURL=split-path.js.map
@@ -1,2 +1,2 @@
1
1
  class StageStore {}
2
- //# sourceMappingURL=store.js.map
2
+ //# sourceMappingURL=store.js.map
package/es/common/text.js CHANGED
@@ -24,4 +24,4 @@ export function textAttributesToStyle(attrs) {
24
24
  attrs.underline ? style["text-decoration"] = "underline" : attrs.lineThrough && (style["text-decoration"] = "line-through"),
25
25
  attrs.fill && isString(attrs.fill) && (style.color = attrs.fill), style;
26
26
  }
27
- //# sourceMappingURL=text.js.map
27
+ //# sourceMappingURL=text.js.map
@@ -148,4 +148,4 @@ export const calculateLineHeight = (lineHeight, fontSize) => {
148
148
  const _lh = _calculateLineHeight(lineHeight, fontSize);
149
149
  return isNaN(_lh) ? _lh : Math.max(fontSize, _lh);
150
150
  };
151
- //# sourceMappingURL=utils.js.map
151
+ //# sourceMappingURL=utils.js.map
package/es/core/camera.js CHANGED
@@ -66,4 +66,4 @@ export class OrthoCamera {
66
66
  export const registerOrthoCamera = () => {
67
67
  Factory.registerPlugin("OrthoCamera", OrthoCamera);
68
68
  };
69
- //# sourceMappingURL=camera.js.map
69
+ //# sourceMappingURL=camera.js.map
@@ -9,4 +9,4 @@ export const StaticLayerHandlerContribution = Symbol.for("StaticLayerHandlerCont
9
9
  export const DynamicLayerHandlerContribution = Symbol.for("DynamicLayerHandlerContribution");
10
10
 
11
11
  export const VirtualLayerHandlerContribution = Symbol.for("VirtualLayerHandlerContribution");
12
- //# sourceMappingURL=constants.js.map
12
+ //# sourceMappingURL=constants.js.map
@@ -21,4 +21,4 @@ export function bindCoreModules({bind: bind}) {
21
21
  }
22
22
 
23
23
  export default bindCoreModules;
24
- //# sourceMappingURL=core-modules.js.map
24
+ //# sourceMappingURL=core-modules.js.map
@@ -1 +1,3 @@
1
+
2
+
1
3
  //# sourceMappingURL=global-module.js.map
package/es/core/global.js CHANGED
@@ -222,4 +222,4 @@ export class DefaultGlobal extends EventListenerManager {
222
222
  return this._env || this.setEnv("browser"), this.envContribution.copyToClipBoard(text);
223
223
  }
224
224
  }
225
- //# sourceMappingURL=global.js.map
225
+ //# sourceMappingURL=global.js.map
@@ -162,4 +162,4 @@ export class DefaultTransformUtil {
162
162
  return this;
163
163
  }
164
164
  }
165
- //# sourceMappingURL=graphic-utils.js.map
165
+ //# sourceMappingURL=graphic-utils.js.map
package/es/core/index.js CHANGED
@@ -15,4 +15,4 @@ export * from "./layer-service";
15
15
  export * from "./constants";
16
16
 
17
17
  export * from "../interface/core";
18
- //# sourceMappingURL=index.js.map
18
+ //# sourceMappingURL=index.js.map