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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -290,12 +290,10 @@ export class Graphic extends Node {
290
290
  };
291
291
  }
292
292
  recomputeCurrentStatePatch() {
293
- var _a, _b, _c, _d;
293
+ var _a, _b;
294
294
  if (!(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length)) return this.effectiveStates = [],
295
295
  this.resolvedStatePatch = void 0, void this.syncSharedStateActiveRegistrations();
296
- const stateResolveBaseAttrs = null !== (_b = this.baseAttributes) && void 0 !== _b ? _b : this.attribute, stateModel = this.createStateModel();
297
- null === (_c = this.stateEngine) || void 0 === _c || _c.setResolveContext(this, stateResolveBaseAttrs);
298
- const transition = stateModel.useStates(this.currentStates), effectiveStates = null !== (_d = transition.effectiveStates) && void 0 !== _d ? _d : transition.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);
296
+ const stateResolveBaseAttrs = this.getStateResolveBaseAttrs(), transition = this.createStateModel(stateResolveBaseAttrs).useStates(this.currentStates), effectiveStates = null !== (_b = transition.effectiveStates) && void 0 !== _b ? _b : transition.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);
299
297
  this.currentStates = transition.states, this.effectiveStates = [ ...effectiveStates ],
300
298
  this.resolvedStatePatch = resolvedStateAttrs, this.syncSharedStateActiveRegistrations();
301
299
  }
@@ -879,7 +877,16 @@ export class Graphic extends Node {
879
877
  var _a;
880
878
  return null === (_a = this.states) || void 0 === _a ? void 0 : _a[stateName];
881
879
  }
