@visactor/vrender-core 1.1.0-alpha.2 → 1.1.0-alpha.20

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 (140) hide show
  1. package/cjs/canvas/constants.js +2 -1
  2. package/cjs/color-string/index.js +1 -2
  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.d.ts +4 -1
  28. package/cjs/core/stage.js +24 -12
  29. package/cjs/core/stage.js.map +1 -1
  30. package/cjs/core/window.js +1 -1
  31. package/cjs/graphic/graphic-service/graphic-service.d.ts +4 -0
  32. package/cjs/graphic/graphic-service/graphic-service.js +6 -5
  33. package/cjs/graphic/graphic-service/graphic-service.js.map +1 -1
  34. package/cjs/graphic/graphic.d.ts +72 -11
  35. package/cjs/graphic/graphic.js +509 -158
  36. package/cjs/graphic/graphic.js.map +1 -1
  37. package/cjs/graphic/group.d.ts +5 -1
  38. package/cjs/graphic/group.js +37 -18
  39. package/cjs/graphic/group.js.map +1 -1
  40. package/cjs/graphic/rect.d.ts +2 -0
  41. package/cjs/graphic/rect.js +44 -0
  42. package/cjs/graphic/rect.js.map +1 -1
  43. package/cjs/graphic/state/shared-state-refresh.js +4 -3
  44. package/cjs/graphic/state/shared-state-refresh.js.map +1 -1
  45. package/cjs/graphic/state/shared-state-scope.js +1 -1
  46. package/cjs/graphic/state/shared-state-scope.js.map +1 -1
  47. package/cjs/graphic/state/state-engine.js +2 -2
  48. package/cjs/graphic/state/state-engine.js.map +1 -1
  49. package/cjs/graphic/state/state-perf-monitor.d.ts +1 -0
  50. package/cjs/graphic/state/state-perf-monitor.js +9 -2
  51. package/cjs/graphic/state/state-perf-monitor.js.map +1 -1
  52. package/cjs/graphic/state/state-style-resolver.d.ts +0 -9
  53. package/cjs/graphic/state/state-style-resolver.js +0 -23
  54. package/cjs/graphic/state/state-style-resolver.js.map +1 -1
  55. package/cjs/graphic/state/state-transition-orchestrator.d.ts +5 -0
  56. package/cjs/graphic/state/state-transition-orchestrator.js +17 -5
  57. package/cjs/graphic/state/state-transition-orchestrator.js.map +1 -1
  58. package/cjs/interface/animation/animate.d.ts +1 -0
  59. package/cjs/interface/animation/animate.js.map +1 -1
  60. package/cjs/interface/graphic.d.ts +9 -0
  61. package/cjs/interface/graphic.js.map +1 -1
  62. package/cjs/interface/node-tree.js.map +1 -1
  63. package/cjs/plugins/builtin-plugin/dirty-bounds-plugin.d.ts +4 -1
  64. package/cjs/plugins/builtin-plugin/dirty-bounds-plugin.js +20 -10
  65. package/cjs/plugins/builtin-plugin/dirty-bounds-plugin.js.map +1 -1
  66. package/cjs/plugins/builtin-plugin/flex-layout-plugin.js +3 -2
  67. package/cjs/plugins/builtin-plugin/flex-layout-plugin.js.map +1 -1
  68. package/cjs/render/contributions/render/base-render.js +8 -7
  69. package/cjs/render/contributions/render/base-render.js.map +1 -1
  70. package/dist/index.es.js +1134 -279
  71. package/es/canvas/constants.js +2 -1
  72. package/es/color-string/index.js +1 -2
  73. package/es/common/diff.js +1 -2
  74. package/es/common/event-transformer.js +2 -1
  75. package/es/common/rect-utils.js +1 -1
  76. package/es/common/render-area.js +1 -1
  77. package/es/common/render-command-list.js +1 -1
  78. package/es/common/render-curve.js +1 -1
  79. package/es/common/render-utils.js +1 -1
  80. package/es/common/seg-context.js +1 -2
  81. package/es/common/simplify.js +1 -1
  82. package/es/common/sort.js +1 -1
  83. package/es/common/split-path.js +1 -1
  84. package/es/common/store.js +1 -1
  85. package/es/common/text.js +1 -1
  86. package/es/common/utils.js +1 -1
  87. package/es/core/camera.js +1 -1
  88. package/es/core/constants.js +1 -1
  89. package/es/core/core-modules.js +1 -1
  90. package/es/core/global-module.js +2 -0
  91. package/es/core/global.js +1 -1
  92. package/es/core/graphic-utils.js +1 -1
  93. package/es/core/index.js +1 -1
  94. package/es/core/layer-service.js +2 -1
  95. package/es/core/layer.js +1 -1
  96. package/es/core/light.js +1 -1
  97. package/es/core/stage.d.ts +4 -1
  98. package/es/core/stage.js +22 -11
  99. package/es/core/stage.js.map +1 -1
  100. package/es/core/window.js +1 -1
  101. package/es/graphic/graphic-service/graphic-service.d.ts +4 -0
  102. package/es/graphic/graphic-service/graphic-service.js +6 -5
  103. package/es/graphic/graphic-service/graphic-service.js.map +1 -1
  104. package/es/graphic/graphic.d.ts +72 -11
  105. package/es/graphic/graphic.js +504 -151
  106. package/es/graphic/graphic.js.map +1 -1
  107. package/es/graphic/group.d.ts +5 -1
  108. package/es/graphic/group.js +36 -18
  109. package/es/graphic/group.js.map +1 -1
  110. package/es/graphic/rect.d.ts +2 -0
  111. package/es/graphic/rect.js +44 -0
  112. package/es/graphic/rect.js.map +1 -1
  113. package/es/graphic/state/shared-state-refresh.js +5 -4
  114. package/es/graphic/state/shared-state-refresh.js.map +1 -1
  115. package/es/graphic/state/shared-state-scope.js +2 -2
  116. package/es/graphic/state/shared-state-scope.js.map +1 -1
  117. package/es/graphic/state/state-engine.js +3 -3
  118. package/es/graphic/state/state-engine.js.map +1 -1
  119. package/es/graphic/state/state-perf-monitor.d.ts +1 -0
  120. package/es/graphic/state/state-perf-monitor.js +7 -0
  121. package/es/graphic/state/state-perf-monitor.js.map +1 -1
  122. package/es/graphic/state/state-style-resolver.d.ts +0 -9
  123. package/es/graphic/state/state-style-resolver.js +0 -23
  124. package/es/graphic/state/state-style-resolver.js.map +1 -1
  125. package/es/graphic/state/state-transition-orchestrator.d.ts +5 -0
  126. package/es/graphic/state/state-transition-orchestrator.js +17 -5
  127. package/es/graphic/state/state-transition-orchestrator.js.map +1 -1
  128. package/es/interface/animation/animate.d.ts +1 -0
  129. package/es/interface/animation/animate.js.map +1 -1
  130. package/es/interface/graphic.d.ts +9 -0
  131. package/es/interface/graphic.js.map +1 -1
  132. package/es/interface/node-tree.js.map +1 -1
  133. package/es/plugins/builtin-plugin/dirty-bounds-plugin.d.ts +4 -1
  134. package/es/plugins/builtin-plugin/dirty-bounds-plugin.js +20 -10
  135. package/es/plugins/builtin-plugin/dirty-bounds-plugin.js.map +1 -1
  136. package/es/plugins/builtin-plugin/flex-layout-plugin.js +3 -2
  137. package/es/plugins/builtin-plugin/flex-layout-plugin.js.map +1 -1
  138. package/es/render/contributions/render/base-render.js +8 -6
  139. package/es/render/contributions/render/base-render.js.map +1 -1
  140. package/package.json +3 -3
@@ -2,17 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
- }), exports.Graphic = exports.NOWORK_ANIMATE_ATTR = exports.shouldUseSimpleAttributeFastPath = exports.GRAPHIC_UPDATE_TAG_KEY = exports.PURE_STYLE_KEY = void 0;
5
+ }), exports.Graphic = exports.NOWORK_ANIMATE_ATTR = exports.GRAPHIC_UPDATE_TAG_KEY = exports.PURE_STYLE_KEY = void 0;
6
6
 
7
7
  const vutils_1 = require("@visactor/vutils"), node_tree_1 = require("./node-tree"), event_1 = require("../event"), config_1 = require("./config"), application_1 = require("../application"), custom_path2d_1 = require("../common/custom-path2d"), loader_1 = require("../resource-loader/loader"), enums_1 = require("../common/enums"), bounds_context_1 = require("../common/bounds-context"), render_command_list_1 = require("../common/render-command-list"), utils_1 = require("../common/utils"), builtin_symbol_1 = require("./builtin-symbol"), xml_1 = require("../common/xml"), constants_1 = require("./constants"), config_2 = require("../animate/config"), canvas_1 = require("../canvas"), state_definition_compiler_1 = require("./state/state-definition-compiler"), state_engine_1 = require("./state/state-engine"), state_model_1 = require("./state/state-model"), attribute_update_classifier_1 = require("./state/attribute-update-classifier"), state_style_resolver_1 = require("./state/state-style-resolver"), state_transition_orchestrator_1 = require("./state/state-transition-orchestrator"), shared_state_scope_1 = require("./state/shared-state-scope"), shared_state_refresh_1 = require("./state/shared-state-refresh"), state_perf_monitor_1 = require("./state/state-perf-monitor"), _tempBounds = new vutils_1.AABBBounds, loadShadowRootFactory = () => require("./shadow-root"), tempMatrix = new vutils_1.Matrix;
8
8
 
9
9
  exports.PURE_STYLE_KEY = [ "stroke", "opacity", "strokeOpacity", "lineDash", "lineDashOffset", "lineCap", "lineJoin", "miterLimit", "fill", "fillOpacity" ],
10
10
  exports.GRAPHIC_UPDATE_TAG_KEY = [ "lineWidth", "scaleX", "scaleY", "angle", "anchor", "visible" ];
11
11
 
12
- const tempConstantXYKey = [ "x", "y" ], tempConstantScaleXYKey = [ "scaleX", "scaleY" ], tempConstantAngleKey = [ "angle" ], builtinTextureTypes = new Set([ "circle", "diamond", "rect", "vertical-line", "horizontal-line", "bias-lr", "bias-rl", "grid", "wave" ]), point = new vutils_1.Point;
12
+ const tempConstantXYKey = [ "x", "y" ], tempConstantScaleXYKey = [ "scaleX", "scaleY" ], tempConstantAngleKey = [ "angle" ], builtinTextureTypes = new Set([ "circle", "diamond", "rect", "vertical-line", "horizontal-line", "bias-lr", "bias-rl", "grid", "wave" ]), FULL_STATE_DEFINITION_KEYS = new Set([ "name", "patch", "priority", "exclude", "suppress", "resolver", "declaredAffectedKeys" ]), point = new vutils_1.Point, EMPTY_STATE_NAMES = [], BROAD_UPDATE_CATEGORY = attribute_update_classifier_1.UpdateCategory.PAINT | attribute_update_classifier_1.UpdateCategory.SHAPE | attribute_update_classifier_1.UpdateCategory.BOUNDS | attribute_update_classifier_1.UpdateCategory.TRANSFORM | attribute_update_classifier_1.UpdateCategory.LAYOUT;
13
13
 
