@visactor/vrender-core 1.1.0-alpha.17 → 1.1.0-alpha.18

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.
@@ -1,6 +1,6 @@
1
1
  import type { ICustomPath2D } from './../interface/path';
2
2
  import { Matrix, Point, type Dict, type IAABBBounds, type IOBBBounds, type IPointLike } from '@visactor/vutils';
3
- import type { GraphicType, IAnimateConfig, IGraphicAttribute, IGraphic, IGraphicJson, ISetAttributeContext, ITransform, GraphicReleaseStatus } from '../interface/graphic';
3
+ import type { GraphicType, IAnimateConfig, IGraphicAttribute, IGraphic, IGraphicJson, ISetAttributeContext, ISetStatesOptions, ITransform, GraphicReleaseStatus } from '../interface/graphic';
4
4
  import { Node } from './node-tree';
5
5
  import type { IAnimate, IAnimateTarget, IGlyphGraphicAttribute, ILayer, IPickerService, IShadowRoot, IStage, IStep, ISymbolClass } from '../interface';
6
6
  import { IContainPointMode } from '../common/enums';
@@ -18,6 +18,16 @@ type AttributeDelta = Map<string, {
18
18
  prev: unknown;
19
19
  next: unknown;
20
20
  }>;
21
+ type ResolvedGraphicStateTransition<T> = {
22
+ transition: {
23
+ changed: boolean;
24
+ states: string[];
25
+ effectiveStates?: string[];
26
+ };
27
+ effectiveStates: string[];
28
+ resolvedStateAttrs: Partial<T>;
29
+ isSimpleLocalTransition: boolean;
30
+ };
21
31
  export declare const NOWORK_ANIMATE_ATTR: {
22
32
  strokeSeg: number;
23
33
  boundsPadding: number;
@@ -242,6 +252,14 @@ export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Par
242
252
  effectiveStates: string[];
243
253
  resolvedStateAttrs: Partial<T>;
244
254
  } | null;
255
+ protected resolveGraphicStateTransition(states: string[], previousStates: readonly string[], forceResolverRefresh?: boolean): ResolvedGraphicStateTransition<T>;
256
+ protected normalizeSetStatesOptions(options?: boolean | ISetStatesOptions): {
257
+ hasAnimation?: boolean;
258
+ animateSameStatePatchChange: boolean;
259
+ shouldRefreshSameStatePatch: boolean;
260
+ };
261
+ protected sameStatePatches(left?: Partial<T>, right?: Partial<T>): boolean;
262
+ protected commitSameStatePatchRefresh(states: string[], hasAnimation?: boolean, animateSameStatePatchChange?: boolean): void;
245
263
  protected resolveStateAnimateConfig(animateConfig?: IAnimateConfig): any;
246
264
  applyStateAttrs(attrs: Partial<T>, stateNames: string[], hasAnimation?: boolean, isClear?: boolean, animateConfig?: IAnimateConfig, extraAnimateAttrs?: Partial<T>): void;
247
265
  updateNormalAttrs(_stateAttrs: Partial<T>): void;
@@ -254,6 +272,7 @@ export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Par
254
272
  toggleState(stateName: string, hasAnimation?: boolean): void;
255
273
  addState(stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean): void;
256
274
  setStates(states?: string[] | null, hasAnimation?: boolean): void;
275
+ setStates(states?: string[] | null, options?: ISetStatesOptions): void;
257
276
  useStates(states: string[], hasAnimation?: boolean): void;
258
277
  invalidateResolver(): void;
259
278
  private sameStateNames;
@@ -917,6 +917,66 @@ class Graphic extends node_tree_1.Node {
917
917
  resolvedStateAttrs: resolvedStateAttrs
918
918
  };
919
919
  }
