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

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 (136) hide show
  1. package/cjs/common/diff.js +1 -2
  2. package/cjs/common/event-transformer.js +2 -1
  3. package/cjs/common/rect-utils.js +1 -1
  4. package/cjs/common/render-area.js +1 -1
  5. package/cjs/common/render-command-list.js +1 -1
  6. package/cjs/common/render-curve.js +1 -1
  7. package/cjs/common/render-utils.js +1 -1
  8. package/cjs/common/seg-context.js +1 -2
  9. package/cjs/common/simplify.js +1 -1
  10. package/cjs/common/sort.js +1 -1
  11. package/cjs/common/split-path.js +1 -1
  12. package/cjs/common/store.js +1 -1
  13. package/cjs/common/text.js +1 -1
  14. package/cjs/common/utils.js +1 -1
  15. package/cjs/core/camera.js +1 -1
  16. package/cjs/core/constants.js +1 -1
  17. package/cjs/core/core-modules.js +1 -1
  18. package/cjs/core/global-module.js +2 -0
  19. package/cjs/core/global.js +1 -1
  20. package/cjs/core/graphic-utils.js +1 -1
  21. package/cjs/core/index.js +1 -1
  22. package/cjs/core/layer-service.js +2 -1
  23. package/cjs/core/layer.js +1 -1
  24. package/cjs/core/light.js +1 -1
  25. package/cjs/core/stage.d.ts +4 -1
  26. package/cjs/core/stage.js +24 -12
  27. package/cjs/core/stage.js.map +1 -1
  28. package/cjs/core/window.js +1 -1
  29. package/cjs/graphic/graphic-service/graphic-service.d.ts +4 -0
  30. package/cjs/graphic/graphic-service/graphic-service.js +6 -5
  31. package/cjs/graphic/graphic-service/graphic-service.js.map +1 -1
  32. package/cjs/graphic/graphic.d.ts +73 -11
  33. package/cjs/graphic/graphic.js +516 -157
  34. package/cjs/graphic/graphic.js.map +1 -1
  35. package/cjs/graphic/group.d.ts +5 -1
  36. package/cjs/graphic/group.js +37 -18
  37. package/cjs/graphic/group.js.map +1 -1
  38. package/cjs/graphic/rect.d.ts +2 -0
  39. package/cjs/graphic/rect.js +44 -0
  40. package/cjs/graphic/rect.js.map +1 -1
  41. package/cjs/graphic/state/shared-state-refresh.js +4 -3
  42. package/cjs/graphic/state/shared-state-refresh.js.map +1 -1
  43. package/cjs/graphic/state/shared-state-scope.js +1 -1
  44. package/cjs/graphic/state/shared-state-scope.js.map +1 -1
  45. package/cjs/graphic/state/state-engine.js +2 -2
  46. package/cjs/graphic/state/state-engine.js.map +1 -1
  47. package/cjs/graphic/state/state-perf-monitor.d.ts +1 -0
  48. package/cjs/graphic/state/state-perf-monitor.js +9 -2
  49. package/cjs/graphic/state/state-perf-monitor.js.map +1 -1
  50. package/cjs/graphic/state/state-style-resolver.d.ts +0 -9
  51. package/cjs/graphic/state/state-style-resolver.js +0 -23
  52. package/cjs/graphic/state/state-style-resolver.js.map +1 -1
  53. package/cjs/graphic/state/state-transition-orchestrator.d.ts +5 -0
  54. package/cjs/graphic/state/state-transition-orchestrator.js +17 -5
  55. package/cjs/graphic/state/state-transition-orchestrator.js.map +1 -1
  56. package/cjs/interface/animation/animate.d.ts +1 -0
  57. package/cjs/interface/animation/animate.js.map +1 -1
  58. package/cjs/interface/graphic.d.ts +9 -0
  59. package/cjs/interface/graphic.js.map +1 -1
  60. package/cjs/interface/node-tree.js.map +1 -1
  61. package/cjs/plugins/builtin-plugin/dirty-bounds-plugin.d.ts +4 -1
  62. package/cjs/plugins/builtin-plugin/dirty-bounds-plugin.js +20 -10
  63. package/cjs/plugins/builtin-plugin/dirty-bounds-plugin.js.map +1 -1
  64. package/cjs/plugins/builtin-plugin/flex-layout-plugin.js +3 -2
  65. package/cjs/plugins/builtin-plugin/flex-layout-plugin.js.map +1 -1
  66. package/cjs/render/contributions/render/base-render.js +8 -7
  67. package/cjs/render/contributions/render/base-render.js.map +1 -1
  68. package/dist/index.es.js +1150 -279
  69. package/es/common/diff.js +1 -2
  70. package/es/common/event-transformer.js +2 -1
  71. package/es/common/rect-utils.js +1 -1
  72. package/es/common/render-area.js +1 -1
  73. package/es/common/render-command-list.js +1 -1
  74. package/es/common/render-curve.js +1 -1
  75. package/es/common/render-utils.js +1 -1
  76. package/es/common/seg-context.js +1 -2
  77. package/es/common/simplify.js +1 -1
  78. package/es/common/sort.js +1 -1
  79. package/es/common/split-path.js +1 -1
  80. package/es/common/store.js +1 -1
  81. package/es/common/text.js +1 -1
  82. package/es/common/utils.js +1 -1
  83. package/es/core/camera.js +1 -1
  84. package/es/core/constants.js +1 -1
  85. package/es/core/core-modules.js +1 -1
  86. package/es/core/global-module.js +2 -0
  87. package/es/core/global.js +1 -1
  88. package/es/core/graphic-utils.js +1 -1
  89. package/es/core/index.js +1 -1
  90. package/es/core/layer-service.js +2 -1
  91. package/es/core/layer.js +1 -1
  92. package/es/core/light.js +1 -1
  93. package/es/core/stage.d.ts +4 -1
  94. package/es/core/stage.js +22 -11
  95. package/es/core/stage.js.map +1 -1
  96. package/es/core/window.js +1 -1
  97. package/es/graphic/graphic-service/graphic-service.d.ts +4 -0
  98. package/es/graphic/graphic-service/graphic-service.js +6 -5
  99. package/es/graphic/graphic-service/graphic-service.js.map +1 -1
  100. package/es/graphic/graphic.d.ts +73 -11
  101. package/es/graphic/graphic.js +511 -150
  102. package/es/graphic/graphic.js.map +1 -1
  103. package/es/graphic/group.d.ts +5 -1
  104. package/es/graphic/group.js +36 -18
  105. package/es/graphic/group.js.map +1 -1
  106. package/es/graphic/rect.d.ts +2 -0
  107. package/es/graphic/rect.js +44 -0
  108. package/es/graphic/rect.js.map +1 -1
  109. package/es/graphic/state/shared-state-refresh.js +5 -4
  110. package/es/graphic/state/shared-state-refresh.js.map +1 -1
  111. package/es/graphic/state/shared-state-scope.js +2 -2
  112. package/es/graphic/state/shared-state-scope.js.map +1 -1
  113. package/es/graphic/state/state-engine.js +3 -3
  114. package/es/graphic/state/state-engine.js.map +1 -1
  115. package/es/graphic/state/state-perf-monitor.d.ts +1 -0
  116. package/es/graphic/state/state-perf-monitor.js +7 -0
  117. package/es/graphic/state/state-perf-monitor.js.map +1 -1
  118. package/es/graphic/state/state-style-resolver.d.ts +0 -9
  119. package/es/graphic/state/state-style-resolver.js +0 -23
  120. package/es/graphic/state/state-style-resolver.js.map +1 -1
  121. package/es/graphic/state/state-transition-orchestrator.d.ts +5 -0
  122. package/es/graphic/state/state-transition-orchestrator.js +17 -5
  123. package/es/graphic/state/state-transition-orchestrator.js.map +1 -1
  124. package/es/interface/animation/animate.d.ts +1 -0
  125. package/es/interface/animation/animate.js.map +1 -1
  126. package/es/interface/graphic.d.ts +9 -0
  127. package/es/interface/graphic.js.map +1 -1
  128. package/es/interface/node-tree.js.map +1 -1
  129. package/es/plugins/builtin-plugin/dirty-bounds-plugin.d.ts +4 -1
  130. package/es/plugins/builtin-plugin/dirty-bounds-plugin.js +20 -10
  131. package/es/plugins/builtin-plugin/dirty-bounds-plugin.js.map +1 -1
  132. package/es/plugins/builtin-plugin/flex-layout-plugin.js +3 -2
  133. package/es/plugins/builtin-plugin/flex-layout-plugin.js.map +1 -1
  134. package/es/render/contributions/render/base-render.js +8 -6
  135. package/es/render/contributions/render/base-render.js.map +1 -1
  136. package/package.json +3 -3
@@ -36,7 +36,7 @@ import { StateEngine } from "./state/state-engine";
36
36
 
37
37
  import { StateModel } from "./state/state-model";
38
38
 
39
- import { UpdateCategory, classifyAttributeDelta } from "./state/attribute-update-classifier";
39
+ import { ATTRIBUTE_CATEGORY, UpdateCategory, classifyAttributeDelta } from "./state/attribute-update-classifier";
40
40
 
41
41
  import { StateStyleResolver } from "./state/state-style-resolver";
42
42
 
@@ -46,7 +46,7 @@ import { collectSharedStateScopeChain, ensureSharedStateScopeFresh } from "./sta
46
46
 
47
47
  import { enqueueGraphicSharedStateRefresh, scheduleStageSharedStateRefresh } from "./state/shared-state-refresh";
48
48
 
49
- import { getStageStatePerfMonitor } from "./state/state-perf-monitor";
49
+ import { getActiveStageStatePerfMonitor } from "./state/state-perf-monitor";
50
50
 
51
51
  const _tempBounds = new AABBBounds, loadShadowRootFactory = () => require("./shadow-root"), tempMatrix = new Matrix;
52
52
 
