@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 {};
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
- }), exports.Graphic = exports.NOWORK_ANIMATE_ATTR = exports.GRAPHIC_UPDATE_TAG_KEY = exports.PURE_STYLE_KEY = void 0;
5
+ }), exports.Graphic = exports.getGraphicClassState = exports.GRAPHIC_CLASS_SYMBOL = exports.NOWORK_ANIMATE_ATTR = exports.GRAPHIC_UPDATE_TAG_KEY = exports.PURE_STYLE_KEY = void 0;
6
6
 
7
7
  const vutils_1 = require("@visactor/vutils"), node_tree_1 = require("./node-tree"), event_1 = require("../event"), config_1 = require("./config"), application_1 = require("../application"), custom_path2d_1 = require("../common/custom-path2d"), loader_1 = require("../resource-loader/loader"), enums_1 = require("../common/enums"), bounds_context_1 = require("../common/bounds-context"), render_command_list_1 = require("../common/render-command-list"), utils_1 = require("../common/utils"), builtin_symbol_1 = require("./builtin-symbol"), xml_1 = require("../common/xml"), constants_1 = require("./constants"), config_2 = require("../animate/config"), canvas_1 = require("../canvas"), state_definition_compiler_1 = require("./state/state-definition-compiler"), state_engine_1 = require("./state/state-engine"), attribute_update_classifier_1 = require("./state/attribute-update-classifier"), state_transition_orchestrator_1 = require("./state/state-transition-orchestrator"), shared_state_scope_1 = require("./state/shared-state-scope"), shared_state_refresh_1 = require("./state/shared-state-refresh"), _tempBounds = new vutils_1.AABBBounds, loadShadowRootFactory = () => require("./shadow-root"), tempMatrix = new vutils_1.Matrix;
8
8
 
@@ -78,12 +78,12 @@ exports.NOWORK_ANIMATE_ATTR = {
78
78
  html: 1
79
79
  };
80
80
 