14
14
  function isPlainObjectValue(value) {
15
- return "object" == typeof value && null != value && !(0, vutils_1.isArray)(value);
15
+ return "object" == typeof value && null != value && !Array.isArray(value);
16
16
  }
17
17
 
18
18
  function cloneAttributeValue(value) {
@@ -24,14 +24,6 @@ function cloneAttributeValue(value) {
24
24
  })), clone;
25
25
  }
26
26
 
27
- function cloneSimpleAttributeRecord(value) {
28
- return isPlainObjectValue(value) ? Object.assign({}, value) : value;
29
- }
30
-
31
- function shouldUseSimpleAttributeFastPath(value) {
32
- return !!isPlainObjectValue(value) && !Object.keys(value).some((key => isPlainObjectValue(value[key])));
33
- }
34
-
35
27
  function cloneAttributeSurface(value) {
36
28
  if (!isPlainObjectValue(value)) return value;
37
29
  const source = value, clone = {};
@@ -41,6 +33,11 @@ function cloneAttributeSurface(value) {
41
33
  })), clone;
42
34
  }
43
35
 
36
+ function areAttributeValuesEqual(left, right) {
37
+ return left === right || !!(isPlainObjectValue(left) || isPlainObjectValue(right) || Array.isArray(left) || Array.isArray(right)) && (0,
38
+ vutils_1.isEqual)(left, right);
39
+ }
40
+
44
41
  function deepMergeAttributeValue(base, value) {
45
42
  var _a;
46
43
  const result = null !== (_a = cloneAttributeValue(base)) && void 0 !== _a ? _a : {};
@@ -50,7 +47,7 @@ function deepMergeAttributeValue(base, value) {
50
47
  })), result;
51
48
  }
52
49
 