@@ -54,10 +54,10 @@ export const PURE_STYLE_KEY = [ "stroke", "opacity", "strokeOpacity", "lineDash"
54
54
 
55
55
  export const GRAPHIC_UPDATE_TAG_KEY = [ "lineWidth", "scaleX", "scaleY", "angle", "anchor", "visible" ];
56
56
 
57
- 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 Point;
57
+ 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 Point, EMPTY_STATE_NAMES = [], BROAD_UPDATE_CATEGORY = UpdateCategory.PAINT | UpdateCategory.SHAPE | UpdateCategory.BOUNDS | UpdateCategory.TRANSFORM | UpdateCategory.LAYOUT;
58
58
 
59
59
  function isPlainObjectValue(value) {
60
- return "object" == typeof value && null != value && !isArray(value);
60
+ return "object" == typeof value && null != value && !Array.isArray(value);
61
61
  }
62
62
 
63
63
  function cloneAttributeValue(value) {
@@ -69,14 +69,6 @@ function cloneAttributeValue(value) {
69
69
  })), clone;
70
70
  }
71
71
 
72
- function cloneSimpleAttributeRecord(value) {
73
- return isPlainObjectValue(value) ? Object.assign({}, value) : value;
74
- }
75
-
76
- export function shouldUseSimpleAttributeFastPath(value) {
77
- return !!isPlainObjectValue(value) && !Object.keys(value).some((key => isPlainObjectValue(value[key])));
78
- }
79
-
80
72
  function cloneAttributeSurface(value) {
81
73
  if (!isPlainObjectValue(value)) return value;
82
74
  const source = value, clone = {};
@@ -86,6 +78,10 @@ function cloneAttributeSurface(value) {
86
78
  })), clone;
87
79
  }
88
80
 
81
+ function areAttributeValuesEqual(left, right) {
82
+ return left === right || !!(isPlainObjectValue(left) || isPlainObjectValue(right) || Array.isArray(left) || Array.isArray(right)) && isEqual(left, right);
83
+ }
84
+
89
85
  function deepMergeAttributeValue(base, value) {
90
86
  var _a;
91
87
  const result = null !== (_a = cloneAttributeValue(base)) && void 0 !== _a ? _a : {};
@@ -149,19 +145,27 @@ export class Graphic extends Node {
149
145
  get globalTransMatrix() {
150
146
  return this.tryUpdateGlobalTransMatrix(!0);
151
147
  }
148
+ get baseAttributes() {
149
+ var _a;
150
+ return null !== (_a = this._baseAttributes) && void 0 !== _a ? _a : this.attribute;
151
+ }
152
+ set baseAttributes(value) {
153
+ value !== this.attribute ? this._baseAttributes = value : this._baseAttributes = void 0;
154
+ }
152
155
  constructor(params = {}) {
153
156
  var _a;
154
- super(), this.resolverEpoch = 0, this._AABBBounds = new AABBBounds, this._updateTag = UpdateTag.INIT;
155
- const useSimpleAttributeFastPath = shouldUseSimpleAttributeFastPath(params), initialBaseAttributes = useSimpleAttributeFastPath ? cloneSimpleAttributeRecord(params) : cloneAttributeValue(params);
156
- this.baseAttributes = initialBaseAttributes, this.attribute = useSimpleAttributeFastPath ? cloneSimpleAttributeRecord(initialBaseAttributes) : cloneAttributeSurface(initialBaseAttributes),
157
+ super(), this._AABBBounds = new AABBBounds, this._updateTag = UpdateTag.INIT, this.attribute = params,
157
158
  this.valid = this.isValid(), this.updateAABBBoundsStamp = 0, params.background && this.loadImage(null !== (_a = params.background.background) && void 0 !== _a ? _a : params.background, !0),
158
- isExternalTexture(params.texture) && this.loadImage(params.texture, !1), params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic);
159
+ params.texture && isExternalTexture(params.texture) && this.loadImage(params.texture, !1),
160
+ params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic);
159
161
  }
160
162
  get normalAttrs() {
161
163
  return this.baseAttributes;
162
164
  }
