@visactor/vrender-core 1.1.4-alpha.0 → 1.1.4-alpha.2

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 (48) hide show
  1. package/cjs/graphic/graphic.d.ts +15 -5
  2. package/cjs/graphic/graphic.js +53 -18
  3. package/cjs/graphic/graphic.js.map +1 -1
  4. package/cjs/graphic/group.d.ts +7 -4
  5. package/cjs/graphic/group.js +31 -17
  6. package/cjs/graphic/group.js.map +1 -1
  7. package/cjs/graphic/node-tree.d.ts +2 -1
  8. package/cjs/graphic/node-tree.js +1 -1
  9. package/cjs/graphic/node-tree.js.map +1 -1
  10. package/cjs/graphic/richtext/utils.js +3 -0
  11. package/cjs/graphic/richtext/utils.js.map +1 -1
  12. package/cjs/graphic/richtext.d.ts +4 -1
  13. package/cjs/graphic/richtext.js +2 -2
  14. package/cjs/graphic/richtext.js.map +1 -1
  15. package/cjs/graphic/state/state-engine.d.ts +1 -0
  16. package/cjs/graphic/state/state-engine.js +17 -0
  17. package/cjs/graphic/state/state-engine.js.map +1 -1
  18. package/cjs/interface/graphic/richText.d.ts +2 -0
  19. package/cjs/interface/graphic/richText.js.map +1 -1
  20. package/cjs/interface/graphic.d.ts +1 -1
  21. package/cjs/interface/graphic.js.map +1 -1
  22. package/cjs/interface/node-tree.d.ts +2 -1
  23. package/cjs/interface/node-tree.js.map +1 -1
  24. package/dist/index.es.js +151 -40
  25. package/es/graphic/graphic.d.ts +15 -5
  26. package/es/graphic/graphic.js +53 -14
  27. package/es/graphic/graphic.js.map +1 -1
  28. package/es/graphic/group.d.ts +7 -4
  29. package/es/graphic/group.js +31 -17
  30. package/es/graphic/group.js.map +1 -1
  31. package/es/graphic/node-tree.d.ts +2 -1
  32. package/es/graphic/node-tree.js +1 -1
  33. package/es/graphic/node-tree.js.map +1 -1
  34. package/es/graphic/richtext/utils.js +3 -0
  35. package/es/graphic/richtext/utils.js.map +1 -1
  36. package/es/graphic/richtext.d.ts +4 -1
  37. package/es/graphic/richtext.js +2 -2
  38. package/es/graphic/richtext.js.map +1 -1
  39. package/es/graphic/state/state-engine.d.ts +1 -0
  40. package/es/graphic/state/state-engine.js +17 -0
  41. package/es/graphic/state/state-engine.js.map +1 -1
  42. package/es/interface/graphic/richText.d.ts +2 -0
  43. package/es/interface/graphic/richText.js.map +1 -1
  44. package/es/interface/graphic.d.ts +1 -1
  45. package/es/interface/graphic.js.map +1 -1
  46. package/es/interface/node-tree.d.ts +2 -1
  47. package/es/interface/node-tree.js.map +1 -1
  48. package/package.json +3 -3
@@ -57,7 +57,7 @@ export declare const NOWORK_ANIMATE_ATTR: {
57
57
  cursor: number;
58
58
  html: number;
59
59
  };
