@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.
- package/cjs/canvas/constants.js +2 -1
- package/cjs/color-string/index.js +1 -2
- package/cjs/common/diff.js +1 -2
- package/cjs/common/event-transformer.js +2 -1
- package/cjs/common/rect-utils.js +1 -1
- package/cjs/common/render-area.js +1 -1
- package/cjs/common/render-command-list.js +1 -1
- package/cjs/common/render-curve.js +1 -1
- package/cjs/common/render-utils.js +1 -1
- package/cjs/common/seg-context.js +1 -2
- package/cjs/common/simplify.js +1 -1
- package/cjs/common/sort.js +1 -1
- package/cjs/common/split-path.js +1 -1
- package/cjs/common/store.js +1 -1
- package/cjs/common/text.js +1 -1
- package/cjs/common/utils.js +1 -1
- package/cjs/core/camera.js +1 -1
- package/cjs/core/constants.js +1 -1
- package/cjs/core/core-modules.js +1 -1
- package/cjs/core/global-module.js +2 -0
- package/cjs/core/global.js +1 -1
- package/cjs/core/graphic-utils.js +1 -1
- package/cjs/core/index.js +1 -1
- package/cjs/core/layer-service.js +2 -1
- package/cjs/core/layer.js +1 -1
- package/cjs/core/light.js +1 -1
- package/cjs/core/stage.d.ts +4 -1
- package/cjs/core/stage.js +24 -12
- package/cjs/core/stage.js.map +1 -1
- package/cjs/core/window.js +1 -1
- package/cjs/graphic/graphic-service/graphic-service.d.ts +4 -0
- package/cjs/graphic/graphic-service/graphic-service.js +6 -5
- package/cjs/graphic/graphic-service/graphic-service.js.map +1 -1
- package/cjs/graphic/graphic.d.ts +72 -11
- package/cjs/graphic/graphic.js +509 -158
- package/cjs/graphic/graphic.js.map +1 -1
- package/cjs/graphic/group.d.ts +5 -1
- package/cjs/graphic/group.js +37 -18
- package/cjs/graphic/group.js.map +1 -1
- package/cjs/graphic/rect.d.ts +2 -0
- package/cjs/graphic/rect.js +44 -0
- package/cjs/graphic/rect.js.map +1 -1
- package/cjs/graphic/state/shared-state-refresh.js +4 -3
- package/cjs/graphic/state/shared-state-refresh.js.map +1 -1
- package/cjs/graphic/state/shared-state-scope.js +1 -1
- package/cjs/graphic/state/shared-state-scope.js.map +1 -1
- package/cjs/graphic/state/state-engine.js +2 -2
- package/cjs/graphic/state/state-engine.js.map +1 -1
- package/cjs/graphic/state/state-perf-monitor.d.ts +1 -0
- package/cjs/graphic/state/state-perf-monitor.js +9 -2
- package/cjs/graphic/state/state-perf-monitor.js.map +1 -1
- package/cjs/graphic/state/state-style-resolver.d.ts +0 -9
- package/cjs/graphic/state/state-style-resolver.js +0 -23
- package/cjs/graphic/state/state-style-resolver.js.map +1 -1
- package/cjs/graphic/state/state-transition-orchestrator.d.ts +5 -0
- package/cjs/graphic/state/state-transition-orchestrator.js +17 -5
- package/cjs/graphic/state/state-transition-orchestrator.js.map +1 -1
- package/cjs/interface/animation/animate.d.ts +1 -0
- package/cjs/interface/animation/animate.js.map +1 -1
- package/cjs/interface/graphic.d.ts +9 -0
- package/cjs/interface/graphic.js.map +1 -1
- package/cjs/interface/node-tree.js.map +1 -1
- package/cjs/plugins/builtin-plugin/dirty-bounds-plugin.d.ts +4 -1
- package/cjs/plugins/builtin-plugin/dirty-bounds-plugin.js +20 -10
- package/cjs/plugins/builtin-plugin/dirty-bounds-plugin.js.map +1 -1
- package/cjs/plugins/builtin-plugin/flex-layout-plugin.js +3 -2
- package/cjs/plugins/builtin-plugin/flex-layout-plugin.js.map +1 -1
- package/cjs/render/contributions/render/base-render.js +8 -7
- package/cjs/render/contributions/render/base-render.js.map +1 -1
- package/dist/index.es.js +1134 -279
- package/es/canvas/constants.js +2 -1
- package/es/color-string/index.js +1 -2
- package/es/common/diff.js +1 -2
- package/es/common/event-transformer.js +2 -1
- package/es/common/rect-utils.js +1 -1
- package/es/common/render-area.js +1 -1
- package/es/common/render-command-list.js +1 -1
- package/es/common/render-curve.js +1 -1
- package/es/common/render-utils.js +1 -1
- package/es/common/seg-context.js +1 -2
- package/es/common/simplify.js +1 -1
- package/es/common/sort.js +1 -1
- package/es/common/split-path.js +1 -1
- package/es/common/store.js +1 -1
- package/es/common/text.js +1 -1
- package/es/common/utils.js +1 -1
- package/es/core/camera.js +1 -1
- package/es/core/constants.js +1 -1
- package/es/core/core-modules.js +1 -1
- package/es/core/global-module.js +2 -0
- package/es/core/global.js +1 -1
- package/es/core/graphic-utils.js +1 -1
- package/es/core/index.js +1 -1
- package/es/core/layer-service.js +2 -1
- package/es/core/layer.js +1 -1
- package/es/core/light.js +1 -1
- package/es/core/stage.d.ts +4 -1
- package/es/core/stage.js +22 -11
- package/es/core/stage.js.map +1 -1
- package/es/core/window.js +1 -1
- package/es/graphic/graphic-service/graphic-service.d.ts +4 -0
- package/es/graphic/graphic-service/graphic-service.js +6 -5
- package/es/graphic/graphic-service/graphic-service.js.map +1 -1
- package/es/graphic/graphic.d.ts +72 -11
- package/es/graphic/graphic.js +504 -151
- package/es/graphic/graphic.js.map +1 -1
- package/es/graphic/group.d.ts +5 -1
- package/es/graphic/group.js +36 -18
- package/es/graphic/group.js.map +1 -1
- package/es/graphic/rect.d.ts +2 -0
- package/es/graphic/rect.js +44 -0
- package/es/graphic/rect.js.map +1 -1
- package/es/graphic/state/shared-state-refresh.js +5 -4
- package/es/graphic/state/shared-state-refresh.js.map +1 -1
- package/es/graphic/state/shared-state-scope.js +2 -2
- package/es/graphic/state/shared-state-scope.js.map +1 -1
- package/es/graphic/state/state-engine.js +3 -3
- package/es/graphic/state/state-engine.js.map +1 -1
- package/es/graphic/state/state-perf-monitor.d.ts +1 -0
- package/es/graphic/state/state-perf-monitor.js +7 -0
- package/es/graphic/state/state-perf-monitor.js.map +1 -1
- package/es/graphic/state/state-style-resolver.d.ts +0 -9
- package/es/graphic/state/state-style-resolver.js +0 -23
- package/es/graphic/state/state-style-resolver.js.map +1 -1
- package/es/graphic/state/state-transition-orchestrator.d.ts +5 -0
- package/es/graphic/state/state-transition-orchestrator.js +17 -5
- package/es/graphic/state/state-transition-orchestrator.js.map +1 -1
- package/es/interface/animation/animate.d.ts +1 -0
- package/es/interface/animation/animate.js.map +1 -1
- package/es/interface/graphic.d.ts +9 -0
- package/es/interface/graphic.js.map +1 -1
- package/es/interface/node-tree.js.map +1 -1
- package/es/plugins/builtin-plugin/dirty-bounds-plugin.d.ts +4 -1
- package/es/plugins/builtin-plugin/dirty-bounds-plugin.js +20 -10
- package/es/plugins/builtin-plugin/dirty-bounds-plugin.js.map +1 -1
- package/es/plugins/builtin-plugin/flex-layout-plugin.js +3 -2
- package/es/plugins/builtin-plugin/flex-layout-plugin.js.map +1 -1
- package/es/render/contributions/render/base-render.js +8 -6
- package/es/render/contributions/render/base-render.js.map +1 -1
- package/package.json +3 -3
package/es/graphic/graphic.js
CHANGED
|
@@ -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 {
|
|
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.
|
|
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),
|
|
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(
|
|
164
|
-
|
|
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
|
-
|
|
207
|
+
syncSharedStateScopeBindingOnTreeChange(markDirty = !0) {
|
|
204
208
|
var _a, _b;
|
|
205
|
-
|
|
206
|
-
|
|
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.
|
|
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.
|
|
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
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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(),
|
|
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
|
-
|
|
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
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
|
342
|
-
null === (
|
|
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.
|
|
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
|
-
|
|
437
|
+
areAttributeValuesEqual(previousValue, nextValue) || (delta.set(key, {
|
|
359
438
|
prev: previousValue,
|
|
360
439
|
next: nextValue
|
|
361
|
-
}), this.attribute[key] =
|
|
440
|
+
}), this.attribute[key] = nextValue);
|
|
362
441
|
}
|
|
363
|
-
this.
|
|
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
|
|
612
|
+
const resolvedGraphicTheme = null != graphicTheme ? graphicTheme : this.getGraphicTheme();
|
|
470
613
|
this._AABBBounds.clear();
|
|
471
|
-
const attribute = this.attribute, bounds = this.updateAABBBounds(attribute,
|
|
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,63 @@ 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) {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
685
|
+
if (!params) return;
|
|
686
|
+
const keys = Object.keys(params);
|
|
687
|
+
this.captureTransientFromAttrsBeforePreventAnimate(params, keys, context), this.visitTrackedAnimates((animate => {
|
|
688
|
+
(animate.priority !== 1 / 0 || ignorePriority) && animate.preventAttrs(keys);
|
|
546
689
|
})), this.applyTransientAttributes(params, forceUpdateTag, context);
|
|
547
690
|
}
|
|
691
|
+
captureTransientFromAttrsBeforePreventAnimate(params, keys, context) {
|
|
692
|
+
var _a, _b;
|
|
693
|
+
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;
|
|
694
|
+
if (!keys.length || !diffAttrs || updateType === AttributeUpdateType.STATE || null != updateType && updateType >= AttributeUpdateType.ANIMATE_BIND && updateType <= AttributeUpdateType.ANIMATE_END) return;
|
|
695
|
+
const sameDiffAttrs = this.transientFromAttrsBeforePreventAnimateDiffAttrs === diffAttrs;
|
|
696
|
+
let fromAttrs = sameDiffAttrs && null !== (_b = this.transientFromAttrsBeforePreventAnimate) && void 0 !== _b ? _b : null;
|
|
697
|
+
sameDiffAttrs || (this.transientFromAttrsBeforePreventAnimate = null, this.transientFromAttrsBeforePreventAnimateDiffAttrs = null);
|
|
698
|
+
let captured = !1;
|
|
699
|
+
for (let i = 0; i < keys.length; i++) {
|
|
700
|
+
const key = keys[i];
|
|
701
|
+
if (!Object.prototype.hasOwnProperty.call(diffAttrs, key)) continue;
|
|
702
|
+
const previousValue = this.attribute[key], nextValue = params[key];
|
|
703
|
+
isEqual(previousValue, nextValue) || (null != fromAttrs || (fromAttrs = {}), fromAttrs[key] = cloneAttributeValue(previousValue),
|
|
704
|
+
captured = !0);
|
|
705
|
+
}
|
|
706
|
+
captured && (this.transientFromAttrsBeforePreventAnimate = fromAttrs, this.transientFromAttrsBeforePreventAnimateDiffAttrs = diffAttrs);
|
|
707
|
+
}
|
|
708
|
+
consumeTransientFromAttrsBeforePreventAnimate(diffAttrs) {
|
|
709
|
+
const transientFromAttrs = this.transientFromAttrsBeforePreventAnimate, sourceDiffAttrs = this.transientFromAttrsBeforePreventAnimateDiffAttrs;
|
|
710
|
+
if (!transientFromAttrs || !sourceDiffAttrs) return null;
|
|
711
|
+
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;
|
|
712
|
+
let fromAttrs = null, remaining = !1;
|
|
713
|
+
for (const key in transientFromAttrs) Object.prototype.hasOwnProperty.call(transientFromAttrs, key) && (Object.prototype.hasOwnProperty.call(diffAttrs, key) ? (null != fromAttrs || (fromAttrs = {}),
|
|
714
|
+
fromAttrs[key] = transientFromAttrs[key]) : remaining = !0);
|
|
715
|
+
if (remaining) {
|
|
716
|
+
const nextTransientFromAttrs = {};
|
|
717
|
+
for (const key in transientFromAttrs) Object.prototype.hasOwnProperty.call(transientFromAttrs, key) && !Object.prototype.hasOwnProperty.call(diffAttrs, key) && (nextTransientFromAttrs[key] = transientFromAttrs[key]);
|
|
718
|
+
this.transientFromAttrsBeforePreventAnimate = nextTransientFromAttrs;
|
|
719
|
+
} else this.transientFromAttrsBeforePreventAnimate = null, this.transientFromAttrsBeforePreventAnimateDiffAttrs = null;
|
|
720
|
+
return fromAttrs;
|
|
721
|
+
}
|
|
548
722
|
setAttributes(params, forceUpdateTag = !1, context) {
|
|
549
723
|
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),
|
|
551
|
-
this._setAttributes(params, forceUpdateTag, context));
|
|
724
|
+
params.texture && isExternalTexture(params.texture) && this.loadImage(params.texture, !1),
|
|
725
|
+
params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic), this._setAttributes(params, forceUpdateTag, context));
|
|
552
726
|
}
|
|
553
727
|
_setAttributes(params, forceUpdateTag = !1, context) {
|
|
554
|
-
this.
|
|
728
|
+
this.canCommitBaseAttributesByTouchedKeys() ? this.commitBaseAttributesByTouchedKeys(params, forceUpdateTag, context) : (this.detachAttributeFromBaseAttributes(),
|
|
729
|
+
this.applyBaseAttributes(params), this.commitBaseAttributeMutation(forceUpdateTag, context));
|
|
555
730
|
}
|
|
556
731
|
setAttribute(key, value, forceUpdateTag, context) {
|
|
557
732
|
const params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate({
|
|
558
733
|
[key]: value
|
|
559
734
|
}, this.attribute, key, context);
|
|
560
|
-
params
|
|
561
|
-
|
|
562
|
-
|
|
735
|
+
if (params) this._setAttributes(params, forceUpdateTag, context); else if (this.canCommitBaseAttributesByTouchedKeys()) this.commitBaseAttributeBySingleKey(key, value, !!forceUpdateTag, context); else {
|
|
736
|
+
const nextAttrs = {
|
|
737
|
+
[key]: value
|
|
738
|
+
};
|
|
739
|
+
this.applyBaseAttributes(nextAttrs), this.commitBaseAttributeMutation(!!forceUpdateTag, context);
|
|
740
|
+
}
|
|
741
|
+
"background" === key ? this.loadImage(value, !0) : "texture" === key && isExternalTexture(value) ? this.loadImage(value, !1) : "shadowGraphic" === key && this.setShadowGraphic(value);
|
|
563
742
|
}
|
|
564
743
|
needUpdateTags(keys, k = GRAPHIC_UPDATE_TAG_KEY) {
|
|
565
744
|
for (let i = 0; i < k.length; i++) {
|
|
@@ -579,10 +758,11 @@ export class Graphic extends Node {
|
|
|
579
758
|
type: AttributeUpdateType.INIT
|
|
580
759
|
};
|
|
581
760
|
params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate(params, this.attribute, null, context) || params,
|
|
582
|
-
this.
|
|
583
|
-
this.
|
|
584
|
-
isExternalTexture(params.texture) && this.loadImage(params.texture, !1),
|
|
585
|
-
|
|
761
|
+
this.attribute = params, this._baseAttributes = void 0, this.resolvedStatePatch = void 0,
|
|
762
|
+
this.attributeMayContainTransientAttrs = !1, this.valid = this.isValid(), params.background && this.loadImage(params.background, !0),
|
|
763
|
+
params.texture && isExternalTexture(params.texture) && this.loadImage(params.texture, !1),
|
|
764
|
+
params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic), this._updateTag = UpdateTag.INIT,
|
|
765
|
+
this.valid = this.isValid(), this.onAttributeUpdate(context);
|
|
586
766
|
}
|
|
587
767
|
translate(x, y) {
|
|
588
768
|
var _a, _b;
|
|
@@ -593,11 +773,15 @@ export class Graphic extends Node {
|
|
|
593
773
|
x: x,
|
|
594
774
|
y: y
|
|
595
775
|
}, this.attribute, tempConstantXYKey, context);
|
|
596
|
-
params && (x = params.x, y = params.y, delete params.x, delete params.y
|
|
597
|
-
const attribute = this.baseAttributes, postMatrix = attribute.postMatrix;
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
776
|
+
params && (x = params.x, y = params.y, delete params.x, delete params.y);
|
|
777
|
+
const attribute = this.baseAttributes, postMatrix = attribute.postMatrix, nextAttrs = params || {};
|
|
778
|
+
if (postMatrix) {
|
|
779
|
+
const nextPostMatrix = postMatrix.clone();
|
|
780
|
+
application.transformUtil.fromMatrix(nextPostMatrix, nextPostMatrix).translate(x, y),
|
|
781
|
+
nextAttrs.postMatrix = nextPostMatrix;
|
|
782
|
+
} else nextAttrs.x = (null !== (_a = attribute.x) && void 0 !== _a ? _a : DefaultTransform.x) + x,
|
|
783
|
+
nextAttrs.y = (null !== (_b = attribute.y) && void 0 !== _b ? _b : DefaultTransform.y) + y;
|
|
784
|
+
return this.commitInternalBaseAttributes(nextAttrs, context), this;
|
|
601
785
|
}
|
|
602
786
|
translateTo(x, y) {
|
|
603
787
|
const attribute = this.baseAttributes;
|
|
@@ -608,9 +792,10 @@ export class Graphic extends Node {
|
|
|
608
792
|
x: x,
|
|
609
793
|
y: y
|
|
610
794
|
}, this.attribute, tempConstantXYKey, context);
|
|
611
|
-
return params ? (this.
|
|
612
|
-
|
|
613
|
-
|
|
795
|
+
return params ? (this.commitInternalBaseAttributes(params, context), this) : (this.commitInternalBaseAttributes({
|
|
796
|
+
x: x,
|
|
797
|
+
y: y
|
|
798
|
+
}, context), this);
|
|
614
799
|
}
|
|
615
800
|
scale(scaleX, scaleY, scaleCenter) {
|
|
616
801
|
var _a, _b;
|
|
@@ -623,14 +808,15 @@ export class Graphic extends Node {
|
|
|
623
808
|
scaleCenter: scaleCenter
|
|
624
809
|
}, this.attribute, tempConstantScaleXYKey, context);
|
|
625
810
|
params && (scaleX = params.scaleX, scaleY = params.scaleY, delete params.scaleX,
|
|
626
|
-
delete params.scaleY
|
|
627
|
-
const attribute = this.baseAttributes;
|
|
811
|
+
delete params.scaleY);
|
|
812
|
+
const attribute = this.baseAttributes, nextAttrs = params || {};
|
|
628
813
|
if (scaleCenter) {
|
|
629
|
-
let {postMatrix: postMatrix} = this.
|
|
630
|
-
postMatrix
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
814
|
+
let {postMatrix: postMatrix} = this.baseAttributes;
|
|
815
|
+
postMatrix = postMatrix ? postMatrix.clone() : new Matrix, application.transformUtil.fromMatrix(postMatrix, postMatrix).scale(scaleX, scaleY, scaleCenter),
|
|
816
|
+
nextAttrs.postMatrix = postMatrix;
|
|
817
|
+
} else nextAttrs.scaleX = (null !== (_a = attribute.scaleX) && void 0 !== _a ? _a : DefaultTransform.scaleX) * scaleX,
|
|
818
|
+
nextAttrs.scaleY = (null !== (_b = attribute.scaleY) && void 0 !== _b ? _b : DefaultTransform.scaleY) * scaleY;
|
|
819
|
+
return this.commitInternalBaseAttributes(nextAttrs, context), this;
|
|
634
820
|
}
|
|
635
821
|
scaleTo(scaleX, scaleY) {
|
|
636
822
|
const attribute = this.baseAttributes;
|
|
@@ -641,9 +827,10 @@ export class Graphic extends Node {
|
|
|
641
827
|
scaleX: scaleX,
|
|
642
828
|
scaleY: scaleY
|
|
643
829
|
}, this.attribute, tempConstantScaleXYKey, context);
|
|
644
|
-
return params ? (this.
|
|
645
|
-
|
|
646
|
-
|
|
830
|
+
return params ? (this.commitInternalBaseAttributes(params, context), this) : (this.commitInternalBaseAttributes({
|
|
831
|
+
scaleX: scaleX,
|
|
832
|
+
scaleY: scaleY
|
|
833
|
+
}, context), this);
|
|
647
834
|
}
|
|
648
835
|
rotate(angle, rotateCenter) {
|
|
649
836
|
var _a;
|
|
@@ -654,24 +841,23 @@ export class Graphic extends Node {
|
|
|
654
841
|
angle: angle,
|
|
655
842
|
rotateCenter: rotateCenter
|
|
656
843
|
}, this.attribute, tempConstantAngleKey, context);
|
|
657
|
-
params &&
|
|
658
|
-
const attribute = this.baseAttributes;
|
|
844
|
+
params && delete params.angle;
|
|
845
|
+
const attribute = this.baseAttributes, nextAttrs = params || {};
|
|
659
846
|
if (rotateCenter) {
|
|
660
847
|
let {postMatrix: postMatrix} = this.baseAttributes;
|
|
661
|
-
postMatrix
|
|
662
|
-
|
|
663
|
-
} else
|
|
664
|
-
return this.
|
|
848
|
+
postMatrix = postMatrix ? postMatrix.clone() : new Matrix, application.transformUtil.fromMatrix(postMatrix, postMatrix).rotate(angle, rotateCenter),
|
|
849
|
+
nextAttrs.postMatrix = postMatrix;
|
|
850
|
+
} else nextAttrs.angle = (null !== (_a = attribute.angle) && void 0 !== _a ? _a : DefaultTransform.angle) + angle;
|
|
851
|
+
return this.commitInternalBaseAttributes(nextAttrs, context), this;
|
|
665
852
|
}
|
|
666
853
|
rotateTo(angle) {
|
|
667
|
-
|
|
668
|
-
if (attribute.angle === angle) return this;
|
|
854
|
+
if (this.baseAttributes.angle === angle) return this;
|
|
669
855
|
const context = {
|
|
670
856
|
type: AttributeUpdateType.ROTATE_TO
|
|
671
857
|
}, params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate(angle, this.attribute, tempConstantAngleKey, context);
|
|
672
|
-
return params ? (this.
|
|
673
|
-
|
|
674
|
-
this);
|
|
858
|
+
return params ? (this.commitInternalBaseAttributes(params, context), this) : (this.commitInternalBaseAttributes({
|
|
859
|
+
angle: angle
|
|
860
|
+
}, context), this);
|
|
675
861
|
}
|
|
676
862
|
skewTo(b, c) {
|
|
677
863
|
return this;
|
|
@@ -691,7 +877,16 @@ export class Graphic extends Node {
|
|
|
691
877
|
var _a;
|
|
692
878
|
return null === (_a = this.states) || void 0 === _a ? void 0 : _a[stateName];
|
|
693
879
|
}
|
|
694
|
-
|
|
880
|
+
getStateResolveBaseAttrs() {
|
|
881
|
+
var _a;
|
|
882
|
+
return null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : this.attribute;
|
|
883
|
+
}
|
|
884
|
+
syncStateResolveContext(stateResolveBaseAttrs = this.getStateResolveBaseAttrs()) {
|
|
885
|
+
var _a;
|
|
886
|
+
return null === (_a = this.stateEngine) || void 0 === _a || _a.setResolveContext(this, stateResolveBaseAttrs),
|
|
887
|
+
stateResolveBaseAttrs;
|
|
888
|
+
}
|
|
889
|
+
createStateModel(stateResolveBaseAttrs = this.getStateResolveBaseAttrs()) {
|
|
695
890
|
const {compiledDefinitions: compiledDefinitions, stateProxyEligibility: stateProxyEligibility, stateProxyModeKey: stateProxyModeKey} = this.resolveEffectiveCompiledDefinitions();
|
|
696
891
|
return this.compiledStateDefinitions = compiledDefinitions, compiledDefinitions ? this.stateEngine && this.stateEngineCompiledDefinitions === compiledDefinitions && this.stateEngineStateProxy === this.stateProxy && this.stateEngineStateSort === this.stateSort && this.stateEngineMergeMode === this.stateMergeMode && this.stateEngineStateProxyModeKey === stateProxyModeKey || (this.stateEngine = new StateEngine({
|
|
697
892
|
compiledDefinitions: compiledDefinitions,
|
|
@@ -704,7 +899,7 @@ export class Graphic extends Node {
|
|
|
704
899
|
this.stateEngineStateSort = this.stateSort, this.stateEngineMergeMode = this.stateMergeMode,
|
|
705
900
|
this.stateEngineStateProxyModeKey = stateProxyModeKey) : (this.stateEngine = void 0,
|
|
706
901
|
this.stateEngineCompiledDefinitions = void 0, this.stateEngineStateProxyModeKey = void 0),
|
|
707
|
-
new StateModel({
|
|
902
|
+
this.syncStateResolveContext(stateResolveBaseAttrs), new StateModel({
|
|
708
903
|
states: this.states,
|
|
709
904
|
currentStates: this.currentStates,
|
|
710
905
|
stateSort: this.stateSort,
|
|
@@ -712,27 +907,148 @@ export class Graphic extends Node {
|
|
|
712
907
|
stateEngine: this.stateEngine
|
|
713
908
|
});
|
|
714
909
|
}
|
|
910
|
+
resolveSimpleLocalStateTransition(states, previousStates) {
|
|
911
|
+
var _a;
|
|
912
|
+
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;
|
|
913
|
+
if (1 === states.length) {
|
|
914
|
+
const stateName = states[0], hasDefinition = Object.prototype.hasOwnProperty.call(this.states, stateName), nextStates = [ stateName ], changed = !this.sameStateNames(previousStates, nextStates), resolvedStateAttrs = {};
|
|
915
|
+
if (hasDefinition) {
|
|
916
|
+
const attrs = this.states[stateName];
|
|
917
|
+
if (null != attrs) {
|
|
918
|
+
if (!isPlainObjectValue(attrs)) return null;
|
|
919
|
+
const keys = Object.keys(attrs);
|
|
920
|
+
for (let keyIndex = 0; keyIndex < keys.length; keyIndex++) {
|
|
921
|
+
const key = keys[keyIndex];
|
|
922
|
+
if (FULL_STATE_DEFINITION_KEYS.has(key)) return null;
|
|
923
|
+
const attrValue = attrs[key];
|
|
924
|
+
resolvedStateAttrs[key] = isPlainObjectValue(attrValue) ? cloneAttributeValue(attrValue) : attrValue;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
return {
|
|
929
|
+
changed: changed,
|
|
930
|
+
states: nextStates,
|
|
931
|
+
effectiveStates: nextStates,
|
|
932
|
+
resolvedStateAttrs: resolvedStateAttrs
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
const uniqueStates = Array.from(new Set(states)), withDefinition = [], withoutDefinition = [];
|
|
936
|
+
for (let i = 0; i < uniqueStates.length; i++) {
|
|
937
|
+
const stateName = uniqueStates[i];
|
|
938
|
+
Object.prototype.hasOwnProperty.call(this.states, stateName) ? withDefinition.push(stateName) : withoutDefinition.push(stateName);
|
|
939
|
+
}
|
|
940
|
+
withDefinition.sort(((left, right) => left.localeCompare(right)));
|
|
941
|
+
const nextStates = withDefinition.concat(withoutDefinition), changed = !this.sameStateNames(previousStates, nextStates), resolvedStateAttrs = {};
|
|
942
|
+
for (let i = 0; i < nextStates.length; i++) {
|
|
943
|
+
const stateName = nextStates[i];
|
|
944
|
+
if (!Object.prototype.hasOwnProperty.call(this.states, stateName)) continue;
|
|
945
|
+
const attrs = this.states[stateName];
|
|
946
|
+
if (null == attrs) continue;
|
|
947
|
+
if (!isPlainObjectValue(attrs)) return null;
|
|
948
|
+
const keys = Object.keys(attrs);
|
|
949
|
+
for (let keyIndex = 0; keyIndex < keys.length; keyIndex++) {
|
|
950
|
+
const key = keys[keyIndex];
|
|
951
|
+
if (FULL_STATE_DEFINITION_KEYS.has(key)) return null;
|
|
952
|
+
const attrValue = attrs[key];
|
|
953
|
+
resolvedStateAttrs[key] = isPlainObjectValue(attrValue) ? cloneAttributeValue(attrValue) : attrValue;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
return {
|
|
957
|
+
changed: changed,
|
|
958
|
+
states: nextStates,
|
|
959
|
+
effectiveStates: nextStates,
|
|
960
|
+
resolvedStateAttrs: resolvedStateAttrs
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
resolveGraphicStateTransition(states, previousStates, forceResolverRefresh = !1) {
|
|
964
|
+
var _a, _b;
|
|
965
|
+
let transition = this.resolveSimpleLocalStateTransition(states, previousStates);
|
|
966
|
+
const isSimpleLocalTransition = !!transition;
|
|
967
|
+
let resolvedStateAttrs;
|
|
968
|
+
if (transition) resolvedStateAttrs = transition.resolvedStateAttrs; else {
|
|
969
|
+
const stateResolveBaseAttrs = this.getStateResolveBaseAttrs(), stateModel = this.createStateModel(stateResolveBaseAttrs);
|
|
970
|
+
forceResolverRefresh && (null === (_a = this.stateEngine) || void 0 === _a || _a.invalidateResolverCache()),
|
|
971
|
+
transition = stateModel.useStates(states), resolvedStateAttrs = this.stateEngine && this.compiledStateDefinitions ? Object.assign({}, this.stateEngine.resolvedPatch) : this.getStateStyleResolver(this.stateMergeMode).resolve(stateResolveBaseAttrs, this.states, this.stateProxy, transition.states, this.stateSort);
|
|
972
|
+
}
|
|
973
|
+
return {
|
|
974
|
+
transition: transition,
|
|
975
|
+
effectiveStates: null !== (_b = transition.effectiveStates) && void 0 !== _b ? _b : transition.states,
|
|
976
|
+
resolvedStateAttrs: resolvedStateAttrs,
|
|
977
|
+
isSimpleLocalTransition: isSimpleLocalTransition
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
normalizeSetStatesOptions(options) {
|
|
981
|
+
return options && "object" == typeof options ? {
|
|
982
|
+
hasAnimation: options.animate,
|
|
983
|
+
animateSameStatePatchChange: !0 === options.animateSameStatePatchChange,
|
|
984
|
+
shouldRefreshSameStatePatch: !0
|
|
985
|
+
} : {
|
|
986
|
+
hasAnimation: "boolean" == typeof options ? options : void 0,
|
|
987
|
+
animateSameStatePatchChange: !1,
|
|
988
|
+
shouldRefreshSameStatePatch: !1
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
sameStatePatches(left, right) {
|
|
992
|
+
const leftRecord = null != left ? left : {}, rightRecord = null != right ? right : {}, keys = new Set([ ...Object.keys(leftRecord), ...Object.keys(rightRecord) ]);
|
|
993
|
+
for (const key of keys) {
|
|
994
|
+
if (Object.prototype.hasOwnProperty.call(leftRecord, key) !== Object.prototype.hasOwnProperty.call(rightRecord, key)) return !1;
|
|
995
|
+
if (!areAttributeValuesEqual(leftRecord[key], rightRecord[key])) return !1;
|
|
996
|
+
}
|
|
997
|
+
return !0;
|
|
998
|
+
}
|
|
999
|
+
commitSameStatePatchRefresh(states, hasAnimation, animateSameStatePatchChange = !1) {
|
|
1000
|
+
var _a;
|
|
1001
|
+
const previousStates = null !== (_a = this.currentStates) && void 0 !== _a ? _a : EMPTY_STATE_NAMES, previousResolvedStatePatch = this.resolvedStatePatch, {transition: transition, effectiveStates: effectiveStates, resolvedStateAttrs: resolvedStateAttrs, isSimpleLocalTransition: isSimpleLocalTransition} = this.resolveGraphicStateTransition(states, previousStates, !0), patchChanged = !this.sameStatePatches(previousResolvedStatePatch, resolvedStateAttrs);
|
|
1002
|
+
if ((!patchChanged || this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) && (this.currentStates = transition.states,
|
|
1003
|
+
this.effectiveStates = isSimpleLocalTransition ? effectiveStates : [ ...effectiveStates ],
|
|
1004
|
+
this.resolvedStatePatch = resolvedStateAttrs, this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(),
|
|
1005
|
+
patchChanged)) {
|
|
1006
|
+
if (this.stage) {
|
|
1007
|
+
const perfMonitor = getActiveStageStatePerfMonitor(this.stage);
|
|
1008
|
+
null == perfMonitor || perfMonitor.incrementCounter("stateCommits"), null == perfMonitor || perfMonitor.recordEvent("state-commit", {
|
|
1009
|
+
graphicId: this._uid,
|
|
1010
|
+
targetStates: [ ...transition.states ]
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
hasAnimation && animateSameStatePatchChange ? (this._syncFinalAttributeFromStaticTruth(),
|
|
1014
|
+
this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !1, void 0, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch))) : (this.stopStateAnimates(),
|
|
1015
|
+
this.attributeMayContainTransientAttrs ? this._restoreAttributeFromStaticTruth({
|
|
1016
|
+
type: AttributeUpdateType.STATE
|
|
1017
|
+
}) : this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, this.resolvedStatePatch, {
|
|
1018
|
+
type: AttributeUpdateType.STATE
|
|
1019
|
+
}), this.emitStateUpdateEvent());
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
715
1022
|
resolveStateAnimateConfig(animateConfig) {
|
|
716
1023
|
var _a, _b, _c;
|
|
717
1024
|
return null !== (_c = null !== (_a = null != animateConfig ? animateConfig : this.stateAnimateConfig) && void 0 !== _a ? _a : null === (_b = this.context) || void 0 === _b ? void 0 : _b.stateAnimateConfig) && void 0 !== _c ? _c : DefaultStateAnimateConfig;
|
|
718
1025
|
}
|
|
719
|
-
applyStateAttrs(attrs, stateNames, hasAnimation, isClear, animateConfig) {
|
|
1026
|
+
applyStateAttrs(attrs, stateNames, hasAnimation, isClear, animateConfig, extraAnimateAttrs) {
|
|
720
1027
|
const resolvedAnimateConfig = hasAnimation ? this.resolveStateAnimateConfig(animateConfig) : void 0, transitionOptions = resolvedAnimateConfig ? {
|
|
721
|
-
animateConfig: resolvedAnimateConfig
|
|
1028
|
+
animateConfig: resolvedAnimateConfig,
|
|
1029
|
+
extraAnimateAttrs: extraAnimateAttrs,
|
|
1030
|
+
shouldSkipDefaultAttribute: this.shouldSkipStateTransitionDefaultAttribute.bind(this)
|
|
722
1031
|
} : void 0;
|
|
723
1032
|
if (isClear) return void this.getStateTransitionOrchestrator().applyClearTransition(this, attrs, hasAnimation, stateNames, transitionOptions);
|
|
724
1033
|
const plan = this.getStateTransitionOrchestrator().analyzeTransition({}, attrs, stateNames, hasAnimation, {
|
|
725
1034
|
noWorkAnimateAttr: this.getNoWorkAnimateAttr(),
|
|
726
|
-
animateConfig: resolvedAnimateConfig
|
|
1035
|
+
animateConfig: resolvedAnimateConfig,
|
|
1036
|
+
extraAnimateAttrs: extraAnimateAttrs,
|
|
1037
|
+
shouldSkipDefaultAttribute: this.shouldSkipStateTransitionDefaultAttribute.bind(this)
|
|
727
1038
|
});
|
|
728
1039
|
this.getStateTransitionOrchestrator().applyTransition(this, plan, hasAnimation, transitionOptions);
|
|
729
1040
|
}
|
|
730
|
-
updateNormalAttrs(
|
|
731
|
-
|
|
1041
|
+
updateNormalAttrs(_stateAttrs) {}
|
|
1042
|
+
getStateTransitionDefaultAttribute(key, targetAttrs) {
|
|
1043
|
+
return this.getDefaultAttribute(key);
|
|
1044
|
+
}
|
|
1045
|
+
shouldSkipStateTransitionDefaultAttribute(_key, _targetAttrs) {
|
|
1046
|
+
return !1;
|
|
732
1047
|
}
|
|
733
1048
|
stopStateAnimates(type = "end") {
|
|
734
1049
|
const stopAnimationState = this.stopAnimationState;
|
|
735
1050
|
if ("function" == typeof stopAnimationState) return void stopAnimationState.call(this, "state", type);
|
|
1051
|
+
if (!this.mayHaveTrackedAnimates()) return;
|
|
736
1052
|
const stateAnimates = [];
|
|
737
1053
|
this.visitTrackedAnimates((animate => {
|
|
738
1054
|
animate.stateNames && stateAnimates.push(animate);
|
|
@@ -745,23 +1061,27 @@ export class Graphic extends Node {
|
|
|
745
1061
|
}
|
|
746
1062
|
clearStates(hasAnimation) {
|
|
747
1063
|
var _a, _b, _c;
|
|
748
|
-
const previousStates =
|
|
1064
|
+
const previousStates = null !== (_a = this.currentStates) && void 0 !== _a ? _a : EMPTY_STATE_NAMES, previousResolvedStatePatch = this.resolvedStatePatch, transition = this.createStateModel().clearStates();
|
|
749
1065
|
if (!transition.changed && 0 === previousStates.length) return this.currentStates = [],
|
|
750
1066
|
this.effectiveStates = [], this.resolvedStatePatch = void 0, this.sharedStateDirty = !1,
|
|
751
1067
|
void this.clearSharedStateActiveRegistrations();
|
|
752
|
-
const resolvedStateAttrs = cloneAttributeValue(null !== (
|
|
753
|
-
transition.changed
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
1068
|
+
const resolvedStateAttrs = hasAnimation || this.hasCustomEvent("beforeStateUpdate") ? cloneAttributeValue(null !== (_b = this.baseAttributes) && void 0 !== _b ? _b : {}) : null !== (_c = this.baseAttributes) && void 0 !== _c ? _c : {};
|
|
1069
|
+
if (!transition.changed || this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !0)) {
|
|
1070
|
+
if (this.currentStates = transition.states, this.effectiveStates = [], this.resolvedStatePatch = void 0,
|
|
1071
|
+
this.sharedStateDirty = !1, this.clearSharedStateActiveRegistrations(), this.stage) {
|
|
1072
|
+
const perfMonitor = getActiveStageStatePerfMonitor(this.stage);
|
|
1073
|
+
null == perfMonitor || perfMonitor.incrementCounter("stateCommits"), null == perfMonitor || perfMonitor.recordEvent("state-commit", {
|
|
1074
|
+
graphicId: this._uid,
|
|
1075
|
+
targetStates: []
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
hasAnimation ? (this._syncFinalAttributeFromStaticTruth(), this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !0, void 0, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch))) : (this.stopStateAnimates(),
|
|
1079
|
+
this.attributeMayContainTransientAttrs ? this._restoreAttributeFromStaticTruth({
|
|
1080
|
+
type: AttributeUpdateType.STATE
|
|
1081
|
+
}) : this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, void 0, {
|
|
1082
|
+
type: AttributeUpdateType.STATE
|
|
1083
|
+
}), this.emitStateUpdateEvent());
|
|
1084
|
+
}
|
|
765
1085
|
}
|
|
766
1086
|
removeState(stateName, hasAnimation) {
|
|
767
1087
|
const transition = this.createStateModel().removeState(stateName);
|
|
@@ -775,41 +1095,51 @@ export class Graphic extends Node {
|
|
|
775
1095
|
const transition = this.createStateModel().addState(stateName, keepCurrentStates);
|
|
776
1096
|
transition.changed && this.useStates(transition.states, hasAnimation);
|
|
777
1097
|
}
|
|
1098
|
+
setStates(states, options) {
|
|
1099
|
+
var _a, _b, _c;
|
|
1100
|
+
const {hasAnimation: hasAnimation, animateSameStatePatchChange: animateSameStatePatchChange, shouldRefreshSameStatePatch: shouldRefreshSameStatePatch} = this.normalizeSetStatesOptions(options), nextStates = (null == states ? void 0 : states.length) ? states : EMPTY_STATE_NAMES, hasCurrentState = !!((null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || (null === (_b = this.effectiveStates) || void 0 === _b ? void 0 : _b.length) || this.resolvedStatePatch || (null === (_c = this.registeredActiveScopes) || void 0 === _c ? void 0 : _c.size));
|
|
1101
|
+
if (nextStates.length) {
|
|
1102
|
+
if (this.sameStateNames(this.currentStates, nextStates)) return shouldRefreshSameStatePatch ? void this.commitSameStatePatchRefresh(nextStates, hasAnimation, animateSameStatePatchChange) : void (this.sharedStateDirty && this.refreshSharedStateBeforeRender());
|
|
1103
|
+
this.useStates(nextStates, hasAnimation);
|
|
1104
|
+
} else {
|
|
1105
|
+
if (!hasCurrentState && !this.sharedStateDirty) return;
|
|
1106
|
+
this.clearStates(hasAnimation);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
778
1109
|
useStates(states, hasAnimation) {
|
|
779
|
-
var _a
|
|
1110
|
+
var _a;
|
|
780
1111
|
if (!states.length) return void this.clearStates(hasAnimation);
|
|
781
|
-
const previousStates =
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
1112
|
+
const previousStates = null !== (_a = this.currentStates) && void 0 !== _a ? _a : EMPTY_STATE_NAMES, previousResolvedStatePatch = this.resolvedStatePatch, {transition: transition, effectiveStates: effectiveStates, resolvedStateAttrs: resolvedStateAttrs, isSimpleLocalTransition: isSimpleLocalTransition} = this.resolveGraphicStateTransition(states, previousStates);
|
|
1113
|
+
if ((transition.changed || !this.sameStateNames(previousStates, transition.states)) && this.beforeStateUpdate(resolvedStateAttrs, previousStates, transition.states, hasAnimation, !1)) {
|
|
1114
|
+
if (this.currentStates = transition.states, this.effectiveStates = isSimpleLocalTransition ? effectiveStates : [ ...effectiveStates ],
|
|
1115
|
+
this.resolvedStatePatch = resolvedStateAttrs, this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(),
|
|
1116
|
+
this.stage) {
|
|
1117
|
+
const perfMonitor = getActiveStageStatePerfMonitor(this.stage);
|
|
1118
|
+
null == perfMonitor || perfMonitor.incrementCounter("stateCommits"), null == perfMonitor || perfMonitor.recordEvent("state-commit", {
|
|
1119
|
+
graphicId: this._uid,
|
|
1120
|
+
targetStates: [ ...transition.states ]
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
hasAnimation ? (this._syncFinalAttributeFromStaticTruth(), this.applyStateAttrs(resolvedStateAttrs, transition.states, hasAnimation, !1, void 0, this.buildRemovedStateAnimationAttrs(resolvedStateAttrs, previousResolvedStatePatch))) : (this.stopStateAnimates(),
|
|
1124
|
+
this.attributeMayContainTransientAttrs ? this._restoreAttributeFromStaticTruth({
|
|
1125
|
+
type: AttributeUpdateType.STATE
|
|
1126
|
+
}) : this.restoreAttributeFromStatePatchDelta(previousResolvedStatePatch, this.resolvedStatePatch, {
|
|
1127
|
+
type: AttributeUpdateType.STATE
|
|
1128
|
+
}), this.emitStateUpdateEvent());
|
|
1129
|
+
}
|
|
798
1130
|
}
|
|
799
1131
|
invalidateResolver() {
|
|
800
1132
|
var _a, _b;
|
|
801
1133
|
if (!this.stateEngine || !(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || !this.compiledStateDefinitions) return;
|
|
802
|
-
|
|
803
|
-
this.
|
|
1134
|
+
this.syncStateResolveContext();
|
|
1135
|
+
this.resolverEpoch = (null !== (_b = this.resolverEpoch) && void 0 !== _b ? _b : 0) + 1,
|
|
804
1136
|
this.stateEngine.invalidateResolverCache();
|
|
805
1137
|
const transition = this.stateEngine.applyStates(this.currentStates), resolvedStateAttrs = Object.assign({}, this.stateEngine.resolvedPatch);
|
|
806
|
-
this.effectiveStates = [ ...transition.effectiveStates ], this.resolvedStatePatch =
|
|
1138
|
+
this.effectiveStates = [ ...transition.effectiveStates ], this.resolvedStatePatch = resolvedStateAttrs,
|
|
807
1139
|
this.sharedStateDirty = !1, this.syncSharedStateActiveRegistrations(), this.stopStateAnimates(),
|
|
808
1140
|
this._restoreAttributeFromStaticTruth({
|
|
809
1141
|
type: AttributeUpdateType.STATE
|
|
810
|
-
}), this.
|
|
811
|
-
type: AttributeUpdateType.STATE
|
|
812
|
-
});
|
|
1142
|
+
}), this.emitStateUpdateEvent();
|
|
813
1143
|
}
|
|
814
1144
|
sameStateNames(left, right) {
|
|
815
1145
|
const normalizedLeft = null != left ? left : [], normalizedRight = null != right ? right : [];
|
|
@@ -831,6 +1161,10 @@ export class Graphic extends Node {
|
|
|
831
1161
|
this._updateTag |= UpdateTag.UPDATE_SHAPE_AND_BOUNDS, this.parent && this.parent.addChildUpdateBoundTag(),
|
|
832
1162
|
this.glyphHost && this.glyphHost.addUpdateBoundTag();
|
|
833
1163
|
}
|
|
1164
|
+
addBroadUpdateTag() {
|
|
1165
|
+
this.shadowRoot && this.shadowRoot.addUpdateGlobalPositionTag(), this._updateTag |= UpdateTag.UPDATE_SHAPE_AND_BOUNDS | UpdateTag.UPDATE_PAINT | UpdateTag.UPDATE_GLOBAL_LOCAL_MATRIX | UpdateTag.UPDATE_LAYOUT,
|
|
1166
|
+
this.parent && this.parent.addChildUpdateBoundTag(), this.glyphHost && this.glyphHost.addUpdateBoundTag();
|
|
1167
|
+
}
|
|
834
1168
|
updateShapeAndBoundsTagSetted() {
|
|
835
1169
|
return (this._updateTag & UpdateTag.UPDATE_SHAPE_AND_BOUNDS) === UpdateTag.UPDATE_SHAPE_AND_BOUNDS;
|
|
836
1170
|
}
|
|
@@ -904,12 +1238,12 @@ export class Graphic extends Node {
|
|
|
904
1238
|
}
|
|
905
1239
|
}
|
|
906
1240
|
setStage(stage, layer) {
|
|
907
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1241
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
908
1242
|
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
1243
|
if (this.stage !== stage || this.layer !== layer) {
|
|
910
|
-
if (this.stage = stage, this.layer = layer,
|
|
911
|
-
this.setStageToShadowRoot(stage, layer), this.hasAnyTrackedAnimate()) {
|
|
912
|
-
const previousTimeline = null === (
|
|
1244
|
+
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),
|
|
1245
|
+
this.setStageToShadowRoot(stage, layer), this.mayHaveTrackedAnimates() && this.hasAnyTrackedAnimate()) {
|
|
1246
|
+
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
1247
|
this.visitTrackedAnimates((a => {
|
|
914
1248
|
(!!previousTimeline && a.timeline === previousTimeline || a.timeline.isGlobal) && (nextTimeline ? a.timeline !== nextTimeline && (previousTimeline && a.timeline === previousTimeline && previousTimeline.removeAnimate(a, !1),
|
|
915
1249
|
a.setTimeline(nextTimeline), nextTimeline.addAnimate(a)) : previousTimeline && a.timeline === previousTimeline && (previousTimeline.removeAnimate(a, !1),
|
|
@@ -923,9 +1257,18 @@ export class Graphic extends Node {
|
|
|
923
1257
|
type: AttributeUpdateType.ANIMATE_END
|
|
924
1258
|
}));
|
|
925
1259
|
}
|
|
926
|
-
return this._onSetStage && this._onSetStage(this, stage, layer), void (null === (
|
|
1260
|
+
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
1261
|
}
|
|
928
|
-
|
|
1262
|
+
((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);
|
|
1263
|
+
}
|
|
1264
|
+
detachStageForRelease() {
|
|
1265
|
+
var _a, _b, _c;
|
|
1266
|
+
(null === (_a = this.registeredActiveScopes) || void 0 === _a ? void 0 : _a.size) && this.clearSharedStateActiveRegistrations(),
|
|
1267
|
+
(this.mayHaveTrackedAnimates() || this.shadowRoot) && this.stopAnimates(), this.boundSharedStateScope = void 0,
|
|
1268
|
+
this.boundSharedStateRevision = void 0, this.localFallbackCompiledDefinitions = void 0,
|
|
1269
|
+
this.compiledStateDefinitions = void 0, this.compiledStateDefinitionsCacheKey = void 0,
|
|
1270
|
+
this.stateEngine = void 0, this.stateEngineCompiledDefinitions = void 0, this.stateEngineStateProxyModeKey = void 0,
|
|
1271
|
+
this.sharedStateDirty = !1, this.stage = null, this.layer = null, this.shadowRoot && (null === (_c = (_b = this.shadowRoot).detachStageForRelease) || void 0 === _c || _c.call(_b));
|
|
929
1272
|
}
|
|
930
1273
|
setStageToShadowRoot(stage, layer) {
|
|
931
1274
|
this.shadowRoot && this.shadowRoot.setStage(stage, layer);
|
|
@@ -999,6 +1342,7 @@ export class Graphic extends Node {
|
|
|
999
1342
|
res && (res.state = "fail", cb && cb());
|
|
1000
1343
|
}
|
|
1001
1344
|
_stopAnimates() {
|
|
1345
|
+
if (!this.mayHaveTrackedAnimates()) return;
|
|
1002
1346
|
const animates = [];
|
|
1003
1347
|
this.visitTrackedAnimates((animate => {
|
|
1004
1348
|
animates.push(animate);
|
|
@@ -1012,15 +1356,19 @@ export class Graphic extends Node {
|
|
|
1012
1356
|
}));
|
|
1013
1357
|
}
|
|
1014
1358
|
release() {
|
|
1015
|
-
var _a, _b, _c;
|
|
1016
|
-
this.releaseStatus = "released", this.
|
|
1017
|
-
|
|
1018
|
-
null
|
|
1359
|
+
var _a, _b, _c, _d;
|
|
1360
|
+
this.releaseStatus = "released", (null === (_a = this.registeredActiveScopes) || void 0 === _a ? void 0 : _a.size) && this.clearSharedStateActiveRegistrations(),
|
|
1361
|
+
(this.mayHaveTrackedAnimates() || this.shadowRoot) && this.stopAnimates();
|
|
1362
|
+
const graphicService = null !== (_c = null === (_b = this.stage) || void 0 === _b ? void 0 : _b.graphicService) && void 0 !== _c ? _c : application.graphicService;
|
|
1363
|
+
null === (_d = null == graphicService ? void 0 : graphicService.onRelease) || void 0 === _d || _d.call(graphicService, this),
|
|
1019
1364
|
super.release();
|
|
1020
1365
|
}
|
|
1366
|
+
hasCustomEvent(type) {
|
|
1367
|
+
return !!this._events && type in this._events;
|
|
1368
|
+
}
|
|
1021
1369
|
_dispatchCustomEvent(type, context) {
|
|
1022
1370
|
var _a, _b;
|
|
1023
|
-
if (this.
|
|
1371
|
+
if (this.hasCustomEvent(type)) {
|
|
1024
1372
|
const changeEvent = new CustomEvent(type, context);
|
|
1025
1373
|
changeEvent.bubbles = !1;
|
|
1026
1374
|
const manager = null === (_b = null === (_a = this.stage) || void 0 === _a ? void 0 : _a.eventSystem) || void 0 === _b ? void 0 : _b.manager;
|
|
@@ -1029,7 +1377,7 @@ export class Graphic extends Node {
|
|
|
1029
1377
|
return !0;
|
|
1030
1378
|
}
|
|
1031
1379
|
beforeStateUpdate(attrs, prevStates, nextStates, hasAnimation, isClear) {
|
|
1032
|
-
return this._dispatchCustomEvent("beforeStateUpdate", {
|
|
1380
|
+
return !this.hasCustomEvent("beforeStateUpdate") || this._dispatchCustomEvent("beforeStateUpdate", {
|
|
1033
1381
|
type: AttributeUpdateType.STATE,
|
|
1034
1382
|
attrs: Object.assign({}, attrs),
|
|
1035
1383
|
prevStates: prevStates.slice(),
|
|
@@ -1038,6 +1386,11 @@ export class Graphic extends Node {
|
|
|
1038
1386
|
isClear: !!isClear
|
|
1039
1387
|
});
|
|
1040
1388
|
}
|
|
1389
|
+
emitStateUpdateEvent() {
|
|
1390
|
+
this.hasCustomEvent("afterStateUpdate") && this._emitCustomEvent("afterStateUpdate", {
|
|
1391
|
+
type: AttributeUpdateType.STATE
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1041
1394
|
_emitCustomEvent(type, context) {
|
|
1042
1395
|
this._dispatchCustomEvent(type, context);
|
|
1043
1396
|
}
|