53
- exports.shouldUseSimpleAttributeFastPath = shouldUseSimpleAttributeFastPath, exports.NOWORK_ANIMATE_ATTR = {
50
+ exports.NOWORK_ANIMATE_ATTR = {
54
51
  strokeSeg: 1,
55
52
  boundsPadding: 2,
56
53
  pickMode: 1,
@@ -104,19 +101,28 @@ class Graphic extends node_tree_1.Node {
104
101
  get globalTransMatrix() {
105
102
  return this.tryUpdateGlobalTransMatrix(!0);
106
103
  }
104
+ get baseAttributes() {
105
+ var _a;
106
+ return null !== (_a = this._baseAttributes) && void 0 !== _a ? _a : this.attribute;
107
+ }
108
+ set baseAttributes(value) {
109
+ value !== this.attribute ? this._baseAttributes = value : this._baseAttributes = void 0;
110
+ }
107
111
  constructor(params = {}) {
108
112
  var _a;
109
- super(), this.resolverEpoch = 0, this._AABBBounds = new vutils_1.AABBBounds, this._updateTag = enums_1.UpdateTag.INIT;
110
- const useSimpleAttributeFastPath = shouldUseSimpleAttributeFastPath(params), initialBaseAttributes = useSimpleAttributeFastPath ? cloneSimpleAttributeRecord(params) : cloneAttributeValue(params);
111
- this.baseAttributes = initialBaseAttributes, this.attribute = useSimpleAttributeFastPath ? cloneSimpleAttributeRecord(initialBaseAttributes) : cloneAttributeSurface(initialBaseAttributes),
112
- this.valid = this.isValid(), this.updateAABBBoundsStamp = 0, params.background && this.loadImage(null !== (_a = params.background.background) && void 0 !== _a ? _a : params.background, !0),
113
- isExternalTexture(params.texture) && this.loadImage(params.texture, !1), params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic);
113
+ super(), this._AABBBounds = new vutils_1.AABBBounds, this._updateTag = enums_1.UpdateTag.INIT,
114
+ this.attribute = params, this.valid = this.isValid(), this.updateAABBBoundsStamp = 0,
115
+ params.background && this.loadImage(null !== (_a = params.background.background) && void 0 !== _a ? _a : params.background, !0),
116
+ params.texture && isExternalTexture(params.texture) && this.loadImage(params.texture, !1),
117
+ params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic);
114
118
  }
115
119
  get normalAttrs() {
116
120
  return this.baseAttributes;
117
121
  }
118
- set normalAttrs(value) {
119
- this._deprecatedNormalAttrsView = null != value ? value : void 0;
122
+ set normalAttrs(_value) {}
123
+ getBaseAttributesStorage() {
124
+ var _a;
125
+ return null !== (_a = this._baseAttributes) && void 0 !== _a ? _a : this.attribute;
120
126
  }
121
127
  getGraphicService() {
122
128
  var _a, _b;
@@ -155,11 +161,18 @@ class Graphic extends node_tree_1.Node {
155
161
  markDirty && (null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) && this.markSharedStateDirty(),
156
162
  !0);
157
163
  }
158
- syncSharedStateActiveRegistrations() {
164
+ syncSharedStateScopeBindingOnTreeChange(markDirty = !0) {
159
165
  var _a, _b;
160
- const nextScopes = (null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) && this.boundSharedStateScope ? new Set((0,
161
- shared_state_scope_1.collectSharedStateScopeChain)(this.boundSharedStateScope)) : new Set;
162
- (null !== (_b = this.registeredActiveScopes) && void 0 !== _b ? _b : new Set).forEach((scope => {
166
+ return !!((null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || this.boundSharedStateScope || (null === (_b = this.registeredActiveScopes) || void 0 === _b ? void 0 : _b.size) || this.sharedStateDirty) && this.syncSharedStateScopeBindingFromTree(markDirty);
167
+ }
168
+ syncSharedStateActiveRegistrations() {
169
+ var _a;
170
+ const previousScopes = this.registeredActiveScopes;
171
+ if (!(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || !this.boundSharedStateScope) return (null == previousScopes ? void 0 : previousScopes.size) && (previousScopes.forEach((scope => {
172
+ scope.subtreeActiveDescendants.delete(this);
173
+ })), previousScopes.clear()), void (this.registeredActiveScopes = void 0);
174
+ const nextScopes = new Set((0, shared_state_scope_1.collectSharedStateScopeChain)(this.boundSharedStateScope));
175
+ null == previousScopes || previousScopes.forEach((scope => {
163
176
  nextScopes.has(scope) || scope.subtreeActiveDescendants.delete(this);
164
177
  })), nextScopes.forEach((scope => {
165
178
  scope.subtreeActiveDescendants.add(this);
@@ -176,7 +189,7 @@ class Graphic extends node_tree_1.Node {
176
189
  (0, shared_state_refresh_1.scheduleStageSharedStateRefresh)(this.stage);
177
190
  }
178
191
  onParentSharedStateTreeChanged(stage, layer) {
179
- this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingFromTree() : this.setStage(stage, layer);
192
+ this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingOnTreeChange() : this.setStage(stage, layer);
180
193
  }
181
194
  refreshSharedStateBeforeRender() {
182
195
  var _a;
@@ -184,9 +197,7 @@ class Graphic extends node_tree_1.Node {
184
197
  this.boundSharedStateScope && (0, shared_state_scope_1.ensureSharedStateScopeFresh)(this.boundSharedStateScope),
185
198
  this.recomputeCurrentStatePatch(), this.stopStateAnimates(), this._restoreAttributeFromStaticTruth({
186
199
  type: enums_1.AttributeUpdateType.STATE
187
- }), this._emitCustomEvent("afterStateUpdate", {
188
- type: enums_1.AttributeUpdateType.STATE
189
- }), this.sharedStateDirty = !1) : this.sharedStateDirty = !1;
200
+ }), this.emitStateUpdateEvent(), this.sharedStateDirty = !1) : this.sharedStateDirty = !1;
190
201
  }
191
202
  getLocalStatesVersion() {
192
203
  var _a, _b;
@@ -237,14 +248,12 @@ class Graphic extends node_tree_1.Node {
237
248
  };
238
249
  }
239
250
  recomputeCurrentStatePatch() {
240
- var _a, _b, _c, _d;
251
+ var _a, _b;
241
252
  if (!(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length)) return this.effectiveStates = [],
242
253
  this.resolvedStatePatch = void 0, void this.syncSharedStateActiveRegistrations();
243
- const stateResolveBaseAttrs = null !== (_b = this.baseAttributes) && void 0 !== _b ? _b : this.attribute, stateModel = this.createStateModel();
244
- null === (_c = this.stateEngine) || void 0 === _c || _c.setResolveContext(this, stateResolveBaseAttrs);
245
- 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);
254
+ 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);
246
255
  this.currentStates = transition.states, this.effectiveStates = [ ...effectiveStates ],
247
- this.resolvedStatePatch = Object.assign({}, resolvedStateAttrs), this.syncSharedStateActiveRegistrations();
256
+ this.resolvedStatePatch = resolvedStateAttrs, this.syncSharedStateActiveRegistrations();
248
257
  }
249
258
  buildStaticAttributeSnapshot() {
250
259
  var _a;
@@ -254,6 +263,22 @@ class Graphic extends node_tree_1.Node {
254
263
  "deep" === this.stateMergeMode && isPlainObjectValue(previousValue) && isPlainObjectValue(nextValue) ? snapshot[key] = deepMergeAttributeValue(previousValue, nextValue) : snapshot[key] = cloneAttributeValue(nextValue);
255
264
  })), snapshot) : snapshot;
256
265
  }
266
+ buildRemovedStateAnimationAttrs(targetStateAttrs, previousResolvedStatePatch) {
267
+ const extraAttrs = {};
268
+ if (!previousResolvedStatePatch) return extraAttrs;
269
+ const snapshot = this.buildStaticAttributeSnapshot(), staticTargetAttrs = snapshot;
270
+ return Object.keys(previousResolvedStatePatch).forEach((key => {
271
+ const hasTargetAttr = Object.prototype.hasOwnProperty.call(targetStateAttrs, key);
272
+ if (hasTargetAttr && void 0 !== targetStateAttrs[key]) return;
273
+ const assignFallbackAttr = value => {
274
+ void 0 === value && this.shouldSkipStateTransitionDefaultAttribute(key, staticTargetAttrs) || (extraAttrs[key] = void 0 === value ? value : cloneAttributeValue(value));
275
+ };
276
+ if (hasTargetAttr) assignFallbackAttr(this.getStateTransitionDefaultAttribute(key, staticTargetAttrs)); else if (Object.prototype.hasOwnProperty.call(snapshot, key)) {
277
+ const snapshotValue = snapshot[key];
278
+ assignFallbackAttr(void 0 === snapshotValue ? this.getStateTransitionDefaultAttribute(key, staticTargetAttrs) : snapshotValue);
279
+ } else assignFallbackAttr(this.getStateTransitionDefaultAttribute(key, staticTargetAttrs));
280
+ })), extraAttrs;
281
+ }
257
282
  syncObjectToSnapshot(target, snapshot) {
258
283
  const delta = new Map;
259
284
  return new Set([ ...Object.keys(target), ...Object.keys(snapshot) ]).forEach((key => {
@@ -263,15 +288,17 @@ class Graphic extends node_tree_1.Node {
263
288
  next: void 0
264
289
  }), delete target[key]));
265
290
  const nextValue = snapshot[key];
266
- (0, vutils_1.isEqual)(previousValue, nextValue) || (delta.set(key, {
291
+ areAttributeValuesEqual(previousValue, nextValue) || (delta.set(key, {
267
292
  prev: previousValue,
268
293
  next: nextValue
269
294
  }), target[key] = cloneAttributeValue(nextValue));
270
295
  })), delta;
271
296
  }
272
297
  _syncAttribute() {
298
+ this.attribute === this.baseAttributes && this.resolvedStatePatch && this.detachAttributeFromBaseAttributes();
273
299
  const snapshot = this.buildStaticAttributeSnapshot(), delta = this.syncObjectToSnapshot(this.attribute, snapshot);
274
- return this.valid = this.isValid(), delta;
300
+ return this.valid = this.isValid(), this.attributeMayContainTransientAttrs = !1,
301
+ delta;
275
302
  }
276
303
  _syncFinalAttributeFromStaticTruth() {
277
304
  const target = this.finalAttribute;
@@ -279,54 +306,155 @@ class Graphic extends node_tree_1.Node {
279
306
  const snapshot = this.buildStaticAttributeSnapshot();
280
307
  this.syncObjectToSnapshot(target, snapshot);
281
308
  }
282
- submitUpdateByDelta(delta, forceUpdateTag = !1) {
309
+ mergeAttributeDeltaCategory(category, key, prev, next) {
310
+ var _a;
311
+ let nextCategory = "stroke" === key || "shadowBlur" === key ? (0, attribute_update_classifier_1.classifyAttributeDelta)(key, prev, next) : null !== (_a = attribute_update_classifier_1.ATTRIBUTE_CATEGORY[key]) && void 0 !== _a ? _a : attribute_update_classifier_1.UpdateCategory.PAINT;
312
+ return nextCategory & attribute_update_classifier_1.UpdateCategory.PICK && (nextCategory |= attribute_update_classifier_1.UpdateCategory.BOUNDS),
313
+ nextCategory === attribute_update_classifier_1.UpdateCategory.PAINT && this.needUpdateTag(key) && (nextCategory = attribute_update_classifier_1.UpdateCategory.SHAPE | attribute_update_classifier_1.UpdateCategory.BOUNDS),
314
+ category | nextCategory;
315
+ }
316
+ submitUpdateByCategory(category, forceUpdateTag = !1) {
283
317
  var _a;
284
318
  if (forceUpdateTag) return this.addUpdateShapeAndBoundsTag(), this.addUpdatePositionTag(),
285
319
  void this.addUpdateLayoutTag();
286
- let category = attribute_update_classifier_1.UpdateCategory.NONE;
287
- delta.forEach(((entry, key) => {
288
- let nextCategory = (0, attribute_update_classifier_1.classifyAttributeDelta)(key, entry.prev, entry.next);
289
- nextCategory & attribute_update_classifier_1.UpdateCategory.PICK && (nextCategory |= attribute_update_classifier_1.UpdateCategory.BOUNDS),
290
- nextCategory === attribute_update_classifier_1.UpdateCategory.PAINT && this.needUpdateTag(key) && (nextCategory = attribute_update_classifier_1.UpdateCategory.SHAPE | attribute_update_classifier_1.UpdateCategory.BOUNDS),
291
- category |= nextCategory;
292
- })), category !== attribute_update_classifier_1.UpdateCategory.NONE && (null === (_a = (0,
293
- state_perf_monitor_1.getStageStatePerfMonitor)(this.stage)) || void 0 === _a || _a.recordCategory(category)),
294
- category & attribute_update_classifier_1.UpdateCategory.SHAPE ? this.addUpdateShapeAndBoundsTag() : category & attribute_update_classifier_1.UpdateCategory.BOUNDS && this.addUpdateBoundTag(),
320
+ if (category !== attribute_update_classifier_1.UpdateCategory.NONE) {
321
+ const stage = this.stage;
322
+ stage && (null === (_a = (0, state_perf_monitor_1.getActiveStageStatePerfMonitor)(stage)) || void 0 === _a || _a.recordCategory(category));
323
+ }
324
+ (category & BROAD_UPDATE_CATEGORY) !== BROAD_UPDATE_CATEGORY ? (category & attribute_update_classifier_1.UpdateCategory.SHAPE ? this.addUpdateShapeAndBoundsTag() : category & attribute_update_classifier_1.UpdateCategory.BOUNDS && this.addUpdateBoundTag(),
295
325
  category & attribute_update_classifier_1.UpdateCategory.PAINT && this.addUpdatePaintTag(),
296
326
  category & attribute_update_classifier_1.UpdateCategory.TRANSFORM && this.addUpdatePositionTag(),
297
- category & attribute_update_classifier_1.UpdateCategory.LAYOUT && this.addUpdateLayoutTag();
327
+ category & attribute_update_classifier_1.UpdateCategory.LAYOUT && this.addUpdateLayoutTag()) : this.addBroadUpdateTag();
328
+ }
329
+ submitUpdateByDelta(delta, forceUpdateTag = !1) {
330
+ let category = attribute_update_classifier_1.UpdateCategory.NONE;
331
+ delta.forEach(((entry, key) => {
332
+ category = this.mergeAttributeDeltaCategory(category, key, entry.prev, entry.next);
333
+ })), this.submitUpdateByCategory(category, forceUpdateTag);
334
+ }
335
+ submitTouchedKeyUpdate(keys, forceUpdateTag = !1) {
336
+ this.submitTouchedUpdate(forceUpdateTag || this.needUpdateTags(keys));
337
+ }
338
+ submitTouchedUpdate(needsShapeAndBounds) {
339
+ !this.updateShapeAndBoundsTagSetted() && needsShapeAndBounds ? this.addUpdateShapeAndBoundsTag() : this.addUpdateBoundTag(),
340
+ this.addUpdatePositionTag(), this.addUpdateLayoutTag();
298
341
  }
299
342
  commitBaseAttributeMutation(forceUpdateTag = !1, context) {
300
- var _a, _b;
301
- (null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) && (this.resolverEpoch += 1,
302
- null === (_b = this.stateEngine) || void 0 === _b || _b.invalidateResolverCache(),
343
+ var _a, _b, _c;
344
+ (null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) && (this.resolverEpoch = (null !== (_b = this.resolverEpoch) && void 0 !== _b ? _b : 0) + 1,
345
+ null === (_c = this.stateEngine) || void 0 === _c || _c.invalidateResolverCache(),
303
346
  this.recomputeCurrentStatePatch());
304
347
  const delta = this._syncAttribute();
305
348
  this.submitUpdateByDelta(delta, forceUpdateTag), this.onAttributeUpdate(context);
306
349
  }
350
+ canCommitBaseAttributesByTouchedKeys() {
351
+ var _a, _b;
352
+ return !((null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || this.resolvedStatePatch || this.attributeMayContainTransientAttrs) && (!(null === (_b = this.animates) || void 0 === _b ? void 0 : _b.size) && !this._animationStateManager || !this.hasAnyTrackedAnimate());
353
+ }
354
+ detachAttributeFromBaseAttributes() {
355
+ this.attribute === this.baseAttributes && (this._baseAttributes = this.attribute,
356
+ this.attribute = cloneAttributeSurface(this.attribute));
357
+ }
358
+ commitInternalBaseAttributes(params, context) {
359
+ params && Object.keys(params).length && (this.canCommitBaseAttributesByTouchedKeys() ? this.commitBaseAttributesByTouchedKeys(params, !1, context) : (this.detachAttributeFromBaseAttributes(),
360
+ this.applyBaseAttributes(params), this.commitBaseAttributeMutation(!1, context)));
361
+ }
362
+ commitBaseAttributesByTouchedKeys(params, forceUpdateTag = !1, context) {
363
+ const source = params, baseAttributes = this.getBaseAttributesStorage();
364
+ let hasKeys = !1, needsShapeAndBounds = forceUpdateTag;
365
+ for (const key in source) Object.prototype.hasOwnProperty.call(source, key) && (hasKeys = !0,
366
+ baseAttributes[key] = source[key], !needsShapeAndBounds && this.needUpdateTag(key) && (needsShapeAndBounds = !0));
367
+ hasKeys && (this.attribute = baseAttributes, this._baseAttributes = void 0, this.valid = this.isValid(),
368
+ this.attributeMayContainTransientAttrs = !1, this.submitTouchedUpdate(needsShapeAndBounds),
369
+ this.onAttributeUpdate(context));
370
+ }
371
+ commitBaseAttributeBySingleKey(key, value, forceUpdateTag = !1, context) {
372
+ this.getBaseAttributesStorage()[key] = value, this.attribute = this.getBaseAttributesStorage(),
373
+ this._baseAttributes = void 0, this.valid = this.isValid(), this.attributeMayContainTransientAttrs = !1,
374
+ this.submitTouchedUpdate(forceUpdateTag || this.needUpdateTag(key)), this.onAttributeUpdate(context);
375
+ }
307
376
  applyBaseAttributes(params) {
308
377
  const keys = Object.keys(params);
309
378
  for (let i = 0; i < keys.length; i++) {
310
379
  const key = keys[i];
311
- this.baseAttributes[key] = cloneAttributeValue(params[key]);
380
+ this.getBaseAttributesStorage()[key] = params[key];
312
381
  }
313
382
  }
383
+ applyAnimationTransientAttributes(params, forceUpdateTag = !1, context) {
384
+ const source = params;
385
+ let target, needsShapeAndBounds = forceUpdateTag;
386
+ for (const key in source) Object.prototype.hasOwnProperty.call(source, key) && (target || (this.detachAttributeFromBaseAttributes(),
387
+ target = this.attribute), target[key] = source[key], !needsShapeAndBounds && this.needUpdateTag(key) && (needsShapeAndBounds = !0));
388
+ target && (this.attributeMayContainTransientAttrs = !0, this.valid = this.isValid(),
389
+ this.submitTouchedUpdate(needsShapeAndBounds), this.onAttributeUpdate(context));
390
+ }
314
391
  applyTransientAttributes(params, forceUpdateTag = !1, context) {
392
+ this.detachAttributeFromBaseAttributes();
315
393
  const delta = new Map, keys = Object.keys(params);
316
394
  for (let i = 0; i < keys.length; i++) {
317
395
  const key = keys[i], previousValue = this.attribute[key], nextValue = params[key];
318
- (0, vutils_1.isEqual)(previousValue, nextValue) || (delta.set(key, {
396
+ areAttributeValuesEqual(previousValue, nextValue) || (delta.set(key, {
319
397
  prev: previousValue,
320
398
  next: nextValue
321
- }), this.attribute[key] = cloneAttributeValue(nextValue));
399
+ }), this.attribute[key] = nextValue);
322
400
  }
323
- this.valid = this.isValid(), this.submitUpdateByDelta(delta, forceUpdateTag), this.onAttributeUpdate(context);
401
+ delta.size && (this.attributeMayContainTransientAttrs = !0), this.valid = this.isValid(),
402
+ this.submitUpdateByDelta(delta, forceUpdateTag), this.onAttributeUpdate(context);
324
403
  }
325
404
  _restoreAttributeFromStaticTruth(context) {
326
405
  this._syncFinalAttributeFromStaticTruth();
327
406
  const delta = this._syncAttribute();
328
407
  this.submitUpdateByDelta(delta), this.onAttributeUpdate(context);
329
408
  }
409
+ collectStatePatchDeltaKeys(previousPatch, nextPatch) {
410
+ const keys = previousPatch ? Object.keys(previousPatch) : [];
411
+ if (!nextPatch) return keys;
412
+ for (const key in nextPatch) Object.prototype.hasOwnProperty.call(nextPatch, key) && !Object.prototype.hasOwnProperty.call(null != previousPatch ? previousPatch : {}, key) && keys.push(key);
413
+ return keys;
414
+ }
415
+ getStaticTruthValueForStateKey(key, nextPatch) {
416
+ var _a;
417
+ const baseAttributes = null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : {}, patch = nextPatch;
418
+ if (patch && Object.prototype.hasOwnProperty.call(patch, key)) {
419
+ const patchValue = patch[key], baseValue = baseAttributes[key];
420
+ return "deep" === this.stateMergeMode && isPlainObjectValue(baseValue) && isPlainObjectValue(patchValue) ? {
421
+ hasValue: !0,
422
+ value: deepMergeAttributeValue(baseValue, patchValue)
423
+ } : {
424
+ hasValue: !0,
425
+ value: patchValue
426
+ };
427
+ }
428
+ return Object.prototype.hasOwnProperty.call(baseAttributes, key) ? {
429
+ hasValue: !0,
430
+ value: baseAttributes[key]
431
+ } : {
432
+ hasValue: !1,
433
+ value: void 0
434
+ };
435
+ }
436
+ syncStatePatchDeltaToTarget(target, keys, nextPatch, collectCategory = !1) {
437
+ let category = attribute_update_classifier_1.UpdateCategory.NONE;
438
+ for (let i = 0; i < keys.length; i++) {
439
+ const key = keys[i], previousValue = target[key], next = this.getStaticTruthValueForStateKey(key, nextPatch);
440
+ if (!next.hasValue) {
441
+ Object.prototype.hasOwnProperty.call(target, key) && (delete target[key], collectCategory && (category = this.mergeAttributeDeltaCategory(category, key, previousValue, void 0)));
442
+ continue;
443
+ }
444
+ if (areAttributeValuesEqual(previousValue, next.value)) continue;
445
+ const nextValue = cloneAttributeValue(next.value);
446
+ target[key] = nextValue, collectCategory && (category = this.mergeAttributeDeltaCategory(category, key, previousValue, nextValue));
447
+ }
448
+ return category;
449
+ }
450
+ restoreAttributeFromStatePatchDelta(previousPatch, nextPatch, context) {
451
+ this.detachAttributeFromBaseAttributes();
452
+ const keys = this.collectStatePatchDeltaKeys(previousPatch, nextPatch), finalAttribute = this.finalAttribute;
453
+ finalAttribute && this.syncStatePatchDeltaToTarget(finalAttribute, keys, nextPatch, !1);
454
+ const category = this.syncStatePatchDeltaToTarget(this.attribute, keys, nextPatch, !0);
455
+ this.valid = this.isValid(), this.attributeMayContainTransientAttrs = !1, this.submitUpdateByCategory(category),
456
+ this.onAttributeUpdate(context);
457
+ }
330
458
  setMode(mode) {
331
459
  "3d" === mode ? this.set3dMode() : this.set2dMode();
332
460
  }
@@ -346,7 +474,7 @@ class Graphic extends node_tree_1.Node {
346
474
  return point;
347
475
  }
348
476
  onAnimateBind(animate) {
349
- this._emitCustomEvent("animate-bind", animate);
477
+ this.detachAttributeFromBaseAttributes(), this._emitCustomEvent("animate-bind", animate);
350
478
  }
351
479
  visitTrackedAnimates(cb) {
352
480
  const hook = this.forEachTrackedAnimate;
@@ -359,8 +487,22 @@ class Graphic extends node_tree_1.Node {
359
487
  const getTrackedAnimates = this.getTrackedAnimates;
360
488
  return "function" == typeof getTrackedAnimates ? getTrackedAnimates.call(this).size > 0 : !!(null === (_a = this.animates) || void 0 === _a ? void 0 : _a.size);
361
489
  }
490
+ mayHaveTrackedAnimates() {
491
+ var _a;
492
+ return !!(null === (_a = this.animates) || void 0 === _a ? void 0 : _a.size) || !!this._animationStateManager;
493
+ }
362
494
  tryUpdateAABBBounds() {
495
+ if (!(this.shadowRoot || this._updateTag & enums_1.UpdateTag.UPDATE_BOUNDS)) return this._AABBBounds;
363
496
  const full = "imprecise" === this.attribute.boundsMode;
497
+ if (!this.shadowRoot) {
498
+ const graphicService = this.getGraphicService(), graphicTheme = this.getGraphicTheme();
499
+ if (!graphicService.validCheck(this.attribute, graphicTheme, this._AABBBounds, this)) return this._AABBBounds;
500
+ if (!this.valid) return this._AABBBounds.clear(), this._AABBBounds;
501
+ graphicService.beforeUpdateAABBBounds(this, this.stage, !0, this._AABBBounds);
502
+ const bounds = this.doUpdateAABBBounds(full, graphicTheme);
503
+ return graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, !0),
504
+ "empty" === this.attribute.boundsMode && bounds.clear(), bounds;
505
+ }
364
506
  if (!this.shouldUpdateAABBBounds()) return this._AABBBounds;
365
507
  if (!this.valid) return this._AABBBounds.clear(), this._AABBBounds;
366
508
  this.getGraphicService().beforeUpdateAABBBounds(this, this.stage, !0, this._AABBBounds);
@@ -426,11 +568,11 @@ class Graphic extends node_tree_1.Node {
426
568
  const _parsedPath = new builtin_symbol_1.CustomSymbolClass(symbolType, cache);
427
569
  return Graphic.userSymbolMap[symbolType] = _parsedPath, _parsedPath;
428
570
  }
429
- doUpdateAABBBounds(full) {
571
+ doUpdateAABBBounds(full, graphicTheme) {
430
572
  this.updateAABBBoundsStamp++;
431
- const graphicTheme = this.getGraphicTheme();
573
+ const resolvedGraphicTheme = null != graphicTheme ? graphicTheme : this.getGraphicTheme();
432
574
  this._AABBBounds.clear();
433
- const attribute = this.attribute, bounds = this.updateAABBBounds(attribute, graphicTheme, this._AABBBounds, full), {boundsPadding: boundsPadding = graphicTheme.boundsPadding} = attribute, paddingArray = (0,
575
+ const attribute = this.attribute, bounds = this.updateAABBBounds(attribute, resolvedGraphicTheme, this._AABBBounds, full), {boundsPadding: boundsPadding = resolvedGraphicTheme.boundsPadding} = attribute, paddingArray = (0,
434
576
  utils_1.parsePadding)(boundsPadding);
435
577
  return paddingArray && bounds.expand(paddingArray), this.clearUpdateBoundTag(),
436
578
  bounds;
@@ -503,27 +645,64 @@ class Graphic extends node_tree_1.Node {
503
645
  this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1, this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1;
504
646
  }
505
647
  setAttributesAndPreventAnimate(params, forceUpdateTag = !1, context, ignorePriority) {
506
- this.visitTrackedAnimates((animate => {
507
- (animate.priority !== 1 / 0 || ignorePriority) && Object.keys(params).forEach((key => {
508
- animate.preventAttr(key);
509
- }));
648
+ if (!params) return;
649
+ const keys = Object.keys(params);
650
+ this.captureTransientFromAttrsBeforePreventAnimate(params, keys, context), this.visitTrackedAnimates((animate => {
651
+ (animate.priority !== 1 / 0 || ignorePriority) && animate.preventAttrs(keys);
510
652
  })), this.applyTransientAttributes(params, forceUpdateTag, context);
511
653
  }
654
+ captureTransientFromAttrsBeforePreventAnimate(params, keys, context) {
655
+ var _a, _b;
656
+ const graphicContext = this.context, diffAttrs = null !== (_a = null == graphicContext ? void 0 : graphicContext.diffAttrs) && void 0 !== _a ? _a : params, updateType = null == context ? void 0 : context.type;
657
+ if (!keys.length || !diffAttrs || updateType === enums_1.AttributeUpdateType.STATE || null != updateType && updateType >= enums_1.AttributeUpdateType.ANIMATE_BIND && updateType <= enums_1.AttributeUpdateType.ANIMATE_END) return;
658
+ const sameDiffAttrs = this.transientFromAttrsBeforePreventAnimateDiffAttrs === diffAttrs;
659
+ let fromAttrs = sameDiffAttrs && null !== (_b = this.transientFromAttrsBeforePreventAnimate) && void 0 !== _b ? _b : null;
660
+ sameDiffAttrs || (this.transientFromAttrsBeforePreventAnimate = null, this.transientFromAttrsBeforePreventAnimateDiffAttrs = null);
661
+ let captured = !1;
662
+ for (let i = 0; i < keys.length; i++) {
663
+ const key = keys[i];
664
+ if (!Object.prototype.hasOwnProperty.call(diffAttrs, key)) continue;
665
+ const previousValue = this.attribute[key], nextValue = params[key];
666
+ (0, vutils_1.isEqual)(previousValue, nextValue) || (null != fromAttrs || (fromAttrs = {}),
667
+ fromAttrs[key] = cloneAttributeValue(previousValue), captured = !0);
668
+ }
669
+ captured && (this.transientFromAttrsBeforePreventAnimate = fromAttrs, this.transientFromAttrsBeforePreventAnimateDiffAttrs = diffAttrs);
670
+ }
671
+ consumeTransientFromAttrsBeforePreventAnimate(diffAttrs) {
672
+ const transientFromAttrs = this.transientFromAttrsBeforePreventAnimate, sourceDiffAttrs = this.transientFromAttrsBeforePreventAnimateDiffAttrs;
673
+ if (!transientFromAttrs || !sourceDiffAttrs) return null;
674
+ for (const key in diffAttrs) if (Object.prototype.hasOwnProperty.call(diffAttrs, key) && (!Object.prototype.hasOwnProperty.call(sourceDiffAttrs, key) || !(0,
675
+ vutils_1.isEqual)(sourceDiffAttrs[key], diffAttrs[key]))) return null;
676
+ let fromAttrs = null, remaining = !1;
677
+ for (const key in transientFromAttrs) Object.prototype.hasOwnProperty.call(transientFromAttrs, key) && (Object.prototype.hasOwnProperty.call(diffAttrs, key) ? (null != fromAttrs || (fromAttrs = {}),
678
+ fromAttrs[key] = transientFromAttrs[key]) : remaining = !0);
679
+ if (remaining) {
680
+ const nextTransientFromAttrs = {};
681
+ for (const key in transientFromAttrs) Object.prototype.hasOwnProperty.call(transientFromAttrs, key) && !Object.prototype.hasOwnProperty.call(diffAttrs, key) && (nextTransientFromAttrs[key] = transientFromAttrs[key]);
682
+ this.transientFromAttrsBeforePreventAnimate = nextTransientFromAttrs;
683
+ } else this.transientFromAttrsBeforePreventAnimate = null, this.transientFromAttrsBeforePreventAnimateDiffAttrs = null;
684
+ return fromAttrs;
685
+ }
512
686
  setAttributes(params, forceUpdateTag = !1, context) {
513
687
  params && ((params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate(params, this.attribute, null, context) || params).background && this.loadImage(params.background, !0),
514
- isExternalTexture(params.texture) && this.loadImage(params.texture, !1), params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic),
515
- this._setAttributes(params, forceUpdateTag, context));
688
+ params.texture && isExternalTexture(params.texture) && this.loadImage(params.texture, !1),
689
+ params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic), this._setAttributes(params, forceUpdateTag, context));
516
690
  }
517
691
  _setAttributes(params, forceUpdateTag = !1, context) {
518
- this.applyBaseAttributes(params), this.commitBaseAttributeMutation(forceUpdateTag, context);
692
+ this.canCommitBaseAttributesByTouchedKeys() ? this.commitBaseAttributesByTouchedKeys(params, forceUpdateTag, context) : (this.detachAttributeFromBaseAttributes(),
693
+ this.applyBaseAttributes(params), this.commitBaseAttributeMutation(forceUpdateTag, context));
519
694
  }
520
695
  setAttribute(key, value, forceUpdateTag, context) {
521
696
  const params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate({
522
697
  [key]: value
523
698
  }, this.attribute, key, context);
524
- params ? this._setAttributes(params, forceUpdateTag, context) : (this.applyBaseAttributes({
525
- [key]: value
526
- }), this.commitBaseAttributeMutation(!!forceUpdateTag, context)), "background" === key ? this.loadImage(value, !0) : "texture" === key && isExternalTexture(value) ? this.loadImage(value, !1) : "shadowGraphic" === key && this.setShadowGraphic(value);
699
+ if (params) this._setAttributes(params, forceUpdateTag, context); else if (this.canCommitBaseAttributesByTouchedKeys()) this.commitBaseAttributeBySingleKey(key, value, !!forceUpdateTag, context); else {
700
+ const nextAttrs = {
701
+ [key]: value
702
+ };
703
+ this.applyBaseAttributes(nextAttrs), this.commitBaseAttributeMutation(!!forceUpdateTag, context);
704
+ }
705
+ "background" === key ? this.loadImage(value, !0) : "texture" === key && isExternalTexture(value) ? this.loadImage(value, !1) : "shadowGraphic" === key && this.setShadowGraphic(value);
527
706
  }
528
707
  needUpdateTags(keys, k = exports.GRAPHIC_UPDATE_TAG_KEY) {
529
708
  for (let i = 0; i < k.length; i++) {
@@ -543,10 +722,11 @@ class Graphic extends node_tree_1.Node {
543
722
  type: enums_1.AttributeUpdateType.INIT
544
723
  };
545
724
  params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate(params, this.attribute, null, context) || params,
546
- this.baseAttributes = cloneAttributeValue(params), this.attribute || (this.attribute = {}),
547
- this.resolvedStatePatch = void 0, this._syncAttribute(), params.background && this.loadImage(params.background, !0),
548
- isExternalTexture(params.texture) && this.loadImage(params.texture, !1), params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic),
549
- this._updateTag = enums_1.UpdateTag.INIT, this.valid = this.isValid(), this.onAttributeUpdate(context);
725
+ this.attribute = params, this._baseAttributes = void 0, this.resolvedStatePatch = void 0,
726
+ this.attributeMayContainTransientAttrs = !1, this.valid = this.isValid(), params.background && this.loadImage(params.background, !0),
727
+ params.texture && isExternalTexture(params.texture) && this.loadImage(params.texture, !1),
728
+ params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic), this._updateTag = enums_1.UpdateTag.INIT,
729
+ this.valid = this.isValid(), this.onAttributeUpdate(context);
550
730
  }
551
731
  translate(x, y) {
552
732
  var _a, _b;
@@ -557,11 +737,15 @@ class Graphic extends node_tree_1.Node {
557
737
  x: x,
558
738
  y: y
559
739
  }, this.attribute, tempConstantXYKey, context);
560
- params && (x = params.x, y = params.y, delete params.x, delete params.y, this.applyBaseAttributes(params));
561
- const attribute = this.baseAttributes, postMatrix = attribute.postMatrix;
562
- return postMatrix ? application_1.application.transformUtil.fromMatrix(postMatrix, postMatrix).translate(x, y) : (attribute.x = (null !== (_a = attribute.x) && void 0 !== _a ? _a : config_1.DefaultTransform.x) + x,
563
- attribute.y = (null !== (_b = attribute.y) && void 0 !== _b ? _b : config_1.DefaultTransform.y) + y),
564
- this.commitBaseAttributeMutation(!1, context), this;
740
+ params && (x = params.x, y = params.y, delete params.x, delete params.y);
741
+ const attribute = this.baseAttributes, postMatrix = attribute.postMatrix, nextAttrs = params || {};
742
+ if (postMatrix) {
743
+ const nextPostMatrix = postMatrix.clone();
744
+ application_1.application.transformUtil.fromMatrix(nextPostMatrix, nextPostMatrix).translate(x, y),
745
+ nextAttrs.postMatrix = nextPostMatrix;
746
+ } else nextAttrs.x = (null !== (_a = attribute.x) && void 0 !== _a ? _a : config_1.DefaultTransform.x) + x,
747
+ nextAttrs.y = (null !== (_b = attribute.y) && void 0 !== _b ? _b : config_1.DefaultTransform.y) + y;
748
+ return this.commitInternalBaseAttributes(nextAttrs, context), this;
565
749
  }
566
750
  translateTo(x, y) {
567
751
  const attribute = this.baseAttributes;
@@ -572,9 +756,10 @@ class Graphic extends node_tree_1.Node {
572
756
  x: x,
573
757
  y: y
574
758
  }, this.attribute, tempConstantXYKey, context);
575
- return params ? (this.applyBaseAttributes(params), this.commitBaseAttributeMutation(!1, context),
576
- this) : (attribute.x = x, attribute.y = y, this.commitBaseAttributeMutation(!1, context),
577
- this);
759
+ return params ? (this.commitInternalBaseAttributes(params, context), this) : (this.commitInternalBaseAttributes({
760
+ x: x,
761
+ y: y
762
+ }, context), this);
578
763
  }
579
764
  scale(scaleX, scaleY, scaleCenter) {
580
765
  var _a, _b;
@@ -587,15 +772,15 @@ class Graphic extends node_tree_1.Node {
587
772
  scaleCenter: scaleCenter
588
773
  }, this.attribute, tempConstantScaleXYKey, context);
589
774
  params && (scaleX = params.scaleX, scaleY = params.scaleY, delete params.scaleX,
590
- delete params.scaleY, this.applyBaseAttributes(params));
591
- const attribute = this.baseAttributes;
775
+ delete params.scaleY);
776
+ const attribute = this.baseAttributes, nextAttrs = params || {};
592
777
  if (scaleCenter) {
593
- let {postMatrix: postMatrix} = this.attribute;
594
- postMatrix || (postMatrix = new vutils_1.Matrix, attribute.postMatrix = postMatrix),
595
- application_1.application.transformUtil.fromMatrix(postMatrix, postMatrix).scale(scaleX, scaleY, scaleCenter);
596
- } else attribute.scaleX = (null !== (_a = attribute.scaleX) && void 0 !== _a ? _a : config_1.DefaultTransform.scaleX) * scaleX,
597
- attribute.scaleY = (null !== (_b = attribute.scaleY) && void 0 !== _b ? _b : config_1.DefaultTransform.scaleY) * scaleY;
598
- return this.commitBaseAttributeMutation(!1, context), this;
778
+ let {postMatrix: postMatrix} = this.baseAttributes;
779
+ postMatrix = postMatrix ? postMatrix.clone() : new vutils_1.Matrix, application_1.application.transformUtil.fromMatrix(postMatrix, postMatrix).scale(scaleX, scaleY, scaleCenter),
780
+ nextAttrs.postMatrix = postMatrix;
781
+ } else nextAttrs.scaleX = (null !== (_a = attribute.scaleX) && void 0 !== _a ? _a : config_1.DefaultTransform.scaleX) * scaleX,
782
+ nextAttrs.scaleY = (null !== (_b = attribute.scaleY) && void 0 !== _b ? _b : config_1.DefaultTransform.scaleY) * scaleY;
783
+ return this.commitInternalBaseAttributes(nextAttrs, context), this;
599
784
  }
600
785
  scaleTo(scaleX, scaleY) {
601
786
  const attribute = this.baseAttributes;
@@ -606,9 +791,10 @@ class Graphic extends node_tree_1.Node {
606
791
  scaleX: scaleX,
607
792
  scaleY: scaleY
608
793
  }, this.attribute, tempConstantScaleXYKey, context);
609
- return params ? (this.applyBaseAttributes(params), this.commitBaseAttributeMutation(!1, context),
610
- this) : (attribute.scaleX = scaleX, attribute.scaleY = scaleY, this.commitBaseAttributeMutation(!1, context),
611
- this);
794
+ return params ? (this.commitInternalBaseAttributes(params, context), this) : (this.commitInternalBaseAttributes({
795
+ scaleX: scaleX,
796
+ scaleY: scaleY
797
+ }, context), this);
612
798
  }
613
799
  rotate(angle, rotateCenter) {
614
800
  var _a;
@@ -619,24 +805,23 @@ class Graphic extends node_tree_1.Node {
619
805
  angle: angle,
620
806
  rotateCenter: rotateCenter
621
807
  }, this.attribute, tempConstantAngleKey, context);
622
- params && (delete params.angle, this.applyBaseAttributes(params));
623
- const attribute = this.baseAttributes;
808
+ params && delete params.angle;
809
+ const attribute = this.baseAttributes, nextAttrs = params || {};
624
810
  if (rotateCenter) {
625
811
  let {postMatrix: postMatrix} = this.baseAttributes;
626
- postMatrix || (postMatrix = new vutils_1.Matrix, this.baseAttributes.postMatrix = postMatrix),
627
- application_1.application.transformUtil.fromMatrix(postMatrix, postMatrix).rotate(angle, rotateCenter);
628
- } else attribute.angle = (null !== (_a = attribute.angle) && void 0 !== _a ? _a : config_1.DefaultTransform.angle) + angle;
629
- return this.commitBaseAttributeMutation(!1, context), this;
812
+ postMatrix = postMatrix ? postMatrix.clone() : new vutils_1.Matrix, application_1.application.transformUtil.fromMatrix(postMatrix, postMatrix).rotate(angle, rotateCenter),
813
+ nextAttrs.postMatrix = postMatrix;
814
+ } else nextAttrs.angle = (null !== (_a = attribute.angle) && void 0 !== _a ? _a : config_1.DefaultTransform.angle) + angle;
815
+ return this.commitInternalBaseAttributes(nextAttrs, context), this;
630
816
  }
631
817
  rotateTo(angle) {
632
- const attribute = this.baseAttributes;
633
- if (attribute.angle === angle) return this;
818
+ if (this.baseAttributes.angle === angle) return this;
634
819
  const context = {
635
820
  type: enums_1.AttributeUpdateType.ROTATE_TO
636
821
  }, params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate(angle, this.attribute, tempConstantAngleKey, context);
637
- return params ? (this.applyBaseAttributes(params), this.commitBaseAttributeMutation(!1, context),
638
- this) : (attribute.angle = angle, this.commitBaseAttributeMutation(!1, context),
639
- this);
822
+ return params ? (this.commitInternalBaseAttributes(params, context), this) : (this.commitInternalBaseAttributes({
823
+ angle: angle
824
+ }, context), this);
640
825
  }
641
826
  skewTo(b, c) {
642
827
  return this;
@@ -656,7 +841,16 @@ class Graphic extends node_tree_1.Node {
656
841
  var _a;
657
842
  return null === (_a = this.states) || void 0 === _a ? void 0 : _a[stateName];
658
843
  }
659
- createStateModel() {
844
+ getStateResolveBaseAttrs() {
845
+ var _a;
846
+ return null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : this.attribute;
847
+ }
848
+ syncStateResolveContext(stateResolveBaseAttrs = this.getStateResolveBaseAttrs()) {
849
+ var _a;
850
+ return null === (_a = this.stateEngine) || void 0 === _a || _a.setResolveContext(this, stateResolveBaseAttrs),
851
+ stateResolveBaseAttrs;
852
+ }
853
+ createStateModel(stateResolveBaseAttrs = this.getStateResolveBaseAttrs()) {
660
854
  const {compiledDefinitions: compiledDefinitions, stateProxyEligibility: stateProxyEligibility, stateProxyModeKey: stateProxyModeKey} = this.resolveEffectiveCompiledDefinitions();
661
855
  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 state_engine_1.StateEngine({
662
856
  compiledDefinitions: compiledDefinitions,
@@ -669,7 +863,7 @@ class Graphic extends node_tree_1.Node {
669
863
  this.stateEngineStateSort = this.stateSort, this.stateEngineMergeMode = this.stateMergeMode,
670
864
  this.stateEngineStateProxyModeKey = stateProxyModeKey) : (this.stateEngine = void 0,
671
865
  this.stateEngineCompiledDefinitions = void 0, this.stateEngineStateProxyModeKey = void 0),
672
- new state_model_1.StateModel({
866
+ this.syncStateResolveContext(stateResolveBaseAttrs), new state_model_1.StateModel({
673
867
  states: this.states,
674
868
  currentStates: this.currentStates,
675
869
  stateSort: this.stateSort,
@@ -677,27 +871,148 @@ class Graphic extends node_tree_1.Node {
677
871
  stateEngine: this.stateEngine
678
872
  });
679
873
  }
874
+ resolveSimpleLocalStateTransition(states, previousStates) {
875
+ var _a;
876
+ if (!this.states || this.stateProxy || this.stateSort || "deep" === this.stateMergeMode || this.parent || (null === (_a = this.stage) || void 0 === _a ? void 0 : _a.rootSharedStateScope) || this.boundSharedStateScope) return null;
877
+ if (1 === states.length) {
878
+ const stateName = states[0], hasDefinition = Object.prototype.hasOwnProperty.call(this.states, stateName), nextStates = [ stateName ], changed = !this.sameStateNames(previousStates, nextStates), resolvedStateAttrs = {};
879
+ if (hasDefinition) {
880
+ const attrs = this.states[stateName];
881
+ if (null != attrs) {
882
+ if (!isPlainObjectValue(attrs)) return null;
883
+ const keys = Object.keys(attrs);
884
+ for (let keyIndex = 0; keyIndex < keys.length; keyIndex++) {
885
+ const key = keys[keyIndex];
886
+ if (FULL_STATE_DEFINITION_KEYS.has(key)) return null;
887
+ const attrValue = attrs[key];
888
+ resolvedStateAttrs[key] = isPlainObjectValue(attrValue) ? cloneAttributeValue(attrValue) : attrValue;
889
+ }
890
+ }
891
+ }
892
+ return {
893
+ changed: changed,
894
+ states: nextStates,
895
+ effectiveStates: nextStates,
896
+ resolvedStateAttrs: resolvedStateAttrs
897
+ };
898
+ }
899
+ const uniqueStates = Array.from(new Set(states)), withDefinition = [], withoutDefinition = [];
900
+ for (let i = 0; i < uniqueStates.length; i++) {
901
+ const stateName = uniqueStates[i];
902
+ Object.prototype.hasOwnProperty.call(this.states, stateName) ? withDefinition.push(stateName) : withoutDefinition.push(stateName);
903
+ }
904
+ withDefinition.sort(((left, right) => left.localeCompare(right)));
905
+ const nextStates = withDefinition.concat(withoutDefinition), changed = !this.sameStateNames(previousStates, nextStates), resolvedStateAttrs = {};
906
+ for (let i = 0; i < nextStates.length; i++) {
907
+ const stateName = nextStates[i];
908
+ if (!Object.prototype.hasOwnProperty.call(this.states, stateName)) continue;
909
+ const attrs = this.states[stateName];
910
+ if (null == attrs) continue;
911
+ if (!isPlainObjectValue(attrs)) return null;
912
+ const keys = Object.keys(attrs);
913
+ for (let keyIndex = 0; keyIndex < keys.length; keyIndex++) {
914
+ const key = keys[keyIndex];
915
+ if (FULL_STATE_DEFINITION_KEYS.has(key)) return null;
916
+ const attrValue = attrs[key];
917
+ resolvedStateAttrs[key] = isPlainObjectValue(attrValue) ? cloneAttributeValue(attrValue) : attrValue;
918
+ }
919
+ }
920
+ return {
921
+ changed: changed,
922
+ states: nextStates,
923
+ effectiveStates: nextStates,
924
+ resolvedStateAttrs: resolvedStateAttrs
925
+ };
926
+ }
927
+ resolveGraphicStateTransition(states, previousStates, forceResolverRefresh = !1) {
928
+ var _a, _b;
929
+ let transition = this.resolveSimpleLocalStateTransition(states, previousStates);
930
+ const isSimpleLocalTransition = !!transition;
931
+ let resolvedStateAttrs;
932
+ if (transition) resolvedStateAttrs = transition.resolvedStateAttrs; else {
933
+ const stateResolveBaseAttrs = this.getStateResolveBaseAttrs(), stateModel = this.createStateModel(stateResolveBaseAttrs);
934
+ forceResolverRefresh && (null === (_a = this.stateEngine) || void 0 === _a || _a.invalidateResolverCache()),
935
+ 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);
936
+ }
937
+ return {
938
+ transition: transition,
939
+ effectiveStates: null !== (_b = transition.effectiveStates) && void 0 !== _b ? _b : transition.states,
940
+ resolvedStateAttrs: resolvedStateAttrs,
941
+ isSimpleLocalTransition: isSimpleLocalTransition
942
+ };
943
+ }
944
+ normalizeSetStatesOptions(options) {
945
+ return options && "object" == typeof options ? {
946
+ hasAnimation: options.animate,
947
+ animateSameStatePatchChange: !0 === options.animateSameStatePatchChange,
948
+ shouldRefreshSameStatePatch: !0
949
+ } : {
950
+ hasAnimation: "boolean" == typeof options ? options : void 0,
951
+ animateSameStatePatchChange: !1,
952
+ shouldRefreshSameStatePatch: !1
953
+ };
954
+ }
955
+ sameStatePatches(left, right) {
956
+ const leftRecord = null != left ? left : {}, rightRecord = null != right ? right : {}, keys = new Set([ ...Object.keys(leftRecord), ...Object.keys(rightRecord) ]);
957
+ for (const key of keys) {
958
+ if (Object.prototype.hasOwnProperty.call(leftRecord, key) !== Object.prototype.hasOwnProperty.call(rightRecord, key)) return !1;
959
+ if (!areAttributeValuesEqual(leftRecord[key], rightRecord[key])) return !1;
960
+ }
961
+ return !0;
962
+ }
963
+ commitSameStatePatchRefresh(states, hasAnimation, animateSameStatePatchChange = !1) {
964
+ var _a;
965
+ 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);
966
+ if ((!patchChanged || this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) && (this.currentStates = transition.states,
967
+ this.effectiveStates = isSimpleLocalTransition ? effectiveStates : [ ...effectiveStates ],
968
+ this.resolvedStatePatch = resolvedStateAttrs, this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(),
969
+ patchChanged)) {
970
+ if (this.stage) {
971
+ const perfMonitor = (0, state_perf_monitor_1.getActiveStageStatePerfMonitor)(this.stage);
972
+ null == perfMonitor || perfMonitor.incrementCounter("stateCommits"), null == perfMonitor || perfMonitor.recordEvent("state-commit", {
973
+ graphicId: this._uid,
974
+ targetStates: [ ...transition.states ]
975
+ });
976
+ }
977
+ hasAnimation && animateSameStatePatchChange ? (this._syncFinalAttributeFromStaticTruth(),
978
+ this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !1, void 0, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch))) : (this.stopStateAnimates(),
979
+ this.attributeMayContainTransientAttrs ? this._restoreAttributeFromStaticTruth({
980
+ type: enums_1.AttributeUpdateType.STATE
981
+ }) : this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, this.resolvedStatePatch, {
982
+ type: enums_1.AttributeUpdateType.STATE
983
+ }), this.emitStateUpdateEvent());
984
+ }
985
+ }
680
986
  resolveStateAnimateConfig(animateConfig) {
681
987
  var _a, _b, _c;
682
988
  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;
683
989
  }
684
- applyStateAttrs(attrs, stateNames, hasAnimation, isClear, animateConfig) {
990
+ applyStateAttrs(attrs, stateNames, hasAnimation, isClear, animateConfig, extraAnimateAttrs) {
685
991
  const resolvedAnimateConfig = hasAnimation ? this.resolveStateAnimateConfig(animateConfig) : void 0, transitionOptions = resolvedAnimateConfig ? {
686
- animateConfig: resolvedAnimateConfig
992
+ animateConfig: resolvedAnimateConfig,
993
+ extraAnimateAttrs: extraAnimateAttrs,
994
+ shouldSkipDefaultAttribute: this.shouldSkipStateTransitionDefaultAttribute.bind(this)
687
995
  } : void 0;
688
996
  if (isClear) return void this.getStateTransitionOrchestrator().applyClearTransition(this, attrs, hasAnimation, stateNames, transitionOptions);
689
997
  const plan = this.getStateTransitionOrchestrator().analyzeTransition({}, attrs, stateNames, hasAnimation, {
690
998
  noWorkAnimateAttr: this.getNoWorkAnimateAttr(),
691
- animateConfig: resolvedAnimateConfig
999
+ animateConfig: resolvedAnimateConfig,
1000
+ extraAnimateAttrs: extraAnimateAttrs,
1001
+ shouldSkipDefaultAttribute: this.shouldSkipStateTransitionDefaultAttribute.bind(this)
692
1002
  });
693
1003
  this.getStateTransitionOrchestrator().applyTransition(this, plan, hasAnimation, transitionOptions);
694
1004
  }
695
- updateNormalAttrs(stateAttrs) {
696
- this._deprecatedNormalAttrsView = cloneAttributeValue(this.baseAttributes);
1005
+ updateNormalAttrs(_stateAttrs) {}
1006
+ getStateTransitionDefaultAttribute(key, targetAttrs) {
1007
+ return this.getDefaultAttribute(key);
1008
+ }
1009
+ shouldSkipStateTransitionDefaultAttribute(_key, _targetAttrs) {
1010
+ return !1;
697
1011
  }
698
1012
  stopStateAnimates(type = "end") {
699
1013
  const stopAnimationState = this.stopAnimationState;
700
1014
  if ("function" == typeof stopAnimationState) return void stopAnimationState.call(this, "state", type);
1015
+ if (!this.mayHaveTrackedAnimates()) return;
701
1016
  const stateAnimates = [];
702
1017
  this.visitTrackedAnimates((animate => {
703
1018
  animate.stateNames && stateAnimates.push(animate);
@@ -710,23 +1025,27 @@ class Graphic extends node_tree_1.Node {
710
1025
  }
711
1026
  clearStates(hasAnimation) {
712
1027
  var _a, _b, _c;
713
- const previousStates = this.currentStates ? this.currentStates.slice() : [], transition = this.createStateModel().clearStates();
1028
+ const previousStates = null !== (_a = this.currentStates) && void 0 !== _a ? _a : EMPTY_STATE_NAMES, previousResolvedStatePatch = this.resolvedStatePatch, transition = this.createStateModel().clearStates();
714
1029
  if (!transition.changed && 0 === previousStates.length) return this.currentStates = [],
715
1030
  this.effectiveStates = [], this.resolvedStatePatch = void 0, this.sharedStateDirty = !1,
716
1031
  void this.clearSharedStateActiveRegistrations();
717
- const resolvedStateAttrs = cloneAttributeValue(null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : {});
718
- transition.changed && !this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !0) || (this.currentStates = transition.states,
719
- this.effectiveStates = [], this.resolvedStatePatch = void 0, this.sharedStateDirty = !1,
720
- this.clearSharedStateActiveRegistrations(), null === (_b = (0, state_perf_monitor_1.getStageStatePerfMonitor)(this.stage)) || void 0 === _b || _b.incrementCounter("stateCommits"),
721
- null === (_c = (0, state_perf_monitor_1.getStageStatePerfMonitor)(this.stage)) || void 0 === _c || _c.recordEvent("state-commit", {
722
- graphicId: this._uid,
723
- targetStates: []
724
- }), hasAnimation ? (this._syncFinalAttributeFromStaticTruth(), this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !0)) : (this.stopStateAnimates(),
725
- this._restoreAttributeFromStaticTruth({
726
- type: enums_1.AttributeUpdateType.STATE
727
- }), this._emitCustomEvent("afterStateUpdate", {
728
- type: enums_1.AttributeUpdateType.STATE
729
- })));
1032
+ const resolvedStateAttrs = hasAnimation || this.hasCustomEvent("beforeStateUpdate") ? cloneAttributeValue(null !== (_b = this.baseAttributes) && void 0 !== _b ? _b : {}) : null !== (_c = this.baseAttributes) && void 0 !== _c ? _c : {};
1033
+ if (!transition.changed || this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !0)) {
1034
+ if (this.currentStates = transition.states, this.effectiveStates = [], this.resolvedStatePatch = void 0,
1035
+ this.sharedStateDirty = !1, this.clearSharedStateActiveRegistrations(), this.stage) {
1036
+ const perfMonitor = (0, state_perf_monitor_1.getActiveStageStatePerfMonitor)(this.stage);
1037
+ null == perfMonitor || perfMonitor.incrementCounter("stateCommits"), null == perfMonitor || perfMonitor.recordEvent("state-commit", {
1038
+ graphicId: this._uid,
1039
+ targetStates: []
1040
+ });
1041
+ }
1042
+ hasAnimation ? (this._syncFinalAttributeFromStaticTruth(), this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !0, void 0, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch))) : (this.stopStateAnimates(),
1043
+ this.attributeMayContainTransientAttrs ? this._restoreAttributeFromStaticTruth({
1044
+ type: enums_1.AttributeUpdateType.STATE
1045
+ }) : this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, void 0, {
1046
+ type: enums_1.AttributeUpdateType.STATE
1047
+ }), this.emitStateUpdateEvent());
1048
+ }
730
1049
  }
731
1050
  removeState(stateName, hasAnimation) {
732
1051
  const transition = this.createStateModel().removeState(stateName);
@@ -740,42 +1059,51 @@ class Graphic extends node_tree_1.Node {
740
1059
  const transition = this.createStateModel().addState(stateName, keepCurrentStates);
741
1060
  transition.changed && this.useStates(transition.states, hasAnimation);
742
1061
  }
1062
+ setStates(states, options) {
1063
+ var _a, _b, _c;
1064
+ 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));
1065
+ if (nextStates.length) {
1066
+ if (this.sameStateNames(this.currentStates, nextStates)) return shouldRefreshSameStatePatch ? void this.commitSameStatePatchRefresh(nextStates, hasAnimation, animateSameStatePatchChange) : void (this.sharedStateDirty && this.refreshSharedStateBeforeRender());
1067
+ this.useStates(nextStates, hasAnimation);
1068
+ } else {
1069
+ if (!hasCurrentState && !this.sharedStateDirty) return;
1070
+ this.clearStates(hasAnimation);
1071
+ }
1072
+ }
743
1073
  useStates(states, hasAnimation) {
744
- var _a, _b, _c, _d, _e;
1074
+ var _a;
745
1075
  if (!states.length) return void this.clearStates(hasAnimation);
746
- const previousStates = this.currentStates ? this.currentStates.slice() : [], stateResolveBaseAttrs = null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : this.attribute, stateModel = this.createStateModel();
747
- null === (_b = this.stateEngine) || void 0 === _b || _b.setResolveContext(this, stateResolveBaseAttrs);
748
- const transition = stateModel.useStates(states);
749
- if (!transition.changed && this.sameStateNames(previousStates, transition.states)) return;
750
- const effectiveStates = null !== (_c = transition.effectiveStates) && void 0 !== _c ? _c : 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);
751
- this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1) && (this.currentStates = transition.states,
752
- this.effectiveStates = [ ...effectiveStates ], this.resolvedStatePatch = Object.assign({}, resolvedStateAttrs),
753
- this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(), null === (_d = (0,
754
- state_perf_monitor_1.getStageStatePerfMonitor)(this.stage)) || void 0 === _d || _d.incrementCounter("stateCommits"),
755
- null === (_e = (0, state_perf_monitor_1.getStageStatePerfMonitor)(this.stage)) || void 0 === _e || _e.recordEvent("state-commit", {
756
- graphicId: this._uid,
757
- targetStates: [ ...transition.states ]
758
- }), hasAnimation ? (this._syncFinalAttributeFromStaticTruth(), this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation)) : (this.stopStateAnimates(),
759
- this._restoreAttributeFromStaticTruth({
760
- type: enums_1.AttributeUpdateType.STATE
761
- }), this._emitCustomEvent("afterStateUpdate", {
762
- type: enums_1.AttributeUpdateType.STATE
763
- })));
1076
+ 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);
1077
+ if ((transition.changed || !this.sameStateNames(previousStates, transition.states)) && this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) {
1078
+ if (this.currentStates = transition.states, this.effectiveStates = isSimpleLocalTransition ? effectiveStates : [ ...effectiveStates ],
1079
+ this.resolvedStatePatch = resolvedStateAttrs, this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(),
1080
+ this.stage) {
1081
+ const perfMonitor = (0, state_perf_monitor_1.getActiveStageStatePerfMonitor)(this.stage);
1082
+ null == perfMonitor || perfMonitor.incrementCounter("stateCommits"), null == perfMonitor || perfMonitor.recordEvent("state-commit", {
1083
+ graphicId: this._uid,
1084
+ targetStates: [ ...transition.states ]
1085
+ });
1086
+ }
1087
+ hasAnimation ? (this._syncFinalAttributeFromStaticTruth(), this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !1, void 0, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch))) : (this.stopStateAnimates(),
1088
+ this.attributeMayContainTransientAttrs ? this._restoreAttributeFromStaticTruth({
1089
+ type: enums_1.AttributeUpdateType.STATE
1090
+ }) : this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, this.resolvedStatePatch, {
1091
+ type: enums_1.AttributeUpdateType.STATE
1092
+ }), this.emitStateUpdateEvent());
1093
+ }
764
1094
  }