163
- set normalAttrs(value) {
164
- this._deprecatedNormalAttrsView = null != value ? value : void 0;
165
+ set normalAttrs(_value) {}
166
+ getBaseAttributesStorage() {
167
+ var _a;
168
+ return null !== (_a = this._baseAttributes) && void 0 !== _a ? _a : this.attribute;
165
169
  }
166
170
  getGraphicService() {
167
171
  var _a, _b;
@@ -200,10 +204,18 @@ export class Graphic extends Node {
200
204
  markDirty && (null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) && this.markSharedStateDirty(),
201
205
  !0);
202
206
  }
203
- syncSharedStateActiveRegistrations() {
207
+ syncSharedStateScopeBindingOnTreeChange(markDirty = !0) {
204
208
  var _a, _b;
205
- const nextScopes = (null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) && this.boundSharedStateScope ? new Set(collectSharedStateScopeChain(this.boundSharedStateScope)) : new Set;
206
- (null !== (_b = this.registeredActiveScopes) && void 0 !== _b ? _b : new Set).forEach((scope => {
209
+ 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);
210
+ }
211
+ syncSharedStateActiveRegistrations() {
212
+ var _a;
213
+ const previousScopes = this.registeredActiveScopes;
214
+ if (!(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || !this.boundSharedStateScope) return (null == previousScopes ? void 0 : previousScopes.size) && (previousScopes.forEach((scope => {
215
+ scope.subtreeActiveDescendants.delete(this);
216
+ })), previousScopes.clear()), void (this.registeredActiveScopes = void 0);
217
+ const nextScopes = new Set(collectSharedStateScopeChain(this.boundSharedStateScope));
218
+ null == previousScopes || previousScopes.forEach((scope => {
207
219
  nextScopes.has(scope) || scope.subtreeActiveDescendants.delete(this);
208
220
  })), nextScopes.forEach((scope => {
209
221
  scope.subtreeActiveDescendants.add(this);
@@ -220,7 +232,7 @@ export class Graphic extends Node {
220
232
  scheduleStageSharedStateRefresh(this.stage);
221
233
  }
222
234
  onParentSharedStateTreeChanged(stage, layer) {
223
- this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingFromTree() : this.setStage(stage, layer);
235
+ this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingOnTreeChange() : this.setStage(stage, layer);
224
236
  }
225
237
  refreshSharedStateBeforeRender() {
226
238
  var _a;
@@ -228,9 +240,7 @@ export class Graphic extends Node {
228
240
  this.boundSharedStateScope && ensureSharedStateScopeFresh(this.boundSharedStateScope),
229
241
  this.recomputeCurrentStatePatch(), this.stopStateAnimates(), this._restoreAttributeFromStaticTruth({
230
242
  type: AttributeUpdateType.STATE
231
- }), this._emitCustomEvent("afterStateUpdate", {
232
- type: AttributeUpdateType.STATE
233
- }), this.sharedStateDirty = !1) : this.sharedStateDirty = !1;
243
+ }), this.emitStateUpdateEvent(), this.sharedStateDirty = !1) : this.sharedStateDirty = !1;
234
244
  }
235
245
  getLocalStatesVersion() {
236
246
  var _a, _b;
@@ -280,14 +290,12 @@ export class Graphic extends Node {
280
290
  };
281
291
  }
282
292
  recomputeCurrentStatePatch() {
283
- var _a, _b, _c, _d;
293
+ var _a, _b;
284
294
  if (!(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length)) return this.effectiveStates = [],
285
295
  this.resolvedStatePatch = void 0, void this.syncSharedStateActiveRegistrations();
286
- const stateResolveBaseAttrs = null !== (_b = this.baseAttributes) && void 0 !== _b ? _b : this.attribute, stateModel = this.createStateModel();
287
- null === (_c = this.stateEngine) || void 0 === _c || _c.setResolveContext(this, stateResolveBaseAttrs);
288
- 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);
289
297
  this.currentStates = transition.states, this.effectiveStates = [ ...effectiveStates ],
290
- this.resolvedStatePatch = Object.assign({}, resolvedStateAttrs), this.syncSharedStateActiveRegistrations();
298
+ this.resolvedStatePatch = resolvedStateAttrs, this.syncSharedStateActiveRegistrations();
291
299
  }
292
300
  buildStaticAttributeSnapshot() {
293
301
  var _a;
@@ -297,6 +305,22 @@ export class Graphic extends Node {
297
305
  "deep" === this.stateMergeMode && isPlainObjectValue(previousValue) && isPlainObjectValue(nextValue) ? snapshot[key] = deepMergeAttributeValue(previousValue, nextValue) : snapshot[key] = cloneAttributeValue(nextValue);
298
306
  })), snapshot) : snapshot;
299
307
  }
308
+ buildRemovedStateAnimationAttrs(targetStateAttrs, previousResolvedStatePatch) {
309
+ const extraAttrs = {};
310
+ if (!previousResolvedStatePatch) return extraAttrs;
311
+ const snapshot = this.buildStaticAttributeSnapshot(), staticTargetAttrs = snapshot;
312
+ return Object.keys(previousResolvedStatePatch).forEach((key => {
313
+ const hasTargetAttr = Object.prototype.hasOwnProperty.call(targetStateAttrs, key);
314
+ if (hasTargetAttr && void 0 !== targetStateAttrs[key]) return;
315
+ const assignFallbackAttr = value => {
316
+ void 0 === value && this.shouldSkipStateTransitionDefaultAttribute(key, staticTargetAttrs) || (extraAttrs[key] = void 0 === value ? value : cloneAttributeValue(value));
317
+ };
318
+ if (hasTargetAttr) assignFallbackAttr(this.getStateTransitionDefaultAttribute(key, staticTargetAttrs)); else if (Object.prototype.hasOwnProperty.call(snapshot, key)) {
319
+ const snapshotValue = snapshot[key];
320
+ assignFallbackAttr(void 0 === snapshotValue ? this.getStateTransitionDefaultAttribute(key, staticTargetAttrs) : snapshotValue);
321
+ } else assignFallbackAttr(this.getStateTransitionDefaultAttribute(key, staticTargetAttrs));
322
+ })), extraAttrs;
323
+ }
300
324
  syncObjectToSnapshot(target, snapshot) {
301
325
  const delta = new Map;
302
326
  return new Set([ ...Object.keys(target), ...Object.keys(snapshot) ]).forEach((key => {
@@ -306,15 +330,17 @@ export class Graphic extends Node {
306
330
  next: void 0
307
331
  }), delete target[key]));
308
332
  const nextValue = snapshot[key];
309
- isEqual(previousValue, nextValue) || (delta.set(key, {
333
+ areAttributeValuesEqual(previousValue, nextValue) || (delta.set(key, {
310
334
  prev: previousValue,
311
335
  next: nextValue
312
336
  }), target[key] = cloneAttributeValue(nextValue));
313
337
  })), delta;
314
338
  }
315
339
  _syncAttribute() {
340
+ this.attribute === this.baseAttributes && this.resolvedStatePatch && this.detachAttributeFromBaseAttributes();
316
341
  const snapshot = this.buildStaticAttributeSnapshot(), delta = this.syncObjectToSnapshot(this.attribute, snapshot);
317
- return this.valid = this.isValid(), delta;
342
+ return this.valid = this.isValid(), this.attributeMayContainTransientAttrs = !1,
343
+ delta;
318
344
  }
319
345
  _syncFinalAttributeFromStaticTruth() {
320
346
  const target = this.finalAttribute;
@@ -322,51 +348,154 @@ export class Graphic extends Node {
322
348
  const snapshot = this.buildStaticAttributeSnapshot();
323
349
  this.syncObjectToSnapshot(target, snapshot);
324
350
  }
325
- submitUpdateByDelta(delta, forceUpdateTag = !1) {
351
+ mergeAttributeDeltaCategory(category, key, prev, next) {
352
+ var _a;
353
+ let nextCategory = "stroke" === key || "shadowBlur" === key ? classifyAttributeDelta(key, prev, next) : null !== (_a = ATTRIBUTE_CATEGORY[key]) && void 0 !== _a ? _a : UpdateCategory.PAINT;
354
+ return nextCategory & UpdateCategory.PICK && (nextCategory |= UpdateCategory.BOUNDS),
355
+ nextCategory === UpdateCategory.PAINT && this.needUpdateTag(key) && (nextCategory = UpdateCategory.SHAPE | UpdateCategory.BOUNDS),
356
+ category | nextCategory;
357
+ }
358
+ submitUpdateByCategory(category, forceUpdateTag = !1) {
326
359
  var _a;
327
360
  if (forceUpdateTag) return this.addUpdateShapeAndBoundsTag(), this.addUpdatePositionTag(),
328
361
  void this.addUpdateLayoutTag();
362
+ if (category !== UpdateCategory.NONE) {
363
+ const stage = this.stage;
364
+ stage && (null === (_a = getActiveStageStatePerfMonitor(stage)) || void 0 === _a || _a.recordCategory(category));
365
+ }
366
+ (category & BROAD_UPDATE_CATEGORY) !== BROAD_UPDATE_CATEGORY ? (category & UpdateCategory.SHAPE ? this.addUpdateShapeAndBoundsTag() : category & UpdateCategory.BOUNDS && this.addUpdateBoundTag(),
367
+ category & UpdateCategory.PAINT && this.addUpdatePaintTag(), category & UpdateCategory.TRANSFORM && this.addUpdatePositionTag(),
368
+ category & UpdateCategory.LAYOUT && this.addUpdateLayoutTag()) : this.addBroadUpdateTag();
369
+ }
370
+ submitUpdateByDelta(delta, forceUpdateTag = !1) {
329
371
  let category = UpdateCategory.NONE;
330
372
  delta.forEach(((entry, key) => {
331
- let nextCategory = classifyAttributeDelta(key, entry.prev, entry.next);
332
- nextCategory & UpdateCategory.PICK && (nextCategory |= UpdateCategory.BOUNDS), nextCategory === UpdateCategory.PAINT && this.needUpdateTag(key) && (nextCategory = UpdateCategory.SHAPE | UpdateCategory.BOUNDS),
333
- category |= nextCategory;
334
- })), category !== UpdateCategory.NONE && (null === (_a = getStageStatePerfMonitor(this.stage)) || void 0 === _a || _a.recordCategory(category)),
335
- category & UpdateCategory.SHAPE ? this.addUpdateShapeAndBoundsTag() : category & UpdateCategory.BOUNDS && this.addUpdateBoundTag(),
336
- category & UpdateCategory.PAINT && this.addUpdatePaintTag(), category & UpdateCategory.TRANSFORM && this.addUpdatePositionTag(),
337
- category & UpdateCategory.LAYOUT && this.addUpdateLayoutTag();
373
+ category = this.mergeAttributeDeltaCategory(category, key, entry.prev, entry.next);
374
+ })), this.submitUpdateByCategory(category, forceUpdateTag);
375
+ }
376
+ submitTouchedKeyUpdate(keys, forceUpdateTag = !1) {
377
+ this.submitTouchedUpdate(forceUpdateTag || this.needUpdateTags(keys));
378
+ }
379
+ submitTouchedUpdate(needsShapeAndBounds) {
380
+ !this.updateShapeAndBoundsTagSetted() && needsShapeAndBounds ? this.addUpdateShapeAndBoundsTag() : this.addUpdateBoundTag(),
381
+ this.addUpdatePositionTag(), this.addUpdateLayoutTag();
338
382
  }
339
383
  commitBaseAttributeMutation(forceUpdateTag = !1, context) {
340
- var _a, _b;
341
- (null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) && (this.resolverEpoch += 1,
342
- null === (_b = this.stateEngine) || void 0 === _b || _b.invalidateResolverCache(),
384
+ var _a, _b, _c;
385
+ (null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) && (this.resolverEpoch = (null !== (_b = this.resolverEpoch) && void 0 !== _b ? _b : 0) + 1,
386
+ null === (_c = this.stateEngine) || void 0 === _c || _c.invalidateResolverCache(),
343
387
  this.recomputeCurrentStatePatch());
344
388
  const delta = this._syncAttribute();
345
389
  this.submitUpdateByDelta(delta, forceUpdateTag), this.onAttributeUpdate(context);
346
390
  }
391
+ canCommitBaseAttributesByTouchedKeys() {
392
+ var _a, _b;
393
+ 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());
394
+ }
395
+ detachAttributeFromBaseAttributes() {
396
+ this.attribute === this.baseAttributes && (this._baseAttributes = this.attribute,
397
+ this.attribute = cloneAttributeSurface(this.attribute));
398
+ }
399
+ commitInternalBaseAttributes(params, context) {
400
+ params && Object.keys(params).length && (this.canCommitBaseAttributesByTouchedKeys() ? this.commitBaseAttributesByTouchedKeys(params, !1, context) : (this.detachAttributeFromBaseAttributes(),
401
+ this.applyBaseAttributes(params), this.commitBaseAttributeMutation(!1, context)));
402
+ }
403
+ commitBaseAttributesByTouchedKeys(params, forceUpdateTag = !1, context) {
404
+ const source = params, baseAttributes = this.getBaseAttributesStorage();
405
+ let hasKeys = !1, needsShapeAndBounds = forceUpdateTag;
406
+ for (const key in source) Object.prototype.hasOwnProperty.call(source, key) && (hasKeys = !0,
407
+ baseAttributes[key] = source[key], !needsShapeAndBounds && this.needUpdateTag(key) && (needsShapeAndBounds = !0));
408
+ hasKeys && (this.attribute = baseAttributes, this._baseAttributes = void 0, this.valid = this.isValid(),
409
+ this.attributeMayContainTransientAttrs = !1, this.submitTouchedUpdate(needsShapeAndBounds),
410
+ this.onAttributeUpdate(context));
411
+ }
412
+ commitBaseAttributeBySingleKey(key, value, forceUpdateTag = !1, context) {
413
+ this.getBaseAttributesStorage()[key] = value, this.attribute = this.getBaseAttributesStorage(),
414
+ this._baseAttributes = void 0, this.valid = this.isValid(), this.attributeMayContainTransientAttrs = !1,
415
+ this.submitTouchedUpdate(forceUpdateTag || this.needUpdateTag(key)), this.onAttributeUpdate(context);
416
+ }
347
417
  applyBaseAttributes(params) {
348
418
  const keys = Object.keys(params);
349
419
  for (let i = 0; i < keys.length; i++) {
350
420
  const key = keys[i];
351
- this.baseAttributes[key] = cloneAttributeValue(params[key]);
421
+ this.getBaseAttributesStorage()[key] = params[key];
352
422
  }
353
423
  }
424
+ applyAnimationTransientAttributes(params, forceUpdateTag = !1, context) {
425
+ const source = params;
426
+ let target, needsShapeAndBounds = forceUpdateTag;
427
+ for (const key in source) Object.prototype.hasOwnProperty.call(source, key) && (target || (this.detachAttributeFromBaseAttributes(),
428
+ target = this.attribute), target[key] = source[key], !needsShapeAndBounds && this.needUpdateTag(key) && (needsShapeAndBounds = !0));
429
+ target && (this.attributeMayContainTransientAttrs = !0, this.valid = this.isValid(),
430
+ this.submitTouchedUpdate(needsShapeAndBounds), this.onAttributeUpdate(context));
431
+ }
354
432
  applyTransientAttributes(params, forceUpdateTag = !1, context) {
433
+ this.detachAttributeFromBaseAttributes();
355
434
  const delta = new Map, keys = Object.keys(params);
356
435
  for (let i = 0; i < keys.length; i++) {
357
436
  const key = keys[i], previousValue = this.attribute[key], nextValue = params[key];
358
- isEqual(previousValue, nextValue) || (delta.set(key, {
437
+ areAttributeValuesEqual(previousValue, nextValue) || (delta.set(key, {
359
438
  prev: previousValue,
360
439
  next: nextValue
361
- }), this.attribute[key] = cloneAttributeValue(nextValue));
440
+ }), this.attribute[key] = nextValue);
362
441
  }
363
- this.valid = this.isValid(), this.submitUpdateByDelta(delta, forceUpdateTag), this.onAttributeUpdate(context);
442
+ delta.size && (this.attributeMayContainTransientAttrs = !0), this.valid = this.isValid(),
443
+ this.submitUpdateByDelta(delta, forceUpdateTag), this.onAttributeUpdate(context);
364
444
  }
365
445
  _restoreAttributeFromStaticTruth(context) {
366
446
  this._syncFinalAttributeFromStaticTruth();
367
447
  const delta = this._syncAttribute();
368
448
  this.submitUpdateByDelta(delta), this.onAttributeUpdate(context);
369
449
  }
450
+ collectStatePatchDeltaKeys(previousPatch, nextPatch) {
451
+ const keys = previousPatch ? Object.keys(previousPatch) : [];
452
+ if (!nextPatch) return keys;
453
+ for (const key in nextPatch) Object.prototype.hasOwnProperty.call(nextPatch, key) && !Object.prototype.hasOwnProperty.call(null != previousPatch ? previousPatch : {}, key) && keys.push(key);
454
+ return keys;
455
+ }
456
+ getStaticTruthValueForStateKey(key, nextPatch) {
457
+ var _a;
458
+ const baseAttributes = null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : {}, patch = nextPatch;
459
+ if (patch && Object.prototype.hasOwnProperty.call(patch, key)) {
460
+ const patchValue = patch[key], baseValue = baseAttributes[key];
461
+ return "deep" === this.stateMergeMode && isPlainObjectValue(baseValue) && isPlainObjectValue(patchValue) ? {
462
+ hasValue: !0,
463
+ value: deepMergeAttributeValue(baseValue, patchValue)
464
+ } : {
465
+ hasValue: !0,
466
+ value: patchValue
467
+ };
468
+ }
469
+ return Object.prototype.hasOwnProperty.call(baseAttributes, key) ? {
470
+ hasValue: !0,
471
+ value: baseAttributes[key]
472
+ } : {
473
+ hasValue: !1,
474
+ value: void 0
475
+ };
476
+ }
477
+ syncStatePatchDeltaToTarget(target, keys, nextPatch, collectCategory = !1) {
478
+ let category = UpdateCategory.NONE;
479
+ for (let i = 0; i < keys.length; i++) {
480
+ const key = keys[i], previousValue = target[key], next = this.getStaticTruthValueForStateKey(key, nextPatch);
481
+ if (!next.hasValue) {
482
+ Object.prototype.hasOwnProperty.call(target, key) && (delete target[key], collectCategory && (category = this.mergeAttributeDeltaCategory(category, key, previousValue, void 0)));
483
+ continue;
484
+ }
485
+ if (areAttributeValuesEqual(previousValue, next.value)) continue;
486
+ const nextValue = cloneAttributeValue(next.value);
487
+ target[key] = nextValue, collectCategory && (category = this.mergeAttributeDeltaCategory(category, key, previousValue, nextValue));
488
+ }
489
+ return category;
490
+ }
491
+ restoreAttributeFromStatePatchDelta(previousPatch, nextPatch, context) {
492
+ this.detachAttributeFromBaseAttributes();
493
+ const keys = this.collectStatePatchDeltaKeys(previousPatch, nextPatch), finalAttribute = this.finalAttribute;
494
+ finalAttribute && this.syncStatePatchDeltaToTarget(finalAttribute, keys, nextPatch, !1);
495
+ const category = this.syncStatePatchDeltaToTarget(this.attribute, keys, nextPatch, !0);
496
+ this.valid = this.isValid(), this.attributeMayContainTransientAttrs = !1, this.submitUpdateByCategory(category),
497
+ this.onAttributeUpdate(context);
498
+ }
370
499
  setMode(mode) {
371
500
  "3d" === mode ? this.set3dMode() : this.set2dMode();
372
501
  }
@@ -386,7 +515,7 @@ export class Graphic extends Node {
386
515
  return point;
387
516
  }
388
517
  onAnimateBind(animate) {
389
- this._emitCustomEvent("animate-bind", animate);
518
+ this.detachAttributeFromBaseAttributes(), this._emitCustomEvent("animate-bind", animate);
390
519
  }
391
520
  visitTrackedAnimates(cb) {
392
521
  const hook = this.forEachTrackedAnimate;
@@ -399,8 +528,22 @@ export class Graphic extends Node {
399
528
  const getTrackedAnimates = this.getTrackedAnimates;
400
529
  return "function" == typeof getTrackedAnimates ? getTrackedAnimates.call(this).size > 0 : !!(null === (_a = this.animates) || void 0 === _a ? void 0 : _a.size);
401
530
  }
531
+ mayHaveTrackedAnimates() {
532
+ var _a;
533
+ return !!(null === (_a = this.animates) || void 0 === _a ? void 0 : _a.size) || !!this._animationStateManager;
534
+ }
402
535
  tryUpdateAABBBounds() {
536
+ if (!(this.shadowRoot || this._updateTag & UpdateTag.UPDATE_BOUNDS)) return this._AABBBounds;
403
537
  const full = "imprecise" === this.attribute.boundsMode;
538
+ if (!this.shadowRoot) {
539
+ const graphicService = this.getGraphicService(), graphicTheme = this.getGraphicTheme();
540
+ if (!graphicService.validCheck(this.attribute, graphicTheme, this._AABBBounds, this)) return this._AABBBounds;
541
+ if (!this.valid) return this._AABBBounds.clear(), this._AABBBounds;
542
+ graphicService.beforeUpdateAABBBounds(this, this.stage, !0, this._AABBBounds);
543
+ const bounds = this.doUpdateAABBBounds(full, graphicTheme);
544
+ return graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, !0),
545
+ "empty" === this.attribute.boundsMode && bounds.clear(), bounds;
546
+ }
404
547
  if (!this.shouldUpdateAABBBounds()) return this._AABBBounds;
405
548
  if (!this.valid) return this._AABBBounds.clear(), this._AABBBounds;
406
549
  this.getGraphicService().beforeUpdateAABBBounds(this, this.stage, !0, this._AABBBounds);
@@ -464,11 +607,11 @@ export class Graphic extends Node {
464
607
  const _parsedPath = new CustomSymbolClass(symbolType, cache);
465
608
  return Graphic.userSymbolMap[symbolType] = _parsedPath, _parsedPath;
466
609
  }
467
- doUpdateAABBBounds(full) {
610
+ doUpdateAABBBounds(full, graphicTheme) {
468
611
  this.updateAABBBoundsStamp++;
469
- const graphicTheme = this.getGraphicTheme();
612
+ const resolvedGraphicTheme = null != graphicTheme ? graphicTheme : this.getGraphicTheme();
470
613
  this._AABBBounds.clear();
471
- const attribute = this.attribute, bounds = this.updateAABBBounds(attribute, graphicTheme, this._AABBBounds, full), {boundsPadding: boundsPadding = graphicTheme.boundsPadding} = attribute, paddingArray = parsePadding(boundsPadding);
614
+ const attribute = this.attribute, bounds = this.updateAABBBounds(attribute, resolvedGraphicTheme, this._AABBBounds, full), {boundsPadding: boundsPadding = resolvedGraphicTheme.boundsPadding} = attribute, paddingArray = parsePadding(boundsPadding);
472
615
  return paddingArray && bounds.expand(paddingArray), this.clearUpdateBoundTag(),
473
616
  bounds;
474
617
  }
@@ -539,27 +682,71 @@ export class Graphic extends Node {
539
682
  this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1, this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1;
540
683
  }
541
684
  setAttributesAndPreventAnimate(params, forceUpdateTag = !1, context, ignorePriority) {
685
+ if (!params) return;
686
+ const keys = Object.keys(params);
687
+ this.captureTransientFromAttrsBeforePreventAnimate(params, keys, context), this.syncFinalAttributesFromUpdateContext(context),
542
688
  this.visitTrackedAnimates((animate => {
543
- (animate.priority !== 1 / 0 || ignorePriority) && Object.keys(params).forEach((key => {
544
- animate.preventAttr(key);
545
- }));
689
+ (animate.priority !== 1 / 0 || ignorePriority) && animate.preventAttrs(keys);
546
690
  })), this.applyTransientAttributes(params, forceUpdateTag, context);
547
691
  }
692
+ syncFinalAttributesFromUpdateContext(context) {
693
+ var _a;
694
+ const updateType = null == context ? void 0 : context.type;
695
+ if (updateType === AttributeUpdateType.STATE || null != updateType && updateType >= AttributeUpdateType.ANIMATE_BIND && updateType <= AttributeUpdateType.ANIMATE_END) return;
696
+ const finalAttrs = null === (_a = this.context) || void 0 === _a ? void 0 : _a.finalAttrs, setFinalAttributes = this.setFinalAttributes;
697
+ finalAttrs && "function" == typeof setFinalAttributes && setFinalAttributes.call(this, finalAttrs);
698
+ }
699
+ captureTransientFromAttrsBeforePreventAnimate(params, keys, context) {
700
+ var _a, _b;
701
+ 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;
702
+ if (!keys.length || !diffAttrs || updateType === AttributeUpdateType.STATE || null != updateType && updateType >= AttributeUpdateType.ANIMATE_BIND && updateType <= AttributeUpdateType.ANIMATE_END) return;
703
+ const sameDiffAttrs = this.transientFromAttrsBeforePreventAnimateDiffAttrs === diffAttrs;
704
+ let fromAttrs = sameDiffAttrs && null !== (_b = this.transientFromAttrsBeforePreventAnimate) && void 0 !== _b ? _b : null;
705
+ sameDiffAttrs || (this.transientFromAttrsBeforePreventAnimate = null, this.transientFromAttrsBeforePreventAnimateDiffAttrs = null);
706
+ let captured = !1;
707
+ for (let i = 0; i < keys.length; i++) {
708
+ const key = keys[i];
709
+ if (!Object.prototype.hasOwnProperty.call(diffAttrs, key)) continue;
710
+ const previousValue = this.attribute[key], nextValue = params[key];
711
+ isEqual(previousValue, nextValue) || (null != fromAttrs || (fromAttrs = {}), fromAttrs[key] = cloneAttributeValue(previousValue),
712
+ captured = !0);
713
+ }
714
+ captured && (this.transientFromAttrsBeforePreventAnimate = fromAttrs, this.transientFromAttrsBeforePreventAnimateDiffAttrs = diffAttrs);
715
+ }
716
+ consumeTransientFromAttrsBeforePreventAnimate(diffAttrs) {
717
+ const transientFromAttrs = this.transientFromAttrsBeforePreventAnimate, sourceDiffAttrs = this.transientFromAttrsBeforePreventAnimateDiffAttrs;
718
+ if (!transientFromAttrs || !sourceDiffAttrs) return null;
719
+ for (const key in diffAttrs) if (Object.prototype.hasOwnProperty.call(diffAttrs, key) && (!Object.prototype.hasOwnProperty.call(sourceDiffAttrs, key) || !isEqual(sourceDiffAttrs[key], diffAttrs[key]))) return null;
720
+ let fromAttrs = null, remaining = !1;
721
+ for (const key in transientFromAttrs) Object.prototype.hasOwnProperty.call(transientFromAttrs, key) && (Object.prototype.hasOwnProperty.call(diffAttrs, key) ? (null != fromAttrs || (fromAttrs = {}),
722
+ fromAttrs[key] = transientFromAttrs[key]) : remaining = !0);
723
+ if (remaining) {
724
+ const nextTransientFromAttrs = {};
725
+ for (const key in transientFromAttrs) Object.prototype.hasOwnProperty.call(transientFromAttrs, key) && !Object.prototype.hasOwnProperty.call(diffAttrs, key) && (nextTransientFromAttrs[key] = transientFromAttrs[key]);
726
+ this.transientFromAttrsBeforePreventAnimate = nextTransientFromAttrs;
727
+ } else this.transientFromAttrsBeforePreventAnimate = null, this.transientFromAttrsBeforePreventAnimateDiffAttrs = null;
728
+ return fromAttrs;
729
+ }
548
730
  setAttributes(params, forceUpdateTag = !1, context) {
549
731
  params && ((params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate(params, this.attribute, null, context) || params).background && this.loadImage(params.background, !0),
550
- isExternalTexture(params.texture) && this.loadImage(params.texture, !1), params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic),
551
- this._setAttributes(params, forceUpdateTag, context));
732
+ params.texture && isExternalTexture(params.texture) && this.loadImage(params.texture, !1),
733
+ params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic), this._setAttributes(params, forceUpdateTag, context));
552
734
  }
