@antv/g 1.0.0-alpha.32 → 1.0.0-alpha.36

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.
@@ -60,12 +60,15 @@ var containerModule = (0, _manaSyringe.Module)(function (register) {
60
60
  register({
61
61
  token: _aabb.GeometryUpdaterFactory,
62
62
  useFactory: function useFactory(context) {
63
+ var cache = {};
63
64
  return function (tagName) {
64
- if (context.container.isBoundNamed(_aabb.GeometryAABBUpdater, tagName)) {
65
- return context.container.getNamed(_aabb.GeometryAABBUpdater, tagName);
65
+ if (!cache[tagName]) {
66
+ if (context.container.isBoundNamed(_aabb.GeometryAABBUpdater, tagName)) {
67
+ cache[tagName] = context.container.getNamed(_aabb.GeometryAABBUpdater, tagName);
68
+ }
66
69
  }
67
70
 
68
- return null;
71
+ return cache[tagName];
69
72
  };
70
73
  }
71
74
  }); // bind style property handlers
@@ -73,36 +76,45 @@ var containerModule = (0, _manaSyringe.Module)(function (register) {
73
76
  register({
74
77
  token: _propertyHandlers.StylePropertyParserFactory,
75
78
  useFactory: function useFactory(context) {
79
+ var cache = {};
76
80
  return function (propertyName) {
77
- if (context.container.isBoundNamed(_propertyHandlers.StylePropertyParser, propertyName)) {
78
- return context.container.getNamed(_propertyHandlers.StylePropertyParser, propertyName);
81
+ if (!cache[propertyName]) {
82
+ if (context.container.isBoundNamed(_propertyHandlers.StylePropertyParser, propertyName)) {
83
+ cache[propertyName] = context.container.getNamed(_propertyHandlers.StylePropertyParser, propertyName);
84
+ }
79
85
  }
80
86
 
81
- return null;
87
+ return cache[propertyName];
82
88
  };
83
89
  }
84
90
  });
85
91
  register({
86
92
  token: _propertyHandlers.StylePropertyUpdaterFactory,
87
93
  useFactory: function useFactory(context) {
94
+ var cache = {};
88
95
  return function (propertyName) {
89
- if (context.container.isBoundNamed(_propertyHandlers.StylePropertyUpdater, propertyName)) {
90
- return context.container.getAllNamed(_propertyHandlers.StylePropertyUpdater, propertyName);
96
+ if (!cache[propertyName]) {
97
+ if (context.container.isBoundNamed(_propertyHandlers.StylePropertyUpdater, propertyName)) {
98
+ cache[propertyName] = context.container.getAllNamed(_propertyHandlers.StylePropertyUpdater, propertyName);
99
+ }
91
100
  }
92
101
 
93
- return null;
102
+ return cache[propertyName];
94
103
  };
95
104
  }
96
105
  });
97
106
  register({
98
107
  token: _propertyHandlers.StylePropertyMergerFactory,
99
108
  useFactory: function useFactory(context) {
109
+ var cache = {};
100
110
  return function (propertyName) {
101
- if (context.container.isBoundNamed(_propertyHandlers.StylePropertyMerger, propertyName)) {
102
- return context.container.getNamed(_propertyHandlers.StylePropertyMerger, propertyName);
111
+ if (!cache[propertyName]) {
112
+ if (context.container.isBoundNamed(_propertyHandlers.StylePropertyMerger, propertyName)) {
113
+ cache[propertyName] = context.container.getNamed(_propertyHandlers.StylePropertyMerger, propertyName);
114
+ }
103
115
  }
104
116
 
105
- return null;
117
+ return cache[propertyName];
106
118
  };
107
119
  }
108
120
  });
@@ -7,6 +7,7 @@ export interface LinearGradient {
7
7
  x1: number;
8
8
  y1: number;
9
9
  steps: string[][];
10
+ hash: string;
10
11
  }
11
12
  export interface RadialGradient {
12
13
  x0: number;
@@ -16,10 +17,12 @@ export interface RadialGradient {
16
17
  y1: number;
17
18
  r1: number;
18
19
  steps: string[][];
20
+ hash: string;
19
21
  }
20
22
  export interface Pattern {
21
23
  repetition: string;
22
24
  src: string;
25
+ hash: string;
23
26
  }
24
27
  export declare enum PARSED_COLOR_TYPE {
25
28
  Constant = 0,
@@ -155,7 +155,8 @@ function parsePattern(patternStr) {
155
155
 
156
156
  return {
157
157
  src: src,
158
- repetition: repetition
158
+ repetition: repetition,
159
+ hash: patternStr
159
160
  };
160
161
  }
161
162
 
@@ -231,7 +232,8 @@ function parseLineGradient(gradientStr) {
231
232
  y0: start.y,
232
233
  x1: x,
233
234
  y1: y,
234
- steps: steps
235
+ steps: steps,
236
+ hash: gradientStr
235
237
  };
236
238
  }
237
239
 
@@ -263,7 +265,8 @@ function parseRadialGradient(gradientStr) {
263
265
  x1: 0.5,
264
266
  y1: 0.5,
265
267
  r1: fr,
266
- steps: steps
268
+ steps: steps,
269
+ hash: gradientStr
267
270
  };
268
271
  }
269
272
 
@@ -644,11 +644,10 @@ function (_super) {
644
644
  }
645
645
 
646
646
  for (var i = 0; i < PROPAGATION_LIMIT && target !== this.rootTarget; i++) {
647
- if (_Node.Node.isNode(target) && !target.parentNode) {
648
- throw new Error('Cannot find propagation path to disconnected target');
649
- }
650
-
651
- if (_Node.Node.isNode(target)) {
647
+ // if (Node.isNode(target) && !target.parentNode) {
648
+ // throw new Error('Cannot find propagation path to disconnected target');
649
+ // }
650
+ if (_Node.Node.isNode(target) && target.parentNode) {
652
651
  // [target, parent, parent, root]
653
652
  propagationPath.push(target.parentNode);
654
653
  target = target.parentNode;
@@ -22,26 +22,27 @@ export interface PickingResult {
22
22
  export declare class RenderingService {
23
23
  private renderingPluginProvider;
24
24
  private renderingContext;
25
+ private sceneGraphService;
25
26
  private inited;
26
27
  hooks: {
27
- init: AsyncSeriesHook<[], import("tapable").UnsetAdditionalOptions>;
28
- prepare: SyncWaterfallHook<[DisplayObject<any, any>], import("tapable").UnsetAdditionalOptions>;
28
+ init: AsyncSeriesHook<any, any, any>;
29
+ prepare: SyncWaterfallHook<DisplayObject<any, any>, any, any>;
29
30
  /**
30
31
  * called at beginning of each frame, won't get called if nothing to re-render
31
32
  */
32
- beginFrame: SyncHook<[], void, import("tapable").UnsetAdditionalOptions>;
33
- beforeRender: SyncHook<[DisplayObject<any, any>], void, import("tapable").UnsetAdditionalOptions>;
34
- render: SyncHook<[DisplayObject<any, any>], void, import("tapable").UnsetAdditionalOptions>;
35
- afterRender: SyncHook<[DisplayObject<any, any>], void, import("tapable").UnsetAdditionalOptions>;
36
- endFrame: SyncHook<[], void, import("tapable").UnsetAdditionalOptions>;
37
- destroy: SyncHook<[], void, import("tapable").UnsetAdditionalOptions>;
38
- pick: AsyncSeriesWaterfallHook<[PickingResult], PickingResult>;
39
- pointerDown: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
40
- pointerUp: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
41
- pointerMove: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
42
- pointerOut: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
43
- pointerOver: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
44
- pointerWheel: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
33
+ beginFrame: SyncHook<any, any, any>;
34
+ beforeRender: SyncHook<DisplayObject<any, any>, any, any>;
35
+ render: SyncHook<DisplayObject<any, any>, any, any>;
36
+ afterRender: SyncHook<DisplayObject<any, any>, any, any>;
37
+ endFrame: SyncHook<any, any, any>;
38
+ destroy: SyncHook<any, any, any>;
39
+ pick: AsyncSeriesWaterfallHook<PickingResult, PickingResult, any>;
40
+ pointerDown: SyncHook<InteractivePointerEvent, any, any>;
41
+ pointerUp: SyncHook<InteractivePointerEvent, any, any>;
42
+ pointerMove: SyncHook<InteractivePointerEvent, any, any>;
43
+ pointerOut: SyncHook<InteractivePointerEvent, any, any>;
44
+ pointerOver: SyncHook<InteractivePointerEvent, any, any>;
45
+ pointerWheel: SyncHook<InteractivePointerEvent, any, any>;
45
46
  };
46
47
  init(): Promise<void>;
47
48
  render(): void;
@@ -43,11 +43,11 @@ function () {
43
43
  /**
44
44
  * called at beginning of each frame, won't get called if nothing to re-render
45
45
  */
46
- beginFrame: new _tapable.SyncHook([]),
46
+ beginFrame: new _tapable.SyncHook(),
47
47
  beforeRender: new _tapable.SyncHook(['objectToRender']),
48
48
  render: new _tapable.SyncHook(['objectToRender']),
49
49
  afterRender: new _tapable.SyncHook(['objectToRender']),
50
- endFrame: new _tapable.SyncHook([]),
50
+ endFrame: new _tapable.SyncHook(),
51
51
  destroy: new _tapable.SyncHook(),
52
52
  pick: new _tapable.AsyncSeriesWaterfallHook(['result']),
53
53
  pointerDown: new _tapable.SyncHook(['event']),
@@ -89,6 +89,8 @@ function () {
89
89
  };
90
90
 
91
91
  RenderingService.prototype.render = function () {
92
+ this.sceneGraphService.syncHierarchy(this.renderingContext.root);
93
+
92
94
  if (this.renderingContext.renderReasons.size && this.inited) {
93
95
  this.renderDisplayObject(this.renderingContext.root);
94
96
 
@@ -152,6 +154,7 @@ function () {
152
154
 
153
155
  (0, _tslib.__decorate)([(0, _manaSyringe.contrib)(RenderingPluginContribution), (0, _tslib.__metadata)("design:type", Object)], RenderingService.prototype, "renderingPluginProvider", void 0);
154
156
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_RenderingContext.RenderingContext), (0, _tslib.__metadata)("design:type", Object)], RenderingService.prototype, "renderingContext", void 0);
157
+ (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_SceneGraphService.SceneGraphService), (0, _tslib.__metadata)("design:type", Object)], RenderingService.prototype, "sceneGraphService", void 0);
155
158
  RenderingService = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)()], RenderingService);
156
159
  return RenderingService;
157
160
  }();
@@ -37,6 +37,7 @@ export interface SceneGraphService {
37
37
  getLocalBounds(element: INode, render?: boolean): AABB | null;
38
38
  getGeometryBounds(element: INode, render?: boolean): AABB | null;
39
39
  getBoundingClientRect(element: INode): Rectangle;
40
+ syncHierarchy(element: INode): void;
40
41
  }
41
42
  /**
42
43
  * update transform in scene graph
@@ -142,5 +143,8 @@ export declare class DefaultSceneGraphService implements SceneGraphService {
142
143
  getLocalBounds(element: INode): AABB | null;
143
144
  getBoundingClientRect(element: INode): Rectangle;
144
145
  private dirtifyWorldInternal;
145
- private updateTransform;
146
+ syncHierarchy(element: INode): void;
147
+ private sync;
148
+ private updateGraphDepth;
149
+ private unfreezeParentToRoot;
146
150
  }
@@ -407,11 +407,16 @@ function () {
407
407
  sortable.dirty = true;
408
408
  }
409
409
 
410
+ this.updateGraphDepth(child);
410
411
  var transform = entity.getComponent(_components.Transform);
411
412
 
412
413
  if (transform) {
413
414
  this.dirtifyWorld(child, transform);
414
415
  }
416
+
417
+ if (transform.frozen) {
418
+ this.unfreezeParentToRoot(child);
419
+ }
415
420
  };
416
421
 
417
422
  DefaultSceneGraphService.prototype.detach = function (child) {
@@ -568,17 +573,14 @@ function () {
568
573
  if (!transform.dirtyFlag) {
569
574
  this.dirtifyWorld(element, transform);
570
575
  }
571
- } // model matrix changed
572
-
573
-
574
- element.emit(_interfaces.ElementEvent.ATTRIBUTE_CHANGED, {
575
- attributeName: 'modelMatrix',
576
- oldValue: null,
577
- newValue: null
578
- });
576
+ }
579
577
  };
580
578
 
581
579
  DefaultSceneGraphService.prototype.dirtifyWorld = function (element, transform) {
580
+ if (!transform.dirtyFlag) {
581
+ this.unfreezeParentToRoot(element);
582
+ }
583
+
582
584
  this.dirtifyWorldInternal(element, transform);
583
585
  };
584
586
 
@@ -602,10 +604,6 @@ function () {
602
604
  transform = element.entity.getComponent(_components.Transform);
603
605
  }
604
606
 
605
- if (!transform) {
606
- return _glMatrix.mat4.create();
607
- }
608
-
609
607
  if (!transform.localDirtyFlag && !transform.dirtyFlag) {
610
608
  return transform.worldTransform;
611
609
  }
@@ -614,7 +612,7 @@ function () {
614
612
  this.getWorldTransform(element.parentNode);
615
613
  }
616
614
 
617
- this.updateTransform(element, transform);
615
+ this.sync(element, transform);
618
616
  return transform.worldTransform;
619
617
  };
620
618
 
@@ -811,13 +809,20 @@ function () {
811
809
 
812
810
  if (!transform.dirtyFlag) {
813
811
  transform.dirtyFlag = true;
812
+ transform.frozen = false;
814
813
  element.childNodes.forEach(function (child) {
815
814
  var childTransform = child.entity.getComponent(_components.Transform);
816
815
 
817
816
  if (!childTransform.dirtyFlag) {
818
817
  _this.dirtifyWorldInternal(child, childTransform);
819
818
  }
820
- }); // emit on leaf node
819
+ }); // model matrix changed
820
+
821
+ element.emit(_interfaces.ElementEvent.ATTRIBUTE_CHANGED, {
822
+ attributeName: 'modelMatrix',
823
+ oldValue: null,
824
+ newValue: null
825
+ }); // FIXME: emit on leaf node
821
826
 
822
827
  if (element.childNodes.length === 0) {
823
828
  dirtifyRenderable(element);
@@ -825,9 +830,31 @@ function () {
825
830
  }
826
831
  };
827
832
 
828
- DefaultSceneGraphService.prototype.updateTransform = function (element, transform) {
833
+ DefaultSceneGraphService.prototype.syncHierarchy = function (element) {
834
+ var transform = element.entity.getComponent(_components.Transform);
835
+
836
+ if (transform.frozen) {
837
+ return;
838
+ }
839
+
840
+ transform.frozen = true;
841
+
842
+ if (transform.localDirtyFlag || transform.dirtyFlag) {
843
+ this.sync(element, transform);
844
+ }
845
+
846
+ var children = element.childNodes;
847
+
848
+ for (var i = 0; i < children.length; i++) {
849
+ this.syncHierarchy(children[i]);
850
+ }
851
+ };
852
+
853
+ DefaultSceneGraphService.prototype.sync = function (element, transform) {
829
854
  if (transform.localDirtyFlag) {
830
- this.getLocalTransform(element);
855
+ _glMatrix.mat4.fromRotationTranslationScaleOrigin(transform.localTransform, transform.localRotation, transform.localPosition, transform.localScale, transform.origin);
856
+
857
+ transform.localDirtyFlag = false;
831
858
  }
832
859
 
833
860
  if (transform.dirtyFlag) {
@@ -846,6 +873,36 @@ function () {
846
873
  }
847
874
  };
848
875
 
876
+ DefaultSceneGraphService.prototype.updateGraphDepth = function (element) {
877
+ var transform = element.entity.getComponent(_components.Transform);
878
+
879
+ if (element.parentNode) {
880
+ transform.graphDepth = element.parentNode.entity.getComponent(_components.Transform).graphDepth + 1;
881
+ } else {
882
+ transform.graphDepth = 0;
883
+ }
884
+
885
+ var children = element.childNodes;
886
+
887
+ for (var i = 0; i < children.length; i++) {
888
+ this.updateGraphDepth(children[i]);
889
+ }
890
+ };
891
+
892
+ DefaultSceneGraphService.prototype.unfreezeParentToRoot = function (child) {
893
+ var p = child.parentNode;
894
+
895
+ while (p) {
896
+ var transform = p.entity.getComponent(_components.Transform);
897
+
898
+ if (transform) {
899
+ transform.frozen = false;
900
+ }
901
+
902
+ p = p.parentNode;
903
+ }
904
+ };
905
+
849
906
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_SceneGraphSelector.SceneGraphSelectorFactory), (0, _tslib.__metadata)("design:type", Function)], DefaultSceneGraphService.prototype, "sceneGraphSelectorFactory", void 0);
850
907
  DefaultSceneGraphService = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)()], DefaultSceneGraphService);
851
908
  return DefaultSceneGraphService;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@antv/g",
3
- "version": "1.0.0-alpha.32",
3
+ "version": "1.0.0-alpha.36",
4
4
  "description": "A core module including ECS and DI container.",
5
5
  "main": "lib/index.js",
6
- "module": "es/index.esm.js",
6
+ "module": "es/index.js",
7
7
  "types": "es/index.d.ts",
8
8
  "unpkg": "dist/index.umd.js",
9
9
  "files": [
@@ -38,19 +38,18 @@
38
38
  },
39
39
  "homepage": "https://github.com/antvis/g#readme",
40
40
  "dependencies": {
41
- "@antv/g-ecs": "^1.0.0-alpha.14",
42
- "@antv/g-math": "^1.0.0-alpha.9",
41
+ "@antv/g-ecs": "^1.0.0-alpha.15",
42
+ "@antv/g-math": "^1.0.0-alpha.11",
43
43
  "@antv/path-util": "^2.0.14",
44
44
  "@antv/util": "^2.0.13",
45
- "@babel/runtime": "^7.16.0",
46
45
  "d3-color": "^1.4.0",
47
46
  "eventemitter3": "^4.0.0",
48
47
  "gl-matrix": "^3.1.0",
49
48
  "mana-syringe": "^0.2.2",
50
- "tapable": "2.2.1"
49
+ "tapable": "1.1.3"
51
50
  },
52
51
  "scripts": {
53
52
  "umd": "webpack"
54
53
  },
55
- "gitHead": "4da9ca442ec295aeec5b2fa19ffe4304160efbb5"
54
+ "gitHead": "c0f918d5477e3099b9bfa3ecb077cc411c0b2e3a"
56
55
  }