765
1095
  invalidateResolver() {
766
1096
  var _a, _b;
767
1097
  if (!this.stateEngine || !(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || !this.compiledStateDefinitions) return;
768
- const stateResolveBaseAttrs = null !== (_b = this.baseAttributes) && void 0 !== _b ? _b : this.attribute;
769
- this.stateEngine.setResolveContext(this, stateResolveBaseAttrs), this.resolverEpoch += 1,
1098
+ this.syncStateResolveContext();
1099
+ this.resolverEpoch = (null !== (_b = this.resolverEpoch) && void 0 !== _b ? _b : 0) + 1,
770
1100
  this.stateEngine.invalidateResolverCache();
771
1101
  const transition = this.stateEngine.applyStates(this.currentStates), resolvedStateAttrs = Object.assign({}, this.stateEngine.resolvedPatch);
772
- this.effectiveStates = [ ...transition.effectiveStates ], this.resolvedStatePatch = Object.assign({}, resolvedStateAttrs),
1102
+ this.effectiveStates = [ ...transition.effectiveStates ], this.resolvedStatePatch = resolvedStateAttrs,
773
1103
  this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(), this.stopStateAnimates(),
774
1104
  this._restoreAttributeFromStaticTruth({
775
1105
  type: enums_1.AttributeUpdateType.STATE
776
- }), this._emitCustomEvent("afterStateUpdate", {
777
- type: enums_1.AttributeUpdateType.STATE
778
- });
1106
+ }), this.emitStateUpdateEvent();
779
1107
  }
