@antv/g 5.0.11 → 5.0.14
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 +2 -2
- package/es/Canvas.js +41 -15
- package/es/display-objects/DisplayObject.d.ts +2 -0
- package/es/display-objects/DisplayObject.js +10 -0
- package/es/display-objects/Polygon.d.ts +2 -5
- package/es/display-objects/Polyline.d.ts +2 -6
- package/es/display-objects/Text.d.ts +0 -2
- package/es/display-objects/Text.js +1 -1
- package/es/dom/Element.js +2 -1
- package/es/dom/FederatedPointerEvent.d.ts +6 -0
- package/es/dom/FederatedPointerEvent.js +8 -0
- package/es/global-module.js +2 -1
- package/es/property-handlers/aabb.js +28 -24
- package/es/services/RenderingService.d.ts +2 -2
- package/es/services/RenderingService.js +2 -2
- package/es/services/SceneGraphService.d.ts +4 -2
- package/es/services/SceneGraphService.js +89 -67
- package/es/services/aabb/RectUpdater.js +3 -0
- package/es/services/aabb/interfaces.d.ts +2 -1
- package/es/services/aabb/interfaces.js +1 -1
- package/es/types.d.ts +2 -7
- package/es/utils/canvas.d.ts +1 -0
- package/es/utils/canvas.js +2 -1
- package/es/utils/raf.d.ts +6 -2
- package/es/utils/raf.js +15 -2
- package/lib/Canvas.js +39 -12
- package/lib/display-objects/DisplayObject.d.ts +2 -0
- package/lib/display-objects/DisplayObject.js +10 -0
- package/lib/display-objects/Polygon.d.ts +2 -5
- package/lib/display-objects/Polyline.d.ts +2 -6
- package/lib/display-objects/Text.d.ts +0 -2
- package/lib/display-objects/Text.js +1 -1
- package/lib/dom/Element.js +2 -1
- package/lib/dom/FederatedPointerEvent.d.ts +6 -0
- package/lib/dom/FederatedPointerEvent.js +8 -0
- package/lib/global-module.js +2 -1
- package/lib/property-handlers/aabb.js +28 -24
- package/lib/services/RenderingService.d.ts +2 -2
- package/lib/services/RenderingService.js +1 -1
- package/lib/services/SceneGraphService.d.ts +4 -2
- package/lib/services/SceneGraphService.js +95 -67
- package/lib/services/aabb/RectUpdater.js +3 -0
- package/lib/services/aabb/interfaces.d.ts +2 -1
- package/lib/services/aabb/interfaces.js +1 -1
- package/lib/types.d.ts +2 -7
- package/lib/utils/canvas.d.ts +1 -0
- package/lib/utils/canvas.js +5 -1
- package/lib/utils/raf.d.ts +6 -2
- package/lib/utils/raf.js +22 -13
- package/package.json +3 -3
package/es/Canvas.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
2
|
import { CanvasConfig } from './types';
|
|
3
|
-
import { cleanExistedCanvas } from './utils/canvas';
|
|
3
|
+
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';
|
|
@@ -8,7 +8,7 @@ import { RenderingContext, RENDER_REASON } from './services/RenderingContext';
|
|
|
8
8
|
import { EventService } from './services/EventService';
|
|
9
9
|
import { Camera, CAMERA_EVENT, CAMERA_PROJECTION_MODE, DefaultCamera } from './camera';
|
|
10
10
|
import { containerModule as commonContainerModule } from './canvas-module';
|
|
11
|
-
import { cancelAnimationFrame, requestAnimationFrame } from './utils/raf';
|
|
11
|
+
import { cancelAnimationFrame, requestAnimationFrame, patch } from './utils/raf';
|
|
12
12
|
import { Document, EventTarget, ElementEvent } from './dom';
|
|
13
13
|
import { CustomElementRegistry } from './dom/CustomElementRegistry';
|
|
14
14
|
import { globalContainer } from './global-module';
|
|
@@ -49,19 +49,47 @@ function (_super) {
|
|
|
49
49
|
_this.document.defaultView = _this; // create registry of custom elements
|
|
50
50
|
|
|
51
51
|
_this.customElements = new CustomElementRegistry();
|
|
52
|
-
|
|
52
|
+
var container = config.container,
|
|
53
|
+
canvas = config.canvas,
|
|
54
|
+
width = config.width,
|
|
55
|
+
height = config.height,
|
|
56
|
+
devicePixelRatio = config.devicePixelRatio,
|
|
57
|
+
renderer = config.renderer,
|
|
58
|
+
background = config.background,
|
|
59
|
+
requestAnimationFrame = config.requestAnimationFrame,
|
|
60
|
+
cancelAnimationFrame = config.cancelAnimationFrame;
|
|
61
|
+
cleanExistedCanvas(container, _this);
|
|
62
|
+
var canvasWidth = width;
|
|
63
|
+
var canvasHeight = height;
|
|
64
|
+
var dpr = devicePixelRatio; // use user-defined <canvas> or OffscreenCanvas
|
|
65
|
+
|
|
66
|
+
if (canvas) {
|
|
67
|
+
// infer width & height with dpr
|
|
68
|
+
dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
|
|
69
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
70
|
+
canvasWidth = width || canvas.width / dpr;
|
|
71
|
+
canvasHeight = height || canvas.height / dpr;
|
|
72
|
+
}
|
|
53
73
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
cursor: 'default'
|
|
58
|
-
}, config);
|
|
74
|
+
if (requestAnimationFrame && cancelAnimationFrame) {
|
|
75
|
+
patch(requestAnimationFrame, cancelAnimationFrame);
|
|
76
|
+
}
|
|
59
77
|
|
|
60
|
-
_this.initRenderingContext(
|
|
78
|
+
_this.initRenderingContext({
|
|
79
|
+
container: container,
|
|
80
|
+
canvas: canvas,
|
|
81
|
+
width: canvasWidth,
|
|
82
|
+
height: canvasHeight,
|
|
83
|
+
renderer: renderer,
|
|
84
|
+
devicePixelRatio: dpr,
|
|
85
|
+
cursor: 'default',
|
|
86
|
+
background: background // background: 'white',
|
|
61
87
|
|
|
62
|
-
|
|
88
|
+
});
|
|
63
89
|
|
|
64
|
-
_this.
|
|
90
|
+
_this.initDefaultCamera(canvasWidth, canvasHeight);
|
|
91
|
+
|
|
92
|
+
_this.initRenderer(renderer);
|
|
65
93
|
|
|
66
94
|
return _this;
|
|
67
95
|
}
|
|
@@ -285,12 +313,10 @@ function (_super) {
|
|
|
285
313
|
Canvas.prototype.run = function () {
|
|
286
314
|
var _this = this;
|
|
287
315
|
|
|
288
|
-
var rAF = this.getConfig().requestAnimationFrame || requestAnimationFrame;
|
|
289
|
-
|
|
290
316
|
var tick = function tick() {
|
|
291
317
|
_this.render();
|
|
292
318
|
|
|
293
|
-
_this.frameId =
|
|
319
|
+
_this.frameId = requestAnimationFrame(tick);
|
|
294
320
|
};
|
|
295
321
|
|
|
296
322
|
tick();
|
|
@@ -107,6 +107,8 @@ export declare class DisplayObject<StyleProps extends BaseStyleProps = any, Pars
|
|
|
107
107
|
setLocalEulerAngles(z: number): this;
|
|
108
108
|
rotateLocal(x: number, y?: number, z?: number): this;
|
|
109
109
|
rotate(x: number, y?: number, z?: number): this;
|
|
110
|
+
setRotation(rotation: quat | number, y?: number, z?: number, w?: number): this;
|
|
111
|
+
setLocalRotation(rotation: quat | number, y?: number, z?: number, w?: number): this;
|
|
110
112
|
getRotation(): quat;
|
|
111
113
|
getLocalRotation(): quat;
|
|
112
114
|
getLocalTransform(): mat4;
|
|
@@ -470,6 +470,16 @@ function (_super) {
|
|
|
470
470
|
return this;
|
|
471
471
|
};
|
|
472
472
|
|
|
473
|
+
DisplayObject.prototype.setRotation = function (rotation, y, z, w) {
|
|
474
|
+
this.sceneGraphService.setRotation(this, rotation, y, z, w);
|
|
475
|
+
return this;
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
DisplayObject.prototype.setLocalRotation = function (rotation, y, z, w) {
|
|
479
|
+
this.sceneGraphService.setLocalRotation(this, rotation, y, z, w);
|
|
480
|
+
return this;
|
|
481
|
+
};
|
|
482
|
+
|
|
473
483
|
DisplayObject.prototype.getRotation = function () {
|
|
474
484
|
return this.sceneGraphService.getRotation(this);
|
|
475
485
|
};
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type { BaseStyleProps } from '../types';
|
|
1
|
+
import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
|
|
2
2
|
import { DisplayObject } from './DisplayObject';
|
|
3
3
|
import type { DisplayObjectConfig } from '../dom';
|
|
4
|
-
import type { ParsedPolylineStyleProps } from './Polyline';
|
|
5
4
|
export interface PolygonStyleProps extends BaseStyleProps {
|
|
6
5
|
points: [number, number][];
|
|
7
6
|
}
|
|
8
|
-
export declare class Polygon extends DisplayObject<PolygonStyleProps, {
|
|
9
|
-
points: ParsedPolylineStyleProps;
|
|
10
|
-
}> {
|
|
7
|
+
export declare class Polygon extends DisplayObject<PolygonStyleProps, ParsedBaseStyleProps> {
|
|
11
8
|
constructor({ style, ...rest }: DisplayObjectConfig<PolygonStyleProps>);
|
|
12
9
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BaseStyleProps } from '../types';
|
|
1
|
+
import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
|
|
2
2
|
import { DisplayObject } from './DisplayObject';
|
|
3
3
|
import type { DisplayObjectConfig } from '../dom';
|
|
4
4
|
import { Point } from '../shapes';
|
|
@@ -7,14 +7,10 @@ export interface PolylineStyleProps extends BaseStyleProps {
|
|
|
7
7
|
}
|
|
8
8
|
export interface ParsedPolylineStyleProps {
|
|
9
9
|
points: [number, number][];
|
|
10
|
-
defX: number;
|
|
11
|
-
defY: number;
|
|
12
10
|
segments: [number, number][];
|
|
13
11
|
totalLength: number;
|
|
14
12
|
}
|
|
15
|
-
export declare class Polyline extends DisplayObject<PolylineStyleProps, {
|
|
16
|
-
points: ParsedPolylineStyleProps;
|
|
17
|
-
}> {
|
|
13
|
+
export declare class Polyline extends DisplayObject<PolylineStyleProps, ParsedBaseStyleProps> {
|
|
18
14
|
constructor({ style, ...rest }: DisplayObjectConfig<PolylineStyleProps>);
|
|
19
15
|
getTotalLength(): number;
|
|
20
16
|
getPoint(ratio: number): Point;
|
|
@@ -22,7 +22,6 @@ export interface TextStyleProps extends BaseStyleProps {
|
|
|
22
22
|
lineHeight?: number;
|
|
23
23
|
letterSpacing?: number;
|
|
24
24
|
miterLimit?: number;
|
|
25
|
-
padding?: number;
|
|
26
25
|
whiteSpace?: 'pre';
|
|
27
26
|
leading?: number;
|
|
28
27
|
wordWrap?: boolean;
|
|
@@ -50,7 +49,6 @@ export interface ParsedTextStyleProps extends ParsedBaseStyleProps {
|
|
|
50
49
|
lineHeight?: number;
|
|
51
50
|
letterSpacing?: number;
|
|
52
51
|
miterLimit?: number;
|
|
53
|
-
padding?: number;
|
|
54
52
|
whiteSpace?: 'pre';
|
|
55
53
|
leading?: number;
|
|
56
54
|
wordWrap?: boolean;
|
package/es/dom/Element.js
CHANGED
|
@@ -64,6 +64,12 @@ export declare class FederatedPointerEvent extends FederatedMouseEvent implement
|
|
|
64
64
|
* @see https://w3c.github.io/pointerevents/#pointerevent-interface
|
|
65
65
|
*/
|
|
66
66
|
twist: number;
|
|
67
|
+
/**
|
|
68
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/getCoalescedEvents
|
|
69
|
+
*/
|
|
67
70
|
getCoalescedEvents(): PointerEvent[];
|
|
71
|
+
/**
|
|
72
|
+
* @see https://chromestatus.com/feature/5765569655603200
|
|
73
|
+
*/
|
|
68
74
|
getPredictedEvents(): PointerEvent[];
|
|
69
75
|
}
|
|
@@ -34,6 +34,10 @@ function (_super) {
|
|
|
34
34
|
_this.isPrimary = false;
|
|
35
35
|
return _this;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/getCoalescedEvents
|
|
39
|
+
*/
|
|
40
|
+
|
|
37
41
|
|
|
38
42
|
FederatedPointerEvent.prototype.getCoalescedEvents = function () {
|
|
39
43
|
if (this.type === 'pointermove' || this.type === 'mousemove' || this.type === 'touchmove') {
|
|
@@ -42,6 +46,10 @@ function (_super) {
|
|
|
42
46
|
|
|
43
47
|
return [];
|
|
44
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* @see https://chromestatus.com/feature/5765569655603200
|
|
51
|
+
*/
|
|
52
|
+
|
|
45
53
|
|
|
46
54
|
FederatedPointerEvent.prototype.getPredictedEvents = function () {
|
|
47
55
|
throw new Error('getPredictedEvents is not supported!');
|
package/es/global-module.js
CHANGED
|
@@ -136,7 +136,8 @@ export var containerModule = Module(function (register) {
|
|
|
136
136
|
addPropertiesHandler(['lineDash'], parseLineDash, // @ts-ignore
|
|
137
137
|
mergeNumberLists, undefined);
|
|
138
138
|
addPropertiesHandler(['x1', 'x2', 'y1', 'y2', 'lineDashOffset', 'shadowOffsetX', 'shadowOffsetY'], parseNumber, mergeNumbers, undefined);
|
|
139
|
-
addPropertiesHandler(['x1', 'x2', 'y1', 'y2', 'r', 'rx', 'ry', 'width', 'height', 'path', 'points', 'text', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'lineWidth', 'filter', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'padding',
|
|
139
|
+
addPropertiesHandler(['x1', 'x2', 'y1', 'y2', 'r', 'rx', 'ry', 'width', 'height', 'path', 'points', 'text', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'lineWidth', 'filter', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', // 'padding',
|
|
140
|
+
'wordWrap', 'wordWrapWidth', 'leading', 'textBaseline', 'textAlign', 'whiteSpace'], undefined, undefined, updateGeometry);
|
|
140
141
|
addPropertiesHandler(['fill', 'stroke', 'shadowColor'], parseColor, mergeColors, undefined);
|
|
141
142
|
addPropertyHandler('clipPath', undefined, undefined, updateClipPath);
|
|
142
143
|
addPropertyHandler('zIndex', undefined, undefined, updateZIndex);
|
|
@@ -28,12 +28,14 @@ export function updateGeometry(oldValue, newValue, object) {
|
|
|
28
28
|
x = _c === void 0 ? 0 : _c,
|
|
29
29
|
_d = _a.y,
|
|
30
30
|
y = _d === void 0 ? 0 : _d,
|
|
31
|
-
_e = _a.
|
|
32
|
-
|
|
33
|
-
_f = _a.
|
|
34
|
-
|
|
35
|
-
_g = _a.
|
|
36
|
-
|
|
31
|
+
_e = _a.z,
|
|
32
|
+
z = _e === void 0 ? 0 : _e,
|
|
33
|
+
_f = _a.offsetX,
|
|
34
|
+
offsetX = _f === void 0 ? 0 : _f,
|
|
35
|
+
_g = _a.offsetY,
|
|
36
|
+
offsetY = _g === void 0 ? 0 : _g,
|
|
37
|
+
_h = _a.offsetZ,
|
|
38
|
+
offsetZ = _h === void 0 ? 0 : _h;
|
|
37
39
|
|
|
38
40
|
object.parsedStyle.width = width;
|
|
39
41
|
object.parsedStyle.height = height;
|
|
@@ -47,22 +49,24 @@ export function updateGeometry(oldValue, newValue, object) {
|
|
|
47
49
|
object.translateLocal(object.parsedStyle.offsetX, object.parsedStyle.offsetY);
|
|
48
50
|
object.parsedStyle.x = object.style.x;
|
|
49
51
|
object.parsedStyle.y = object.style.y;
|
|
52
|
+
object.parsedStyle.z = z;
|
|
50
53
|
} else {
|
|
51
54
|
object.parsedStyle.x = x;
|
|
52
55
|
object.parsedStyle.y = y;
|
|
56
|
+
object.parsedStyle.z = z;
|
|
53
57
|
} // init with content box
|
|
54
58
|
|
|
55
59
|
|
|
56
60
|
var halfExtents = vec3.fromValues(width / 2, height / 2, depth / 2); // anchor is center by default, don't account for lineWidth here
|
|
57
61
|
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
lineWidth =
|
|
61
|
-
|
|
62
|
-
anchor =
|
|
63
|
-
shadowColor =
|
|
64
|
-
|
|
65
|
-
filter =
|
|
62
|
+
var _j = object.parsedStyle,
|
|
63
|
+
_k = _j.lineWidth,
|
|
64
|
+
lineWidth = _k === void 0 ? 0 : _k,
|
|
65
|
+
_l = _j.anchor,
|
|
66
|
+
anchor = _l === void 0 ? [0, 0] : _l,
|
|
67
|
+
shadowColor = _j.shadowColor,
|
|
68
|
+
_m = _j.filter,
|
|
69
|
+
filter = _m === void 0 ? [] : _m; // <Text> use textAlign & textBaseline instead of anchor
|
|
66
70
|
|
|
67
71
|
if (object.nodeName === SHAPE.Text) {
|
|
68
72
|
delete object.parsedStyle.anchor;
|
|
@@ -80,16 +84,16 @@ export function updateGeometry(oldValue, newValue, object) {
|
|
|
80
84
|
geometry_1.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
|
|
81
85
|
|
|
82
86
|
if (shadowColor && shadowColor.type === PARSED_COLOR_TYPE.Constant) {
|
|
83
|
-
var
|
|
84
|
-
min =
|
|
85
|
-
max =
|
|
86
|
-
var
|
|
87
|
-
|
|
88
|
-
shadowBlur =
|
|
89
|
-
|
|
90
|
-
shadowOffsetX =
|
|
91
|
-
|
|
92
|
-
shadowOffsetY =
|
|
87
|
+
var _o = geometry_1.renderBounds,
|
|
88
|
+
min = _o.min,
|
|
89
|
+
max = _o.max;
|
|
90
|
+
var _p = object.parsedStyle,
|
|
91
|
+
_q = _p.shadowBlur,
|
|
92
|
+
shadowBlur = _q === void 0 ? 0 : _q,
|
|
93
|
+
_r = _p.shadowOffsetX,
|
|
94
|
+
shadowOffsetX = _r === void 0 ? 0 : _r,
|
|
95
|
+
_s = _p.shadowOffsetY,
|
|
96
|
+
shadowOffsetY = _s === void 0 ? 0 : _s;
|
|
93
97
|
var shadowLeft = min[0] - shadowBlur + shadowOffsetX;
|
|
94
98
|
var shadowRight = max[0] + shadowBlur + shadowOffsetX;
|
|
95
99
|
var shadowTop = min[1] - shadowBlur + shadowOffsetY;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Syringe } from 'mana-syringe';
|
|
2
|
-
import { SyncHook, SyncWaterfallHook,
|
|
2
|
+
import { SyncHook, SyncWaterfallHook, AsyncParallelHook, AsyncSeriesWaterfallHook } from 'tapable';
|
|
3
3
|
import type { DisplayObject } from '..';
|
|
4
4
|
import type { EventPosition, InteractivePointerEvent } from '../types';
|
|
5
5
|
export interface RenderingPlugin {
|
|
@@ -27,7 +27,7 @@ export declare class RenderingService {
|
|
|
27
27
|
private stats;
|
|
28
28
|
private zIndexCounter;
|
|
29
29
|
hooks: {
|
|
30
|
-
init:
|
|
30
|
+
init: AsyncParallelHook<[], import("tapable").UnsetAdditionalOptions>;
|
|
31
31
|
prepare: SyncWaterfallHook<[DisplayObject<any, any>], import("tapable").UnsetAdditionalOptions>;
|
|
32
32
|
/**
|
|
33
33
|
* called at beginning of each frame, won't get called if nothing to re-render
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter, __decorate, __generator, __metadata } from "tslib";
|
|
2
2
|
import { inject, singleton, contrib, Syringe, Contribution } from 'mana-syringe';
|
|
3
|
-
import { SyncHook, SyncWaterfallHook,
|
|
3
|
+
import { SyncHook, SyncWaterfallHook, AsyncParallelHook, AsyncSeriesWaterfallHook } from 'tapable';
|
|
4
4
|
import { ElementEvent } from '../dom';
|
|
5
5
|
import { RenderingContext, RENDER_REASON } from './RenderingContext';
|
|
6
6
|
import { SceneGraphService, sortByZIndex } from './SceneGraphService';
|
|
@@ -26,7 +26,7 @@ function () {
|
|
|
26
26
|
};
|
|
27
27
|
this.zIndexCounter = 0;
|
|
28
28
|
this.hooks = {
|
|
29
|
-
init: new
|
|
29
|
+
init: new AsyncParallelHook(),
|
|
30
30
|
prepare: new SyncWaterfallHook(['object']),
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -12,7 +12,6 @@ export interface SceneGraphService {
|
|
|
12
12
|
querySelectorAll: <R extends IElement, T extends IElement>(query: string, root: R) => T[];
|
|
13
13
|
attach: <C extends INode, P extends INode & IParentNode>(child: C, parent: P, index?: number) => void;
|
|
14
14
|
detach: <C extends INode>(child: C) => void;
|
|
15
|
-
sort: (object1: IElement, object2: IElement) => number;
|
|
16
15
|
getOrigin: (element: INode) => vec3;
|
|
17
16
|
setOrigin: (element: INode, origin: vec3 | number, y?: number, z?: number) => void;
|
|
18
17
|
setPosition: (element: INode, position: vec3 | vec2) => void;
|
|
@@ -30,6 +29,8 @@ export interface SceneGraphService {
|
|
|
30
29
|
rotateLocal: (element: INode, degrees: vec3 | number, y?: number, z?: number) => void;
|
|
31
30
|
rotate: (element: INode, degrees: vec3 | number, y?: number, z?: number) => void;
|
|
32
31
|
getRotation: (element: INode) => quat;
|
|
32
|
+
setRotation: (element: INode, rotation: quat | number, y?: number, z?: number, w?: number) => void;
|
|
33
|
+
setLocalRotation: (element: INode, rotation: quat | number, y?: number, z?: number, w?: number) => void;
|
|
33
34
|
getLocalRotation: (element: INode) => quat;
|
|
34
35
|
getWorldTransform: (element: INode, transform?: Transform) => mat4;
|
|
35
36
|
getLocalTransform: (element: INode, transform?: Transform) => mat4;
|
|
@@ -58,7 +59,6 @@ export declare class DefaultSceneGraphService implements SceneGraphService {
|
|
|
58
59
|
* use materialized path
|
|
59
60
|
* @see https://stackoverflow.com/questions/31470730/comparing-tree-nodes
|
|
60
61
|
*/
|
|
61
|
-
sort: (object1: INode, object2: INode) => number;
|
|
62
62
|
getOrigin(element: INode): vec3;
|
|
63
63
|
setOrigin(element: INode, origin: vec3 | number, y?: number, z?: number): void;
|
|
64
64
|
/**
|
|
@@ -117,6 +117,8 @@ export declare class DefaultSceneGraphService implements SceneGraphService {
|
|
|
117
117
|
* @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L665-L676
|
|
118
118
|
*/
|
|
119
119
|
translate: (element: INode, translation: vec3 | number, y?: number, z?: number) => void;
|
|
120
|
+
setRotation: () => (element: INode, rotation: quat | number, y?: number, z?: number, w?: number) => void;
|
|
121
|
+
setLocalRotation(element: INode, rotation: quat | number, y?: number, z?: number, w?: number): void;
|
|
120
122
|
dirtifyLocal(element: INode, transform: Transform): void;
|
|
121
123
|
dirtifyWorld(element: INode, transform: Transform): void;
|
|
122
124
|
getPosition(element: INode): vec3;
|
|
@@ -56,72 +56,6 @@ var DefaultSceneGraphService =
|
|
|
56
56
|
function () {
|
|
57
57
|
function DefaultSceneGraphService() {
|
|
58
58
|
var _this = this;
|
|
59
|
-
/**
|
|
60
|
-
* compare two display objects by hierarchy-index and z-index
|
|
61
|
-
*
|
|
62
|
-
* use materialized path
|
|
63
|
-
* @see https://stackoverflow.com/questions/31470730/comparing-tree-nodes
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
this.sort = function (object1, object2) {
|
|
68
|
-
if (!object1.parentNode) {
|
|
69
|
-
return -1;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (!object2.parentNode) {
|
|
73
|
-
return 1;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
var hierarchyDiff = object1.transformable.graphDepth - object2.transformable.graphDepth;
|
|
77
|
-
var o1 = object1;
|
|
78
|
-
var o2 = object2;
|
|
79
|
-
|
|
80
|
-
if (hierarchyDiff < 0) {
|
|
81
|
-
o2 = object2.getAncestor(-hierarchyDiff);
|
|
82
|
-
|
|
83
|
-
if (o2 === o1) {
|
|
84
|
-
return -1;
|
|
85
|
-
}
|
|
86
|
-
} else if (hierarchyDiff > 0) {
|
|
87
|
-
o1 = object1.getAncestor(hierarchyDiff);
|
|
88
|
-
|
|
89
|
-
if (o2 === o1) {
|
|
90
|
-
return 1;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
while (o1 && o2 && o1.parentNode !== o2.parentNode) {
|
|
95
|
-
o1 = o1.parentNode;
|
|
96
|
-
o2 = o2.parentNode;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
var parent = o1.parentNode;
|
|
100
|
-
|
|
101
|
-
if (parent) {
|
|
102
|
-
var parentSortable = parent.sortable;
|
|
103
|
-
|
|
104
|
-
if (parentSortable) {
|
|
105
|
-
// no need to re-sort, use cached sorted children
|
|
106
|
-
if (!parentSortable.sorted) {
|
|
107
|
-
parentSortable.sorted = parent.childNodes.slice();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (parentSortable.dirty) {
|
|
111
|
-
parentSortable.sorted = parent.childNodes.slice().sort(sortByZIndex); // parentSortable.sorted.forEach(
|
|
112
|
-
// (child, i) => ((child as Element).sortable.lastSortedIndex = i),
|
|
113
|
-
// );
|
|
114
|
-
|
|
115
|
-
parentSortable.dirty = false;
|
|
116
|
-
} // return (o1 as Element).sortable.lastSortedIndex - (o2 as Element).sortable.lastSortedIndex;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return parentSortable.sorted.indexOf(o1) - parentSortable.sorted.indexOf(o2);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return -1;
|
|
124
|
-
};
|
|
125
59
|
/**
|
|
126
60
|
* rotate in world space
|
|
127
61
|
*/
|
|
@@ -156,7 +90,7 @@ function () {
|
|
|
156
90
|
|
|
157
91
|
quat.copy(parentInvertRotation, parentRot);
|
|
158
92
|
quat.invert(parentInvertRotation, parentInvertRotation);
|
|
159
|
-
quat.multiply(
|
|
93
|
+
quat.multiply(rotation, parentInvertRotation, rotation);
|
|
160
94
|
quat.multiply(transform.localRotation, rotation, rot);
|
|
161
95
|
quat.normalize(transform.localRotation, transform.localRotation);
|
|
162
96
|
|
|
@@ -335,6 +269,30 @@ function () {
|
|
|
335
269
|
_this.setPosition(element, tr);
|
|
336
270
|
};
|
|
337
271
|
}();
|
|
272
|
+
|
|
273
|
+
this.setRotation = function () {
|
|
274
|
+
var parentInvertRotation = quat.create();
|
|
275
|
+
return function (element, rotation, y, z, w) {
|
|
276
|
+
var transform = element.transformable;
|
|
277
|
+
|
|
278
|
+
if (typeof rotation === 'number') {
|
|
279
|
+
rotation = quat.fromValues(rotation, y, z, w);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (element.parentNode === null || !element.parentNode.transformable) {
|
|
283
|
+
_this.setLocalRotation(element, rotation);
|
|
284
|
+
} else {
|
|
285
|
+
var parentRot = _this.getRotation(element.parentNode);
|
|
286
|
+
|
|
287
|
+
quat.copy(parentInvertRotation, parentRot);
|
|
288
|
+
quat.invert(parentInvertRotation, parentInvertRotation);
|
|
289
|
+
quat.multiply(transform.localRotation, parentInvertRotation, rotation);
|
|
290
|
+
quat.normalize(transform.localRotation, transform.localRotation);
|
|
291
|
+
|
|
292
|
+
_this.dirtifyLocal(element, transform);
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
};
|
|
338
296
|
}
|
|
339
297
|
|
|
340
298
|
DefaultSceneGraphService.prototype.matches = function (query, root) {
|
|
@@ -413,6 +371,60 @@ function () {
|
|
|
413
371
|
child.parentNode = null;
|
|
414
372
|
}
|
|
415
373
|
};
|
|
374
|
+
/**
|
|
375
|
+
* compare two display objects by hierarchy-index and z-index
|
|
376
|
+
*
|
|
377
|
+
* use materialized path
|
|
378
|
+
* @see https://stackoverflow.com/questions/31470730/comparing-tree-nodes
|
|
379
|
+
*/
|
|
380
|
+
// sort = (object1: INode, object2: INode): number => {
|
|
381
|
+
// if (!object1.parentNode) {
|
|
382
|
+
// return -1;
|
|
383
|
+
// }
|
|
384
|
+
// if (!object2.parentNode) {
|
|
385
|
+
// return 1;
|
|
386
|
+
// }
|
|
387
|
+
// const hierarchyDiff =
|
|
388
|
+
// (object1 as Element).transformable.graphDepth - (object2 as Element).transformable.graphDepth;
|
|
389
|
+
// let o1 = object1;
|
|
390
|
+
// let o2 = object2;
|
|
391
|
+
// if (hierarchyDiff < 0) {
|
|
392
|
+
// o2 = object2.getAncestor(-hierarchyDiff)!;
|
|
393
|
+
// if (o2 === o1) {
|
|
394
|
+
// return -1;
|
|
395
|
+
// }
|
|
396
|
+
// } else if (hierarchyDiff > 0) {
|
|
397
|
+
// o1 = object1.getAncestor(hierarchyDiff)!;
|
|
398
|
+
// if (o2 === o1) {
|
|
399
|
+
// return 1;
|
|
400
|
+
// }
|
|
401
|
+
// }
|
|
402
|
+
// while (o1 && o2 && o1.parentNode !== o2.parentNode) {
|
|
403
|
+
// o1 = o1.parentNode!;
|
|
404
|
+
// o2 = o2.parentNode!;
|
|
405
|
+
// }
|
|
406
|
+
// const parent = o1.parentNode;
|
|
407
|
+
// if (parent) {
|
|
408
|
+
// const parentSortable = (parent as Element).sortable;
|
|
409
|
+
// if (parentSortable) {
|
|
410
|
+
// // no need to re-sort, use cached sorted children
|
|
411
|
+
// if (!parentSortable.sorted) {
|
|
412
|
+
// parentSortable.sorted = (parent.childNodes as IElement[]).slice();
|
|
413
|
+
// }
|
|
414
|
+
// if (parentSortable.dirty) {
|
|
415
|
+
// parentSortable.sorted = (parent.childNodes as IElement[]).slice().sort(sortByZIndex);
|
|
416
|
+
// // parentSortable.sorted.forEach(
|
|
417
|
+
// // (child, i) => ((child as Element).sortable.lastSortedIndex = i),
|
|
418
|
+
// // );
|
|
419
|
+
// parentSortable.dirty = false;
|
|
420
|
+
// }
|
|
421
|
+
// // return (o1 as Element).sortable.lastSortedIndex - (o2 as Element).sortable.lastSortedIndex;
|
|
422
|
+
// return parentSortable.sorted.indexOf(o1) - parentSortable.sorted.indexOf(o2);
|
|
423
|
+
// }
|
|
424
|
+
// }
|
|
425
|
+
// return -1;
|
|
426
|
+
// };
|
|
427
|
+
|
|
416
428
|
|
|
417
429
|
DefaultSceneGraphService.prototype.getOrigin = function (element) {
|
|
418
430
|
return element.transformable.origin;
|
|
@@ -504,6 +516,16 @@ function () {
|
|
|
504
516
|
this.dirtifyLocal(element, transform);
|
|
505
517
|
};
|
|
506
518
|
|
|
519
|
+
DefaultSceneGraphService.prototype.setLocalRotation = function (element, rotation, y, z, w) {
|
|
520
|
+
if (typeof rotation === 'number') {
|
|
521
|
+
rotation = quat.fromValues(rotation, y, z, w);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
var transform = element.transformable;
|
|
525
|
+
quat.copy(transform.localRotation, rotation);
|
|
526
|
+
this.dirtifyLocal(element, transform);
|
|
527
|
+
};
|
|
528
|
+
|
|
507
529
|
DefaultSceneGraphService.prototype.dirtifyLocal = function (element, transform) {
|
|
508
530
|
if (!transform.localDirtyFlag) {
|
|
509
531
|
transform.localDirtyFlag = true;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DisplayObject } from '../../display-objects/DisplayObject';
|
|
2
2
|
import type { ParsedBaseStyleProps } from '../../types';
|
|
3
3
|
export declare const GeometryUpdaterFactory = "GeometryUpdaterFactory";
|
|
4
|
-
export declare const GeometryAABBUpdater = "
|
|
4
|
+
export declare const GeometryAABBUpdater = "GeometryAABBUpdater";
|
|
5
5
|
export interface GeometryAABBUpdater<T extends ParsedBaseStyleProps = any> {
|
|
6
6
|
update: (parsedStyle: T, object: DisplayObject) => {
|
|
7
7
|
width: number;
|
|
@@ -9,6 +9,7 @@ export interface GeometryAABBUpdater<T extends ParsedBaseStyleProps = any> {
|
|
|
9
9
|
depth?: number;
|
|
10
10
|
x: number;
|
|
11
11
|
y: number;
|
|
12
|
+
z?: number;
|
|
12
13
|
offsetX?: number;
|
|
13
14
|
offsetY?: number;
|
|
14
15
|
offsetZ?: number;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export var GeometryUpdaterFactory = 'GeometryUpdaterFactory';
|
|
2
|
-
export var GeometryAABBUpdater = '
|
|
2
|
+
export var GeometryAABBUpdater = 'GeometryAABBUpdater';
|
package/es/types.d.ts
CHANGED
|
@@ -110,7 +110,6 @@ export interface BaseStyleProps {
|
|
|
110
110
|
*/
|
|
111
111
|
lineDash?: number[] | null;
|
|
112
112
|
lineDashOffset?: number;
|
|
113
|
-
padding?: number[] | number;
|
|
114
113
|
/**
|
|
115
114
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/shadowBlur
|
|
116
115
|
*/
|
|
@@ -190,19 +189,15 @@ export interface CanvasConfig {
|
|
|
190
189
|
/**
|
|
191
190
|
* 画布宽度
|
|
192
191
|
*/
|
|
193
|
-
width
|
|
192
|
+
width?: number;
|
|
194
193
|
/**
|
|
195
194
|
* 画布高度
|
|
196
195
|
*/
|
|
197
|
-
height
|
|
196
|
+
height?: number;
|
|
198
197
|
/**
|
|
199
198
|
* 画布背景色
|
|
200
199
|
*/
|
|
201
200
|
background?: ColorType;
|
|
202
|
-
/**
|
|
203
|
-
* 是否可监听
|
|
204
|
-
*/
|
|
205
|
-
capture?: boolean;
|
|
206
201
|
/**
|
|
207
202
|
* 画布的 cursor 样式
|
|
208
203
|
*/
|
package/es/utils/canvas.d.ts
CHANGED
package/es/utils/canvas.js
CHANGED