553
735
  _setAttributes(params, forceUpdateTag = !1, context) {
554
- this.applyBaseAttributes(params), this.commitBaseAttributeMutation(forceUpdateTag, context);
736
+ this.canCommitBaseAttributesByTouchedKeys() ? this.commitBaseAttributesByTouchedKeys(params, forceUpdateTag, context) : (this.detachAttributeFromBaseAttributes(),
737
+ this.applyBaseAttributes(params), this.commitBaseAttributeMutation(forceUpdateTag, context));
555
738
  }
556
739
  setAttribute(key, value, forceUpdateTag, context) {
557
740
  const params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate({
558
741
  [key]: value
559
742
  }, this.attribute, key, context);
560
- params ? this._setAttributes(params, forceUpdateTag, context) : (this.applyBaseAttributes({
561
- [key]: value
562
- }), this.commitBaseAttributeMutation(!!forceUpdateTag, context)), "background" === key ? this.loadImage(value, !0) : "texture" === key && isExternalTexture(value) ? this.loadImage(value, !1) : "shadowGraphic" === key && this.setShadowGraphic(value);
743
+ if (params) this._setAttributes(params, forceUpdateTag, context); else if (this.canCommitBaseAttributesByTouchedKeys()) this.commitBaseAttributeBySingleKey(key, value, !!forceUpdateTag, context); else {
744
+ const nextAttrs = {
745
+ [key]: value
746
+ };
747
+ this.applyBaseAttributes(nextAttrs), this.commitBaseAttributeMutation(!!forceUpdateTag, context);
748
+ }
749
+ "background" === key ? this.loadImage(value, !0) : "texture" === key && isExternalTexture(value) ? this.loadImage(value, !1) : "shadowGraphic" === key && this.setShadowGraphic(value);
563
750
  }