780
1108
  sameStateNames(left, right) {
781
1109
  const normalizedLeft = null != left ? left : [], normalizedRight = null != right ? right : [];
@@ -797,6 +1125,10 @@ class Graphic extends node_tree_1.Node {
797
1125
  this._updateTag |= enums_1.UpdateTag.UPDATE_SHAPE_AND_BOUNDS, this.parent && this.parent.addChildUpdateBoundTag(),
798
1126
  this.glyphHost && this.glyphHost.addUpdateBoundTag();
799
1127
  }
1128
+ addBroadUpdateTag() {
1129
+ this.shadowRoot && this.shadowRoot.addUpdateGlobalPositionTag(), this._updateTag |= enums_1.UpdateTag.UPDATE_SHAPE_AND_BOUNDS | enums_1.UpdateTag.UPDATE_PAINT | enums_1.UpdateTag.UPDATE_GLOBAL_LOCAL_MATRIX | enums_1.UpdateTag.UPDATE_LAYOUT,
1130
+ this.parent && this.parent.addChildUpdateBoundTag(), this.glyphHost && this.glyphHost.addUpdateBoundTag();
1131
+ }
800
1132
  updateShapeAndBoundsTagSetted() {
801
1133
  return (this._updateTag & enums_1.UpdateTag.UPDATE_SHAPE_AND_BOUNDS) === enums_1.UpdateTag.UPDATE_SHAPE_AND_BOUNDS;
802
1134
  }
@@ -871,12 +1203,12 @@ class Graphic extends node_tree_1.Node {
871
1203
  }
872
1204
  }
