@antv/g 5.0.15 → 5.0.18
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/dist/index.umd.min.js +18 -2
- package/es/Canvas.d.ts +7 -1
- package/es/Canvas.js +9 -10
- package/es/camera/Camera.d.ts +3 -2
- package/es/camera/Camera.js +16 -8
- package/es/canvas-module.js +4 -2
- package/es/components/Transform.d.ts +0 -1
- package/es/components/Transform.js +0 -1
- package/es/display-objects/Circle.d.ts +1 -1
- package/es/display-objects/Circle.js +8 -3
- package/es/display-objects/CustomElement.d.ts +3 -2
- package/es/display-objects/CustomElement.js +9 -6
- package/es/display-objects/DisplayObject.d.ts +9 -3
- package/es/display-objects/DisplayObject.js +97 -50
- package/es/display-objects/Ellipse.d.ts +1 -1
- package/es/display-objects/Ellipse.js +8 -3
- package/es/display-objects/Group.d.ts +18 -2
- package/es/display-objects/Group.js +11 -9
- package/es/display-objects/HTML.d.ts +1 -1
- package/es/display-objects/HTML.js +9 -4
- package/es/display-objects/Image.d.ts +5 -3
- package/es/display-objects/Image.js +8 -3
- package/es/display-objects/Line.d.ts +1 -1
- package/es/display-objects/Line.js +12 -4
- package/es/display-objects/Path.d.ts +3 -2
- package/es/display-objects/Path.js +10 -5
- package/es/display-objects/Polygon.d.ts +1 -1
- package/es/display-objects/Polygon.js +9 -3
- package/es/display-objects/Polyline.d.ts +1 -1
- package/es/display-objects/Polyline.js +10 -5
- package/es/display-objects/Rect.d.ts +1 -1
- package/es/display-objects/Rect.js +8 -3
- package/es/display-objects/Text.d.ts +32 -4
- package/es/display-objects/Text.js +70 -10
- package/es/dom/Animation.js +2 -2
- package/es/dom/AnimationTimeline.js +1 -2
- package/es/dom/CustomElementRegistry.js +12 -12
- package/es/dom/Document.d.ts +2 -1
- package/es/dom/Document.js +22 -2
- package/es/dom/Element.d.ts +38 -5
- package/es/dom/Element.js +115 -16
- package/es/dom/EventTarget.d.ts +2 -2
- package/es/dom/EventTarget.js +4 -3
- package/es/dom/FederatedEvent.d.ts +4 -1
- package/es/dom/KeyframeList.js +1 -1
- package/es/dom/MutationEvent.d.ts +15 -0
- package/es/dom/MutationEvent.js +29 -0
- package/es/dom/MutationObserver.d.ts +36 -0
- package/es/dom/MutationObserver.js +413 -0
- package/es/dom/MutationRecord.d.ts +14 -0
- package/es/dom/MutationRecord.js +31 -0
- package/es/dom/Node.d.ts +35 -3
- package/es/dom/Node.js +184 -17
- package/es/dom/index.d.ts +3 -0
- package/es/dom/index.js +3 -0
- package/es/dom/interfaces.d.ts +39 -8
- package/es/dom/interfaces.js +23 -5
- package/es/global-module.d.ts +1 -0
- package/es/global-module.js +11 -13
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/plugins/CullingPlugin.d.ts +0 -2
- package/es/plugins/CullingPlugin.js +3 -24
- package/es/plugins/DirtyCheckPlugin.js +2 -2
- package/es/plugins/EventPlugin.d.ts +1 -0
- package/es/plugins/EventPlugin.js +15 -5
- package/es/plugins/FrustumCullingStrategy.d.ts +1 -0
- package/es/plugins/FrustumCullingStrategy.js +41 -33
- package/es/plugins/PrepareRendererPlugin.js +21 -5
- package/es/property-handlers/aabb.js +19 -20
- package/es/property-handlers/color.js +5 -2
- package/es/property-handlers/dimension.d.ts +15 -3
- package/es/property-handlers/dimension.js +50 -9
- package/es/property-handlers/index.d.ts +3 -0
- package/es/property-handlers/index.js +4 -1
- package/es/property-handlers/inherit.d.ts +6 -0
- package/es/property-handlers/inherit.js +25 -0
- package/es/property-handlers/interfaces.d.ts +2 -2
- package/es/property-handlers/lineDash.d.ts +6 -1
- package/es/property-handlers/lineDash.js +23 -4
- package/es/property-handlers/offsetDistance.js +2 -2
- package/es/property-handlers/text.d.ts +2 -0
- package/es/property-handlers/text.js +3 -0
- package/es/property-handlers/textTransform.d.ts +6 -0
- package/es/property-handlers/textTransform.js +19 -0
- package/es/services/EventService.js +11 -7
- package/es/services/RenderingContext.d.ts +5 -8
- package/es/services/RenderingContext.js +6 -7
- package/es/services/RenderingService.d.ts +12 -2
- package/es/services/RenderingService.js +23 -12
- package/es/services/SceneGraphSelector.d.ts +3 -2
- package/es/services/SceneGraphSelector.js +8 -4
- package/es/services/SceneGraphService.d.ts +0 -7
- package/es/services/SceneGraphService.js +17 -87
- package/es/services/aabb/CircleUpdater.js +3 -3
- package/es/services/aabb/EllipseUpdater.js +2 -2
- package/es/services/aabb/LineUpdater.js +2 -2
- package/es/services/aabb/PathUpdater.js +2 -2
- package/es/services/aabb/PolylineUpdater.js +3 -3
- package/es/services/aabb/RectUpdater.js +4 -4
- package/es/services/aabb/TextUpdater.js +31 -10
- package/es/services/text/index.js +19 -21
- package/es/shapes/AABB.js +5 -0
- package/es/types.d.ts +48 -24
- package/es/types.js +50 -31
- package/es/utils/animation.js +1 -1
- package/es/utils/custom-easing.js +1 -1
- package/es/utils/event.js +7 -4
- package/es/utils/index.d.ts +2 -0
- package/es/utils/index.js +3 -1
- package/es/utils/interpolation.d.ts +1 -0
- package/es/utils/interpolation.js +41 -8
- package/es/utils/path.js +11 -11
- package/es/utils/raf.d.ts +1 -1
- package/es/utils/raf.js +0 -2
- package/es/utils/string.d.ts +1 -0
- package/es/utils/string.js +9 -0
- package/es/utils/text.js +3 -3
- package/lib/Canvas.d.ts +7 -1
- package/lib/Canvas.js +7 -8
- package/lib/camera/Camera.d.ts +3 -2
- package/lib/camera/Camera.js +20 -10
- package/lib/canvas-module.js +3 -1
- package/lib/components/Transform.d.ts +0 -1
- package/lib/components/Transform.js +0 -1
- package/lib/display-objects/Circle.d.ts +1 -1
- package/lib/display-objects/Circle.js +7 -2
- package/lib/display-objects/CustomElement.d.ts +3 -2
- package/lib/display-objects/CustomElement.js +9 -6
- package/lib/display-objects/DisplayObject.d.ts +9 -3
- package/lib/display-objects/DisplayObject.js +97 -47
- package/lib/display-objects/Ellipse.d.ts +1 -1
- package/lib/display-objects/Ellipse.js +7 -2
- package/lib/display-objects/Group.d.ts +18 -2
- package/lib/display-objects/Group.js +10 -9
- package/lib/display-objects/HTML.d.ts +1 -1
- package/lib/display-objects/HTML.js +8 -4
- package/lib/display-objects/Image.d.ts +5 -3
- package/lib/display-objects/Image.js +7 -2
- package/lib/display-objects/Line.d.ts +1 -1
- package/lib/display-objects/Line.js +11 -3
- package/lib/display-objects/Path.d.ts +3 -2
- package/lib/display-objects/Path.js +9 -4
- package/lib/display-objects/Polygon.d.ts +1 -1
- package/lib/display-objects/Polygon.js +8 -2
- package/lib/display-objects/Polyline.d.ts +1 -1
- package/lib/display-objects/Polyline.js +9 -4
- package/lib/display-objects/Rect.d.ts +1 -1
- package/lib/display-objects/Rect.js +7 -2
- package/lib/display-objects/Text.d.ts +32 -4
- package/lib/display-objects/Text.js +69 -9
- package/lib/dom/Animation.js +2 -2
- package/lib/dom/AnimationTimeline.js +1 -2
- package/lib/dom/CustomElementRegistry.js +11 -11
- package/lib/dom/Document.d.ts +2 -1
- package/lib/dom/Document.js +24 -3
- package/lib/dom/Element.d.ts +38 -5
- package/lib/dom/Element.js +117 -16
- package/lib/dom/EventTarget.d.ts +2 -2
- package/lib/dom/EventTarget.js +4 -3
- package/lib/dom/FederatedEvent.d.ts +4 -1
- package/lib/dom/KeyframeList.js +1 -1
- package/lib/dom/MutationEvent.d.ts +15 -0
- package/lib/dom/MutationEvent.js +37 -0
- package/lib/dom/MutationObserver.d.ts +36 -0
- package/lib/dom/MutationObserver.js +424 -0
- package/lib/dom/MutationRecord.d.ts +14 -0
- package/lib/dom/MutationRecord.js +38 -0
- package/lib/dom/Node.d.ts +35 -3
- package/lib/dom/Node.js +185 -16
- package/lib/dom/index.d.ts +3 -0
- package/lib/dom/index.js +39 -0
- package/lib/dom/interfaces.d.ts +39 -8
- package/lib/dom/interfaces.js +23 -5
- package/lib/global-module.d.ts +1 -0
- package/lib/global-module.js +12 -8
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/plugins/CullingPlugin.d.ts +0 -2
- package/lib/plugins/CullingPlugin.js +2 -23
- package/lib/plugins/DirtyCheckPlugin.js +1 -1
- package/lib/plugins/EventPlugin.d.ts +1 -0
- package/lib/plugins/EventPlugin.js +13 -5
- package/lib/plugins/FrustumCullingStrategy.d.ts +1 -0
- package/lib/plugins/FrustumCullingStrategy.js +42 -33
- package/lib/plugins/PrepareRendererPlugin.js +24 -4
- package/lib/property-handlers/aabb.js +18 -19
- package/lib/property-handlers/color.js +6 -3
- package/lib/property-handlers/dimension.d.ts +15 -3
- package/lib/property-handlers/dimension.js +50 -8
- package/lib/property-handlers/index.d.ts +3 -0
- package/lib/property-handlers/index.js +39 -0
- package/lib/property-handlers/inherit.d.ts +6 -0
- package/lib/property-handlers/inherit.js +34 -0
- package/lib/property-handlers/interfaces.d.ts +2 -2
- package/lib/property-handlers/lineDash.d.ts +6 -1
- package/lib/property-handlers/lineDash.js +25 -4
- package/lib/property-handlers/offsetDistance.js +1 -1
- package/lib/property-handlers/text.d.ts +2 -0
- package/lib/property-handlers/text.js +10 -0
- package/lib/property-handlers/textTransform.d.ts +6 -0
- package/lib/property-handlers/textTransform.js +27 -0
- package/lib/services/EventService.js +11 -7
- package/lib/services/RenderingContext.d.ts +5 -8
- package/lib/services/RenderingContext.js +8 -9
- package/lib/services/RenderingService.d.ts +12 -2
- package/lib/services/RenderingService.js +23 -11
- package/lib/services/SceneGraphSelector.d.ts +3 -2
- package/lib/services/SceneGraphSelector.js +10 -3
- package/lib/services/SceneGraphService.d.ts +0 -7
- package/lib/services/SceneGraphService.js +18 -91
- package/lib/services/aabb/CircleUpdater.js +2 -2
- package/lib/services/aabb/EllipseUpdater.js +1 -1
- package/lib/services/aabb/LineUpdater.js +1 -1
- package/lib/services/aabb/PathUpdater.js +1 -1
- package/lib/services/aabb/PolylineUpdater.js +2 -2
- package/lib/services/aabb/RectUpdater.js +3 -3
- package/lib/services/aabb/TextUpdater.js +30 -9
- package/lib/services/text/index.js +19 -21
- package/lib/shapes/AABB.js +5 -0
- package/lib/types.d.ts +48 -24
- package/lib/types.js +56 -35
- package/lib/utils/animation.js +1 -1
- package/lib/utils/custom-easing.js +1 -1
- package/lib/utils/event.js +7 -4
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +26 -0
- package/lib/utils/interpolation.d.ts +1 -0
- package/lib/utils/interpolation.js +43 -7
- package/lib/utils/path.js +10 -10
- package/lib/utils/raf.d.ts +1 -1
- package/lib/utils/raf.js +0 -2
- package/lib/utils/string.d.ts +1 -0
- package/lib/utils/string.js +16 -0
- package/lib/utils/text.js +3 -3
- package/package.json +5 -3
package/es/Canvas.d.ts
CHANGED
|
@@ -71,8 +71,14 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
71
71
|
getRenderingContext(): RenderingContext;
|
|
72
72
|
getStats(): {
|
|
73
73
|
total: number;
|
|
74
|
-
rendered: number;
|
|
74
|
+
rendered: number; /**
|
|
75
|
+
* window.document
|
|
76
|
+
*/
|
|
77
|
+
renderedOnscreen: number;
|
|
75
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getComputedStyle
|
|
81
|
+
*/
|
|
76
82
|
getComputedStyle(node: DisplayObject): any;
|
|
77
83
|
get ready(): Promise<any>;
|
|
78
84
|
destroy(destroyScenegraph?: boolean): void;
|
package/es/Canvas.js
CHANGED
|
@@ -4,9 +4,9 @@ import { cleanExistedCanvas, isBrowser } from './utils/canvas';
|
|
|
4
4
|
import { DisplayObject } from './display-objects/DisplayObject';
|
|
5
5
|
import { ContextService } from './services';
|
|
6
6
|
import { RenderingService } from './services/RenderingService';
|
|
7
|
-
import { RenderingContext,
|
|
7
|
+
import { RenderingContext, RenderReason } from './services/RenderingContext';
|
|
8
8
|
import { EventService } from './services/EventService';
|
|
9
|
-
import { Camera,
|
|
9
|
+
import { Camera, CameraEvent, CAMERA_PROJECTION_MODE, DefaultCamera } from './camera';
|
|
10
10
|
import { containerModule as commonContainerModule } from './canvas-module';
|
|
11
11
|
import { cancelAnimationFrame, requestAnimationFrame, patch } from './utils/raf';
|
|
12
12
|
import { Document, EventTarget, ElementEvent } from './dom';
|
|
@@ -109,11 +109,6 @@ function (_super) {
|
|
|
109
109
|
* the root node in scene graph
|
|
110
110
|
*/
|
|
111
111
|
root: this.document.documentElement,
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* removed render bounds
|
|
115
|
-
*/
|
|
116
|
-
removedRenderBoundsList: [],
|
|
117
112
|
renderReasons: new Set(),
|
|
118
113
|
force: false,
|
|
119
114
|
dirty: false
|
|
@@ -132,8 +127,8 @@ function (_super) {
|
|
|
132
127
|
var camera = new Camera().setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0).setOrthographic(width / -2, width / 2, height / 2, height / -2, 0.1, 1000); // redraw when camera changed
|
|
133
128
|
|
|
134
129
|
var context = this.container.get(RenderingContext);
|
|
135
|
-
camera.on(
|
|
136
|
-
context.renderReasons.add(
|
|
130
|
+
camera.on(CameraEvent.UPDATED, function () {
|
|
131
|
+
context.renderReasons.add(RenderReason.CAMERA_CHANGED);
|
|
137
132
|
}); // bind camera
|
|
138
133
|
|
|
139
134
|
this.container.register({
|
|
@@ -186,6 +181,10 @@ function (_super) {
|
|
|
186
181
|
Canvas.prototype.getStats = function () {
|
|
187
182
|
return this.getRenderingService().getStats();
|
|
188
183
|
};
|
|
184
|
+
/**
|
|
185
|
+
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getComputedStyle
|
|
186
|
+
*/
|
|
187
|
+
|
|
189
188
|
|
|
190
189
|
Canvas.prototype.getComputedStyle = function (node) {
|
|
191
190
|
return node.parsedStyle;
|
|
@@ -304,7 +303,7 @@ function (_super) {
|
|
|
304
303
|
|
|
305
304
|
if (this.container.isBound(RenderingService)) {
|
|
306
305
|
var renderingService = this.container.get(RenderingService);
|
|
307
|
-
renderingService.render();
|
|
306
|
+
renderingService.render(this.getConfig());
|
|
308
307
|
}
|
|
309
308
|
|
|
310
309
|
this.emit(CanvasEvent.AFTER_RENDER, {});
|
package/es/camera/Camera.d.ts
CHANGED
|
@@ -18,8 +18,8 @@ export declare enum CAMERA_PROJECTION_MODE {
|
|
|
18
18
|
ORTHOGRAPHIC = "ORTHOGRAPHIC",
|
|
19
19
|
PERSPECTIVE = "PERSPECTIVE"
|
|
20
20
|
}
|
|
21
|
-
export declare const
|
|
22
|
-
|
|
21
|
+
export declare const CameraEvent: {
|
|
22
|
+
UPDATED: string;
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* 参考「WebGL Insights - 23.Designing Cameras for WebGL Applications」,基于 Responsible Camera 思路设计
|
|
@@ -277,4 +277,5 @@ export declare class Camera extends EventEmitter {
|
|
|
277
277
|
*/
|
|
278
278
|
private _getDistance;
|
|
279
279
|
private _getOrthoMatrix;
|
|
280
|
+
private triggerUpdate;
|
|
280
281
|
}
|
package/es/camera/Camera.js
CHANGED
|
@@ -30,8 +30,8 @@ export var CAMERA_PROJECTION_MODE;
|
|
|
30
30
|
CAMERA_PROJECTION_MODE["PERSPECTIVE"] = "PERSPECTIVE";
|
|
31
31
|
})(CAMERA_PROJECTION_MODE || (CAMERA_PROJECTION_MODE = {}));
|
|
32
32
|
|
|
33
|
-
export var
|
|
34
|
-
|
|
33
|
+
export var CameraEvent = {
|
|
34
|
+
UPDATED: 'updated'
|
|
35
35
|
};
|
|
36
36
|
var DEG_2_RAD = Math.PI / 180;
|
|
37
37
|
var RAD_2_DEG = 180 / Math.PI;
|
|
@@ -415,7 +415,7 @@ function (_super) {
|
|
|
415
415
|
|
|
416
416
|
mat4.scale(this.projectionMatrix, this.projectionMatrix, vec3.fromValues(1, -1, 1));
|
|
417
417
|
mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
|
|
418
|
-
this.
|
|
418
|
+
this.triggerUpdate();
|
|
419
419
|
return this;
|
|
420
420
|
};
|
|
421
421
|
|
|
@@ -452,7 +452,7 @@ function (_super) {
|
|
|
452
452
|
|
|
453
453
|
this._getOrthoMatrix();
|
|
454
454
|
|
|
455
|
-
this.
|
|
455
|
+
this.triggerUpdate();
|
|
456
456
|
return this;
|
|
457
457
|
};
|
|
458
458
|
/**
|
|
@@ -696,7 +696,7 @@ function (_super) {
|
|
|
696
696
|
|
|
697
697
|
this._setPosition(pos);
|
|
698
698
|
|
|
699
|
-
this.
|
|
699
|
+
this.triggerUpdate();
|
|
700
700
|
return this;
|
|
701
701
|
};
|
|
702
702
|
/**
|
|
@@ -725,7 +725,7 @@ function (_super) {
|
|
|
725
725
|
vec3.add(this.focalPoint, pos, this.distanceVector);
|
|
726
726
|
}
|
|
727
727
|
|
|
728
|
-
this.
|
|
728
|
+
this.triggerUpdate();
|
|
729
729
|
return this;
|
|
730
730
|
};
|
|
731
731
|
|
|
@@ -800,7 +800,7 @@ function (_super) {
|
|
|
800
800
|
|
|
801
801
|
_this.computeMatrix();
|
|
802
802
|
|
|
803
|
-
_this.
|
|
803
|
+
_this.triggerUpdate();
|
|
804
804
|
|
|
805
805
|
var dist = vec3.dist(interFocalPoint, destFocalPoint_1) + vec3.dist(interPosition, destPosition_1);
|
|
806
806
|
|
|
@@ -842,7 +842,7 @@ function (_super) {
|
|
|
842
842
|
|
|
843
843
|
this._getOrthoMatrix();
|
|
844
844
|
|
|
845
|
-
this.
|
|
845
|
+
this.triggerUpdate();
|
|
846
846
|
};
|
|
847
847
|
/**
|
|
848
848
|
* 计算相机矩阵
|
|
@@ -971,6 +971,14 @@ function (_super) {
|
|
|
971
971
|
mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.top - this.bottom) / 2 - position[1], 0), vec3.fromValues(this.zoom, this.zoom, 1), position);
|
|
972
972
|
};
|
|
973
973
|
|
|
974
|
+
Camera.prototype.triggerUpdate = function () {
|
|
975
|
+
// update frustum
|
|
976
|
+
var viewMatrix = this.getViewTransform();
|
|
977
|
+
var vpMatrix = mat4.multiply(mat4.create(), this.getPerspective(), viewMatrix);
|
|
978
|
+
this.getFrustum().extractFromVPMatrix(vpMatrix);
|
|
979
|
+
this.emit(CameraEvent.UPDATED);
|
|
980
|
+
};
|
|
981
|
+
|
|
974
982
|
Camera.ProjectionMode = {
|
|
975
983
|
ORTHOGRAPHIC: 'ORTHOGRAPHIC',
|
|
976
984
|
PERSPECTIVE: 'PERSPECTIVE'
|
package/es/canvas-module.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Module, Contribution } from 'mana-syringe';
|
|
2
2
|
import { DirtyCheckPlugin } from './plugins/DirtyCheckPlugin';
|
|
3
3
|
import { CullingPlugin, CullingStrategyContribution } from './plugins/CullingPlugin';
|
|
4
|
-
import { PrepareRendererPlugin } from './plugins/PrepareRendererPlugin';
|
|
4
|
+
import { PrepareRendererPlugin } from './plugins/PrepareRendererPlugin'; // import { CSSCalculatorPlugin } from './plugins/CSSStyleCalculator';
|
|
5
|
+
|
|
5
6
|
import { FrustumCullingStrategy } from './plugins/FrustumCullingStrategy';
|
|
6
7
|
import { RenderingPluginContribution, RenderingService } from './services';
|
|
7
8
|
import { EventPlugin } from './plugins/EventPlugin';
|
|
@@ -18,7 +19,8 @@ export var containerModule = Module(function (register) {
|
|
|
18
19
|
register(RenderingService);
|
|
19
20
|
register(EventService);
|
|
20
21
|
register(EventPlugin);
|
|
21
|
-
register(PrepareRendererPlugin);
|
|
22
|
+
register(PrepareRendererPlugin); // register(CSSCalculatorPlugin);
|
|
23
|
+
|
|
22
24
|
register(DirtyCheckPlugin);
|
|
23
25
|
register(CullingPlugin);
|
|
24
26
|
register(FrustumCullingStrategy);
|
|
@@ -10,5 +10,5 @@ export interface ParsedCircleStyleProps extends ParsedBaseStyleProps {
|
|
|
10
10
|
rInPixels: number;
|
|
11
11
|
}
|
|
12
12
|
export declare class Circle extends DisplayObject<CircleStyleProps, ParsedCircleStyleProps> {
|
|
13
|
-
constructor({ style, ...rest }
|
|
13
|
+
constructor({ style, ...rest }?: DisplayObjectConfig<CircleStyleProps>);
|
|
14
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __assign, __extends, __rest } from "tslib";
|
|
2
|
-
import {
|
|
2
|
+
import { Shape } from '../types';
|
|
3
3
|
import { DisplayObject } from './DisplayObject';
|
|
4
4
|
|
|
5
5
|
var Circle =
|
|
@@ -8,14 +8,19 @@ function (_super) {
|
|
|
8
8
|
__extends(Circle, _super);
|
|
9
9
|
|
|
10
10
|
function Circle(_a) {
|
|
11
|
+
if (_a === void 0) {
|
|
12
|
+
_a = {};
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
var style = _a.style,
|
|
12
16
|
rest = __rest(_a, ["style"]);
|
|
13
17
|
|
|
14
18
|
return _super.call(this, __assign({
|
|
15
|
-
type:
|
|
19
|
+
type: Shape.CIRCLE,
|
|
16
20
|
style: __assign({
|
|
17
21
|
r: 0,
|
|
18
|
-
anchor: [0.5, 0.5]
|
|
22
|
+
anchor: [0.5, 0.5],
|
|
23
|
+
lineWidth: 0
|
|
19
24
|
}, style)
|
|
20
25
|
}, rest)) || this;
|
|
21
26
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { DisplayObject } from './DisplayObject';
|
|
2
2
|
import type { DisplayObjectConfig } from '../dom/interfaces';
|
|
3
|
+
import type { BaseStyleProps } from '../types';
|
|
3
4
|
/**
|
|
4
5
|
* shadow root
|
|
5
6
|
* @see https://yuque.antfin-inc.com/antv/czqvg5/pgqipg
|
|
6
7
|
*/
|
|
7
|
-
export declare abstract class CustomElement<CustomElementStyleProps> extends DisplayObject<CustomElementStyleProps> {
|
|
8
|
-
constructor(config
|
|
8
|
+
export declare abstract class CustomElement<CustomElementStyleProps extends BaseStyleProps> extends DisplayObject<CustomElementStyleProps> {
|
|
9
|
+
constructor(config?: DisplayObjectConfig<CustomElementStyleProps>);
|
|
9
10
|
/**
|
|
10
11
|
* fired after element insert into DOM tree
|
|
11
12
|
*/
|
|
@@ -13,6 +13,10 @@ function (_super) {
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
function CustomElement(config) {
|
|
16
|
+
if (config === void 0) {
|
|
17
|
+
config = {};
|
|
18
|
+
}
|
|
19
|
+
|
|
16
20
|
var _this = _super.call(this, config) || this;
|
|
17
21
|
|
|
18
22
|
_this.handleMounted = function (e) {
|
|
@@ -56,20 +60,19 @@ function (_super) {
|
|
|
56
60
|
return;
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
newValue = _a.newValue;
|
|
63
|
+
var attrName = e.attrName,
|
|
64
|
+
prevValue = e.prevValue,
|
|
65
|
+
newValue = e.newValue;
|
|
63
66
|
|
|
64
67
|
if (_this.attributeChangedCallback) {
|
|
65
|
-
_this.attributeChangedCallback(
|
|
68
|
+
_this.attributeChangedCallback(attrName, prevValue, newValue);
|
|
66
69
|
}
|
|
67
70
|
}; // this.addEventListener(ElementEvent.CHILD_INSERTED, this.handleChildInserted);
|
|
68
71
|
// this.addEventListener(ElementEvent.CHILD_REMOVED, this.handleChildRemoved);
|
|
69
72
|
|
|
70
73
|
|
|
71
74
|
if (_this.attributeChangedCallback) {
|
|
72
|
-
_this.addEventListener(ElementEvent.
|
|
75
|
+
_this.addEventListener(ElementEvent.ATTR_MODIFIED, _this.handleAttributeChanged);
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
if (_this.connectedCallback) {
|
|
@@ -35,18 +35,24 @@ export declare class DisplayObject<StyleProps extends BaseStyleProps = any, Pars
|
|
|
35
35
|
destroy(): void;
|
|
36
36
|
cloneNode(deep?: boolean): this;
|
|
37
37
|
private initAttributes;
|
|
38
|
-
setAttribute<Key extends keyof StyleProps>(
|
|
38
|
+
setAttribute<Key extends keyof StyleProps>(name: Key, value: StyleProps[Key], force?: boolean): void;
|
|
39
39
|
/**
|
|
40
40
|
* parse property, eg.
|
|
41
41
|
* * fill: 'red' => [1, 0, 0, 1]
|
|
42
42
|
* * translateX: '10px' => { unit: 'px', value: 10 }
|
|
43
|
+
* * fontSize: '2em' => { unit: 'px', value: 32 }
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
parseStyleProperty<Key extends keyof ParsedStyleProps>(name: Key, value: ParsedStyleProps[Key]): void;
|
|
46
|
+
updateStyleProperty<Key extends keyof ParsedStyleProps>(name: Key, oldParsedValue: ParsedStyleProps[Key], newParsedValue: ParsedStyleProps[Key]): void;
|
|
46
47
|
/**
|
|
47
48
|
* called when attributes get changed or initialized
|
|
48
49
|
*/
|
|
49
50
|
private changeAttribute;
|
|
51
|
+
/**
|
|
52
|
+
* returns different values than getBoundingClientRect(), as the latter returns value relative to the viewport
|
|
53
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox
|
|
54
|
+
*/
|
|
55
|
+
getBBox(): DOMRect;
|
|
50
56
|
setOrigin(position: vec3 | vec2 | number, y?: number, z?: number): this;
|
|
51
57
|
getOrigin(): vec3;
|
|
52
58
|
/**
|
|
@@ -5,12 +5,12 @@ import { DisplayObjectPool } from '../DisplayObjectPool';
|
|
|
5
5
|
import { KeyframeEffect } from '../dom/KeyframeEffect';
|
|
6
6
|
import { Element } from '../dom/Element';
|
|
7
7
|
import { ElementEvent } from '../dom/interfaces';
|
|
8
|
-
import {
|
|
9
|
-
import { createVec3, fromRotationTranslationScale, getEuler, rad2deg } from '../utils';
|
|
10
|
-
// import { StylePropertyParserFactory, StylePropertyUpdaterFactory } from '../property-handlers';
|
|
11
|
-
|
|
8
|
+
import { Shape } from '../types';
|
|
9
|
+
import { createVec3, formatAttribute, fromRotationTranslationScale, getEuler, rad2deg } from '../utils';
|
|
12
10
|
import { globalContainer, stylePropertyParserFactory, stylePropertyUpdaterFactory } from '../global-module';
|
|
13
11
|
import { dirtifyToRoot } from '../services';
|
|
12
|
+
import { MutationEvent } from '../dom/MutationEvent';
|
|
13
|
+
import { Rectangle } from '../shapes';
|
|
14
14
|
var DEFAULT_STYLE_PROPS = {
|
|
15
15
|
anchor: [0, 0, 0],
|
|
16
16
|
origin: [0, 0, 0],
|
|
@@ -42,23 +42,18 @@ var DEFAULT_STYLE_PROPS = {
|
|
|
42
42
|
var DisplayObject =
|
|
43
43
|
/** @class */
|
|
44
44
|
function (_super) {
|
|
45
|
-
__extends(DisplayObject, _super);
|
|
46
|
-
// <Key extends keyof StyleProps>(stylePropertyName: Key) => StylePropertyUpdater<any>[]
|
|
47
|
-
// >(StylePropertyUpdaterFactory);
|
|
48
|
-
// stylePropertyParserFactory = globalContainer.get<
|
|
49
|
-
// <Key extends keyof ParsedStyleProps>(stylePropertyName: Key) => StylePropertyParser<any, any>
|
|
50
|
-
// >(StylePropertyParserFactory);
|
|
51
|
-
|
|
45
|
+
__extends(DisplayObject, _super);
|
|
52
46
|
|
|
53
47
|
function DisplayObject(config) {
|
|
48
|
+
var _this = this;
|
|
49
|
+
|
|
54
50
|
var _a, _b, _c;
|
|
55
51
|
|
|
56
|
-
|
|
52
|
+
_this = _super.call(this) || this;
|
|
57
53
|
/**
|
|
58
54
|
* push to active animations after calling `animate()`
|
|
59
55
|
*/
|
|
60
56
|
|
|
61
|
-
|
|
62
57
|
_this.activeAnimations = []; // assign name, id to config
|
|
63
58
|
// eg. group.get('name')
|
|
64
59
|
|
|
@@ -68,17 +63,38 @@ function (_super) {
|
|
|
68
63
|
|
|
69
64
|
_this.id = _this.config.id || '';
|
|
70
65
|
_this.name = _this.config.name || '';
|
|
71
|
-
|
|
66
|
+
|
|
67
|
+
if (_this.config.className || _this.config.class) {
|
|
68
|
+
_this.className = _this.config.className || _this.config.class;
|
|
69
|
+
}
|
|
70
|
+
|
|
72
71
|
_this.interactive = (_b = _this.config.interactive) !== null && _b !== void 0 ? _b : true;
|
|
73
|
-
_this.nodeName = _this.config.type ||
|
|
72
|
+
_this.nodeName = _this.config.type || Shape.GROUP; // compatible with G 3.0
|
|
74
73
|
|
|
75
74
|
_this.config.style = __assign(__assign(__assign(__assign({}, DEFAULT_STYLE_PROPS), {
|
|
76
75
|
zIndex: (_c = _this.config.zIndex) !== null && _c !== void 0 ? _c : 0,
|
|
77
76
|
visibility: _this.config.visible === false ? 'hidden' : 'visible'
|
|
78
77
|
}), _this.config.style), _this.config.attrs);
|
|
79
|
-
_this.style = new Proxy(_this.attributes, {
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
_this.style = new Proxy(__assign(__assign({}, _this.attributes), {
|
|
79
|
+
setProperty: function setProperty(propertyName, value) {
|
|
80
|
+
_this.setAttribute(propertyName, value);
|
|
81
|
+
},
|
|
82
|
+
getPropertyValue: function getPropertyValue(propertyName) {
|
|
83
|
+
return _this.getAttribute(propertyName);
|
|
84
|
+
},
|
|
85
|
+
removeProperty: function removeProperty(propertyName) {
|
|
86
|
+
_this.removeAttribute(propertyName);
|
|
87
|
+
},
|
|
88
|
+
item: function item() {
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
}), {
|
|
92
|
+
get: function get(target, name) {
|
|
93
|
+
if (name in target) {
|
|
94
|
+
return target[name];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return _this.getAttribute(name);
|
|
82
98
|
},
|
|
83
99
|
set: function set(_, prop, value) {
|
|
84
100
|
_this.setAttribute(prop, value);
|
|
@@ -113,7 +129,7 @@ function (_super) {
|
|
|
113
129
|
name: this.name,
|
|
114
130
|
className: this.name,
|
|
115
131
|
interactive: this.interactive,
|
|
116
|
-
style: __assign({}, this.
|
|
132
|
+
style: __assign({}, this.attributes)
|
|
117
133
|
});
|
|
118
134
|
|
|
119
135
|
if (deep) {
|
|
@@ -136,51 +152,62 @@ function (_super) {
|
|
|
136
152
|
var renderable = this.renderable; // parse attributes first
|
|
137
153
|
|
|
138
154
|
for (var attributeName in attributes) {
|
|
139
|
-
var
|
|
140
|
-
|
|
155
|
+
var _a = __read(formatAttribute(attributeName, attributes[attributeName]), 2),
|
|
156
|
+
name_1 = _a[0],
|
|
157
|
+
value = _a[1];
|
|
158
|
+
|
|
159
|
+
this.attributes[name_1] = value; // @ts-ignore
|
|
141
160
|
|
|
142
|
-
this.parseStyleProperty(
|
|
161
|
+
this.parseStyleProperty(name_1, value);
|
|
143
162
|
}
|
|
144
163
|
|
|
145
164
|
var priorities = {
|
|
146
|
-
x:
|
|
147
|
-
y:
|
|
165
|
+
x: Infinity,
|
|
166
|
+
y: Infinity
|
|
148
167
|
}; // update x, y at last
|
|
149
168
|
|
|
150
169
|
var sortedNames = Object.keys(attributes).sort(function (a, b) {
|
|
151
170
|
return (priorities[a] || 0) - (priorities[b] || 0);
|
|
152
171
|
});
|
|
153
172
|
sortedNames.forEach(function (attributeName) {
|
|
154
|
-
|
|
155
|
-
|
|
173
|
+
var _a = __read(formatAttribute(attributeName, ''), 1),
|
|
174
|
+
name = _a[0]; // @ts-ignore
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
_this.updateStyleProperty(name, undefined, _this.parsedStyle[name]);
|
|
156
178
|
}); // redraw at next frame
|
|
157
179
|
|
|
158
180
|
renderable.dirty = true;
|
|
159
181
|
};
|
|
160
182
|
|
|
161
|
-
DisplayObject.prototype.setAttribute = function (
|
|
183
|
+
DisplayObject.prototype.setAttribute = function (name, value, force) {
|
|
162
184
|
if (force === void 0) {
|
|
163
185
|
force = false;
|
|
164
186
|
}
|
|
165
187
|
|
|
166
|
-
|
|
188
|
+
var _a = __read(formatAttribute(name, value), 2),
|
|
189
|
+
attributeName = _a[0],
|
|
190
|
+
attributeValue = _a[1];
|
|
191
|
+
|
|
192
|
+
if (force || !isEqual(attributeValue, this.attributes[attributeName]) || attributeName === 'transformOrigin' || attributeName === 'visibility' // will affect children
|
|
167
193
|
) {
|
|
168
194
|
if (attributeName === 'visibility') {
|
|
169
195
|
// set value cascade
|
|
170
196
|
this.forEach(function (object) {
|
|
171
|
-
object.changeAttribute(attributeName,
|
|
197
|
+
object.changeAttribute(attributeName, attributeValue);
|
|
172
198
|
});
|
|
173
199
|
} else {
|
|
174
|
-
this.changeAttribute(attributeName,
|
|
200
|
+
this.changeAttribute(attributeName, attributeValue);
|
|
175
201
|
}
|
|
176
202
|
|
|
177
|
-
_super.prototype.setAttribute.call(this, attributeName,
|
|
203
|
+
_super.prototype.setAttribute.call(this, attributeName, attributeValue);
|
|
178
204
|
}
|
|
179
205
|
};
|
|
180
206
|
/**
|
|
181
207
|
* parse property, eg.
|
|
182
208
|
* * fill: 'red' => [1, 0, 0, 1]
|
|
183
209
|
* * translateX: '10px' => { unit: 'px', value: 10 }
|
|
210
|
+
* * fontSize: '2em' => { unit: 'px', value: 32 }
|
|
184
211
|
*/
|
|
185
212
|
|
|
186
213
|
|
|
@@ -190,16 +217,14 @@ function (_super) {
|
|
|
190
217
|
|
|
191
218
|
if (stylePropertyParser) {
|
|
192
219
|
// @ts-ignore
|
|
193
|
-
this.parsedStyle[name] = stylePropertyParser(value, this);
|
|
220
|
+
this.parsedStyle[name] = stylePropertyParser(value, this, name);
|
|
194
221
|
} else {
|
|
195
222
|
this.parsedStyle[name] = value;
|
|
196
223
|
}
|
|
197
224
|
};
|
|
198
225
|
|
|
199
226
|
DisplayObject.prototype.updateStyleProperty = function (name, oldParsedValue, newParsedValue) {
|
|
200
|
-
var _this = this; //
|
|
201
|
-
// @ts-ignore
|
|
202
|
-
// const stylePropertyUpdaters = this.stylePropertyUpdaterFactory(name);
|
|
227
|
+
var _this = this; // @ts-ignore
|
|
203
228
|
|
|
204
229
|
|
|
205
230
|
var stylePropertyUpdaters = stylePropertyUpdaterFactory[name];
|
|
@@ -207,7 +232,7 @@ function (_super) {
|
|
|
207
232
|
if (stylePropertyUpdaters) {
|
|
208
233
|
stylePropertyUpdaters.forEach(function (updater) {
|
|
209
234
|
// @ts-ignore
|
|
210
|
-
updater(oldParsedValue, newParsedValue, _this, _this.sceneGraphService);
|
|
235
|
+
updater(oldParsedValue, newParsedValue, _this, _this.sceneGraphService, name);
|
|
211
236
|
});
|
|
212
237
|
}
|
|
213
238
|
};
|
|
@@ -234,26 +259,48 @@ function (_super) {
|
|
|
234
259
|
|
|
235
260
|
if (this.attributes.clipPathTargets && this.attributes.clipPathTargets.length) {
|
|
236
261
|
this.attributes.clipPathTargets.forEach(function (target) {
|
|
237
|
-
dirtifyToRoot(target);
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
262
|
+
dirtifyToRoot(target); // target.emit(ElementEvent.ATTR_MODIFIED, {
|
|
263
|
+
// attributeName: 'clipPath',
|
|
264
|
+
// oldValue: this,
|
|
265
|
+
// newValue: this,
|
|
266
|
+
// });
|
|
267
|
+
|
|
268
|
+
target.dispatchEvent(new MutationEvent(ElementEvent.ATTR_MODIFIED, target, _this, _this, 'clipPath', MutationEvent.MODIFICATION, _this, _this));
|
|
243
269
|
});
|
|
244
270
|
} // redraw at next frame
|
|
245
271
|
|
|
246
272
|
|
|
247
273
|
renderable.dirty = true;
|
|
248
|
-
this.emit(ElementEvent.
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
274
|
+
this.dispatchEvent(new MutationEvent(ElementEvent.ATTR_MODIFIED, this, oldValue, value, name, MutationEvent.MODIFICATION, oldParsedValue, newParsedValue)); // this.emit(ElementEvent.ATTR_MODIFIED, {
|
|
275
|
+
// attrName: name,
|
|
276
|
+
// attributeName: name,
|
|
277
|
+
// prevValue: oldValue,
|
|
278
|
+
// oldValue,
|
|
279
|
+
// newValue: value,
|
|
280
|
+
// oldParsedValue,
|
|
281
|
+
// newParsedValue,
|
|
282
|
+
// });
|
|
255
283
|
}; // #region transformable
|
|
256
284
|
|
|
285
|
+
/**
|
|
286
|
+
* returns different values than getBoundingClientRect(), as the latter returns value relative to the viewport
|
|
287
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
DisplayObject.prototype.getBBox = function () {
|
|
292
|
+
var aabb = this.getBounds();
|
|
293
|
+
|
|
294
|
+
var _a = __read(aabb.getMin(), 2),
|
|
295
|
+
left = _a[0],
|
|
296
|
+
top = _a[1];
|
|
297
|
+
|
|
298
|
+
var _b = __read(aabb.getMax(), 2),
|
|
299
|
+
right = _b[0],
|
|
300
|
+
bottom = _b[1];
|
|
301
|
+
|
|
302
|
+
return new Rectangle(left, top, right - left, bottom - top);
|
|
303
|
+
};
|
|
257
304
|
|
|
258
305
|
DisplayObject.prototype.setOrigin = function (position, y, z) {
|
|
259
306
|
if (y === void 0) {
|
|
@@ -575,7 +622,7 @@ function (_super) {
|
|
|
575
622
|
|
|
576
623
|
DisplayObject.prototype.isVisible = function () {
|
|
577
624
|
var cullable = this.cullable;
|
|
578
|
-
return this.
|
|
625
|
+
return this.getAttribute('visibility') === 'visible' && (!cullable || cullable && !cullable.isCulled());
|
|
579
626
|
};
|
|
580
627
|
/**
|
|
581
628
|
* bring to front in current group
|
|
@@ -13,5 +13,5 @@ export interface ParsedEllipseStyleProps extends ParsedBaseStyleProps {
|
|
|
13
13
|
ryInPixels: number;
|
|
14
14
|
}
|
|
15
15
|
export declare class Ellipse extends DisplayObject<EllipseStyleProps, ParsedEllipseStyleProps> {
|
|
16
|
-
constructor({ style, ...rest }
|
|
16
|
+
constructor({ style, ...rest }?: DisplayObjectConfig<EllipseStyleProps>);
|
|
17
17
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __assign, __extends, __rest } from "tslib";
|
|
2
|
-
import {
|
|
2
|
+
import { Shape } from '../types';
|
|
3
3
|
import { DisplayObject } from './DisplayObject';
|
|
4
4
|
|
|
5
5
|
var Ellipse =
|
|
@@ -8,15 +8,20 @@ function (_super) {
|
|
|
8
8
|
__extends(Ellipse, _super);
|
|
9
9
|
|
|
10
10
|
function Ellipse(_a) {
|
|
11
|
+
if (_a === void 0) {
|
|
12
|
+
_a = {};
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
var style = _a.style,
|
|
12
16
|
rest = __rest(_a, ["style"]);
|
|
13
17
|
|
|
14
18
|
return _super.call(this, __assign({
|
|
15
|
-
type:
|
|
19
|
+
type: Shape.ELLIPSE,
|
|
16
20
|
style: __assign({
|
|
17
21
|
rx: 0,
|
|
18
22
|
ry: 0,
|
|
19
|
-
anchor: [0.5, 0.5]
|
|
23
|
+
anchor: [0.5, 0.5],
|
|
24
|
+
lineWidth: 0
|
|
20
25
|
}, style)
|
|
21
26
|
}, rest)) || this;
|
|
22
27
|
}
|
|
@@ -1,6 +1,22 @@
|
|
|
1
|
-
import type { BaseStyleProps } from '../types';
|
|
1
|
+
import type { BaseStyleProps, ParsedBaseStyleProps, TextAlign } from '../types';
|
|
2
2
|
import { DisplayObject } from './DisplayObject';
|
|
3
3
|
import type { DisplayObjectConfig } from '../dom';
|
|
4
|
+
import type { ParsedElement } from '../property-handlers';
|
|
5
|
+
export interface GroupStyleProps extends BaseStyleProps {
|
|
6
|
+
width?: number | string;
|
|
7
|
+
height?: number | string;
|
|
8
|
+
textAlign?: TextAlign | 'inherit';
|
|
9
|
+
fontSize?: number | string | 'inherit';
|
|
10
|
+
fontFamily?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ParsedGroupStyleProps extends ParsedBaseStyleProps {
|
|
13
|
+
width?: ParsedElement;
|
|
14
|
+
height?: ParsedElement;
|
|
15
|
+
widthInPixels?: number;
|
|
16
|
+
heightInPixels?: number;
|
|
17
|
+
textAlign?: TextAlign;
|
|
18
|
+
fontSize?: ParsedElement;
|
|
19
|
+
}
|
|
4
20
|
export declare class Group extends DisplayObject {
|
|
5
|
-
constructor(
|
|
21
|
+
constructor({ style, ...rest }?: DisplayObjectConfig<GroupStyleProps>);
|
|
6
22
|
}
|