920
+ resolveGraphicStateTransition(states, previousStates, forceResolverRefresh = !1) {
921
+ var _a, _b, _c, _d;
922
+ let transition = this.resolveSimpleLocalStateTransition(states, previousStates);
923
+ const isSimpleLocalTransition = !!transition;
924
+ let resolvedStateAttrs;
925
+ if (transition) resolvedStateAttrs = transition.resolvedStateAttrs; else {
926
+ const stateResolveBaseAttrs = null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : this.attribute, stateModel = this.createStateModel();
927
+ null === (_b = this.stateEngine) || void 0 === _b || _b.setResolveContext(this, stateResolveBaseAttrs),
928
+ forceResolverRefresh && (null === (_c = this.stateEngine) || void 0 === _c || _c.invalidateResolverCache()),
929
+ transition = stateModel.useStates(states), resolvedStateAttrs = this.stateEngine && this.compiledStateDefinitions ? Object.assign({}, this.stateEngine.resolvedPatch) : this.getStateStyleResolver(this.stateMergeMode).resolve(stateResolveBaseAttrs, this.states, this.stateProxy, transition.states, this.stateSort);
930
+ }
931
+ return {
932
+ transition: transition,
933
+ effectiveStates: null !== (_d = transition.effectiveStates) && void 0 !== _d ? _d : transition.states,
934
+ resolvedStateAttrs: resolvedStateAttrs,
935
+ isSimpleLocalTransition: isSimpleLocalTransition
936
+ };
937
+ }
938
+ normalizeSetStatesOptions(options) {
939
+ return options && "object" == typeof options ? {
940
+ hasAnimation: options.animate,
941
+ animateSameStatePatchChange: !0 === options.animateSameStatePatchChange,
942
+ shouldRefreshSameStatePatch: !0
943
+ } : {
944
+ hasAnimation: "boolean" == typeof options ? options : void 0,
945
+ animateSameStatePatchChange: !1,
946
+ shouldRefreshSameStatePatch: !1
947
+ };
948
+ }
949
+ sameStatePatches(left, right) {
950
+ const leftRecord = null != left ? left : {}, rightRecord = null != right ? right : {}, keys = new Set([ ...Object.keys(leftRecord), ...Object.keys(rightRecord) ]);
951
+ for (const key of keys) {
952
+ if (Object.prototype.hasOwnProperty.call(leftRecord, key) !== Object.prototype.hasOwnProperty.call(rightRecord, key)) return !1;
953
+ if (!areAttributeValuesEqual(leftRecord[key], rightRecord[key])) return !1;
954
+ }
955
+ return !0;
956
+ }
957
+ commitSameStatePatchRefresh(states, hasAnimation, animateSameStatePatchChange = !1) {
958
+ var _a;
959
+ const previousStates = null !== (_a = this.currentStates) && void 0 !== _a ? _a : EMPTY_STATE_NAMES, previousResolvedStatePatch = this.resolvedStatePatch, {transition: transition, effectiveStates: effectiveStates, resolvedStateAttrs: resolvedStateAttrs, isSimpleLocalTransition: isSimpleLocalTransition} = this.resolveGraphicStateTransition(states, previousStates, !0), patchChanged = !this.sameStatePatches(previousResolvedStatePatch, resolvedStateAttrs);
960
+ if ((!patchChanged || this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) && (this.currentStates = transition.states,
961
+ this.effectiveStates = isSimpleLocalTransition ? effectiveStates : [ ...effectiveStates ],
962
+ this.resolvedStatePatch = resolvedStateAttrs, this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(),
963
+ patchChanged)) {
964
+ if (this.stage) {
965
+ const perfMonitor = (0, state_perf_monitor_1.getActiveStageStatePerfMonitor)(this.stage);
966
+ null == perfMonitor || perfMonitor.incrementCounter("stateCommits"), null == perfMonitor || perfMonitor.recordEvent("state-commit", {
967
+ graphicId: this._uid,
968
+ targetStates: [ ...transition.states ]
969
+ });
970
+ }
971
+ hasAnimation && animateSameStatePatchChange ? (this._syncFinalAttributeFromStaticTruth(),
972
+ this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !1, void 0, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch))) : (this.stopStateAnimates(),
973
+ this.attributeMayContainTransientAttrs ? this._restoreAttributeFromStaticTruth({
974
+ type: enums_1.AttributeUpdateType.STATE
975
+ }) : this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, this.resolvedStatePatch, {
976
+ type: enums_1.AttributeUpdateType.STATE
977
+ }), this.emitStateUpdateEvent());
978
+ }
979
+ }
920
980
  resolveStateAnimateConfig(animateConfig) {
921
981
  var _a, _b, _c;
922
982
  return null !== (_c = null !== (_a = null != animateConfig ? animateConfig : this.stateAnimateConfig) && void 0 !== _a ? _a : null === (_b = this.context) || void 0 === _b ? void 0 : _b.stateAnimateConfig) && void 0 !== _c ? _c : config_2.DefaultStateAnimateConfig;
@@ -993,32 +1053,22 @@ class Graphic extends node_tree_1.Node {
993
1053
  const transition = this.createStateModel().addState(stateName, keepCurrentStates);
994
1054
  transition.changed && this.useStates(transition.states, hasAnimation);
995
1055
  }
996
- setStates(states, hasAnimation) {
1056
+ setStates(states, options) {
997
1057
  var _a, _b, _c;
998
- const nextStates = (null == states ? void 0 : states.length) ? states : EMPTY_STATE_NAMES, hasCurrentState = !!((null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || (null === (_b = this.effectiveStates) || void 0 === _b ? void 0 : _b.length) || this.resolvedStatePatch || (null === (_c = this.registeredActiveScopes) || void 0 === _c ? void 0 : _c.size));
999
- if (nextStates.length) this.sameStateNames(this.currentStates, nextStates) ? this.sharedStateDirty && this.refreshSharedStateBeforeRender() : this.useStates(nextStates, hasAnimation); else {
1058
+ const {hasAnimation: hasAnimation, animateSameStatePatchChange: animateSameStatePatchChange, shouldRefreshSameStatePatch: shouldRefreshSameStatePatch} = this.normalizeSetStatesOptions(options), nextStates = (null == states ? void 0 : states.length) ? states : EMPTY_STATE_NAMES, hasCurrentState = !!((null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || (null === (_b = this.effectiveStates) || void 0 === _b ? void 0 : _b.length) || this.resolvedStatePatch || (null === (_c = this.registeredActiveScopes) || void 0 === _c ? void 0 : _c.size));
1059
+ if (nextStates.length) {
1060
+ if (this.sameStateNames(this.currentStates, nextStates)) return shouldRefreshSameStatePatch ? void this.commitSameStatePatchRefresh(nextStates, hasAnimation, animateSameStatePatchChange) : void (this.sharedStateDirty && this.refreshSharedStateBeforeRender());
1061
+ this.useStates(nextStates, hasAnimation);
1062
+ } else {
1000
1063
  if (!hasCurrentState && !this.sharedStateDirty) return;
1001
1064
  this.clearStates(hasAnimation);
1002
1065
  }
1003
1066
  }
1004
1067
  useStates(states, hasAnimation) {
1005
- var _a, _b, _c, _d;
1068
+ var _a;
1006
1069
  if (!states.length) return void this.clearStates(hasAnimation);
1007
- const previousStates = null !== (_a = this.currentStates) && void 0 !== _a ? _a : EMPTY_STATE_NAMES, previousResolvedStatePatch = this.resolvedStatePatch;
1008
- let transition = this.resolveSimpleLocalStateTransition(states, previousStates);
1009
- const isSimpleLocalTransition = !!transition;
1010
- let resolvedStateAttrs;
1011
- if (transition) {
1012
- if (!transition.changed) return;
1013
- resolvedStateAttrs = transition.resolvedStateAttrs;
1014
- } else {
1015
- const stateResolveBaseAttrs = null !== (_b = this.baseAttributes) && void 0 !== _b ? _b : this.attribute, stateModel = this.createStateModel();
1016
- if (null === (_c = this.stateEngine) || void 0 === _c || _c.setResolveContext(this, stateResolveBaseAttrs),
1017
- transition = stateModel.useStates(states), !transition.changed && this.sameStateNames(previousStates, transition.states)) return;
1018
- resolvedStateAttrs = this.stateEngine && this.compiledStateDefinitions ? Object.assign({}, this.stateEngine.resolvedPatch) : this.getStateStyleResolver(this.stateMergeMode).resolve(stateResolveBaseAttrs, this.states, this.stateProxy, transition.states, this.stateSort);
1019
- }
1020
- const effectiveStates = null !== (_d = transition.effectiveStates) && void 0 !== _d ? _d : transition.states;
1021
- if (this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) {
1070
+ const previousStates = null !== (_a = this.currentStates) && void 0 !== _a ? _a : EMPTY_STATE_NAMES, previousResolvedStatePatch = this.resolvedStatePatch, {transition: transition, effectiveStates: effectiveStates, resolvedStateAttrs: resolvedStateAttrs, isSimpleLocalTransition: isSimpleLocalTransition} = this.resolveGraphicStateTransition(states, previousStates);
1071
+ if ((transition.changed || !this.sameStateNames(previousStates, transition.states)) && this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) {
1022
1072
  if (this.currentStates = transition.states, this.effectiveStates = isSimpleLocalTransition ? effectiveStates : [ ...effectiveStates ],
1023
1073
  this.resolvedStatePatch = resolvedStateAttrs, this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(),
1024
1074
  this.stage) {