882
- createStateModel() {
880
+ getStateResolveBaseAttrs() {
881
+ var _a;
882
+ return null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : this.attribute;
883
+ }
884
+ syncStateResolveContext(stateResolveBaseAttrs = this.getStateResolveBaseAttrs()) {
885
+ var _a;
886
+ return null === (_a = this.stateEngine) || void 0 === _a || _a.setResolveContext(this, stateResolveBaseAttrs),
887
+ stateResolveBaseAttrs;
888
+ }
889
+ createStateModel(stateResolveBaseAttrs = this.getStateResolveBaseAttrs()) {
883
890
  const {compiledDefinitions: compiledDefinitions, stateProxyEligibility: stateProxyEligibility, stateProxyModeKey: stateProxyModeKey} = this.resolveEffectiveCompiledDefinitions();
884
891
  return this.compiledStateDefinitions = compiledDefinitions, compiledDefinitions ? this.stateEngine && this.stateEngineCompiledDefinitions === compiledDefinitions && this.stateEngineStateProxy === this.stateProxy && this.stateEngineStateSort === this.stateSort && this.stateEngineMergeMode === this.stateMergeMode && this.stateEngineStateProxyModeKey === stateProxyModeKey || (this.stateEngine = new StateEngine({
885
892
  compiledDefinitions: compiledDefinitions,
@@ -892,7 +899,7 @@ export class Graphic extends Node {
892
899
  this.stateEngineStateSort = this.stateSort, this.stateEngineMergeMode = this.stateMergeMode,
893
900
  this.stateEngineStateProxyModeKey = stateProxyModeKey) : (this.stateEngine = void 0,
894
901
  this.stateEngineCompiledDefinitions = void 0, this.stateEngineStateProxyModeKey = void 0),
895
- new StateModel({
902
+ this.syncStateResolveContext(stateResolveBaseAttrs), new StateModel({
896
903
  states: this.states,
897
904
  currentStates: this.currentStates,
898
905
  stateSort: this.stateSort,
@@ -953,6 +960,65 @@ export class Graphic extends Node {
953
960
  resolvedStateAttrs: resolvedStateAttrs
954
961
  };
955
962
  }
963
+ resolveGraphicStateTransition(states, previousStates, forceResolverRefresh = !1) {
964
+ var _a, _b;
965
+ let transition = this.resolveSimpleLocalStateTransition(states, previousStates);
966
+ const isSimpleLocalTransition = !!transition;
967
+ let resolvedStateAttrs;
968
+ if (transition) resolvedStateAttrs = transition.resolvedStateAttrs; else {
969
+ const stateResolveBaseAttrs = this.getStateResolveBaseAttrs(), stateModel = this.createStateModel(stateResolveBaseAttrs);
970
+ forceResolverRefresh && (null === (_a = this.stateEngine) || void 0 === _a || _a.invalidateResolverCache()),
971
+ 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);
972
+ }
973
+ return {
974
+ transition: transition,
975
+ effectiveStates: null !== (_b = transition.effectiveStates) && void 0 !== _b ? _b : transition.states,
976
+ resolvedStateAttrs: resolvedStateAttrs,
977
+ isSimpleLocalTransition: isSimpleLocalTransition
978
+ };
979
+ }
980
+ normalizeSetStatesOptions(options) {
981
+ return options && "object" == typeof options ? {
982
+ hasAnimation: options.animate,
983
+ animateSameStatePatchChange: !0 === options.animateSameStatePatchChange,
984
+ shouldRefreshSameStatePatch: !0
985
+ } : {
986
+ hasAnimation: "boolean" == typeof options ? options : void 0,
987
+ animateSameStatePatchChange: !1,
988
+ shouldRefreshSameStatePatch: !1
989
+ };
990
+ }
991
+ sameStatePatches(left, right) {
992
+ const leftRecord = null != left ? left : {}, rightRecord = null != right ? right : {}, keys = new Set([ ...Object.keys(leftRecord), ...Object.keys(rightRecord) ]);
993
+ for (const key of keys) {
994
+ if (Object.prototype.hasOwnProperty.call(leftRecord, key) !== Object.prototype.hasOwnProperty.call(rightRecord, key)) return !1;
995
+ if (!areAttributeValuesEqual(leftRecord[key], rightRecord[key])) return !1;
996
+ }
997
+ return !0;
998
+ }
999
+ commitSameStatePatchRefresh(states, hasAnimation, animateSameStatePatchChange = !1) {
1000
+ var _a;
1001
+ 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);
1002
+ if ((!patchChanged || this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) && (this.currentStates = transition.states,
1003
+ this.effectiveStates = isSimpleLocalTransition ? effectiveStates : [ ...effectiveStates ],
1004
+ this.resolvedStatePatch = resolvedStateAttrs, this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(),
1005
+ patchChanged)) {
1006
+ if (this.stage) {
1007
+ const perfMonitor = getActiveStageStatePerfMonitor(this.stage);
1008
+ null == perfMonitor || perfMonitor.incrementCounter("stateCommits"), null == perfMonitor || perfMonitor.recordEvent("state-commit", {
1009
+ graphicId: this._uid,
1010
+ targetStates: [ ...transition.states ]
1011
+ });
1012
+ }
1013
+ hasAnimation && animateSameStatePatchChange ? (this._syncFinalAttributeFromStaticTruth(),
1014
+ this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !1, void 0, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch))) : (this.stopStateAnimates(),
1015
+ this.attributeMayContainTransientAttrs ? this._restoreAttributeFromStaticTruth({
1016
+ type: AttributeUpdateType.STATE
1017
+ }) : this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, this.resolvedStatePatch, {
1018
+ type: AttributeUpdateType.STATE
1019
+ }), this.emitStateUpdateEvent());
1020
+ }
1021
+ }
956
1022
  resolveStateAnimateConfig(animateConfig) {
957
1023
  var _a, _b, _c;
958
1024
  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 : DefaultStateAnimateConfig;
@@ -1029,32 +1095,22 @@ export class Graphic extends Node {
1029
1095
  const transition = this.createStateModel().addState(stateName, keepCurrentStates);
1030
1096
  transition.changed && this.useStates(transition.states, hasAnimation);
1031
1097
  }
1032
- setStates(states, hasAnimation) {
1098
+ setStates(states, options) {
1033
1099
  var _a, _b, _c;
1034
- 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));
1035
- if (nextStates.length) this.sameStateNames(this.currentStates, nextStates) ? this.sharedStateDirty && this.refreshSharedStateBeforeRender() : this.useStates(nextStates, hasAnimation); else {
1100
+ 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));
1101
+ if (nextStates.length) {
1102
+ if (this.sameStateNames(this.currentStates, nextStates)) return shouldRefreshSameStatePatch ? void this.commitSameStatePatchRefresh(nextStates, hasAnimation, animateSameStatePatchChange) : void (this.sharedStateDirty && this.refreshSharedStateBeforeRender());
1103
+ this.useStates(nextStates, hasAnimation);
1104
+ } else {
1036
1105
  if (!hasCurrentState && !this.sharedStateDirty) return;
1037
1106
  this.clearStates(hasAnimation);
1038
1107
  }
1039
1108
  }
1040
1109
  useStates(states, hasAnimation) {
1041
- var _a, _b, _c, _d;
1110
+ var _a;
1042
1111
  if (!states.length) return void this.clearStates(hasAnimation);
1043
- const previousStates = null !== (_a = this.currentStates) && void 0 !== _a ? _a : EMPTY_STATE_NAMES, previousResolvedStatePatch = this.resolvedStatePatch;
1044
- let transition = this.resolveSimpleLocalStateTransition(states, previousStates);
1045
- const isSimpleLocalTransition = !!transition;
1046
- let resolvedStateAttrs;
1047
- if (transition) {
1048
- if (!transition.changed) return;
1049
- resolvedStateAttrs = transition.resolvedStateAttrs;
1050
- } else {
1051
- const stateResolveBaseAttrs = null !== (_b = this.baseAttributes) && void 0 !== _b ? _b : this.attribute, stateModel = this.createStateModel();
1052
- if (null === (_c = this.stateEngine) || void 0 === _c || _c.setResolveContext(this, stateResolveBaseAttrs),
1053
- transition = stateModel.useStates(states), !transition.changed && this.sameStateNames(previousStates, transition.states)) return;
1054
- resolvedStateAttrs = this.stateEngine && this.compiledStateDefinitions ? Object.assign({}, this.stateEngine.resolvedPatch) : this.getStateStyleResolver(this.stateMergeMode).resolve(stateResolveBaseAttrs, this.states, this.stateProxy, transition.states, this.stateSort);
1055
- }
1056
- const effectiveStates = null !== (_d = transition.effectiveStates) && void 0 !== _d ? _d : transition.states;
1057
- if (this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) {
1112
+ 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);
1113
+ if ((transition.changed || !this.sameStateNames(previousStates, transition.states)) && this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) {
1058
1114
  if (this.currentStates = transition.states, this.effectiveStates = isSimpleLocalTransition ? effectiveStates : [ ...effectiveStates ],
1059
1115
  this.resolvedStatePatch = resolvedStateAttrs, this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(),
1060
1116
  this.stage) {
@@ -1073,10 +1129,10 @@ export class Graphic extends Node {
1073
1129
  }
1074
1130
  }
1075
1131
  invalidateResolver() {
1076
- var _a, _b, _c;
1132
+ var _a, _b;
1077
1133
  if (!this.stateEngine || !(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || !this.compiledStateDefinitions) return;
1078
- const stateResolveBaseAttrs = null !== (_b = this.baseAttributes) && void 0 !== _b ? _b : this.attribute;
1079
- this.stateEngine.setResolveContext(this, stateResolveBaseAttrs), this.resolverEpoch = (null !== (_c = this.resolverEpoch) && void 0 !== _c ? _c : 0) + 1,
1134
+ this.syncStateResolveContext();
1135
+ this.resolverEpoch = (null !== (_b = this.resolverEpoch) && void 0 !== _b ? _b : 0) + 1,
1080
1136
  this.stateEngine.invalidateResolverCache();
1081
1137
  const transition = this.stateEngine.applyStates(this.currentStates), resolvedStateAttrs = Object.assign({}, this.stateEngine.resolvedPatch);
1082
1138
  this.effectiveStates = [ ...transition.effectiveStates ], this.resolvedStatePatch = resolvedStateAttrs,