@visactor/vrender-core 1.1.0-alpha.6 → 1.1.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/graphic/graphic.d.ts +4 -2
- package/cjs/graphic/graphic.js +30 -12
- package/cjs/graphic/graphic.js.map +1 -1
- package/cjs/graphic/rect.d.ts +2 -0
- package/cjs/graphic/rect.js +44 -0
- package/cjs/graphic/rect.js.map +1 -1
- package/cjs/graphic/state/state-transition-orchestrator.d.ts +5 -0
- package/cjs/graphic/state/state-transition-orchestrator.js +17 -5
- package/cjs/graphic/state/state-transition-orchestrator.js.map +1 -1
- package/dist/index.es.js +131 -21
- package/es/graphic/graphic.d.ts +4 -2
- package/es/graphic/graphic.js +30 -12
- package/es/graphic/graphic.js.map +1 -1
- package/es/graphic/rect.d.ts +2 -0
- package/es/graphic/rect.js +44 -0
- package/es/graphic/rect.js.map +1 -1
- package/es/graphic/state/state-transition-orchestrator.d.ts +5 -0
- package/es/graphic/state/state-transition-orchestrator.js +17 -5
- package/es/graphic/state/state-transition-orchestrator.js.map +1 -1
- package/package.json +1 -1
package/es/graphic/rect.d.ts
CHANGED
|
@@ -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>;
|
package/es/graphic/rect.js
CHANGED
|
@@ -46,6 +46,50 @@ export class Rect extends Graphic {
|
|
|
46
46
|
needUpdateTag(key) {
|
|
47
47
|
return super.needUpdateTag(key, RECT_UPDATE_TAG_KEY);
|
|
48
48
|
}
|
|
49
|
+
shouldSkipStateTransitionDefaultAttribute(key, targetAttrs) {
|
|
50
|
+
var _a;
|
|
51
|
+
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];
|
|
52
|
+
switch (key) {
|
|
53
|
+
case "width":
|
|
54
|
+
return isNilValue("width") && hasValue("x") && hasValue("x1");
|
|
55
|
+
|
|
56
|
+
case "height":
|
|
57
|
+
return isNilValue("height") && hasValue("y") && hasValue("y1");
|
|
58
|
+
|
|
59
|
+
case "x1":
|
|
60
|
+
return isNilValue("x1") && hasValue("x") && hasValue("width");
|
|
61
|
+
|
|
62
|
+
case "y1":
|
|
63
|
+
return isNilValue("y1") && hasValue("y") && hasValue("height");
|
|
64
|
+
|
|
65
|
+
default:
|
|
66
|
+
return !1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
getStateTransitionDefaultAttribute(key, targetAttrs) {
|
|
70
|
+
var _a;
|
|
71
|
+
const attrs = null !== (_a = null != targetAttrs ? targetAttrs : this.baseAttributes) && void 0 !== _a ? _a : this.attribute, getNumber = attrKey => {
|
|
72
|
+
const value = attrs[attrKey];
|
|
73
|
+
return "number" == typeof value && Number.isFinite(value) ? value : void 0;
|
|
74
|
+
}, x = getNumber("x"), y = getNumber("y"), x1 = getNumber("x1"), y1 = getNumber("y1"), width = getNumber("width"), height = getNumber("height");
|
|
75
|
+
switch (key) {
|
|
76
|
+
case "width":
|
|
77
|
+
if (null == width && null != x && null != x1) return x1 - x;
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
case "height":
|
|
81
|
+
if (null == height && null != y && null != y1) return y1 - y;
|
|
82
|
+
break;
|
|
83
|
+
|
|
84
|
+
case "x1":
|
|
85
|
+
if (null == x1 && null != x && null != width) return x + width;
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case "y1":
|
|
89
|
+
if (null == y1 && null != y && null != height) return y + height;
|
|
90
|
+
}
|
|
91
|
+
return super.getStateTransitionDefaultAttribute(key, targetAttrs);
|
|
92
|
+
}
|
|
49
93
|
toCustomPath() {
|
|
50
94
|
let path = super.toCustomPath();
|
|
51
95
|
if (path) return path;
|
package/es/graphic/rect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/rect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAG9F,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,sBAAsB,CAAC,CAAC;AAEvG,MAAM,OAAO,IAAK,SAAQ,OAA8B;IAKtD,YAAY,MAA6B;QACvC,KAAK,CAAC,MAAM,CAAC,CAAC;QALhB,SAAI,GAAgB,MAAM,CAAC;QAMzB,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC;IACrC,CAAC;IAED,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;IACO,QAAQ;QACd,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Bounds } 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,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAE9F,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,cA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H,OAAO,IAAI,IAAI,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IACzC,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AA3IM,wBAAmB,GAAG,mBAAmB,CAAC;AA8InD,MAAM,UAAU,UAAU,CAAC,UAAiC;IAC1D,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC","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>;
|
|
@@ -23,11 +23,21 @@ export class StateTransitionOrchestrator {
|
|
|
23
23
|
noAnimateAttrs: {}
|
|
24
24
|
};
|
|
25
25
|
if (!hasAnimation) return plan;
|
|
26
|
-
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
|
|
26
|
+
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) => {
|
|
27
|
+
if (noWorkAnimateAttr[key]) return plan.jumpAttrs[key] = value, void (plan.noAnimateAttrs[key] = value);
|
|
28
|
+
if (isClear && void 0 === value) {
|
|
29
|
+
if (null == shouldSkipDefaultAttribute ? void 0 : shouldSkipDefaultAttribute(key, targetAttrs)) return;
|
|
30
|
+
plan.animateAttrs[key] = getDefaultAttribute ? getDefaultAttribute(key) : value;
|
|
31
|
+
} else plan.animateAttrs[key] = value;
|
|
32
|
+
};
|
|
27
33
|
for (const key in targetAttrs) {
|
|
28
34
|
if (!Object.prototype.hasOwnProperty.call(targetAttrs, key)) continue;
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
assignTransitionAttr(key, targetAttrs[key]);
|
|
36
|
+
}
|
|
37
|
+
const extraAnimateAttrs = options.extraAnimateAttrs;
|
|
38
|
+
if (extraAnimateAttrs) for (const key in extraAnimateAttrs) {
|
|
39
|
+
const hasTargetAttr = Object.prototype.hasOwnProperty.call(targetAttrs, key);
|
|
40
|
+
!Object.prototype.hasOwnProperty.call(extraAnimateAttrs, key) || hasTargetAttr && void 0 !== targetAttrs[key] || assignTransitionAttr(key, extraAnimateAttrs[key]);
|
|
31
41
|
}
|
|
32
42
|
return plan;
|
|
33
43
|
}
|
|
@@ -55,12 +65,14 @@ export class StateTransitionOrchestrator {
|
|
|
55
65
|
}), plan;
|
|
56
66
|
}
|
|
57
67
|
applyClearTransition(graphic, targetAttrs, hasAnimation, stateNames, options = {}) {
|
|
58
|
-
var _a, _b;
|
|
68
|
+
var _a, _b, _c, _d;
|
|
59
69
|
const plan = this.analyzeTransition({}, targetAttrs, stateNames, hasAnimation, {
|
|
60
70
|
noWorkAnimateAttr: null === (_a = graphic.getNoWorkAnimateAttr) || void 0 === _a ? void 0 : _a.call(graphic),
|
|
61
71
|
isClear: !0,
|
|
62
72
|
getDefaultAttribute: null === (_b = graphic.getDefaultAttribute) || void 0 === _b ? void 0 : _b.bind(graphic),
|
|
63
|
-
|
|
73
|
+
shouldSkipDefaultAttribute: null !== (_c = options.shouldSkipDefaultAttribute) && void 0 !== _c ? _c : null === (_d = graphic.shouldSkipStateTransitionDefaultAttribute) || void 0 === _d ? void 0 : _d.bind(graphic),
|
|
74
|
+
animateConfig: options.animateConfig,
|
|
75
|
+
extraAnimateAttrs: options.extraAnimateAttrs
|
|
64
76
|
});
|
|
65
77
|
return this.applyTransition(graphic, plan, hasAnimation, options);
|
|
66
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/state/state-transition-orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;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,MAAM,OAAO,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,EA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ACrC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;CACF","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,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;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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AO,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","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"]}
|