60
- export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Partial<IGraphicAttribute>> extends Node implements IGraphic<T>, IAnimateTarget {
60
+ declare abstract class GraphicImpl<T extends Partial<IGraphicAttribute> = Partial<IGraphicAttribute>> extends Node implements IGraphic<T>, IAnimateTarget {
61
61
  static mixin(source: Dict<any>): void;
62
62
  _events?: any;
63
63
  context?: Record<string, any>;
@@ -142,12 +142,14 @@ export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Par
142
142
  getAttributes(): T;
143
143
  protected getStateTransitionOrchestrator(): StateTransitionOrchestrator<T>;
144
144
  protected resolveBoundSharedStateScope(): SharedStateScope<T> | SharedStateScope<Record<string, any>> | undefined;
145
- protected syncSharedStateScopeBindingFromTree(markDirty?: boolean): boolean;
146
- protected syncSharedStateScopeBindingOnTreeChange(markDirty?: boolean): boolean;
145
+ protected syncSharedStateScopeBinding(nextScope: SharedStateScope<T> | SharedStateScope<Record<string, any>> | undefined, markDirty?: boolean): boolean;
146
+ protected syncSharedStateScopeBindingFromTree(markDirty?: boolean, inheritedSharedStateScope?: SharedStateScope<Record<string, any>> | null): boolean;
147
+ protected syncSharedStateScopeBindingOnTreeChange(markDirty?: boolean, inheritedSharedStateScope?: SharedStateScope<Record<string, any>> | null): boolean;
147
148
  protected syncSharedStateActiveRegistrations(): void;
149
+ protected isSharedStateScopeChainRegistered(previousScopes: Set<SharedStateScope<T>>): boolean;
148
150
  protected clearSharedStateActiveRegistrations(): void;
149
151
  protected markSharedStateDirty(): void;
150
- onParentSharedStateTreeChanged(stage?: IStage, layer?: ILayer): void;
152
+ onParentSharedStateTreeChanged(stage?: IStage, layer?: ILayer, inheritedSharedStateScope?: SharedStateScope<Record<string, any>> | null): void;
151
153
  refreshSharedStateBeforeRender(): void;
152
154
  protected getLocalStatesVersion(): number;
153
155
  protected resolveEffectiveCompiledDefinitions(): {
@@ -237,6 +239,7 @@ export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Par
237
239
  }): void;
238
240
  hasState(stateName?: string): boolean;
239
241
  getState(stateName: string): Partial<T> | StateDefinition<T> | undefined;
242
+ setStateDefinitionsWithCompiled(definitions: StateDefinitionsInput<T>, compiledDefinitions: Map<string, CompiledStateDefinition<T>>): void;
240
243
  protected getStateResolveBaseAttrs(): Partial<T>;
241
244
  protected syncStateResolveContext(stateResolveBaseAttrs?: Partial<T>): Partial<T>;
242
245
  protected ensureStateEngine(stateResolveBaseAttrs?: Partial<T>): StateEngine<T>;
@@ -292,7 +295,7 @@ export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Par
292
295
  }, resetScale?: boolean): [number, number];
293
296
  protected doUpdateLocalMatrix(): void;
294
297
  protected doUpdateGlobalMatrix(): void;
295
- setStage(stage?: IStage, layer?: ILayer): void;
298
+ setStage(stage?: IStage, layer?: ILayer, inheritedSharedStateScope?: SharedStateScope<Record<string, any>> | null): void;
296
299
  detachStageForRelease(): void;
297
300
  setStageToShadowRoot(stage?: IStage, layer?: ILayer): void;
298
301
  onAddStep(step: IStep): void;
@@ -320,4 +323,11 @@ export declare abstract class Graphic<T extends Partial<IGraphicAttribute> = Par
320
323
  abstract clone(): IGraphic<any>;
321
324
  toCustomPath(): ICustomPath2D;
322
325
  }
326
+ export type Graphic<T extends Partial<IGraphicAttribute> = Partial<IGraphicAttribute>> = GraphicImpl<T>;
327
+ export declare const GRAPHIC_CLASS_SYMBOL: unique symbol;
328
+ export interface IGraphicClassState {
329
+ Graphic: typeof GraphicImpl;
330
+ }
331
+ export declare function getGraphicClassState(): IGraphicClassState;
332
+ export declare const Graphic: typeof GraphicImpl;
323
333
  export {};
@@ -116,12 +116,12 @@ export const NOWORK_ANIMATE_ATTR = {
116
116
  html: 1
117
117
  };
118
118
 
