@antv/g 5.0.15 → 5.0.16
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 +3 -0
- package/es/Canvas.js +8 -9
- 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 +4 -3
- package/es/display-objects/DisplayObject.js +77 -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 +9 -4
- package/es/display-objects/Text.js +14 -9
- package/es/dom/Animation.js +1 -1
- package/es/dom/AnimationTimeline.js +1 -2
- package/es/dom/CustomElementRegistry.js +12 -12
- package/es/dom/Document.d.ts +1 -0
- package/es/dom/Document.js +21 -1
- package/es/dom/Element.d.ts +10 -5
- package/es/dom/Element.js +41 -15
- package/es/dom/EventTarget.d.ts +2 -2
- package/es/dom/EventTarget.js +4 -3
- 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 +36 -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/FrustumCullingStrategy.d.ts +1 -0
- package/es/plugins/FrustumCullingStrategy.js +40 -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 +3 -5
- package/es/services/RenderingContext.d.ts +5 -8
- package/es/services/RenderingContext.js +6 -7
- package/es/services/RenderingService.js +2 -8
- 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 +9 -77
- 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 +19 -10
- package/es/services/text/index.js +19 -21
- package/es/types.d.ts +48 -24
- package/es/types.js +50 -31
- package/es/utils/custom-easing.js +1 -1
- package/es/utils/event.js +5 -3
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +2 -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 +3 -0
- package/lib/Canvas.js +6 -7
- 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 +4 -3
- package/lib/display-objects/DisplayObject.js +76 -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 +9 -4
- package/lib/display-objects/Text.js +13 -8
- package/lib/dom/Animation.js +1 -1
- package/lib/dom/AnimationTimeline.js +1 -2
- package/lib/dom/CustomElementRegistry.js +11 -11
- package/lib/dom/Document.d.ts +1 -0
- package/lib/dom/Document.js +22 -1
- package/lib/dom/Element.d.ts +10 -5
- package/lib/dom/Element.js +43 -15
- package/lib/dom/EventTarget.d.ts +2 -2
- package/lib/dom/EventTarget.js +4 -3
- 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 +36 -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/FrustumCullingStrategy.d.ts +1 -0
- package/lib/plugins/FrustumCullingStrategy.js +41 -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 +3 -5
- package/lib/services/RenderingContext.d.ts +5 -8
- package/lib/services/RenderingContext.js +8 -9
- package/lib/services/RenderingService.js +1 -7
- 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 +10 -77
- 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 +18 -9
- package/lib/services/text/index.js +19 -21
- package/lib/types.d.ts +48 -24
- package/lib/types.js +56 -35
- package/lib/utils/custom-easing.js +1 -1
- package/lib/utils/event.js +5 -3
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +13 -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
|
@@ -2,7 +2,7 @@ import { __decorate, __metadata } from "tslib";
|
|
|
2
2
|
import { inject, singleton } from 'mana-syringe';
|
|
3
3
|
import { CanvasConfig } from '../types';
|
|
4
4
|
import { RenderingPluginContribution } from '../services/RenderingService';
|
|
5
|
-
import { RenderingContext,
|
|
5
|
+
import { RenderingContext, RenderReason } from '../services/RenderingContext';
|
|
6
6
|
/**
|
|
7
7
|
* Filter dirty renderables and calculate the "dirty rectangle" which will be clear when frame began
|
|
8
8
|
*/
|
|
@@ -23,7 +23,7 @@ function () {
|
|
|
23
23
|
|
|
24
24
|
var renderable = object.renderable;
|
|
25
25
|
|
|
26
|
-
var isDirty = renderable.dirty || _this.renderingContext.renderReasons.has(
|
|
26
|
+
var isDirty = renderable.dirty || _this.renderingContext.renderReasons.has(RenderReason.CAMERA_CHANGED);
|
|
27
27
|
|
|
28
28
|
if (isDirty || !enableDirtyRectangleRendering) {
|
|
29
29
|
return object;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CullingStrategyContribution } from './CullingPlugin';
|
|
2
2
|
import type { DisplayObject } from '../display-objects/DisplayObject';
|
|
3
3
|
export declare class FrustumCullingStrategy implements CullingStrategyContribution {
|
|
4
|
+
private camera;
|
|
4
5
|
isVisible(object: DisplayObject): boolean;
|
|
5
6
|
/**
|
|
6
7
|
*
|
|
@@ -1,41 +1,39 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { inject, singleton } from 'mana-syringe';
|
|
4
3
|
import { vec3 } from 'gl-matrix';
|
|
5
|
-
import { singleton } from 'mana-syringe';
|
|
6
4
|
import { CullingStrategyContribution } from './CullingPlugin';
|
|
7
|
-
import { Mask } from '../shapes';
|
|
5
|
+
import { Mask } from '../shapes';
|
|
6
|
+
import { DefaultCamera, Camera } from '../camera/Camera';
|
|
7
|
+
import { Shape } from '..'; // group is not a 2d shape
|
|
8
|
+
|
|
9
|
+
var shape2D = [Shape.CIRCLE, Shape.ELLIPSE, Shape.IMAGE, Shape.RECT, Shape.LINE, Shape.POLYLINE, Shape.POLYGON, Shape.TEXT, Shape.PATH, Shape.HTML];
|
|
8
10
|
|
|
9
11
|
var FrustumCullingStrategy =
|
|
10
12
|
/** @class */
|
|
11
13
|
function () {
|
|
12
|
-
function FrustumCullingStrategy() {}
|
|
13
|
-
// private camera: Camera;
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
15
|
-
|
|
14
|
+
function FrustumCullingStrategy() {}
|
|
16
15
|
|
|
17
16
|
FrustumCullingStrategy.prototype.isVisible = function (object) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// return cullable.visible;
|
|
17
|
+
var _a, _b;
|
|
18
|
+
|
|
19
|
+
var cullable = object.cullable;
|
|
20
|
+
|
|
21
|
+
if (!cullable.enable) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var renderBounds = object.getRenderBounds();
|
|
26
|
+
|
|
27
|
+
if (!renderBounds) {
|
|
28
|
+
return false;
|
|
29
|
+
} // get VP matrix from camera
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var frustum = this.camera.getFrustum();
|
|
33
|
+
var parentVisibilityPlaneMask = (_b = (_a = object.parentNode) === null || _a === void 0 ? void 0 : _a.cullable) === null || _b === void 0 ? void 0 : _b.visibilityPlaneMask;
|
|
34
|
+
cullable.visibilityPlaneMask = this.computeVisibilityWithPlaneMask(object, renderBounds, parentVisibilityPlaneMask || Mask.INDETERMINATE, frustum.planes);
|
|
35
|
+
cullable.visible = cullable.visibilityPlaneMask !== Mask.OUTSIDE;
|
|
36
|
+
return cullable.visible;
|
|
39
37
|
};
|
|
40
38
|
/**
|
|
41
39
|
*
|
|
@@ -53,7 +51,7 @@ function () {
|
|
|
53
51
|
*/
|
|
54
52
|
|
|
55
53
|
|
|
56
|
-
FrustumCullingStrategy.prototype.computeVisibilityWithPlaneMask = function (aabb, parentPlaneMask, planes) {
|
|
54
|
+
FrustumCullingStrategy.prototype.computeVisibilityWithPlaneMask = function (object, aabb, parentPlaneMask, planes) {
|
|
57
55
|
if (parentPlaneMask === Mask.OUTSIDE || parentPlaneMask === Mask.INSIDE) {
|
|
58
56
|
// 父节点完全位于视锥内或者外部,直接返回
|
|
59
57
|
return parentPlaneMask;
|
|
@@ -62,14 +60,21 @@ function () {
|
|
|
62
60
|
|
|
63
61
|
|
|
64
62
|
var mask = Mask.INSIDE;
|
|
63
|
+
var isShape2D = shape2D.indexOf(object.nodeName) > -1; // Use viewport culling for 2D shapes
|
|
64
|
+
// @see https://github.com/antvis/g/issues/914
|
|
65
65
|
|
|
66
66
|
for (var k = 0, len = planes.length; k < len; ++k) {
|
|
67
67
|
// For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.
|
|
68
|
-
var flag =
|
|
68
|
+
var flag = 1 << k;
|
|
69
69
|
|
|
70
|
-
if (
|
|
70
|
+
if ((parentPlaneMask & flag) === 0) {
|
|
71
71
|
// 父节点处于当前面内部,可以跳过
|
|
72
72
|
continue;
|
|
73
|
+
} // skip near & far planes when testing 2D shapes
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if (isShape2D && (k === 4 || k === 5)) {
|
|
77
|
+
continue;
|
|
73
78
|
} // p-vertex n-vertex <-|plane p-vertex n-vertex
|
|
74
79
|
// 使用 p-vertex 和 n-vertex 加速,避免进行平面和 aabb 全部顶点的相交检测
|
|
75
80
|
|
|
@@ -91,6 +96,8 @@ function () {
|
|
|
91
96
|
return mask;
|
|
92
97
|
};
|
|
93
98
|
|
|
99
|
+
__decorate([inject(DefaultCamera), __metadata("design:type", Camera)], FrustumCullingStrategy.prototype, "camera", void 0);
|
|
100
|
+
|
|
94
101
|
FrustumCullingStrategy = __decorate([singleton({
|
|
95
102
|
contrib: CullingStrategyContribution
|
|
96
103
|
})], FrustumCullingStrategy);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { isNil } from '@antv/util';
|
|
2
3
|
import { inject, singleton } from 'mana-syringe';
|
|
3
4
|
import { ElementEvent } from '../dom';
|
|
4
|
-
import {
|
|
5
|
+
import { INHERIT_PROPERTIES } from '../global-module';
|
|
6
|
+
import { computeInheritStyleProperty } from '../property-handlers';
|
|
7
|
+
import { RenderingContext, RenderReason, RenderingPluginContribution, dirtifyToRoot } from '../services';
|
|
5
8
|
|
|
6
9
|
var PrepareRendererPlugin =
|
|
7
10
|
/** @class */
|
|
@@ -14,7 +17,7 @@ function () {
|
|
|
14
17
|
var _this = this;
|
|
15
18
|
|
|
16
19
|
var handleAttributeChanged = function handleAttributeChanged() {
|
|
17
|
-
_this.renderingContext.renderReasons.add(
|
|
20
|
+
_this.renderingContext.renderReasons.add(RenderReason.DISPLAY_OBJECT_CHANGED);
|
|
18
21
|
};
|
|
19
22
|
|
|
20
23
|
var handleBoundsChanged = function handleBoundsChanged() {
|
|
@@ -22,7 +25,20 @@ function () {
|
|
|
22
25
|
};
|
|
23
26
|
|
|
24
27
|
var handleMounted = function handleMounted(e) {
|
|
25
|
-
|
|
28
|
+
var object = e.target; // compute some style when mounted
|
|
29
|
+
|
|
30
|
+
INHERIT_PROPERTIES.forEach(function (name) {
|
|
31
|
+
if (object.getAttribute(name) === 'inherit') {
|
|
32
|
+
var computedValue = computeInheritStyleProperty(object, name);
|
|
33
|
+
|
|
34
|
+
if (!isNil(computedValue)) {
|
|
35
|
+
var oldParsedValue = object.parsedStyle[name];
|
|
36
|
+
object.parsedStyle[name] = computedValue;
|
|
37
|
+
object.updateStyleProperty(name, oldParsedValue, computedValue);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
dirtifyToRoot(object);
|
|
26
42
|
renderingService.dirtify();
|
|
27
43
|
};
|
|
28
44
|
|
|
@@ -36,7 +52,7 @@ function () {
|
|
|
36
52
|
|
|
37
53
|
_this.renderingContext.root.addEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
|
|
38
54
|
|
|
39
|
-
_this.renderingContext.root.addEventListener(ElementEvent.
|
|
55
|
+
_this.renderingContext.root.addEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
40
56
|
|
|
41
57
|
_this.renderingContext.root.addEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
|
|
42
58
|
});
|
|
@@ -45,7 +61,7 @@ function () {
|
|
|
45
61
|
|
|
46
62
|
_this.renderingContext.root.removeEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
|
|
47
63
|
|
|
48
|
-
_this.renderingContext.root.removeEventListener(ElementEvent.
|
|
64
|
+
_this.renderingContext.root.removeEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
49
65
|
|
|
50
66
|
_this.renderingContext.root.removeEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
|
|
51
67
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { vec3 } from 'gl-matrix';
|
|
2
2
|
import { AABB } from '../shapes';
|
|
3
3
|
import { dirtifyToRoot, GeometryUpdaterFactory } from '../services';
|
|
4
|
-
import {
|
|
4
|
+
import { Shape } from '../types';
|
|
5
5
|
import { PARSED_COLOR_TYPE } from './color';
|
|
6
6
|
import { globalContainer } from '../global-module';
|
|
7
7
|
export function updateGeometry(oldValue, newValue, object) {
|
|
@@ -40,7 +40,7 @@ export function updateGeometry(oldValue, newValue, object) {
|
|
|
40
40
|
// object.parsedStyle.depth = depth;
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
if (object.nodeName ===
|
|
43
|
+
if (object.nodeName === Shape.LINE || object.nodeName === Shape.POLYLINE || object.nodeName === Shape.POLYGON || object.nodeName === Shape.PATH) {
|
|
44
44
|
object.parsedStyle.offsetX = x - (object.parsedStyle.defX || 0);
|
|
45
45
|
object.parsedStyle.offsetY = y - (object.parsedStyle.defY || 0);
|
|
46
46
|
object.parsedStyle.defX = x;
|
|
@@ -59,15 +59,14 @@ export function updateGeometry(oldValue, newValue, object) {
|
|
|
59
59
|
var halfExtents = vec3.fromValues(width / 2, height / 2, depth / 2); // anchor is center by default, don't account for lineWidth here
|
|
60
60
|
|
|
61
61
|
var _j = object.parsedStyle,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
anchor = _l === void 0 ? [0, 0] : _l,
|
|
62
|
+
lineWidth = _j.lineWidth,
|
|
63
|
+
_k = _j.anchor,
|
|
64
|
+
anchor = _k === void 0 ? [0, 0] : _k,
|
|
66
65
|
shadowColor = _j.shadowColor,
|
|
67
|
-
|
|
68
|
-
filter =
|
|
66
|
+
_l = _j.filter,
|
|
67
|
+
filter = _l === void 0 ? [] : _l; // <Text> use textAlign & textBaseline instead of anchor
|
|
69
68
|
|
|
70
|
-
if (object.nodeName ===
|
|
69
|
+
if (object.nodeName === Shape.TEXT) {
|
|
71
70
|
delete object.parsedStyle.anchor;
|
|
72
71
|
}
|
|
73
72
|
|
|
@@ -77,22 +76,22 @@ export function updateGeometry(oldValue, newValue, object) {
|
|
|
77
76
|
|
|
78
77
|
if (lineWidth) {
|
|
79
78
|
// append border
|
|
80
|
-
vec3.add(halfExtents, halfExtents, vec3.fromValues(lineWidth / 2, lineWidth / 2, 0));
|
|
79
|
+
vec3.add(halfExtents, halfExtents, vec3.fromValues(lineWidth.value / 2, lineWidth.value / 2, 0));
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
geometry_1.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
|
|
84
83
|
|
|
85
84
|
if (shadowColor && shadowColor.type === PARSED_COLOR_TYPE.Constant) {
|
|
86
|
-
var
|
|
87
|
-
min =
|
|
88
|
-
max =
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
shadowBlur =
|
|
92
|
-
|
|
93
|
-
shadowOffsetX =
|
|
94
|
-
|
|
95
|
-
shadowOffsetY =
|
|
85
|
+
var _m = geometry_1.renderBounds,
|
|
86
|
+
min = _m.min,
|
|
87
|
+
max = _m.max;
|
|
88
|
+
var _o = object.parsedStyle,
|
|
89
|
+
_p = _o.shadowBlur,
|
|
90
|
+
shadowBlur = _p === void 0 ? 0 : _p,
|
|
91
|
+
_q = _o.shadowOffsetX,
|
|
92
|
+
shadowOffsetX = _q === void 0 ? 0 : _q,
|
|
93
|
+
_r = _o.shadowOffsetY,
|
|
94
|
+
shadowOffsetY = _r === void 0 ? 0 : _r;
|
|
96
95
|
var shadowLeft = min[0] - shadowBlur + shadowOffsetX;
|
|
97
96
|
var shadowRight = max[0] + shadowBlur + shadowOffsetX;
|
|
98
97
|
var shadowTop = min[1] - shadowBlur + shadowOffsetY;
|
|
@@ -25,6 +25,9 @@ export function parseColor(colorStr) {
|
|
|
25
25
|
value: [0, 0, 0, 0],
|
|
26
26
|
formatted: 'rgba(0,0,0,0)'
|
|
27
27
|
};
|
|
28
|
+
} else if (colorStr === 'currentColor') {
|
|
29
|
+
// @see https://github.com/adobe-webplatform/Snap.svg/issues/526
|
|
30
|
+
colorStr = 'black';
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
var type = colorStr[0];
|
|
@@ -81,7 +84,7 @@ export function parseColor(colorStr) {
|
|
|
81
84
|
return {
|
|
82
85
|
type: PARSED_COLOR_TYPE.Constant,
|
|
83
86
|
value: rgba,
|
|
84
|
-
formatted: color && "rgba("
|
|
87
|
+
formatted: color && "rgba(".concat(color.r, ",").concat(color.g, ",").concat(color.b, ",").concat(color.opacity, ")") || 'rgba(0,0,0,0)'
|
|
85
88
|
};
|
|
86
89
|
}
|
|
87
90
|
export function mergeColors(left, right) {
|
|
@@ -100,7 +103,7 @@ export function mergeColors(left, right) {
|
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
rgba[3] = clamp(rgba[3], 0, 1);
|
|
103
|
-
return "rgba("
|
|
106
|
+
return "rgba(".concat(rgba.join(','), ")");
|
|
104
107
|
}];
|
|
105
108
|
}
|
|
106
109
|
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import type { DisplayObject } from '../display-objects/DisplayObject';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @see https://drafts.csswg.org/css-values-4/#dimension
|
|
4
|
+
*/
|
|
5
|
+
export declare type LengthUnit = 'px' | '%' | 'em';
|
|
3
6
|
export declare type AngleUnit = 'deg' | 'rad' | 'turn';
|
|
4
|
-
export declare type Unit = LengthUnit | AngleUnit | ''
|
|
7
|
+
export declare type Unit = LengthUnit | AngleUnit | '';
|
|
5
8
|
export interface ParsedElement {
|
|
6
9
|
unit: Unit;
|
|
10
|
+
/**
|
|
11
|
+
* absolute value in pixels
|
|
12
|
+
*/
|
|
7
13
|
value: number;
|
|
8
14
|
}
|
|
9
|
-
export declare function parseDimension(unitRegExp: RegExp, string: string): ParsedElement | undefined;
|
|
15
|
+
export declare function parseDimension(unitRegExp: RegExp, string: string, object: DisplayObject, name: string): ParsedElement | undefined;
|
|
10
16
|
/**
|
|
11
17
|
* eg. 10px + 20px = 30px
|
|
12
18
|
*/
|
|
13
19
|
export declare function mergeDimensions(left: ParsedElement, right: ParsedElement, nonNegative?: boolean, target?: DisplayObject | null, index?: number): [number, number, (value: number) => string];
|
|
20
|
+
/**
|
|
21
|
+
* length with only absolute unit, eg. 1px
|
|
22
|
+
*/
|
|
14
23
|
export declare const parseLength: any;
|
|
24
|
+
/**
|
|
25
|
+
* length with absolute or relative unit, eg. 1px, 0.7em, 50%
|
|
26
|
+
*/
|
|
15
27
|
export declare const parseLengthOrPercent: any;
|
|
16
28
|
export declare const parseAngle: any;
|
|
17
29
|
export declare function parseLengthOrPercentList(list: (string | number)[]): ParsedElement[];
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import { numberToString } from './numeric';
|
|
2
2
|
import { rad2deg } from '../utils/math';
|
|
3
|
-
import { isFinite } from '@antv/util';
|
|
3
|
+
import { isFinite, isNil } from '@antv/util';
|
|
4
4
|
import { AABB } from '../shapes';
|
|
5
|
+
import { computeInheritStyleProperty } from './inherit';
|
|
5
6
|
|
|
6
7
|
function isLengthUnit(unit) {
|
|
7
|
-
return unit === 'px' || unit === '%';
|
|
8
|
+
return unit === 'px' || unit === '%' || unit === 'em';
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
function isAngleUnit(unit) {
|
|
11
12
|
return unit === 'deg' || unit === 'rad' || unit === 'turn';
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
export function parseDimension(unitRegExp, string) {
|
|
15
|
-
string =
|
|
15
|
+
export function parseDimension(unitRegExp, string, object, name) {
|
|
16
|
+
string = "".concat(string).trim().toLowerCase();
|
|
17
|
+
|
|
18
|
+
if (string === 'inherit') {
|
|
19
|
+
var computed = computeInheritStyleProperty(object, name);
|
|
20
|
+
|
|
21
|
+
if (!isNil(computed)) {
|
|
22
|
+
return computed;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
16
25
|
|
|
17
26
|
if (string === '0') {
|
|
18
27
|
if ('px'.search(unitRegExp) >= 0) {
|
|
@@ -28,17 +37,41 @@ export function parseDimension(unitRegExp, string) {
|
|
|
28
37
|
value: 0
|
|
29
38
|
};
|
|
30
39
|
}
|
|
31
|
-
} else if (string === 'auto') {
|
|
40
|
+
} else if (string === 'auto' || string === 'inherit') {
|
|
32
41
|
return {
|
|
33
|
-
unit: '
|
|
42
|
+
unit: '',
|
|
34
43
|
value: 0
|
|
35
44
|
};
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
if (isFinite(Number(string))) {
|
|
48
|
+
if ('px'.search(unitRegExp) >= 0) {
|
|
49
|
+
return {
|
|
50
|
+
unit: 'px',
|
|
51
|
+
value: Number(string)
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
return {
|
|
55
|
+
unit: '',
|
|
56
|
+
value: Number(string)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (string.endsWith('em')) {
|
|
62
|
+
var pxValue = 0;
|
|
63
|
+
|
|
64
|
+
if (object.parentElement) {
|
|
65
|
+
var fontSize = object.parentElement.parsedStyle.fontSize;
|
|
66
|
+
|
|
67
|
+
if (fontSize && fontSize.value) {
|
|
68
|
+
pxValue = fontSize.value * Number(string.replace('em', ''));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
39
72
|
return {
|
|
40
|
-
unit: '',
|
|
41
|
-
value:
|
|
73
|
+
unit: 'px',
|
|
74
|
+
value: pxValue
|
|
42
75
|
};
|
|
43
76
|
}
|
|
44
77
|
|
|
@@ -94,8 +127,16 @@ export function mergeDimensions(left, right, nonNegative, target, index) {
|
|
|
94
127
|
}];
|
|
95
128
|
}
|
|
96
129
|
var lengthUnits = 'px';
|
|
130
|
+
/**
|
|
131
|
+
* length with only absolute unit, eg. 1px
|
|
132
|
+
*/
|
|
133
|
+
|
|
97
134
|
export var parseLength = parseDimension.bind(null, new RegExp(lengthUnits, 'g'));
|
|
98
|
-
|
|
135
|
+
/**
|
|
136
|
+
* length with absolute or relative unit, eg. 1px, 0.7em, 50%
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
export var parseLengthOrPercent = parseDimension.bind(null, new RegExp(lengthUnits + '|%|em', 'g'));
|
|
99
140
|
export var parseAngle = parseDimension.bind(null, /deg|rad|grad|turn/g);
|
|
100
141
|
export function parseLengthOrPercentList(list) {
|
|
101
142
|
return list.map(parseLengthOrPercent);
|
|
@@ -15,4 +15,7 @@ export * from './dimension';
|
|
|
15
15
|
export * from './path';
|
|
16
16
|
export * from './points';
|
|
17
17
|
export * from './filter';
|
|
18
|
-
export * from './lineDash';
|
|
18
|
+
export * from './lineDash';
|
|
19
|
+
export * from './text';
|
|
20
|
+
export * from './textTransform';
|
|
21
|
+
export * from './inherit';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DisplayObject } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* update descendants
|
|
4
|
+
*/
|
|
5
|
+
export declare function updateInherit(oldValue: any, newValue: any, o: DisplayObject, service: any, name: string): void;
|
|
6
|
+
export declare function computeInheritStyleProperty(child: DisplayObject, name: string): any;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* update descendants
|
|
3
|
+
*/
|
|
4
|
+
export function updateInherit(oldValue, newValue, o, service, name) {
|
|
5
|
+
o.children.forEach(function (child) {
|
|
6
|
+
if (child.getAttribute(name) === 'inherit') {
|
|
7
|
+
child.parsedStyle[name] = newValue;
|
|
8
|
+
var oldParsedValue = child.parsedStyle[name];
|
|
9
|
+
child.updateStyleProperty(name, oldParsedValue, newValue);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export function computeInheritStyleProperty(child, name) {
|
|
14
|
+
var ascendant = child.parentElement;
|
|
15
|
+
|
|
16
|
+
while (ascendant) {
|
|
17
|
+
if (ascendant.getAttribute(name) !== 'inherit' && ascendant.parsedStyle.hasOwnProperty(name)) {
|
|
18
|
+
return ascendant.parsedStyle[name];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
ascendant = ascendant.parentElement;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IElement } from '../dom/interfaces';
|
|
2
2
|
import type { SceneGraphService } from '../services/SceneGraphService';
|
|
3
3
|
export declare const StylePropertyParser = "StylePropertyParser";
|
|
4
|
-
export declare type StylePropertyParser<Original, Parsed> = (value: Original, displayObject: IElement | null) => Parsed;
|
|
4
|
+
export declare type StylePropertyParser<Original, Parsed> = (value: Original, displayObject: IElement | null, name: string) => Parsed;
|
|
5
5
|
export declare const StylePropertyParserFactory = "StylePropertyParserFactory";
|
|
6
6
|
export declare type StylePropertyParserFactory = <Original, Parsed>(name: string) => StylePropertyParser<Original, Parsed>;
|
|
7
7
|
export interface ParsedStyleProperty<T, V, Formatted = string> {
|
|
@@ -11,7 +11,7 @@ export interface ParsedStyleProperty<T, V, Formatted = string> {
|
|
|
11
11
|
}
|
|
12
12
|
export declare type Interpolatable = number | boolean | number[] | boolean[];
|
|
13
13
|
export declare const StylePropertyUpdater = "StylePropertyUpdater";
|
|
14
|
-
export declare type StylePropertyUpdater<Original> = (oldValue: Original, newValue: Original, displayObject: IElement, sceneGraphService: SceneGraphService) => void;
|
|
14
|
+
export declare type StylePropertyUpdater<Original> = (oldValue: Original, newValue: Original, displayObject: IElement, sceneGraphService: SceneGraphService, name: string) => void;
|
|
15
15
|
export declare const StylePropertyUpdaterFactory = "StylePropertyUpdaterFactory";
|
|
16
16
|
export declare type StylePropertyUpdaterFactory = <Original>(name: string) => StylePropertyUpdater<Original>;
|
|
17
17
|
export declare const StylePropertyMerger = "StylePropertyMerger";
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* format lineDash to [dash, dash]
|
|
3
|
+
*
|
|
4
|
+
* also support string format such as `"stroke-dasharray": "2px 4px"`
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseLineDash(lineDash: number[] | string): number[];
|
|
@@ -1,8 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import { __read, __spreadArray } from "tslib";
|
|
2
|
+
import { isString } from '@antv/util';
|
|
3
|
+
import { parseLength } from './dimension';
|
|
4
|
+
/**
|
|
5
|
+
* format lineDash to [dash, dash]
|
|
6
|
+
*
|
|
7
|
+
* also support string format such as `"stroke-dasharray": "2px 4px"`
|
|
8
|
+
*/
|
|
9
|
+
|
|
2
10
|
export function parseLineDash(lineDash) {
|
|
3
|
-
|
|
4
|
-
|
|
11
|
+
var formatted = [];
|
|
12
|
+
|
|
13
|
+
if (isString(lineDash)) {
|
|
14
|
+
lineDash.split(' ').forEach(function (segment) {
|
|
15
|
+
var dimension = parseLength(segment);
|
|
16
|
+
formatted.push(dimension.value);
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
formatted.push.apply(formatted, __spreadArray([], __read(lineDash), false));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (formatted && formatted.length === 1) {
|
|
23
|
+
return [formatted[0], formatted[0]];
|
|
5
24
|
}
|
|
6
25
|
|
|
7
|
-
return [
|
|
26
|
+
return [formatted[0], formatted[1]];
|
|
8
27
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Shape } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* @see /zh/docs/api/animation#%E8%B7%AF%E5%BE%84%E5%8A%A8%E7%94%BB
|
|
4
4
|
*/
|
|
@@ -10,7 +10,7 @@ export function updateOffsetDistance(oldOffsetDistance, newOffsetDistance, objec
|
|
|
10
10
|
|
|
11
11
|
var offsetPathNodeName = object.attributes.offsetPath.nodeName;
|
|
12
12
|
|
|
13
|
-
if (offsetPathNodeName ===
|
|
13
|
+
if (offsetPathNodeName === Shape.LINE || offsetPathNodeName === Shape.PATH || offsetPathNodeName === Shape.POLYLINE) {
|
|
14
14
|
var point = object.attributes.offsetPath.getPoint(newOffsetDistance);
|
|
15
15
|
|
|
16
16
|
if (point) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TextTransform } from '../types';
|
|
2
|
+
import type { DisplayObject } from '../display-objects';
|
|
3
|
+
/**
|
|
4
|
+
* @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/text-transform
|
|
5
|
+
*/
|
|
6
|
+
export declare function updateTextTransform(oldTextTransform: TextTransform, newTextTransform: TextTransform, o: DisplayObject): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TextTransform } from '../types';
|
|
2
|
+
import { Shape } from '..';
|
|
3
|
+
/**
|
|
4
|
+
* @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/text-transform
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export function updateTextTransform(oldTextTransform, newTextTransform, o) {
|
|
8
|
+
if (o.nodeName === Shape.TEXT) {
|
|
9
|
+
var object = o;
|
|
10
|
+
|
|
11
|
+
if (newTextTransform === TextTransform.CAPITALIZE) {
|
|
12
|
+
object.style.text = object.style.text.charAt(0).toUpperCase() + object.style.text.slice(1);
|
|
13
|
+
} else if (newTextTransform === TextTransform.LOWERCASE) {
|
|
14
|
+
object.style.text = object.style.text.toLowerCase();
|
|
15
|
+
} else if (newTextTransform === TextTransform.UPPERCASE) {
|
|
16
|
+
object.style.text = object.style.text.toUpperCase(); // } else if (newTextTransform === TextTransform.NONE) {
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -149,10 +149,8 @@ function (_super) {
|
|
|
149
149
|
clickHistory.timeStamp = now;
|
|
150
150
|
clickEvent.detail = clickHistory.clickCount;
|
|
151
151
|
|
|
152
|
-
if (clickEvent.pointerType === 'mouse') {
|
|
152
|
+
if (clickEvent.pointerType === 'mouse' || clickEvent.pointerType === 'touch') {
|
|
153
153
|
this.dispatchEvent(clickEvent, 'click');
|
|
154
|
-
} else if (clickEvent.pointerType === 'touch') {
|
|
155
|
-
this.dispatchEvent(clickEvent, 'tap');
|
|
156
154
|
} else {
|
|
157
155
|
this.dispatchEvent(clickEvent, 'pointertap');
|
|
158
156
|
}
|
|
@@ -563,7 +561,7 @@ function (_super) {
|
|
|
563
561
|
mappers[i].fn(e);
|
|
564
562
|
}
|
|
565
563
|
} else {
|
|
566
|
-
console.warn("[EventService]: Event mapping not defined for "
|
|
564
|
+
console.warn("[EventService]: Event mapping not defined for ".concat(e.type));
|
|
567
565
|
}
|
|
568
566
|
};
|
|
569
567
|
|
|
@@ -853,7 +851,7 @@ function (_super) {
|
|
|
853
851
|
|
|
854
852
|
EventService.prototype.notifyTarget = function (e, type) {
|
|
855
853
|
type = type !== null && type !== void 0 ? type : e.type;
|
|
856
|
-
var key = e.eventPhase === e.CAPTURING_PHASE || e.eventPhase === e.AT_TARGET ? type
|
|
854
|
+
var key = e.eventPhase === e.CAPTURING_PHASE || e.eventPhase === e.AT_TARGET ? "".concat(type, "capture") : type;
|
|
857
855
|
this.notifyListeners(e, key);
|
|
858
856
|
|
|
859
857
|
if (e.eventPhase === e.AT_TARGET) {
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { Group } from '../display-objects';
|
|
2
|
-
import type { AABB } from '../shapes';
|
|
3
2
|
/**
|
|
4
3
|
* why we need re-render
|
|
5
4
|
*/
|
|
6
|
-
export declare enum
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
None = 3
|
|
5
|
+
export declare enum RenderReason {
|
|
6
|
+
CAMERA_CHANGED = 0,
|
|
7
|
+
DISPLAY_OBJECT_CHANGED = 1,
|
|
8
|
+
NONE = 2
|
|
11
9
|
}
|
|
12
10
|
export declare const RenderingContext = "RenderingContext";
|
|
13
11
|
export interface RenderingContext {
|
|
@@ -19,10 +17,9 @@ export interface RenderingContext {
|
|
|
19
17
|
* force rendering at next frame
|
|
20
18
|
*/
|
|
21
19
|
force: boolean;
|
|
22
|
-
removedRenderBoundsList: AABB[];
|
|
23
20
|
/**
|
|
24
21
|
* reason of re-render, reset after every renderred frame
|
|
25
22
|
*/
|
|
26
|
-
renderReasons: Set<
|
|
23
|
+
renderReasons: Set<RenderReason>;
|
|
27
24
|
dirty: boolean;
|
|
28
25
|
}
|