564
751
  needUpdateTags(keys, k = GRAPHIC_UPDATE_TAG_KEY) {
565
752
  for (let i = 0; i < k.length; i++) {
@@ -579,10 +766,11 @@ export class Graphic extends Node {
579
766
  type: AttributeUpdateType.INIT
580
767
  };
581
768
  params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate(params, this.attribute, null, context) || params,
582
- this.baseAttributes = cloneAttributeValue(params), this.attribute || (this.attribute = {}),
583
- this.resolvedStatePatch = void 0, this._syncAttribute(), params.background && this.loadImage(params.background, !0),
584
- isExternalTexture(params.texture) && this.loadImage(params.texture, !1), params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic),
585
- this._updateTag = UpdateTag.INIT, this.valid = this.isValid(), this.onAttributeUpdate(context);
769
+ this.attribute = params, this._baseAttributes = void 0, this.resolvedStatePatch = void 0,
770
+ this.attributeMayContainTransientAttrs = !1, this.valid = this.isValid(), params.background && this.loadImage(params.background, !0),
771
+ params.texture && isExternalTexture(params.texture) && this.loadImage(params.texture, !1),
772
+ params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic), this._updateTag = UpdateTag.INIT,
773
+ this.valid = this.isValid(), this.onAttributeUpdate(context);
586
774
  }
587
775
  translate(x, y) {
588
776
  var _a, _b;
@@ -593,11 +781,15 @@ export class Graphic extends Node {
593
781
  x: x,
594
782
  y: y
595
783
  }, this.attribute, tempConstantXYKey, context);
596
- params && (x = params.x, y = params.y, delete params.x, delete params.y, this.applyBaseAttributes(params));
597
- const attribute = this.baseAttributes, postMatrix = attribute.postMatrix;
598
- return postMatrix ? application.transformUtil.fromMatrix(postMatrix, postMatrix).translate(x, y) : (attribute.x = (null !== (_a = attribute.x) && void 0 !== _a ? _a : DefaultTransform.x) + x,
599
- attribute.y = (null !== (_b = attribute.y) && void 0 !== _b ? _b : DefaultTransform.y) + y),
600
- this.commitBaseAttributeMutation(!1, context), this;
784
+ params && (x = params.x, y = params.y, delete params.x, delete params.y);
785
+ const attribute = this.baseAttributes, postMatrix = attribute.postMatrix, nextAttrs = params || {};
786
+ if (postMatrix) {
787
+ const nextPostMatrix = postMatrix.clone();
788
+ application.transformUtil.fromMatrix(nextPostMatrix, nextPostMatrix).translate(x, y),
789
+ nextAttrs.postMatrix = nextPostMatrix;
790
+ } else nextAttrs.x = (null !== (_a = attribute.x) && void 0 !== _a ? _a : DefaultTransform.x) + x,
791
+ nextAttrs.y = (null !== (_b = attribute.y) && void 0 !== _b ? _b : DefaultTransform.y) + y;
792
+ return this.commitInternalBaseAttributes(nextAttrs, context), this;
601
793
  }
602
794
  translateTo(x, y) {
603
795
  const attribute = this.baseAttributes;
@@ -608,9 +800,10 @@ export class Graphic extends Node {
608
800
  x: x,
609
801
  y: y
610
802
  }, this.attribute, tempConstantXYKey, context);
611
- return params ? (this.applyBaseAttributes(params), this.commitBaseAttributeMutation(!1, context),
612
- this) : (attribute.x = x, attribute.y = y, this.commitBaseAttributeMutation(!1, context),
613
- this);
803
+ return params ? (this.commitInternalBaseAttributes(params, context), this) : (this.commitInternalBaseAttributes({
804
+ x: x,
805
+ y: y
806
+ }, context), this);
614
807
  }
615
808
  scale(scaleX, scaleY, scaleCenter) {
616
809
  var _a, _b;
@@ -623,14 +816,15 @@ export class Graphic extends Node {
623
816
  scaleCenter: scaleCenter
624
817
  }, this.attribute, tempConstantScaleXYKey, context);
625
818
  params && (scaleX = params.scaleX, scaleY = params.scaleY, delete params.scaleX,
626
- delete params.scaleY, this.applyBaseAttributes(params));
627
- const attribute = this.baseAttributes;
819
+ delete params.scaleY);
820
+ const attribute = this.baseAttributes, nextAttrs = params || {};
628
821
  if (scaleCenter) {
629
- let {postMatrix: postMatrix} = this.attribute;
630
- postMatrix || (postMatrix = new Matrix, attribute.postMatrix = postMatrix), application.transformUtil.fromMatrix(postMatrix, postMatrix).scale(scaleX, scaleY, scaleCenter);
631
- } else attribute.scaleX = (null !== (_a = attribute.scaleX) && void 0 !== _a ? _a : DefaultTransform.scaleX) * scaleX,
632
- attribute.scaleY = (null !== (_b = attribute.scaleY) && void 0 !== _b ? _b : DefaultTransform.scaleY) * scaleY;
633
- return this.commitBaseAttributeMutation(!1, context), this;
822
+ let {postMatrix: postMatrix} = this.baseAttributes;
823
+ postMatrix = postMatrix ? postMatrix.clone() : new Matrix, application.transformUtil.fromMatrix(postMatrix, postMatrix).scale(scaleX, scaleY, scaleCenter),
824
+ nextAttrs.postMatrix = postMatrix;
825
+ } else nextAttrs.scaleX = (null !== (_a = attribute.scaleX) && void 0 !== _a ? _a : DefaultTransform.scaleX) * scaleX,
826
+ nextAttrs.scaleY = (null !== (_b = attribute.scaleY) && void 0 !== _b ? _b : DefaultTransform.scaleY) * scaleY;
827
+ return this.commitInternalBaseAttributes(nextAttrs, context), this;
634
828
  }
635
829
  scaleTo(scaleX, scaleY) {
636
830
  const attribute = this.baseAttributes;
@@ -641,9 +835,10 @@ export class Graphic extends Node {
641
835
  scaleX: scaleX,
642
836
  scaleY: scaleY
643
837
  }, this.attribute, tempConstantScaleXYKey, context);