119
- export class Graphic extends Node {
119
+ class GraphicImpl extends Node {
120
120
  static mixin(source) {
121
121
  const keys = Object.keys(source);
122
122
  for (let i = 0; i < keys.length; ++i) {
123
123
  const propertyName = keys[i];
124
- Object.defineProperty(Graphic.prototype, propertyName, Object.getOwnPropertyDescriptor(source, propertyName));
124
+ Object.defineProperty(this.prototype, propertyName, Object.getOwnPropertyDescriptor(source, propertyName));
125
125
  }
126
126
  }
127
127
  get AABBBounds() {
@@ -181,9 +181,8 @@ export class Graphic extends Node {
181
181
  }
182
182
  return null === (_a = this.stage) || void 0 === _a ? void 0 : _a.rootSharedStateScope;
183
183
  }
184
- syncSharedStateScopeBindingFromTree(markDirty = !0) {
184
+ syncSharedStateScopeBinding(nextScope, markDirty = !0) {
185
185
  var _a;
186
- const nextScope = this.resolveBoundSharedStateScope();
187
186
  return this.boundSharedStateScope === nextScope ? (this.syncSharedStateActiveRegistrations(),
188
187
  !1) : (this.boundSharedStateScope = nextScope, this.boundSharedStateRevision = void 0,
189
188
  this.compiledStateDefinitions = void 0, this.compiledStateDefinitionsCacheKey = void 0,
@@ -191,9 +190,13 @@ export class Graphic extends Node {
191
190
  markDirty && (null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) && this.markSharedStateDirty(),
192
191
  !0);
193
192
  }
194
- syncSharedStateScopeBindingOnTreeChange(markDirty = !0) {
193
+ syncSharedStateScopeBindingFromTree(markDirty = !0, inheritedSharedStateScope) {
194
+ const nextScope = void 0 === inheritedSharedStateScope ? this.resolveBoundSharedStateScope() : null != inheritedSharedStateScope ? inheritedSharedStateScope : void 0;
195
+ return this.syncSharedStateScopeBinding(nextScope, markDirty);
196
+ }
197
+ syncSharedStateScopeBindingOnTreeChange(markDirty = !0, inheritedSharedStateScope) {
195
198
  var _a, _b;
196
- 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);
199
+ 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, inheritedSharedStateScope);
197
200
  }
198
201
  syncSharedStateActiveRegistrations() {
199
202
  var _a;
@@ -201,6 +204,7 @@ export class Graphic extends Node {
201
204
  if (!(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || !this.boundSharedStateScope) return (null == previousScopes ? void 0 : previousScopes.size) && (previousScopes.forEach((scope => {
202
205
  scope.subtreeActiveDescendants.delete(this);
203
206
  })), previousScopes.clear()), void (this.registeredActiveScopes = void 0);
207
+ if ((null == previousScopes ? void 0 : previousScopes.size) && this.isSharedStateScopeChainRegistered(previousScopes)) return;
204
208
  const nextScopes = new Set(collectSharedStateScopeChain(this.boundSharedStateScope));
205
209
  null == previousScopes || previousScopes.forEach((scope => {
206
210
  nextScopes.has(scope) || scope.subtreeActiveDescendants.delete(this);
@@ -208,6 +212,14 @@ export class Graphic extends Node {
208
212
  scope.subtreeActiveDescendants.add(this);
209
213
  })), this.registeredActiveScopes = nextScopes;
210
214
  }
215
+ isSharedStateScopeChainRegistered(previousScopes) {
216
+ let scope = this.boundSharedStateScope, scopeCount = 0;
217
+ for (;scope; ) {
218
+ if (!previousScopes.has(scope)) return !1;
219
+ scopeCount += 1, scope = scope.parentScope;
220
+ }
221
+ return scopeCount === previousScopes.size;
222
+ }
211
223
  clearSharedStateActiveRegistrations() {
212
224
  const previousScopes = this.registeredActiveScopes;
213
225
  previousScopes && (previousScopes.forEach((scope => {
@@ -218,8 +230,8 @@ export class Graphic extends Node {
218
230
  this.sharedStateDirty = !0, enqueueGraphicSharedStateRefresh(this.stage, this),
219
231
  scheduleStageSharedStateRefresh(this.stage);
220
232
  }
221
- onParentSharedStateTreeChanged(stage, layer) {
222
- this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingOnTreeChange() : this.setStage(stage, layer);
233
+ onParentSharedStateTreeChanged(stage, layer, inheritedSharedStateScope) {
234
+ this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingOnTreeChange(!0, inheritedSharedStateScope) : this.setStage(stage, layer, inheritedSharedStateScope);
223
235
  }
224
236
  refreshSharedStateBeforeRender() {
225
237
  var _a;
@@ -862,6 +874,12 @@ export class Graphic extends Node {
862
874
  var _a;
863
875
  return null === (_a = this.states) || void 0 === _a ? void 0 : _a[stateName];
864
876
  }
877
+ setStateDefinitionsWithCompiled(definitions, compiledDefinitions) {
878
+ var _a;
879
+ this.states = definitions, this.localStateDefinitionsSource !== definitions && (this.localStateDefinitionsSource = definitions,
880
+ this.localStateDefinitionsVersion = (null !== (_a = this.localStateDefinitionsVersion) && void 0 !== _a ? _a : 0) + 1),
881
+ this.compiledStateDefinitions = compiledDefinitions, this.compiledStateDefinitionsCacheKey = `local:${this.localStateDefinitionsVersion}`;
882
+ }
865
883
  getStateResolveBaseAttrs() {
866
884
  var _a;
867
885
  return null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : this.attribute;
@@ -1050,8 +1068,10 @@ export class Graphic extends Node {
1050
1068
  transition.changed && this.useStates(transition.states, hasAnimation);
1051
1069
  }
1052
1070
  addState(stateName, keepCurrentStates, hasAnimation) {
1053
- const transition = this.resolveAddStateTransition(stateName, keepCurrentStates);
1054
- transition.changed && this.useStates(transition.states, hasAnimation);
1071
+ const currentStates = this.currentStates;
1072
+ if ((null == currentStates ? void 0 : currentStates.includes(stateName)) && (keepCurrentStates || 1 === currentStates.length)) return;
1073
+ const nextStates = keepCurrentStates && (null == currentStates ? void 0 : currentStates.length) ? currentStates.concat([ stateName ]) : [ stateName ];
1074
+ this.useStates(nextStates, hasAnimation);
1055
1075
  }
1056
1076
  setStates(states, options) {
1057
1077
  var _a, _b, _c;
@@ -1186,11 +1206,11 @@ export class Graphic extends Node {
1186
1206
  this._globalTransMatrix.translate(scrollX, scrollY);
1187
1207
  }
1188
1208
  }
1189
- setStage(stage, layer) {
1209
+ setStage(stage, layer, inheritedSharedStateScope) {
1190
1210
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1191
1211
  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;
1192
1212
  if (this.stage !== stage || this.layer !== layer) {
1193
- 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),
1213
+ 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, inheritedSharedStateScope),
1194
1214
  this.setStageToShadowRoot(stage, layer), this.mayHaveTrackedAnimates() && this.hasAnyTrackedAnimate()) {
1195
1215
  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 = [];
1196
1216
  this.visitTrackedAnimates((a => {
@@ -1208,7 +1228,7 @@ export class Graphic extends Node {
1208
1228
  }
1209
1229
  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));
1210
1230
  }
1211
- ((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);
1231
+ ((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, inheritedSharedStateScope);
1212
1232
  }
1213
1233
  detachStageForRelease() {
1214
1234
  var _a, _b, _c;
@@ -1353,6 +1373,25 @@ export class Graphic extends Node {
1353
1373
  }
1354
1374
  }
1355
1375
 
1376
+ GraphicImpl.userSymbolMap = {};
1377
+
1378
+ export const GRAPHIC_CLASS_SYMBOL = Symbol.for("@visactor/vrender-core/graphic-class");
1379
+
1380
+ function createGraphicClassState() {
1381
+ return {
1382
+ Graphic: GraphicImpl
1383
+ };
1384
+ }
1385
+
1386
+ export function getGraphicClassState() {
1387
+ var _a;
1388
+ const globalScope = globalThis;
1389
+ return null !== (_a = globalScope[GRAPHIC_CLASS_SYMBOL]) && void 0 !== _a || (globalScope[GRAPHIC_CLASS_SYMBOL] = createGraphicClassState()),
1390
+ globalScope[GRAPHIC_CLASS_SYMBOL];
1391
+ }
1392
+
1393
+ export const Graphic = getGraphicClassState().Graphic;
1394
+
1356
1395
  function backgroundNotImage(image) {
1357
1396
  return "string" == typeof image ? !(image.startsWith("<svg") || isValidUrl(image) || image.includes("/") || isBase64(image)) : !(!image.fill && !image.stroke) || !("string" != typeof image.gradient || !Array.isArray(image.stops));
1358
1397
  }
@@ -1361,5 +1400,5 @@ function isExternalTexture(texture) {
1361
1400
  return !!texture && ("string" == typeof texture ? !builtinTextureTypes.has(texture) && (texture.startsWith("<svg") || isValidUrl(texture) || texture.includes("/") || isBase64(texture)) : isObject(texture));
1362
1401
  }
1363
1402
 
1364
- Graphic.userSymbolMap = {}, Graphic.mixin(EventTarget);
1403
+ Graphic.mixin(EventTarget);
1365
1404
  //# sourceMappingURL=graphic.js.map