@antv/g 5.0.14 → 5.0.17
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/es/AbstractRenderer.js +1 -3
- package/es/Canvas.d.ts +3 -0
- package/es/Canvas.js +10 -12
- package/es/DisplayObjectPool.js +1 -3
- package/es/camera/Camera.d.ts +3 -2
- package/es/camera/Camera.js +17 -11
- package/es/camera/Landmark.js +1 -3
- package/es/canvas-module.js +11 -17
- package/es/components/Cullable.js +1 -3
- package/es/components/Geometry.js +1 -3
- package/es/components/Renderable.js +1 -3
- package/es/components/Sortable.js +1 -3
- package/es/components/Transform.d.ts +0 -1
- package/es/components/Transform.js +1 -4
- package/es/display-objects/Circle.d.ts +4 -2
- package/es/display-objects/Circle.js +9 -6
- package/es/display-objects/CustomElement.d.ts +3 -2
- package/es/display-objects/CustomElement.js +10 -9
- package/es/display-objects/DisplayObject.d.ts +9 -3
- package/es/display-objects/DisplayObject.js +98 -50
- package/es/display-objects/Ellipse.d.ts +6 -3
- package/es/display-objects/Ellipse.js +9 -6
- package/es/display-objects/Group.d.ts +18 -2
- package/es/display-objects/Group.js +15 -12
- package/es/display-objects/HTML.d.ts +6 -1
- package/es/display-objects/HTML.js +8 -6
- package/es/display-objects/Image.d.ts +12 -7
- package/es/display-objects/Image.js +11 -6
- package/es/display-objects/Line.d.ts +1 -1
- package/es/display-objects/Line.js +13 -7
- package/es/display-objects/Path.d.ts +3 -2
- package/es/display-objects/Path.js +11 -8
- package/es/display-objects/Polygon.d.ts +1 -1
- package/es/display-objects/Polygon.js +10 -6
- package/es/display-objects/Polyline.d.ts +1 -1
- package/es/display-objects/Polyline.js +11 -8
- package/es/display-objects/Rect.d.ts +8 -5
- package/es/display-objects/Rect.js +10 -7
- package/es/display-objects/TSpan.d.ts +1 -0
- package/es/display-objects/TSpan.js +0 -0
- package/es/display-objects/Text.d.ts +32 -4
- package/es/display-objects/Text.js +71 -14
- package/es/dom/Animation.js +2 -4
- package/es/dom/AnimationEffectTiming.js +1 -3
- package/es/dom/AnimationEvent.js +1 -3
- package/es/dom/AnimationTimeline.js +2 -5
- package/es/dom/CustomElementRegistry.js +13 -15
- package/es/dom/CustomEvent.js +1 -3
- package/es/dom/Document.d.ts +2 -1
- package/es/dom/Document.js +23 -5
- package/es/dom/Element.d.ts +36 -9
- package/es/dom/Element.js +103 -15
- package/es/dom/EventTarget.d.ts +2 -2
- package/es/dom/EventTarget.js +3 -4
- package/es/dom/FederatedEvent.d.ts +5 -2
- package/es/dom/FederatedEvent.js +1 -3
- package/es/dom/FederatedMouseEvent.js +1 -3
- package/es/dom/FederatedPointerEvent.js +1 -3
- package/es/dom/FederatedWheelEvent.js +1 -3
- package/es/dom/KeyframeEffect.js +1 -3
- package/es/dom/MutationEvent.d.ts +15 -0
- package/es/dom/MutationEvent.js +27 -0
- package/es/dom/MutationObserver.d.ts +36 -0
- package/es/dom/MutationObserver.js +406 -0
- package/es/dom/MutationRecord.d.ts +14 -0
- package/es/dom/MutationRecord.js +29 -0
- package/es/dom/Node.d.ts +35 -3
- package/es/dom/Node.js +185 -20
- 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 +4 -1
- package/es/global-module.js +36 -79
- 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 +4 -27
- package/es/plugins/DirtyCheckPlugin.js +3 -5
- package/es/plugins/EventPlugin.d.ts +2 -1
- package/es/plugins/EventPlugin.js +16 -8
- package/es/plugins/FrustumCullingStrategy.d.ts +1 -0
- package/es/plugins/FrustumCullingStrategy.js +40 -35
- package/es/plugins/PrepareRendererPlugin.js +22 -8
- package/es/property-handlers/aabb.js +22 -24
- package/es/property-handlers/anchor.js +2 -1
- package/es/property-handlers/color.js +3 -0
- package/es/property-handlers/dimension.d.ts +15 -2
- package/es/property-handlers/dimension.js +77 -8
- 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/path.d.ts +1 -1
- 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 +2 -6
- package/es/services/RenderingContext.d.ts +5 -8
- package/es/services/RenderingContext.js +6 -7
- package/es/services/RenderingService.js +3 -11
- package/es/services/SceneGraphSelector.d.ts +3 -2
- package/es/services/SceneGraphSelector.js +9 -7
- package/es/services/SceneGraphService.d.ts +7 -14
- package/es/services/SceneGraphService.js +15 -85
- package/es/services/aabb/CircleUpdater.d.ts +2 -2
- package/es/services/aabb/CircleUpdater.js +22 -14
- package/es/services/aabb/EllipseUpdater.d.ts +2 -2
- package/es/services/aabb/EllipseUpdater.js +29 -16
- package/es/services/aabb/LineUpdater.js +3 -5
- package/es/services/aabb/PathUpdater.js +3 -5
- package/es/services/aabb/PolylineUpdater.js +4 -6
- package/es/services/aabb/RectUpdater.d.ts +2 -2
- package/es/services/aabb/RectUpdater.js +32 -21
- package/es/services/aabb/TextUpdater.js +20 -13
- package/es/services/text/OffscreenCanvasCreator.js +1 -3
- package/es/services/text/index.js +18 -22
- package/es/shapes/AABB.d.ts +1 -0
- package/es/shapes/AABB.js +9 -3
- package/es/shapes/BoundingSphere.js +1 -3
- package/es/shapes/Frustum.js +1 -3
- package/es/shapes/Plane.js +1 -3
- package/es/shapes/Point.js +1 -3
- package/es/shapes/Polygon.js +1 -3
- package/es/shapes/Ray.js +1 -3
- package/es/shapes/Rect.js +1 -3
- package/es/shapes/Rectangle.js +1 -3
- package/es/types.d.ts +48 -26
- package/es/types.js +50 -31
- package/es/utils/animation.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.d.ts +1 -1
- package/es/utils/path.js +13 -13
- 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 +1 -1
- package/lib/AbstractRenderer.js +1 -3
- package/lib/Canvas.d.ts +3 -0
- package/lib/Canvas.js +9 -11
- package/lib/DisplayObjectPool.js +1 -3
- package/lib/camera/Camera.d.ts +3 -2
- package/lib/camera/Camera.js +21 -13
- package/lib/camera/Landmark.js +1 -3
- package/lib/canvas-module.js +10 -15
- package/lib/components/Cullable.js +2 -4
- package/lib/components/Geometry.js +1 -3
- package/lib/components/Renderable.js +1 -3
- package/lib/components/Sortable.js +1 -3
- package/lib/components/Transform.d.ts +0 -1
- package/lib/components/Transform.js +1 -4
- package/lib/display-objects/Circle.d.ts +4 -2
- package/lib/display-objects/Circle.js +8 -5
- package/lib/display-objects/CustomElement.d.ts +3 -2
- package/lib/display-objects/CustomElement.js +10 -9
- package/lib/display-objects/DisplayObject.d.ts +9 -3
- package/lib/display-objects/DisplayObject.js +98 -47
- package/lib/display-objects/Ellipse.d.ts +6 -3
- package/lib/display-objects/Ellipse.js +8 -5
- package/lib/display-objects/Group.d.ts +18 -2
- package/lib/display-objects/Group.js +14 -12
- package/lib/display-objects/HTML.d.ts +6 -1
- package/lib/display-objects/HTML.js +7 -5
- package/lib/display-objects/Image.d.ts +12 -7
- package/lib/display-objects/Image.js +10 -5
- package/lib/display-objects/Line.d.ts +1 -1
- package/lib/display-objects/Line.js +12 -6
- package/lib/display-objects/Path.d.ts +3 -2
- package/lib/display-objects/Path.js +10 -7
- package/lib/display-objects/Polygon.d.ts +1 -1
- package/lib/display-objects/Polygon.js +9 -5
- package/lib/display-objects/Polyline.d.ts +1 -1
- package/lib/display-objects/Polyline.js +10 -7
- package/lib/display-objects/Rect.d.ts +8 -5
- package/lib/display-objects/Rect.js +9 -6
- package/lib/display-objects/TSpan.d.ts +1 -0
- package/lib/display-objects/TSpan.js +1 -0
- package/lib/display-objects/Text.d.ts +32 -4
- package/lib/display-objects/Text.js +71 -13
- package/lib/dom/Animation.js +2 -4
- package/lib/dom/AnimationEffectTiming.js +1 -3
- package/lib/dom/AnimationEvent.js +1 -3
- package/lib/dom/AnimationTimeline.js +3 -6
- package/lib/dom/CustomElementRegistry.js +12 -14
- package/lib/dom/CustomEvent.js +1 -3
- package/lib/dom/Document.d.ts +2 -1
- package/lib/dom/Document.js +25 -6
- package/lib/dom/Element.d.ts +36 -9
- package/lib/dom/Element.js +105 -15
- package/lib/dom/EventTarget.d.ts +2 -2
- package/lib/dom/EventTarget.js +3 -4
- package/lib/dom/FederatedEvent.d.ts +5 -2
- package/lib/dom/FederatedEvent.js +1 -3
- package/lib/dom/FederatedMouseEvent.js +1 -3
- package/lib/dom/FederatedPointerEvent.js +1 -3
- package/lib/dom/FederatedWheelEvent.js +1 -3
- package/lib/dom/KeyframeEffect.js +2 -4
- package/lib/dom/MutationEvent.d.ts +15 -0
- package/lib/dom/MutationEvent.js +35 -0
- package/lib/dom/MutationObserver.d.ts +36 -0
- package/lib/dom/MutationObserver.js +417 -0
- package/lib/dom/MutationRecord.d.ts +14 -0
- package/lib/dom/MutationRecord.js +36 -0
- package/lib/dom/Node.d.ts +35 -3
- package/lib/dom/Node.js +186 -19
- 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 +4 -1
- package/lib/global-module.js +42 -76
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/plugins/CullingPlugin.d.ts +0 -2
- package/lib/plugins/CullingPlugin.js +4 -27
- package/lib/plugins/DirtyCheckPlugin.js +2 -4
- package/lib/plugins/EventPlugin.d.ts +2 -1
- package/lib/plugins/EventPlugin.js +14 -8
- package/lib/plugins/FrustumCullingStrategy.d.ts +1 -0
- package/lib/plugins/FrustumCullingStrategy.js +41 -35
- package/lib/plugins/PrepareRendererPlugin.js +25 -7
- package/lib/property-handlers/aabb.js +21 -23
- package/lib/property-handlers/anchor.js +3 -1
- package/lib/property-handlers/color.js +5 -2
- package/lib/property-handlers/dimension.d.ts +15 -2
- package/lib/property-handlers/dimension.js +84 -12
- 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/interfaces.js +1 -1
- package/lib/property-handlers/lineDash.d.ts +6 -1
- package/lib/property-handlers/lineDash.js +25 -4
- package/lib/property-handlers/numeric.js +3 -3
- package/lib/property-handlers/offsetDistance.js +1 -1
- package/lib/property-handlers/path.d.ts +1 -1
- package/lib/property-handlers/path.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/property-handlers/transform.js +1 -1
- package/lib/services/EventService.js +2 -6
- package/lib/services/RenderingContext.d.ts +5 -8
- package/lib/services/RenderingContext.js +8 -9
- package/lib/services/RenderingService.js +2 -10
- package/lib/services/SceneGraphSelector.d.ts +3 -2
- package/lib/services/SceneGraphSelector.js +12 -7
- package/lib/services/SceneGraphService.d.ts +7 -14
- package/lib/services/SceneGraphService.js +18 -87
- package/lib/services/aabb/CircleUpdater.d.ts +2 -2
- package/lib/services/aabb/CircleUpdater.js +21 -13
- package/lib/services/aabb/EllipseUpdater.d.ts +2 -2
- package/lib/services/aabb/EllipseUpdater.js +28 -15
- package/lib/services/aabb/LineUpdater.js +2 -4
- package/lib/services/aabb/PathUpdater.js +2 -4
- package/lib/services/aabb/PolylineUpdater.js +3 -5
- package/lib/services/aabb/RectUpdater.d.ts +2 -2
- package/lib/services/aabb/RectUpdater.js +31 -20
- package/lib/services/aabb/TextUpdater.js +19 -12
- package/lib/services/aabb/index.js +10 -10
- package/lib/services/aabb/interfaces.js +1 -1
- package/lib/services/text/OffscreenCanvasCreator.js +1 -3
- package/lib/services/text/index.js +18 -22
- package/lib/shapes/AABB.d.ts +1 -0
- package/lib/shapes/AABB.js +9 -3
- package/lib/shapes/BoundingSphere.js +1 -3
- package/lib/shapes/Frustum.js +2 -4
- package/lib/shapes/Plane.js +1 -3
- package/lib/shapes/Point.js +1 -3
- package/lib/shapes/Polygon.js +1 -3
- package/lib/shapes/Ray.js +1 -3
- package/lib/shapes/Rect.js +1 -3
- package/lib/shapes/Rectangle.js +1 -3
- package/lib/types.d.ts +48 -26
- package/lib/types.js +56 -35
- package/lib/utils/animation.js +3 -4
- package/lib/utils/bezier-easing.js +1 -1
- package/lib/utils/custom-easing.js +1 -1
- package/lib/utils/event.js +7 -6
- 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/math.js +5 -5
- package/lib/utils/path.d.ts +1 -1
- package/lib/utils/path.js +15 -15
- package/lib/utils/raf.d.ts +1 -1
- package/lib/utils/raf.js +1 -4
- package/lib/utils/string.d.ts +1 -0
- package/lib/utils/string.js +16 -0
- package/lib/utils/text.js +1 -1
- package/package.json +6 -4
- package/dist/index.umd.min.js +0 -15
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import {
|
|
2
|
+
import { singleton, contrib, Syringe, Contribution } from 'mana-syringe';
|
|
3
3
|
import { RenderingPluginContribution } from '../services/RenderingService';
|
|
4
|
-
import { RenderingContext, RENDER_REASON } from '../services/RenderingContext';
|
|
5
|
-
import { CanvasConfig } from '../types';
|
|
6
4
|
export var CullingStrategyContribution = Syringe.defineToken('CullingStrategyContribution');
|
|
7
5
|
/**
|
|
8
6
|
* apply following rules:
|
|
@@ -10,16 +8,12 @@ export var CullingStrategyContribution = Syringe.defineToken('CullingStrategyCon
|
|
|
10
8
|
* 2. other custom culling strategies, eg. frustum culling
|
|
11
9
|
*/
|
|
12
10
|
|
|
13
|
-
var CullingPlugin =
|
|
14
|
-
/** @class */
|
|
15
|
-
function () {
|
|
11
|
+
var CullingPlugin = function () {
|
|
16
12
|
function CullingPlugin() {}
|
|
17
13
|
|
|
18
14
|
CullingPlugin_1 = CullingPlugin;
|
|
19
15
|
|
|
20
16
|
CullingPlugin.prototype.apply = function (renderingService) {
|
|
21
|
-
var _this = this;
|
|
22
|
-
|
|
23
17
|
var strategies = this.strategyProvider.getContributions();
|
|
24
18
|
renderingService.hooks.prepare.tap(CullingPlugin_1.tag, function (object) {
|
|
25
19
|
if (object) {
|
|
@@ -36,22 +30,9 @@ function () {
|
|
|
36
30
|
|
|
37
31
|
if (object.isVisible()) {
|
|
38
32
|
return object;
|
|
39
|
-
} else {
|
|
40
|
-
// Those invisible objects which get renderred in last frame should be saved for later use.
|
|
41
|
-
var enableDirtyRectangleRendering = _this.canvasConfig.renderer.getConfig().enableDirtyRectangleRendering;
|
|
42
|
-
|
|
43
|
-
if (enableDirtyRectangleRendering) {
|
|
44
|
-
var removedRenderBounds = object.getRenderBounds();
|
|
45
|
-
|
|
46
|
-
if (removedRenderBounds) {
|
|
47
|
-
_this.renderingContext.removedRenderBoundsList.push(removedRenderBounds);
|
|
48
|
-
|
|
49
|
-
_this.renderingContext.renderReasons.add(RENDER_REASON.DisplayObjectRemoved);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return null;
|
|
54
33
|
}
|
|
34
|
+
|
|
35
|
+
return null;
|
|
55
36
|
}
|
|
56
37
|
|
|
57
38
|
return object;
|
|
@@ -64,12 +45,8 @@ function () {
|
|
|
64
45
|
var CullingPlugin_1;
|
|
65
46
|
CullingPlugin.tag = 'CullingPlugin';
|
|
66
47
|
|
|
67
|
-
__decorate([inject(CanvasConfig), __metadata("design:type", Object)], CullingPlugin.prototype, "canvasConfig", void 0);
|
|
68
|
-
|
|
69
48
|
__decorate([contrib(CullingStrategyContribution), __metadata("design:type", Object)], CullingPlugin.prototype, "strategyProvider", void 0);
|
|
70
49
|
|
|
71
|
-
__decorate([inject(RenderingContext), __metadata("design:type", Object)], CullingPlugin.prototype, "renderingContext", void 0);
|
|
72
|
-
|
|
73
50
|
CullingPlugin = CullingPlugin_1 = __decorate([singleton({
|
|
74
51
|
contrib: RenderingPluginContribution
|
|
75
52
|
})], CullingPlugin);
|
|
@@ -2,14 +2,12 @@ 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
|
*/
|
|
9
9
|
|
|
10
|
-
var DirtyCheckPlugin =
|
|
11
|
-
/** @class */
|
|
12
|
-
function () {
|
|
10
|
+
var DirtyCheckPlugin = function () {
|
|
13
11
|
function DirtyCheckPlugin() {}
|
|
14
12
|
|
|
15
13
|
DirtyCheckPlugin_1 = DirtyCheckPlugin;
|
|
@@ -23,7 +21,7 @@ function () {
|
|
|
23
21
|
|
|
24
22
|
var renderable = object.renderable;
|
|
25
23
|
|
|
26
|
-
var isDirty = renderable.dirty || _this.renderingContext.renderReasons.has(
|
|
24
|
+
var isDirty = renderable.dirty || _this.renderingContext.renderReasons.has(RenderReason.CAMERA_CHANGED);
|
|
27
25
|
|
|
28
26
|
if (isDirty || !enableDirtyRectangleRendering) {
|
|
29
27
|
return object;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RenderingPlugin } from '../services';
|
|
2
2
|
import { RenderingService } from '../services';
|
|
3
3
|
/**
|
|
4
4
|
* support mouse & touch events
|
|
@@ -11,6 +11,7 @@ export declare class EventPlugin implements RenderingPlugin {
|
|
|
11
11
|
private canvasConfig;
|
|
12
12
|
private contextService;
|
|
13
13
|
private renderingService;
|
|
14
|
+
private renderingContext;
|
|
14
15
|
private eventService;
|
|
15
16
|
private autoPreventDefault;
|
|
16
17
|
private rootPointerEvent;
|
|
@@ -2,6 +2,7 @@ import { __awaiter, __decorate, __generator, __metadata, __values } from "tslib"
|
|
|
2
2
|
import { inject, singleton } from 'mana-syringe';
|
|
3
3
|
import { FederatedPointerEvent } from '../dom/FederatedPointerEvent';
|
|
4
4
|
import { FederatedWheelEvent } from '../dom/FederatedWheelEvent';
|
|
5
|
+
import { RenderingContext } from '../services';
|
|
5
6
|
import { ContextService, RenderingService, EventService, RenderingPluginContribution } from '../services';
|
|
6
7
|
import { Point } from '../shapes';
|
|
7
8
|
import { CanvasConfig } from '../types';
|
|
@@ -13,9 +14,7 @@ import { normalizeToPointerEvent, supportsTouchEvents, TOUCH_TO_POINTER } from '
|
|
|
13
14
|
* also provide some extra events such as `drag`
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
|
-
var EventPlugin =
|
|
17
|
-
/** @class */
|
|
18
|
-
function () {
|
|
17
|
+
var EventPlugin = function () {
|
|
19
18
|
function EventPlugin() {
|
|
20
19
|
var _this = this;
|
|
21
20
|
|
|
@@ -26,6 +25,8 @@ function () {
|
|
|
26
25
|
this.onPointerMove = function (nativeEvent) {
|
|
27
26
|
var e_1, _a;
|
|
28
27
|
|
|
28
|
+
var _b, _c;
|
|
29
|
+
|
|
29
30
|
if (supportsTouchEvents && nativeEvent.pointerType === 'touch') return;
|
|
30
31
|
var normalizedEvents = normalizeToPointerEvent(nativeEvent);
|
|
31
32
|
|
|
@@ -33,7 +34,7 @@ function () {
|
|
|
33
34
|
for (var normalizedEvents_1 = __values(normalizedEvents), normalizedEvents_1_1 = normalizedEvents_1.next(); !normalizedEvents_1_1.done; normalizedEvents_1_1 = normalizedEvents_1.next()) {
|
|
34
35
|
var normalizedEvent = normalizedEvents_1_1.value;
|
|
35
36
|
|
|
36
|
-
var event_1 = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent);
|
|
37
|
+
var event_1 = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, (_c = (_b = _this.renderingContext.root) === null || _b === void 0 ? void 0 : _b.ownerDocument) === null || _c === void 0 ? void 0 : _c.defaultView);
|
|
37
38
|
|
|
38
39
|
_this.eventService.mapEvent(event_1);
|
|
39
40
|
}
|
|
@@ -88,6 +89,8 @@ function () {
|
|
|
88
89
|
renderingService.hooks.pointerDown.tap(EventPlugin_1.tag, function (nativeEvent) {
|
|
89
90
|
var e_2, _a;
|
|
90
91
|
|
|
92
|
+
var _b, _c;
|
|
93
|
+
|
|
91
94
|
if (supportsTouchEvents && nativeEvent.pointerType === 'touch') {
|
|
92
95
|
return;
|
|
93
96
|
}
|
|
@@ -106,7 +109,7 @@ function () {
|
|
|
106
109
|
for (var events_1 = __values(events), events_1_1 = events_1.next(); !events_1_1.done; events_1_1 = events_1.next()) {
|
|
107
110
|
var event_2 = events_1_1.value;
|
|
108
111
|
|
|
109
|
-
var federatedEvent = _this.bootstrapEvent(_this.rootPointerEvent, event_2);
|
|
112
|
+
var federatedEvent = _this.bootstrapEvent(_this.rootPointerEvent, event_2, (_c = (_b = _this.renderingContext.root) === null || _b === void 0 ? void 0 : _b.ownerDocument) === null || _c === void 0 ? void 0 : _c.defaultView);
|
|
110
113
|
|
|
111
114
|
_this.eventService.mapEvent(federatedEvent);
|
|
112
115
|
}
|
|
@@ -127,6 +130,8 @@ function () {
|
|
|
127
130
|
renderingService.hooks.pointerUp.tap(EventPlugin_1.tag, function (nativeEvent) {
|
|
128
131
|
var e_3, _a;
|
|
129
132
|
|
|
133
|
+
var _b, _c;
|
|
134
|
+
|
|
130
135
|
if (supportsTouchEvents && nativeEvent.pointerType === 'touch') return; // account for element in SVG
|
|
131
136
|
|
|
132
137
|
var $element = _this.contextService.getDomElement();
|
|
@@ -140,7 +145,7 @@ function () {
|
|
|
140
145
|
for (var normalizedEvents_2 = __values(normalizedEvents), normalizedEvents_2_1 = normalizedEvents_2.next(); !normalizedEvents_2_1.done; normalizedEvents_2_1 = normalizedEvents_2.next()) {
|
|
141
146
|
var normalizedEvent = normalizedEvents_2_1.value;
|
|
142
147
|
|
|
143
|
-
var event_3 = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent);
|
|
148
|
+
var event_3 = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, (_c = (_b = _this.renderingContext.root) === null || _b === void 0 ? void 0 : _b.ownerDocument) === null || _c === void 0 ? void 0 : _c.defaultView);
|
|
144
149
|
|
|
145
150
|
event_3.type += outside;
|
|
146
151
|
|
|
@@ -165,8 +170,9 @@ function () {
|
|
|
165
170
|
renderingService.hooks.pointerOut.tap(EventPlugin_1.tag, this.onPointerMove);
|
|
166
171
|
};
|
|
167
172
|
|
|
168
|
-
EventPlugin.prototype.bootstrapEvent = function (event, nativeEvent) {
|
|
169
|
-
// @ts-ignore
|
|
173
|
+
EventPlugin.prototype.bootstrapEvent = function (event, nativeEvent, view) {
|
|
174
|
+
event.view = view; // @ts-ignore
|
|
175
|
+
|
|
170
176
|
event._originalEvent = null;
|
|
171
177
|
event.nativeEvent = nativeEvent;
|
|
172
178
|
event.pointerId = nativeEvent.pointerId;
|
|
@@ -278,6 +284,8 @@ function () {
|
|
|
278
284
|
|
|
279
285
|
__decorate([inject(RenderingService), __metadata("design:type", RenderingService)], EventPlugin.prototype, "renderingService", void 0);
|
|
280
286
|
|
|
287
|
+
__decorate([inject(RenderingContext), __metadata("design:type", Object)], EventPlugin.prototype, "renderingContext", void 0);
|
|
288
|
+
|
|
281
289
|
__decorate([inject(EventService), __metadata("design:type", EventService)], EventPlugin.prototype, "eventService", void 0);
|
|
282
290
|
|
|
283
291
|
EventPlugin = EventPlugin_1 = __decorate([singleton({
|
|
@@ -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,37 @@
|
|
|
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
8
|
|
|
9
|
-
var
|
|
10
|
-
/** @class */
|
|
11
|
-
function () {
|
|
12
|
-
function FrustumCullingStrategy() {} // @inject(DefaultCamera)
|
|
13
|
-
// private camera: Camera;
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
+
var shape2D = [Shape.CIRCLE, Shape.ELLIPSE, Shape.IMAGE, Shape.RECT, Shape.LINE, Shape.POLYLINE, Shape.POLYGON, Shape.TEXT, Shape.PATH, Shape.HTML];
|
|
15
10
|
|
|
11
|
+
var FrustumCullingStrategy = function () {
|
|
12
|
+
function FrustumCullingStrategy() {}
|
|
16
13
|
|
|
17
14
|
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;
|
|
15
|
+
var _a, _b;
|
|
16
|
+
|
|
17
|
+
var cullable = object.cullable;
|
|
18
|
+
|
|
19
|
+
if (!cullable.enable) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var renderBounds = object.getRenderBounds();
|
|
24
|
+
|
|
25
|
+
if (!renderBounds) {
|
|
26
|
+
return false;
|
|
27
|
+
} // get VP matrix from camera
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var frustum = this.camera.getFrustum();
|
|
31
|
+
var parentVisibilityPlaneMask = (_b = (_a = object.parentNode) === null || _a === void 0 ? void 0 : _a.cullable) === null || _b === void 0 ? void 0 : _b.visibilityPlaneMask;
|
|
32
|
+
cullable.visibilityPlaneMask = this.computeVisibilityWithPlaneMask(object, renderBounds, parentVisibilityPlaneMask || Mask.INDETERMINATE, frustum.planes);
|
|
33
|
+
cullable.visible = cullable.visibilityPlaneMask !== Mask.OUTSIDE;
|
|
34
|
+
return cullable.visible;
|
|
39
35
|
};
|
|
40
36
|
/**
|
|
41
37
|
*
|
|
@@ -53,7 +49,7 @@ function () {
|
|
|
53
49
|
*/
|
|
54
50
|
|
|
55
51
|
|
|
56
|
-
FrustumCullingStrategy.prototype.computeVisibilityWithPlaneMask = function (aabb, parentPlaneMask, planes) {
|
|
52
|
+
FrustumCullingStrategy.prototype.computeVisibilityWithPlaneMask = function (object, aabb, parentPlaneMask, planes) {
|
|
57
53
|
if (parentPlaneMask === Mask.OUTSIDE || parentPlaneMask === Mask.INSIDE) {
|
|
58
54
|
// 父节点完全位于视锥内或者外部,直接返回
|
|
59
55
|
return parentPlaneMask;
|
|
@@ -62,14 +58,21 @@ function () {
|
|
|
62
58
|
|
|
63
59
|
|
|
64
60
|
var mask = Mask.INSIDE;
|
|
61
|
+
var isShape2D = shape2D.indexOf(object.nodeName) > -1; // Use viewport culling for 2D shapes
|
|
62
|
+
// @see https://github.com/antvis/g/issues/914
|
|
65
63
|
|
|
66
64
|
for (var k = 0, len = planes.length; k < len; ++k) {
|
|
67
65
|
// For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.
|
|
68
|
-
var flag =
|
|
66
|
+
var flag = 1 << k;
|
|
69
67
|
|
|
70
|
-
if (
|
|
68
|
+
if ((parentPlaneMask & flag) === 0) {
|
|
71
69
|
// 父节点处于当前面内部,可以跳过
|
|
72
70
|
continue;
|
|
71
|
+
} // skip near & far planes when testing 2D shapes
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
if (isShape2D && (k === 4 || k === 5)) {
|
|
75
|
+
continue;
|
|
73
76
|
} // p-vertex n-vertex <-|plane p-vertex n-vertex
|
|
74
77
|
// 使用 p-vertex 和 n-vertex 加速,避免进行平面和 aabb 全部顶点的相交检测
|
|
75
78
|
|
|
@@ -91,6 +94,8 @@ function () {
|
|
|
91
94
|
return mask;
|
|
92
95
|
};
|
|
93
96
|
|
|
97
|
+
__decorate([inject(DefaultCamera), __metadata("design:type", Camera)], FrustumCullingStrategy.prototype, "camera", void 0);
|
|
98
|
+
|
|
94
99
|
FrustumCullingStrategy = __decorate([singleton({
|
|
95
100
|
contrib: CullingStrategyContribution
|
|
96
101
|
})], FrustumCullingStrategy);
|
|
@@ -1,11 +1,12 @@
|
|
|
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
|
-
var PrepareRendererPlugin =
|
|
7
|
-
/** @class */
|
|
8
|
-
function () {
|
|
9
|
+
var PrepareRendererPlugin = function () {
|
|
9
10
|
function PrepareRendererPlugin() {}
|
|
10
11
|
|
|
11
12
|
PrepareRendererPlugin_1 = PrepareRendererPlugin;
|
|
@@ -14,7 +15,7 @@ function () {
|
|
|
14
15
|
var _this = this;
|
|
15
16
|
|
|
16
17
|
var handleAttributeChanged = function handleAttributeChanged() {
|
|
17
|
-
_this.renderingContext.renderReasons.add(
|
|
18
|
+
_this.renderingContext.renderReasons.add(RenderReason.DISPLAY_OBJECT_CHANGED);
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
var handleBoundsChanged = function handleBoundsChanged() {
|
|
@@ -22,7 +23,20 @@ function () {
|
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
var handleMounted = function handleMounted(e) {
|
|
25
|
-
|
|
26
|
+
var object = e.target; // compute some style when mounted
|
|
27
|
+
|
|
28
|
+
INHERIT_PROPERTIES.forEach(function (name) {
|
|
29
|
+
if (object.getAttribute(name) === 'inherit') {
|
|
30
|
+
var computedValue = computeInheritStyleProperty(object, name);
|
|
31
|
+
|
|
32
|
+
if (!isNil(computedValue)) {
|
|
33
|
+
var oldParsedValue = object.parsedStyle[name];
|
|
34
|
+
object.parsedStyle[name] = computedValue;
|
|
35
|
+
object.updateStyleProperty(name, oldParsedValue, computedValue);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
dirtifyToRoot(object);
|
|
26
40
|
renderingService.dirtify();
|
|
27
41
|
};
|
|
28
42
|
|
|
@@ -36,7 +50,7 @@ function () {
|
|
|
36
50
|
|
|
37
51
|
_this.renderingContext.root.addEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
|
|
38
52
|
|
|
39
|
-
_this.renderingContext.root.addEventListener(ElementEvent.
|
|
53
|
+
_this.renderingContext.root.addEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
40
54
|
|
|
41
55
|
_this.renderingContext.root.addEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
|
|
42
56
|
});
|
|
@@ -45,7 +59,7 @@ function () {
|
|
|
45
59
|
|
|
46
60
|
_this.renderingContext.root.removeEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
|
|
47
61
|
|
|
48
|
-
_this.renderingContext.root.removeEventListener(ElementEvent.
|
|
62
|
+
_this.renderingContext.root.removeEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
49
63
|
|
|
50
64
|
_this.renderingContext.root.removeEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
|
|
51
65
|
});
|
|
@@ -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) {
|
|
@@ -35,13 +35,12 @@ export function updateGeometry(oldValue, newValue, object) {
|
|
|
35
35
|
_g = _a.offsetY,
|
|
36
36
|
offsetY = _g === void 0 ? 0 : _g,
|
|
37
37
|
_h = _a.offsetZ,
|
|
38
|
-
offsetZ = _h === void 0 ? 0 : _h;
|
|
38
|
+
offsetZ = _h === void 0 ? 0 : _h; // object.parsedStyle.width = width;
|
|
39
|
+
// object.parsedStyle.height = height;
|
|
40
|
+
// object.parsedStyle.depth = depth;
|
|
39
41
|
|
|
40
|
-
object.parsedStyle.width = width;
|
|
41
|
-
object.parsedStyle.height = height;
|
|
42
|
-
object.parsedStyle.depth = depth;
|
|
43
42
|
|
|
44
|
-
if (object.nodeName ===
|
|
43
|
+
if (object.nodeName === Shape.LINE || object.nodeName === Shape.POLYLINE || object.nodeName === Shape.POLYGON || object.nodeName === Shape.PATH) {
|
|
45
44
|
object.parsedStyle.offsetX = x - (object.parsedStyle.defX || 0);
|
|
46
45
|
object.parsedStyle.offsetY = y - (object.parsedStyle.defY || 0);
|
|
47
46
|
object.parsedStyle.defX = x;
|
|
@@ -60,15 +59,14 @@ export function updateGeometry(oldValue, newValue, object) {
|
|
|
60
59
|
var halfExtents = vec3.fromValues(width / 2, height / 2, depth / 2); // anchor is center by default, don't account for lineWidth here
|
|
61
60
|
|
|
62
61
|
var _j = object.parsedStyle,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
anchor = _l === void 0 ? [0, 0] : _l,
|
|
62
|
+
lineWidth = _j.lineWidth,
|
|
63
|
+
_k = _j.anchor,
|
|
64
|
+
anchor = _k === void 0 ? [0, 0] : _k,
|
|
67
65
|
shadowColor = _j.shadowColor,
|
|
68
|
-
|
|
69
|
-
filter =
|
|
66
|
+
_l = _j.filter,
|
|
67
|
+
filter = _l === void 0 ? [] : _l; // <Text> use textAlign & textBaseline instead of anchor
|
|
70
68
|
|
|
71
|
-
if (object.nodeName ===
|
|
69
|
+
if (object.nodeName === Shape.TEXT) {
|
|
72
70
|
delete object.parsedStyle.anchor;
|
|
73
71
|
}
|
|
74
72
|
|
|
@@ -78,22 +76,22 @@ export function updateGeometry(oldValue, newValue, object) {
|
|
|
78
76
|
|
|
79
77
|
if (lineWidth) {
|
|
80
78
|
// append border
|
|
81
|
-
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));
|
|
82
80
|
}
|
|
83
81
|
|
|
84
82
|
geometry_1.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
|
|
85
83
|
|
|
86
84
|
if (shadowColor && shadowColor.type === PARSED_COLOR_TYPE.Constant) {
|
|
87
|
-
var
|
|
88
|
-
min =
|
|
89
|
-
max =
|
|
90
|
-
var
|
|
91
|
-
|
|
92
|
-
shadowBlur =
|
|
93
|
-
|
|
94
|
-
shadowOffsetX =
|
|
95
|
-
|
|
96
|
-
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;
|
|
97
95
|
var shadowLeft = min[0] - shadowBlur + shadowOffsetX;
|
|
98
96
|
var shadowRight = max[0] + shadowBlur + shadowOffsetX;
|
|
99
97
|
var shadowTop = min[1] - shadowBlur + shadowOffsetY;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { __read, __spreadArray } from "tslib";
|
|
2
2
|
import { vec3 } from 'gl-matrix';
|
|
3
3
|
import { dirtifyToRoot } from '../services';
|
|
4
|
+
import { AABB } from '../shapes';
|
|
4
5
|
import { createVec3 } from '../utils';
|
|
5
6
|
export function updateAnchor(oldValue, newValue, object) {
|
|
6
7
|
var bounds = object.getGeometryBounds();
|
|
7
8
|
|
|
8
|
-
if (bounds) {
|
|
9
|
+
if (!AABB.isEmpty(bounds)) {
|
|
9
10
|
var geometry = object.geometry;
|
|
10
11
|
|
|
11
12
|
if (geometry && geometry.contentBounds) {
|
|
@@ -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];
|
|
@@ -1,18 +1,31 @@
|
|
|
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
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;
|
|
29
|
+
export declare function parseLengthOrPercentList(list: (string | number)[]): ParsedElement[];
|
|
17
30
|
export declare function convertPercentUnit(valueWithUnit: ParsedElement, vec3Index: number, target: DisplayObject | null): number;
|
|
18
31
|
export declare function convertAngleUnit(valueWithUnit: ParsedElement): number;
|
|
@@ -1,17 +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
|
+
import { AABB } from '../shapes';
|
|
5
|
+
import { computeInheritStyleProperty } from './inherit';
|
|
4
6
|
|
|
5
7
|
function isLengthUnit(unit) {
|
|
6
|
-
return unit === 'px' || unit === '%';
|
|
8
|
+
return unit === 'px' || unit === '%' || unit === 'em';
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
function isAngleUnit(unit) {
|
|
10
12
|
return unit === 'deg' || unit === 'rad' || unit === 'turn';
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export function parseDimension(unitRegExp, string) {
|
|
14
|
-
string = string.trim().toLowerCase();
|
|
15
|
+
export function parseDimension(unitRegExp, string, object, name) {
|
|
16
|
+
string = ("" + string).trim().toLowerCase();
|
|
17
|
+
|
|
18
|
+
if (string === 'inherit') {
|
|
19
|
+
var computed = computeInheritStyleProperty(object, name);
|
|
20
|
+
|
|
21
|
+
if (!isNil(computed)) {
|
|
22
|
+
return computed;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
15
25
|
|
|
16
26
|
if (string === '0') {
|
|
17
27
|
if ('px'.search(unitRegExp) >= 0) {
|
|
@@ -27,12 +37,41 @@ export function parseDimension(unitRegExp, string) {
|
|
|
27
37
|
value: 0
|
|
28
38
|
};
|
|
29
39
|
}
|
|
40
|
+
} else if (string === 'auto' || string === 'inherit') {
|
|
41
|
+
return {
|
|
42
|
+
unit: '',
|
|
43
|
+
value: 0
|
|
44
|
+
};
|
|
30
45
|
}
|
|
31
46
|
|
|
32
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
|
+
|
|
33
72
|
return {
|
|
34
|
-
unit: '',
|
|
35
|
-
value:
|
|
73
|
+
unit: 'px',
|
|
74
|
+
value: pxValue
|
|
36
75
|
};
|
|
37
76
|
}
|
|
38
77
|
|
|
@@ -88,9 +127,39 @@ export function mergeDimensions(left, right, nonNegative, target, index) {
|
|
|
88
127
|
}];
|
|
89
128
|
}
|
|
90
129
|
var lengthUnits = 'px';
|
|
130
|
+
/**
|
|
131
|
+
* length with only absolute unit, eg. 1px
|
|
132
|
+
*/
|
|
133
|
+
|
|
91
134
|
export var parseLength = parseDimension.bind(null, new RegExp(lengthUnits, 'g'));
|
|
92
|
-
|
|
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'));
|
|
93
140
|
export var parseAngle = parseDimension.bind(null, /deg|rad|grad|turn/g);
|
|
141
|
+
export function parseLengthOrPercentList(list) {
|
|
142
|
+
return list.map(parseLengthOrPercent);
|
|
143
|
+
} // export function mergeDimensionsLists(
|
|
144
|
+
// left: ParsedElement[],
|
|
145
|
+
// right: ParsedElement[],
|
|
146
|
+
// target: DisplayObject | null,
|
|
147
|
+
// ): [ParsedElement[], ParsedElement[], (list: ParsedElement[]) => string] | undefined {
|
|
148
|
+
// if (left.length != right.length) {
|
|
149
|
+
// return;
|
|
150
|
+
// }
|
|
151
|
+
// return [
|
|
152
|
+
// leftValue,
|
|
153
|
+
// rightValue,
|
|
154
|
+
// (value: number) => {
|
|
155
|
+
// if (nonNegative) {
|
|
156
|
+
// value = Math.max(value, 0);
|
|
157
|
+
// }
|
|
158
|
+
// return numberToString(value) + unit;
|
|
159
|
+
// },
|
|
160
|
+
// ];
|
|
161
|
+
// }
|
|
162
|
+
|
|
94
163
|
export function convertPercentUnit(valueWithUnit, vec3Index, target) {
|
|
95
164
|
if (valueWithUnit.unit === 'px') {
|
|
96
165
|
return Number(valueWithUnit.value);
|
|
@@ -99,7 +168,7 @@ export function convertPercentUnit(valueWithUnit, vec3Index, target) {
|
|
|
99
168
|
var bounds = target.getBounds();
|
|
100
169
|
var size = 0;
|
|
101
170
|
|
|
102
|
-
if (bounds) {
|
|
171
|
+
if (!AABB.isEmpty(bounds)) {
|
|
103
172
|
size = bounds.halfExtents[vec3Index] * 2;
|
|
104
173
|
}
|
|
105
174
|
|
|
@@ -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';
|