873
1205
  setStage(stage, layer) {
874
- var _a, _b, _c, _d, _e, _f, _g, _h;
1206
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
875
1207
  const graphicService = null !== (_c = null !== (_a = null == stage ? void 0 : stage.graphicService) && void 0 !== _a ? _a : null === (_b = this.stage) || void 0 === _b ? void 0 : _b.graphicService) && void 0 !== _c ? _c : application_1.application.graphicService, previousStage = this.stage;
876
1208
  if (this.stage !== stage || this.layer !== layer) {
877
- if (this.stage = stage, this.layer = layer, this.syncSharedStateScopeBindingFromTree(!!(null === (_d = this.currentStates) || void 0 === _d ? void 0 : _d.length)),
878
- this.setStageToShadowRoot(stage, layer), this.hasAnyTrackedAnimate()) {
879
- const previousTimeline = null === (_e = null == previousStage ? void 0 : previousStage.getTimeline) || void 0 === _e ? void 0 : _e.call(previousStage), nextTimeline = null === (_f = null == stage ? void 0 : stage.getTimeline) || void 0 === _f ? void 0 : _f.call(stage), detachedStageAnimates = [];
1209
+ if (this.stage = stage, this.layer = layer, ((null === (_d = this.currentStates) || void 0 === _d ? void 0 : _d.length) || this.boundSharedStateScope || (null === (_e = this.registeredActiveScopes) || void 0 === _e ? void 0 : _e.size) || this.sharedStateDirty) && this.syncSharedStateScopeBindingOnTreeChange(!0),
1210
+ this.setStageToShadowRoot(stage, layer), this.mayHaveTrackedAnimates() && this.hasAnyTrackedAnimate()) {
1211
+ const previousTimeline = null === (_f = null == previousStage ? void 0 : previousStage.getTimeline) || void 0 === _f ? void 0 : _f.call(previousStage), nextTimeline = null === (_g = null == stage ? void 0 : stage.getTimeline) || void 0 === _g ? void 0 : _g.call(stage), detachedStageAnimates = [];
880
1212
  this.visitTrackedAnimates((a => {
881
1213
  (!!previousTimeline && a.timeline === previousTimeline || a.timeline.isGlobal) && (nextTimeline ? a.timeline !== nextTimeline && (previousTimeline && a.timeline === previousTimeline && previousTimeline.removeAnimate(a, !1),
882
1214
  a.setTimeline(nextTimeline), nextTimeline.addAnimate(a)) : previousTimeline && a.timeline === previousTimeline && (previousTimeline.removeAnimate(a, !1),
@@ -890,9 +1222,18 @@ class Graphic extends node_tree_1.Node {
890
1222
  type: enums_1.AttributeUpdateType.ANIMATE_END
891
1223
  }));
892
1224
  }
893
- return this._onSetStage && this._onSetStage(this, stage, layer), void (null === (_g = null == graphicService ? void 0 : graphicService.onSetStage) || void 0 === _g || _g.call(graphicService, this, stage));
1225
+ return this._onSetStage && this._onSetStage(this, stage, layer), void (null === (_h = null == graphicService ? void 0 : graphicService.onSetStage) || void 0 === _h || _h.call(graphicService, this, stage));
894
1226
  }
895
- this.syncSharedStateScopeBindingFromTree(!!(null === (_h = this.currentStates) || void 0 === _h ? void 0 : _h.length));
1227
+ ((null === (_j = this.currentStates) || void 0 === _j ? void 0 : _j.length) || this.boundSharedStateScope || (null === (_k = this.registeredActiveScopes) || void 0 === _k ? void 0 : _k.size) || this.sharedStateDirty) && this.syncSharedStateScopeBindingOnTreeChange(!0);
1228
+ }
1229
+ detachStageForRelease() {
1230
+ var _a, _b, _c;
1231
+ (null === (_a = this.registeredActiveScopes) || void 0 === _a ? void 0 : _a.size) && this.clearSharedStateActiveRegistrations(),
1232
+ (this.mayHaveTrackedAnimates() || this.shadowRoot) && this.stopAnimates(), this.boundSharedStateScope = void 0,
1233
+ this.boundSharedStateRevision = void 0, this.localFallbackCompiledDefinitions = void 0,
1234
+ this.compiledStateDefinitions = void 0, this.compiledStateDefinitionsCacheKey = void 0,
1235
+ this.stateEngine = void 0, this.stateEngineCompiledDefinitions = void 0, this.stateEngineStateProxyModeKey = void 0,
1236
+ this.sharedStateDirty = !1, this.stage = null, this.layer = null, this.shadowRoot && (null === (_c = (_b = this.shadowRoot).detachStageForRelease) || void 0 === _c || _c.call(_b));
896
1237
  }
897
1238
  setStageToShadowRoot(stage, layer) {
898
1239
  this.shadowRoot && this.shadowRoot.setStage(stage, layer);
@@ -967,6 +1308,7 @@ class Graphic extends node_tree_1.Node {
967
1308
  res && (res.state = "fail", cb && cb());
968
1309
  }
969
1310
  _stopAnimates() {
1311
+ if (!this.mayHaveTrackedAnimates()) return;
970
1312
  const animates = [];
971
1313
  this.visitTrackedAnimates((animate => {
972
1314
  animates.push(animate);
@@ -980,15 +1322,19 @@ class Graphic extends node_tree_1.Node {
980
1322
  }));
981
1323
  }
982
1324
  release() {
983
- var _a, _b, _c;
984
- this.releaseStatus = "released", this.clearSharedStateActiveRegistrations(), this.stopAnimates();
985
- const graphicService = null !== (_b = null === (_a = this.stage) || void 0 === _a ? void 0 : _a.graphicService) && void 0 !== _b ? _b : application_1.application.graphicService;
986
- null === (_c = null == graphicService ? void 0 : graphicService.onRelease) || void 0 === _c || _c.call(graphicService, this),
1325
+ var _a, _b, _c, _d;
1326
+ this.releaseStatus = "released", (null === (_a = this.registeredActiveScopes) || void 0 === _a ? void 0 : _a.size) && this.clearSharedStateActiveRegistrations(),
1327
+ (this.mayHaveTrackedAnimates() || this.shadowRoot) && this.stopAnimates();
1328
+ const graphicService = null !== (_c = null === (_b = this.stage) || void 0 === _b ? void 0 : _b.graphicService) && void 0 !== _c ? _c : application_1.application.graphicService;
1329
+ null === (_d = null == graphicService ? void 0 : graphicService.onRelease) || void 0 === _d || _d.call(graphicService, this),
987
1330
  super.release();
988
1331
  }
1332
+ hasCustomEvent(type) {
1333
+ return !!this._events && type in this._events;
1334
+ }
989
1335
  _dispatchCustomEvent(type, context) {
990
1336
  var _a, _b;
991
- if (this._events && type in this._events) {
1337
+ if (this.hasCustomEvent(type)) {
992
1338
  const changeEvent = new event_1.CustomEvent(type, context);
993
1339
  changeEvent.bubbles = !1;
994
1340
  const manager = null === (_b = null === (_a = this.stage) || void 0 === _a ? void 0 : _a.eventSystem) || void 0 === _b ? void 0 : _b.manager;
@@ -997,7 +1343,7 @@ class Graphic extends node_tree_1.Node {
997
1343
  return !0;
998
1344
  }
999
1345
  beforeStateUpdate(attrs, prevStates, nextStates, hasAnimation, isClear) {
1000
- return this._dispatchCustomEvent("beforeStateUpdate", {
1346
+ return !this.hasCustomEvent("beforeStateUpdate") || this._dispatchCustomEvent("beforeStateUpdate", {
1001
1347
  type: enums_1.AttributeUpdateType.STATE,
1002
1348
  attrs: Object.assign({}, attrs),
1003
1349
  prevStates: prevStates.slice(),
@@ -1006,6 +1352,11 @@ class Graphic extends node_tree_1.Node {
1006
1352
  isClear: !!isClear
1007
1353
  });
1008
1354
  }
1355
+ emitStateUpdateEvent() {
1356
+ this.hasCustomEvent("afterStateUpdate") && this._emitCustomEvent("afterStateUpdate", {
1357
+ type: enums_1.AttributeUpdateType.STATE
1358
+ });
1359
+ }
1009
1360
  _emitCustomEvent(type, context) {
1010
1361
  this._dispatchCustomEvent(type, context);
1011
1362
  }