644
- return params ? (this.applyBaseAttributes(params), this.commitBaseAttributeMutation(!1, context),
645
- this) : (attribute.scaleX = scaleX, attribute.scaleY = scaleY, this.commitBaseAttributeMutation(!1, context),
646
- this);
838
+ return params ? (this.commitInternalBaseAttributes(params, context), this) : (this.commitInternalBaseAttributes({
839
+ scaleX: scaleX,
840
+ scaleY: scaleY
841
+ }, context), this);
647
842
  }
648
843
  rotate(angle, rotateCenter) {
649
844
  var _a;
@@ -654,24 +849,23 @@ export class Graphic extends Node {
654
849
  angle: angle,
655
850
  rotateCenter: rotateCenter
656
851
  }, this.attribute, tempConstantAngleKey, context);
657
- params && (delete params.angle, this.applyBaseAttributes(params));
658
- const attribute = this.baseAttributes;
852
+ params && delete params.angle;
853
+ const attribute = this.baseAttributes, nextAttrs = params || {};
659
854
  if (rotateCenter) {
660
855
  let {postMatrix: postMatrix} = this.baseAttributes;
661
- postMatrix || (postMatrix = new Matrix, this.baseAttributes.postMatrix = postMatrix),
662
- application.transformUtil.fromMatrix(postMatrix, postMatrix).rotate(angle, rotateCenter);
663
- } else attribute.angle = (null !== (_a = attribute.angle) && void 0 !== _a ? _a : DefaultTransform.angle) + angle;
664
- return this.commitBaseAttributeMutation(!1, context), this;
856
+ postMatrix = postMatrix ? postMatrix.clone() : new Matrix, application.transformUtil.fromMatrix(postMatrix, postMatrix).rotate(angle, rotateCenter),
857
+ nextAttrs.postMatrix = postMatrix;
858
+ } else nextAttrs.angle = (null !== (_a = attribute.angle) && void 0 !== _a ? _a : DefaultTransform.angle) + angle;
859
+ return this.commitInternalBaseAttributes(nextAttrs, context), this;
665
860
  }
666
861
  rotateTo(angle) {
667
- const attribute = this.baseAttributes;
668
- if (attribute.angle === angle) return this;
862
+ if (this.baseAttributes.angle === angle) return this;
669
863
  const context = {
670
864
  type: AttributeUpdateType.ROTATE_TO
671
865
  }, params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate(angle, this.attribute, tempConstantAngleKey, context);
672
- return params ? (this.applyBaseAttributes(params), this.commitBaseAttributeMutation(!1, context),
673
- this) : (attribute.angle = angle, this.commitBaseAttributeMutation(!1, context),
674
- this);
866
+ return params ? (this.commitInternalBaseAttributes(params, context), this) : (this.commitInternalBaseAttributes({
867
+ angle: angle
868
+ }, context), this);
675
869
  }