81
- class Graphic extends node_tree_1.Node {
81
+ class GraphicImpl extends node_tree_1.Node {
82
82
  static mixin(source) {
83
83
  const keys = Object.keys(source);
84
84
  for (let i = 0; i < keys.length; ++i) {
85
85
  const propertyName = keys[i];
86
- Object.defineProperty(Graphic.prototype, propertyName, Object.getOwnPropertyDescriptor(source, propertyName));
86
+ Object.defineProperty(this.prototype, propertyName, Object.getOwnPropertyDescriptor(source, propertyName));
87
87
  }
88
88
  }
89
89
  get AABBBounds() {
@@ -144,9 +144,8 @@ class Graphic extends node_tree_1.Node {
144
144
  }
145
145
  return null === (_a = this.stage) || void 0 === _a ? void 0 : _a.rootSharedStateScope;
146
146
  }
147
- syncSharedStateScopeBindingFromTree(markDirty = !0) {
147
+ syncSharedStateScopeBinding(nextScope, markDirty = !0) {
148
148
  var _a;
149
- const nextScope = this.resolveBoundSharedStateScope();
150
149
  return this.boundSharedStateScope === nextScope ? (this.syncSharedStateActiveRegistrations(),
151
150
  !1) : (this.boundSharedStateScope = nextScope, this.boundSharedStateRevision = void 0,
152
151
  this.compiledStateDefinitions = void 0, this.compiledStateDefinitionsCacheKey = void 0,
@@ -154,9 +153,13 @@ class Graphic extends node_tree_1.Node {
154
153
  markDirty && (null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) && this.markSharedStateDirty(),
155
154
  !0);
156
155
  }
157
- syncSharedStateScopeBindingOnTreeChange(markDirty = !0) {
156
+ syncSharedStateScopeBindingFromTree(markDirty = !0, inheritedSharedStateScope) {
157
+ const nextScope = void 0 === inheritedSharedStateScope ? this.resolveBoundSharedStateScope() : null != inheritedSharedStateScope ? inheritedSharedStateScope : void 0;
158
+ return this.syncSharedStateScopeBinding(nextScope, markDirty);
159
+ }
160
+ syncSharedStateScopeBindingOnTreeChange(markDirty = !0, inheritedSharedStateScope) {
158
161
  var _a, _b;
159
- 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);
162
+ 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);
160
163
  }
161
164
  syncSharedStateActiveRegistrations() {
162
165
  var _a;
@@ -164,6 +167,7 @@ class Graphic extends node_tree_1.Node {
164
167
  if (!(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || !this.boundSharedStateScope) return (null == previousScopes ? void 0 : previousScopes.size) && (previousScopes.forEach((scope => {
165
168
  scope.subtreeActiveDescendants.delete(this);
166
169
  })), previousScopes.clear()), void (this.registeredActiveScopes = void 0);
170
+ if ((null == previousScopes ? void 0 : previousScopes.size) && this.isSharedStateScopeChainRegistered(previousScopes)) return;
167
171
  const nextScopes = new Set((0, shared_state_scope_1.collectSharedStateScopeChain)(this.boundSharedStateScope));
168
172
  null == previousScopes || previousScopes.forEach((scope => {
169
173
  nextScopes.has(scope) || scope.subtreeActiveDescendants.delete(this);
@@ -171,6 +175,14 @@ class Graphic extends node_tree_1.Node {
171
175
  scope.subtreeActiveDescendants.add(this);
172
176
  })), this.registeredActiveScopes = nextScopes;
173
177
  }
178
+ isSharedStateScopeChainRegistered(previousScopes) {
179
+ let scope = this.boundSharedStateScope, scopeCount = 0;
180
+ for (;scope; ) {
181
+ if (!previousScopes.has(scope)) return !1;
182
+ scopeCount += 1, scope = scope.parentScope;
183
+ }
184
+ return scopeCount === previousScopes.size;
185
+ }
174
186
  clearSharedStateActiveRegistrations() {
175
187
  const previousScopes = this.registeredActiveScopes;
176
188
  previousScopes && (previousScopes.forEach((scope => {
@@ -181,8 +193,8 @@ class Graphic extends node_tree_1.Node {
181
193
  this.sharedStateDirty = !0, (0, shared_state_refresh_1.enqueueGraphicSharedStateRefresh)(this.stage, this),
182
194
  (0, shared_state_refresh_1.scheduleStageSharedStateRefresh)(this.stage);
183
195
  }
184
- onParentSharedStateTreeChanged(stage, layer) {
185
- this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingOnTreeChange() : this.setStage(stage, layer);
196
+ onParentSharedStateTreeChanged(stage, layer, inheritedSharedStateScope) {
197
+ this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingOnTreeChange(!0, inheritedSharedStateScope) : this.setStage(stage, layer, inheritedSharedStateScope);
186
198
  }
187
199
  refreshSharedStateBeforeRender() {
188
200
  var _a;
@@ -522,7 +534,7 @@ class Graphic extends node_tree_1.Node {
522
534
  if (!symbolType) return null;
523
535
  let path = builtin_symbol_1.builtinSymbolsMap[symbolType];
524
536
  if (path) return path;
525
- if (path = Graphic.userSymbolMap[symbolType], path) return path;
537
+ if (path = exports.Graphic.userSymbolMap[symbolType], path) return path;
526
538
  symbolType = builtin_symbol_1.builtInSymbolStrMap[symbolType] || symbolType;
527
539
  if (!0 === (0, xml_1.isSvg)(symbolType)) {
528
540
  const parser = new xml_1.XMLParser, {svg: svg} = parser.parse(symbolType);
@@ -543,13 +555,13 @@ class Graphic extends node_tree_1.Node {
543
555
  vutils_1.max)(width, height);
544
556
  cacheList.forEach((cache => cache.path.transform(0, 0, scale, scale)));
545
557
  const _parsedPath = new builtin_symbol_1.CustomSymbolClass(symbolType, cacheList, !0);
546
- return Graphic.userSymbolMap[symbolType] = _parsedPath, _parsedPath;
558
+ return exports.Graphic.userSymbolMap[symbolType] = _parsedPath, _parsedPath;
547
559
  }
548
560
  const cache = (new custom_path2d_1.CustomPath2D).fromString(symbolType), width = cache.bounds.width(), height = cache.bounds.height(), scale = 1 / (0,
549
561
  vutils_1.max)(width, height);
550
562
  cache.transform(0, 0, scale, scale);
551
563
  const _parsedPath = new builtin_symbol_1.CustomSymbolClass(symbolType, cache);
552
- return Graphic.userSymbolMap[symbolType] = _parsedPath, _parsedPath;
564
+ return exports.Graphic.userSymbolMap[symbolType] = _parsedPath, _parsedPath;
553
565
  }
554
566
  doUpdateAABBBounds(full, graphicTheme) {
555
567
  this.updateAABBBoundsStamp++;
@@ -832,6 +844,12 @@ class Graphic extends node_tree_1.Node {
832
844
  var _a;
833
845
  return null === (_a = this.states) || void 0 === _a ? void 0 : _a[stateName];
834
846
  }
847
+ setStateDefinitionsWithCompiled(definitions, compiledDefinitions) {
848
+ var _a;
849
+ this.states = definitions, this.localStateDefinitionsSource !== definitions && (this.localStateDefinitionsSource = definitions,
850
+ this.localStateDefinitionsVersion = (null !== (_a = this.localStateDefinitionsVersion) && void 0 !== _a ? _a : 0) + 1),
851
+ this.compiledStateDefinitions = compiledDefinitions, this.compiledStateDefinitionsCacheKey = `local:${this.localStateDefinitionsVersion}`;
852
+ }
835
853
  getStateResolveBaseAttrs() {
836
854
  var _a;
837
855
  return null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : this.attribute;
@@ -1020,8 +1038,10 @@ class Graphic extends node_tree_1.Node {
1020
1038
  transition.changed && this.useStates(transition.states, hasAnimation);
1021
1039
  }
1022
1040
  addState(stateName, keepCurrentStates, hasAnimation) {
1023
- const transition = this.resolveAddStateTransition(stateName, keepCurrentStates);
1024
- transition.changed && this.useStates(transition.states, hasAnimation);
1041
+ const currentStates = this.currentStates;
1042
+ if ((null == currentStates ? void 0 : currentStates.includes(stateName)) && (keepCurrentStates || 1 === currentStates.length)) return;
1043
+ const nextStates = keepCurrentStates && (null == currentStates ? void 0 : currentStates.length) ? currentStates.concat([ stateName ]) : [ stateName ];
1044
+ this.useStates(nextStates, hasAnimation);
1025
1045
  }
1026
1046
  setStates(states, options) {
1027
1047
  var _a, _b, _c;
@@ -1157,11 +1177,11 @@ class Graphic extends node_tree_1.Node {
1157
1177
  this._globalTransMatrix.translate(scrollX, scrollY);
1158
1178
  }
1159
1179
  }
1160
- setStage(stage, layer) {
1180
+ setStage(stage, layer, inheritedSharedStateScope) {
1161
1181
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1162
1182
  const graphicService = null !== (_c = null !== (_a = null == stage ? void 0 : stage.graphicService) && void 0 !== _a ? _a : null === (_b = this.stage) || void 0 === _b ? void 0 : _b.graphicService) && void 0 !== _c ? _c : application_1.application.graphicService, previousStage = this.stage;
1163
1183
  if (this.stage !== stage || this.layer !== layer) {
1164
- 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),
1184
+ 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),
1165
1185
  this.setStageToShadowRoot(stage, layer), this.mayHaveTrackedAnimates() && this.hasAnyTrackedAnimate()) {
1166
1186
  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 = [];
1167
1187
  this.visitTrackedAnimates((a => {
@@ -1179,7 +1199,7 @@ class Graphic extends node_tree_1.Node {
1179
1199
  }
1180
1200
  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));
1181
1201
  }
1182
- ((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);
1202
+ ((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);
1183
1203
  }
1184
1204
  detachStageForRelease() {
1185
1205
  var _a, _b, _c;
@@ -1325,6 +1345,19 @@ class Graphic extends node_tree_1.Node {
1325
1345
  }
1326
1346
  }
1327
1347
 
1348
+ function createGraphicClassState() {
1349
+ return {
1350
+ Graphic: GraphicImpl
1351
+ };
1352
+ }
1353
+
1354
+ function getGraphicClassState() {
1355
+ var _a;
1356
+ const globalScope = globalThis;
1357
+ return null !== (_a = globalScope[exports.GRAPHIC_CLASS_SYMBOL]) && void 0 !== _a || (globalScope[exports.GRAPHIC_CLASS_SYMBOL] = createGraphicClassState()),
1358
+ globalScope[exports.GRAPHIC_CLASS_SYMBOL];
1359
+ }
1360
+
1328
1361
  function backgroundNotImage(image) {
1329
1362
  return "string" == typeof image ? !(image.startsWith("<svg") || (0, vutils_1.isValidUrl)(image) || image.includes("/") || (0,
1330
1363
  vutils_1.isBase64)(image)) : !(!image.fill && !image.stroke) || !("string" != typeof image.gradient || !Array.isArray(image.stops));
@@ -1336,5 +1369,7 @@ function isExternalTexture(texture) {
1336
1369
  vutils_1.isObject)(texture));
1337
1370
  }
1338
1371
 
1339
- exports.Graphic = Graphic, Graphic.userSymbolMap = {}, Graphic.mixin(event_1.EventTarget);
1372
+ GraphicImpl.userSymbolMap = {}, exports.GRAPHIC_CLASS_SYMBOL = Symbol.for("@visactor/vrender-core/graphic-class"),
1373
+ exports.getGraphicClassState = getGraphicClassState, exports.Graphic = getGraphicClassState().Graphic,
1374
+ exports.Graphic.mixin(event_1.EventTarget);
1340
1375
  //# sourceMappingURL=graphic.js.map