676
870
  skewTo(b, c) {
677
871
  return this;
@@ -691,7 +885,16 @@ export class Graphic extends Node {
691
885
  var _a;
692
886
  return null === (_a = this.states) || void 0 === _a ? void 0 : _a[stateName];
693
887
  }
694
- createStateModel() {
888
+ getStateResolveBaseAttrs() {
889
+ var _a;
890
+ return null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : this.attribute;
891
+ }
892
+ syncStateResolveContext(stateResolveBaseAttrs = this.getStateResolveBaseAttrs()) {
893
+ var _a;
894
+ return null === (_a = this.stateEngine) || void 0 === _a || _a.setResolveContext(this, stateResolveBaseAttrs),
895
+ stateResolveBaseAttrs;
896
+ }
897
+ createStateModel(stateResolveBaseAttrs = this.getStateResolveBaseAttrs()) {
695
898
  const {compiledDefinitions: compiledDefinitions, stateProxyEligibility: stateProxyEligibility, stateProxyModeKey: stateProxyModeKey} = this.resolveEffectiveCompiledDefinitions();
696
899
  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({
697
900
  compiledDefinitions: compiledDefinitions,
@@ -704,7 +907,7 @@ export class Graphic extends Node {
704
907
  this.stateEngineStateSort = this.stateSort, this.stateEngineMergeMode = this.stateMergeMode,
705
908
  this.stateEngineStateProxyModeKey = stateProxyModeKey) : (this.stateEngine = void 0,
706
909
  this.stateEngineCompiledDefinitions = void 0, this.stateEngineStateProxyModeKey = void 0),
707
- new StateModel({
910
+ this.syncStateResolveContext(stateResolveBaseAttrs), new StateModel({
708
911
  states: this.states,
709
912
  currentStates: this.currentStates,
710
913
  stateSort: this.stateSort,
@@ -712,27 +915,148 @@ export class Graphic extends Node {
712
915
  stateEngine: this.stateEngine
713
916
  });
714
917
  }
918
+ resolveSimpleLocalStateTransition(states, previousStates) {
919
+ var _a;
920
+ 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;
921
+ if (1 === states.length) {
922
+ const stateName = states[0], hasDefinition = Object.prototype.hasOwnProperty.call(this.states, stateName), nextStates = [ stateName ], changed = !this.sameStateNames(previousStates, nextStates), resolvedStateAttrs = {};
923
+ if (hasDefinition) {
924
+ const attrs = this.states[stateName];
925
+ if (null != attrs) {
926
+ if (!isPlainObjectValue(attrs)) return null;
927
+ const keys = Object.keys(attrs);
928
+ for (let keyIndex = 0; keyIndex < keys.length; keyIndex++) {
929
+ const key = keys[keyIndex];
930
+ if (FULL_STATE_DEFINITION_KEYS.has(key)) return null;
931
+ const attrValue = attrs[key];
932
+ resolvedStateAttrs[key] = isPlainObjectValue(attrValue) ? cloneAttributeValue(attrValue) : attrValue;
933
+ }
934
+ }
935
+ }
936
+ return {
937
+ changed: changed,
938
+ states: nextStates,
939
+ effectiveStates: nextStates,
940
+ resolvedStateAttrs: resolvedStateAttrs
941
+ };
942
+ }
943
+ const uniqueStates = Array.from(new Set(states)), withDefinition = [], withoutDefinition = [];
944
+ for (let i = 0; i < uniqueStates.length; i++) {
945
+ const stateName = uniqueStates[i];
946
+ Object.prototype.hasOwnProperty.call(this.states, stateName) ? withDefinition.push(stateName) : withoutDefinition.push(stateName);
947
+ }
948
+ withDefinition.sort(((left, right) => left.localeCompare(right)));
949
+ const nextStates = withDefinition.concat(withoutDefinition), changed = !this.sameStateNames(previousStates, nextStates), resolvedStateAttrs = {};
950
+ for (let i = 0; i < nextStates.length; i++) {
951
+ const stateName = nextStates[i];
952
+ if (!Object.prototype.hasOwnProperty.call(this.states, stateName)) continue;
953
+ const attrs = this.states[stateName];
954
+ if (null == attrs) continue;
955
+ if (!isPlainObjectValue(attrs)) return null;
956
+ const keys = Object.keys(attrs);
957
+ for (let keyIndex = 0; keyIndex < keys.length; keyIndex++) {
958
+ const key = keys[keyIndex];
959
+ if (FULL_STATE_DEFINITION_KEYS.has(key)) return null;
960
+ const attrValue = attrs[key];
961
+ resolvedStateAttrs[key] = isPlainObjectValue(attrValue) ? cloneAttributeValue(attrValue) : attrValue;
962
+ }
963
+ }
964
+ return {
965
+ changed: changed,
966
+ states: nextStates,
967
+ effectiveStates: nextStates,
968
+ resolvedStateAttrs: resolvedStateAttrs
969
+ };
970
+ }
971
+ resolveGraphicStateTransition(states, previousStates, forceResolverRefresh = !1) {
972
+ var _a, _b;
973
+ let transition = this.resolveSimpleLocalStateTransition(states, previousStates);
974
+ const isSimpleLocalTransition = !!transition;
975
+ let resolvedStateAttrs;
976
+ if (transition) resolvedStateAttrs = transition.resolvedStateAttrs; else {
977
+ const stateResolveBaseAttrs = this.getStateResolveBaseAttrs(), stateModel = this.createStateModel(stateResolveBaseAttrs);
978
+ forceResolverRefresh && (null === (_a = this.stateEngine) || void 0 === _a || _a.invalidateResolverCache()),
979
+ 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);
980
+ }
981
+ return {
982
+ transition: transition,
983
+ effectiveStates: null !== (_b = transition.effectiveStates) && void 0 !== _b ? _b : transition.states,
984
+ resolvedStateAttrs: resolvedStateAttrs,
985
+ isSimpleLocalTransition: isSimpleLocalTransition
986
+ };
987
+ }
988
+ normalizeSetStatesOptions(options) {
989
+ return options && "object" == typeof options ? {
990
+ hasAnimation: options.animate,
991
+ animateSameStatePatchChange: !0 === options.animateSameStatePatchChange,
992
+ shouldRefreshSameStatePatch: !0
993
+ } : {
994
+ hasAnimation: "boolean" == typeof options ? options : void 0,
995
+ animateSameStatePatchChange: !1,
996
+ shouldRefreshSameStatePatch: !1
997
+ };
998
+ }
999
+ sameStatePatches(left, right) {
1000
+ const leftRecord = null != left ? left : {}, rightRecord = null != right ? right : {}, keys = new Set([ ...Object.keys(leftRecord), ...Object.keys(rightRecord) ]);
1001
+ for (const key of keys) {
1002
+ if (Object.prototype.hasOwnProperty.call(leftRecord, key) !== Object.prototype.hasOwnProperty.call(rightRecord, key)) return !1;
1003
+ if (!areAttributeValuesEqual(leftRecord[key], rightRecord[key])) return !1;
1004
+ }
1005
+ return !0;
1006
+ }
1007
+ commitSameStatePatchRefresh(states, hasAnimation, animateSameStatePatchChange = !1) {
1008
+ var _a;
1009
+ 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);
1010
+ if ((!patchChanged || this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) && (this.currentStates = transition.states,
1011
+ this.effectiveStates = isSimpleLocalTransition ? effectiveStates : [ ...effectiveStates ],
1012
+ this.resolvedStatePatch = resolvedStateAttrs, this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(),
1013
+ patchChanged)) {
1014
+ if (this.stage) {
1015
+ const perfMonitor = getActiveStageStatePerfMonitor(this.stage);
1016
+ null == perfMonitor || perfMonitor.incrementCounter("stateCommits"), null == perfMonitor || perfMonitor.recordEvent("state-commit", {
1017
+ graphicId: this._uid,
1018
+ targetStates: [ ...transition.states ]
1019
+ });
1020
+ }
1021
+ hasAnimation && animateSameStatePatchChange ? (this._syncFinalAttributeFromStaticTruth(),
1022
+ this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !1, void 0, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch))) : (this.stopStateAnimates(),
1023
+ this.attributeMayContainTransientAttrs ? this._restoreAttributeFromStaticTruth({
1024
+ type: AttributeUpdateType.STATE
1025
+ }) : this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, this.resolvedStatePatch, {
1026
+ type: AttributeUpdateType.STATE
1027
+ }), this.emitStateUpdateEvent());
1028
+ }
1029
+ }
715
1030
  resolveStateAnimateConfig(animateConfig) {
716
1031
  var _a, _b, _c;
717
1032
  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;
718
1033
  }
719
- applyStateAttrs(attrs, stateNames, hasAnimation, isClear, animateConfig) {
1034
+ applyStateAttrs(attrs, stateNames, hasAnimation, isClear, animateConfig, extraAnimateAttrs) {
720
1035
  const resolvedAnimateConfig = hasAnimation ? this.resolveStateAnimateConfig(animateConfig) : void 0, transitionOptions = resolvedAnimateConfig ? {
721
- animateConfig: resolvedAnimateConfig
1036
+ animateConfig: resolvedAnimateConfig,
1037
+ extraAnimateAttrs: extraAnimateAttrs,
1038
+ shouldSkipDefaultAttribute: this.shouldSkipStateTransitionDefaultAttribute.bind(this)
722
1039
  } : void 0;
723
1040
  if (isClear) return void this.getStateTransitionOrchestrator().applyClearTransition(this, attrs, hasAnimation, stateNames, transitionOptions);
724
1041
  const plan = this.getStateTransitionOrchestrator().analyzeTransition({}, attrs, stateNames, hasAnimation, {
725
1042
  noWorkAnimateAttr: this.getNoWorkAnimateAttr(),
726
- animateConfig: resolvedAnimateConfig
1043
+ animateConfig: resolvedAnimateConfig,
1044
+ extraAnimateAttrs: extraAnimateAttrs,
1045
+ shouldSkipDefaultAttribute: this.shouldSkipStateTransitionDefaultAttribute.bind(this)
727
1046
  });
728
1047
  this.getStateTransitionOrchestrator().applyTransition(this, plan, hasAnimation, transitionOptions);
729
1048
  }
730
- updateNormalAttrs(stateAttrs) {
731
- this._deprecatedNormalAttrsView = cloneAttributeValue(this.baseAttributes);
1049
+ updateNormalAttrs(_stateAttrs) {}
1050
+ getStateTransitionDefaultAttribute(key, targetAttrs) {
1051
+ return this.getDefaultAttribute(key);
1052
+ }
1053
+ shouldSkipStateTransitionDefaultAttribute(_key, _targetAttrs) {
1054
+ return !1;
732
1055
  }
733
1056
  stopStateAnimates(type = "end") {
734
1057
  const stopAnimationState = this.stopAnimationState;
735
1058
  if ("function" == typeof stopAnimationState) return void stopAnimationState.call(this, "state", type);
1059
+ if (!this.mayHaveTrackedAnimates()) return;
736
1060
  const stateAnimates = [];
737
1061
  this.visitTrackedAnimates((animate => {
738
1062
  animate.stateNames && stateAnimates.push(animate);
@@ -745,23 +1069,27 @@ export class Graphic extends Node {
745
1069
  }
746
1070
  clearStates(hasAnimation) {
747
1071
  var _a, _b, _c;
748
- const previousStates = this.currentStates ? this.currentStates.slice() : [], transition = this.createStateModel().clearStates();
1072
+ const previousStates = null !== (_a = this.currentStates) && void 0 !== _a ? _a : EMPTY_STATE_NAMES, previousResolvedStatePatch = this.resolvedStatePatch, transition = this.createStateModel().clearStates();
749
1073
  if (!transition.changed && 0 === previousStates.length) return this.currentStates = [],
750
1074
  this.effectiveStates = [], this.resolvedStatePatch = void 0, this.sharedStateDirty = !1,
751
1075
  void this.clearSharedStateActiveRegistrations();
752
- const resolvedStateAttrs = cloneAttributeValue(null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : {});
753
- transition.changed && !this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !0) || (this.currentStates = transition.states,
754
- this.effectiveStates = [], this.resolvedStatePatch = void 0, this.sharedStateDirty = !1,
755
- this.clearSharedStateActiveRegistrations(), null === (_b = getStageStatePerfMonitor(this.stage)) || void 0 === _b || _b.incrementCounter("stateCommits"),
756
- null === (_c = getStageStatePerfMonitor(this.stage)) || void 0 === _c || _c.recordEvent("state-commit", {
757
- graphicId: this._uid,
758
- targetStates: []
759
- }), hasAnimation ? (this._syncFinalAttributeFromStaticTruth(), this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !0)) : (this.stopStateAnimates(),
760
- this._restoreAttributeFromStaticTruth({
761
- type: AttributeUpdateType.STATE
762
- }), this._emitCustomEvent("afterStateUpdate", {
763
- type: AttributeUpdateType.STATE
764
- })));
1076
+ const resolvedStateAttrs = hasAnimation || this.hasCustomEvent("beforeStateUpdate") ? cloneAttributeValue(null !== (_b = this.baseAttributes) && void 0 !== _b ? _b : {}) : null !== (_c = this.baseAttributes) && void 0 !== _c ? _c : {};
1077
+ if (!transition.changed || this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !0)) {
1078
+ if (this.currentStates = transition.states, this.effectiveStates = [], this.resolvedStatePatch = void 0,
1079
+ this.sharedStateDirty = !1, this.clearSharedStateActiveRegistrations(), this.stage) {
1080
+ const perfMonitor = getActiveStageStatePerfMonitor(this.stage);
1081
+ null == perfMonitor || perfMonitor.incrementCounter("stateCommits"), null == perfMonitor || perfMonitor.recordEvent("state-commit", {
1082
+ graphicId: this._uid,
1083
+ targetStates: []
1084
+ });
1085
+ }
1086
+ hasAnimation ? (this._syncFinalAttributeFromStaticTruth(), this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !0, void 0, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch))) : (this.stopStateAnimates(),
1087
+ this.attributeMayContainTransientAttrs ? this._restoreAttributeFromStaticTruth({
1088
+ type: AttributeUpdateType.STATE
1089
+ }) : this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, void 0, {
1090
+ type: AttributeUpdateType.STATE
1091
+ }), this.emitStateUpdateEvent());
1092
+ }
765
1093
  }
766
1094
  removeState(stateName, hasAnimation) {
767
1095
  const transition = this.createStateModel().removeState(stateName);
@@ -775,41 +1103,51 @@ export class Graphic extends Node {
775
1103
  const transition = this.createStateModel().addState(stateName, keepCurrentStates);
776
1104
  transition.changed && this.useStates(transition.states, hasAnimation);
777
1105
  }
1106
+ setStates(states, options) {
1107
+ var _a, _b, _c;
1108
+ 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));
1109
+ if (nextStates.length) {
1110
+ if (this.sameStateNames(this.currentStates, nextStates)) return shouldRefreshSameStatePatch ? void this.commitSameStatePatchRefresh(nextStates, hasAnimation, animateSameStatePatchChange) : void (this.sharedStateDirty && this.refreshSharedStateBeforeRender());
1111
+ this.useStates(nextStates, hasAnimation);
1112
+ } else {
1113
+ if (!hasCurrentState && !this.sharedStateDirty) return;
1114
+ this.clearStates(hasAnimation);
1115
+ }
1116
+ }
778
1117
  useStates(states, hasAnimation) {
779
- var _a, _b, _c, _d, _e;
1118
+ var _a;
780
1119
  if (!states.length) return void this.clearStates(hasAnimation);
781
- const previousStates = this.currentStates ? this.currentStates.slice() : [], stateResolveBaseAttrs = null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : this.attribute, stateModel = this.createStateModel();
782
- null === (_b = this.stateEngine) || void 0 === _b || _b.setResolveContext(this, stateResolveBaseAttrs);
783
- const transition = stateModel.useStates(states);
784
- if (!transition.changed && this.sameStateNames(previousStates, transition.states)) return;
785
- 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);
786
- this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1) && (this.currentStates = transition.states,
787
- this.effectiveStates = [ ...effectiveStates ], this.resolvedStatePatch = Object.assign({}, resolvedStateAttrs),
788
- this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(), null === (_d = getStageStatePerfMonitor(this.stage)) || void 0 === _d || _d.incrementCounter("stateCommits"),
789
- null === (_e = getStageStatePerfMonitor(this.stage)) || void 0 === _e || _e.recordEvent("state-commit", {
790
- graphicId: this._uid,
791
- targetStates: [ ...transition.states ]
792
- }), hasAnimation ? (this._syncFinalAttributeFromStaticTruth(), this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation)) : (this.stopStateAnimates(),
793
- this._restoreAttributeFromStaticTruth({
794
- type: AttributeUpdateType.STATE
795
- }), this._emitCustomEvent("afterStateUpdate", {
796
- type: AttributeUpdateType.STATE
797
- })));
1120
+ 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);
1121
+ if ((transition.changed || !this.sameStateNames(previousStates, transition.states)) && this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) {
1122
+ if (this.currentStates = transition.states, this.effectiveStates = isSimpleLocalTransition ? effectiveStates : [ ...effectiveStates ],
1123
+ this.resolvedStatePatch = resolvedStateAttrs, this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(),
1124
+ this.stage) {
1125
+ const perfMonitor = getActiveStageStatePerfMonitor(this.stage);
1126
+ null == perfMonitor || perfMonitor.incrementCounter("stateCommits"), null == perfMonitor || perfMonitor.recordEvent("state-commit", {
1127
+ graphicId: this._uid,
1128
+ targetStates: [ ...transition.states ]
1129
+ });
1130
+ }
1131
+ hasAnimation ? (this._syncFinalAttributeFromStaticTruth(), this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !1, void 0, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch))) : (this.stopStateAnimates(),
1132
+ this.attributeMayContainTransientAttrs ? this._restoreAttributeFromStaticTruth({
1133
+ type: AttributeUpdateType.STATE
1134
+ }) : this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, this.resolvedStatePatch, {
1135
+ type: AttributeUpdateType.STATE
1136
+ }), this.emitStateUpdateEvent());
1137
+ }
798
1138
  }
799
1139
  invalidateResolver() {
800
1140
  var _a, _b;
801
1141
  if (!this.stateEngine || !(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || !this.compiledStateDefinitions) return;
802
- const stateResolveBaseAttrs = null !== (_b = this.baseAttributes) && void 0 !== _b ? _b : this.attribute;
803
- this.stateEngine.setResolveContext(this, stateResolveBaseAttrs), this.resolverEpoch += 1,
1142
+ this.syncStateResolveContext();
1143
+ this.resolverEpoch = (null !== (_b = this.resolverEpoch) && void 0 !== _b ? _b : 0) + 1,
804
1144
  this.stateEngine.invalidateResolverCache();
805
1145
  const transition = this.stateEngine.applyStates(this.currentStates), resolvedStateAttrs = Object.assign({}, this.stateEngine.resolvedPatch);
806
- this.effectiveStates = [ ...transition.effectiveStates ], this.resolvedStatePatch = Object.assign({}, resolvedStateAttrs),
1146
+ this.effectiveStates = [ ...transition.effectiveStates ], this.resolvedStatePatch = resolvedStateAttrs,
807
1147
  this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(), this.stopStateAnimates(),
808
1148
  this._restoreAttributeFromStaticTruth({
809
1149
  type: AttributeUpdateType.STATE
810
- }), this._emitCustomEvent("afterStateUpdate", {
811
- type: AttributeUpdateType.STATE
812
- });
1150
+ }), this.emitStateUpdateEvent();
813
1151
  }
814
1152
  sameStateNames(left, right) {
815
1153
  const normalizedLeft = null != left ? left : [], normalizedRight = null != right ? right : [];
@@ -831,6 +1169,10 @@ export class Graphic extends Node {
831
1169
  this._updateTag |= UpdateTag.UPDATE_SHAPE_AND_BOUNDS, this.parent && this.parent.addChildUpdateBoundTag(),
832
1170
  this.glyphHost && this.glyphHost.addUpdateBoundTag();
833
1171
  }
1172
+ addBroadUpdateTag() {
1173
+ this.shadowRoot && this.shadowRoot.addUpdateGlobalPositionTag(), this._updateTag |= UpdateTag.UPDATE_SHAPE_AND_BOUNDS | UpdateTag.UPDATE_PAINT | UpdateTag.UPDATE_GLOBAL_LOCAL_MATRIX | UpdateTag.UPDATE_LAYOUT,
1174
+ this.parent && this.parent.addChildUpdateBoundTag(), this.glyphHost && this.glyphHost.addUpdateBoundTag();
1175
+ }
834
1176
  updateShapeAndBoundsTagSetted() {
835
1177
  return (this._updateTag & UpdateTag.UPDATE_SHAPE_AND_BOUNDS) === UpdateTag.UPDATE_SHAPE_AND_BOUNDS;
836
1178
  }
@@ -904,12 +1246,12 @@ export class Graphic extends Node {
904
1246
  }
905
1247
  }
906
1248
  setStage(stage, layer) {
907
- var _a, _b, _c, _d, _e, _f, _g, _h;
1249
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
908
1250
  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.graphicService, previousStage = this.stage;
909
1251
  if (this.stage !== stage || this.layer !== layer) {
910
- if (this.stage = stage, this.layer = layer, this.syncSharedStateScopeBindingFromTree(!!(null === (_d = this.currentStates) || void 0 === _d ? void 0 : _d.length)),
911
- this.setStageToShadowRoot(stage, layer), this.hasAnyTrackedAnimate()) {
912
- 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 = [];
1252
+ 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),
1253
+ this.setStageToShadowRoot(stage, layer), this.mayHaveTrackedAnimates() && this.hasAnyTrackedAnimate()) {
1254
+ 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 = [];
913
1255
  this.visitTrackedAnimates((a => {
914
1256
  (!!previousTimeline && a.timeline === previousTimeline || a.timeline.isGlobal) && (nextTimeline ? a.timeline !== nextTimeline && (previousTimeline && a.timeline === previousTimeline && previousTimeline.removeAnimate(a, !1),
915
1257
  a.setTimeline(nextTimeline), nextTimeline.addAnimate(a)) : previousTimeline && a.timeline === previousTimeline && (previousTimeline.removeAnimate(a, !1),
@@ -923,9 +1265,18 @@ export class Graphic extends Node {
923
1265
  type: AttributeUpdateType.ANIMATE_END
924
1266
  }));
925
1267
  }
926
- 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));
1268
+ 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));
927
1269
  }
928
- this.syncSharedStateScopeBindingFromTree(!!(null === (_h = this.currentStates) || void 0 === _h ? void 0 : _h.length));
1270
+ ((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);
1271
+ }
1272
+ detachStageForRelease() {
1273
+ var _a, _b, _c;
1274
+ (null === (_a = this.registeredActiveScopes) || void 0 === _a ? void 0 : _a.size) && this.clearSharedStateActiveRegistrations(),
1275
+ (this.mayHaveTrackedAnimates() || this.shadowRoot) && this.stopAnimates(), this.boundSharedStateScope = void 0,
1276
+ this.boundSharedStateRevision = void 0, this.localFallbackCompiledDefinitions = void 0,
1277
+ this.compiledStateDefinitions = void 0, this.compiledStateDefinitionsCacheKey = void 0,
1278
+ this.stateEngine = void 0, this.stateEngineCompiledDefinitions = void 0, this.stateEngineStateProxyModeKey = void 0,
1279
+ this.sharedStateDirty = !1, this.stage = null, this.layer = null, this.shadowRoot && (null === (_c = (_b = this.shadowRoot).detachStageForRelease) || void 0 === _c || _c.call(_b));
929
1280
  }
930
1281
  setStageToShadowRoot(stage, layer) {
931
1282
  this.shadowRoot && this.shadowRoot.setStage(stage, layer);
@@ -999,6 +1350,7 @@ export class Graphic extends Node {
999
1350
  res && (res.state = "fail", cb && cb());
1000
1351
  }
1001
1352
  _stopAnimates() {
1353
+ if (!this.mayHaveTrackedAnimates()) return;
1002
1354
  const animates = [];
1003
1355
  this.visitTrackedAnimates((animate => {
1004
1356
  animates.push(animate);
@@ -1012,15 +1364,19 @@ export class Graphic extends Node {
1012
1364
  }));
1013
1365
  }
1014
1366
  release() {
1015
- var _a, _b, _c;
1016
- this.releaseStatus = "released", this.clearSharedStateActiveRegistrations(), this.stopAnimates();
1017
- const graphicService = null !== (_b = null === (_a = this.stage) || void 0 === _a ? void 0 : _a.graphicService) && void 0 !== _b ? _b : application.graphicService;
1018
- null === (_c = null == graphicService ? void 0 : graphicService.onRelease) || void 0 === _c || _c.call(graphicService, this),
1367
+ var _a, _b, _c, _d;
1368
+ this.releaseStatus = "released", (null === (_a = this.registeredActiveScopes) || void 0 === _a ? void 0 : _a.size) && this.clearSharedStateActiveRegistrations(),
1369
+ (this.mayHaveTrackedAnimates() || this.shadowRoot) && this.stopAnimates();
1370
+ const graphicService = null !== (_c = null === (_b = this.stage) || void 0 === _b ? void 0 : _b.graphicService) && void 0 !== _c ? _c : application.graphicService;
1371
+ null === (_d = null == graphicService ? void 0 : graphicService.onRelease) || void 0 === _d || _d.call(graphicService, this),
1019
1372
  super.release();
1020
1373
  }
1374
+ hasCustomEvent(type) {
1375
+ return !!this._events && type in this._events;
1376
+ }
1021
1377
  _dispatchCustomEvent(type, context) {
1022
1378
  var _a, _b;
1023
- if (this._events && type in this._events) {
1379
+ if (this.hasCustomEvent(type)) {
1024
1380
  const changeEvent = new CustomEvent(type, context);
1025
1381
  changeEvent.bubbles = !1;
1026
1382
  const manager = null === (_b = null === (_a = this.stage) || void 0 === _a ? void 0 : _a.eventSystem) || void 0 === _b ? void 0 : _b.manager;
@@ -1029,7 +1385,7 @@ export class Graphic extends Node {
1029
1385
  return !0;
1030
1386
  }
1031
1387
  beforeStateUpdate(attrs, prevStates, nextStates, hasAnimation, isClear) {
1032
- return this._dispatchCustomEvent("beforeStateUpdate", {
1388
+ return !this.hasCustomEvent("beforeStateUpdate") || this._dispatchCustomEvent("beforeStateUpdate", {
1033
1389
  type: AttributeUpdateType.STATE,
1034
1390
  attrs: Object.assign({}, attrs),
1035
1391
  prevStates: prevStates.slice(),
@@ -1038,6 +1394,11 @@ export class Graphic extends Node {
1038
1394
  isClear: !!isClear
1039
1395
  });
1040
1396
  }
1397
+ emitStateUpdateEvent() {
1398
+ this.hasCustomEvent("afterStateUpdate") && this._emitCustomEvent("afterStateUpdate", {
1399
+ type: AttributeUpdateType.STATE
1400
+ });
1401
+ }
1041
1402
  _emitCustomEvent(type, context) {
1042
1403
  this._dispatchCustomEvent(type, context);
1043
1404
  }