@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/utils/raf.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* use user-defined raf instead of requestAnimationFrame
|
|
3
|
+
*/
|
|
4
|
+
export declare function patch(requestAFPatch: (callback: Function) => number, cancelAFPatch: (id: number) => void): void;
|
|
5
|
+
export declare const requestAnimationFrame: (callback: Function) => number;
|
|
6
|
+
export declare const cancelAnimationFrame: (id: number) => void;
|
package/es/utils/raf.js
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
import { requestAnimationFrame, cancelAnimationFrame } from 'request-animation-frame-polyfill';
|
|
2
|
-
export { requestAnimationFrame, cancelAnimationFrame };
|
|
1
|
+
// import { requestAnimationFrame, cancelAnimationFrame } from 'request-animation-frame-polyfill';
|
|
2
|
+
// export { requestAnimationFrame, cancelAnimationFrame };
|
|
3
|
+
import { requestAnimationFrame as rAF, cancelAnimationFrame as cancelRAF } from 'request-animation-frame-polyfill';
|
|
4
|
+
var requestAF = rAF;
|
|
5
|
+
var cancelAF = cancelRAF;
|
|
6
|
+
/**
|
|
7
|
+
* use user-defined raf instead of requestAnimationFrame
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export function patch(requestAFPatch, cancelAFPatch) {
|
|
11
|
+
requestAF = requestAFPatch;
|
|
12
|
+
cancelAF = cancelAFPatch;
|
|
13
|
+
}
|
|
14
|
+
export var requestAnimationFrame = requestAF;
|
|
15
|
+
export var cancelAnimationFrame = cancelAF;
|
package/lib/Canvas.js
CHANGED
|
@@ -71,18 +71,47 @@ function (_super) {
|
|
|
71
71
|
_this.document.defaultView = _this; // create registry of custom elements
|
|
72
72
|
|
|
73
73
|
_this.customElements = new _CustomElementRegistry.CustomElementRegistry();
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
var container = config.container,
|
|
75
|
+
canvas = config.canvas,
|
|
76
|
+
width = config.width,
|
|
77
|
+
height = config.height,
|
|
78
|
+
devicePixelRatio = config.devicePixelRatio,
|
|
79
|
+
renderer = config.renderer,
|
|
80
|
+
background = config.background,
|
|
81
|
+
requestAnimationFrame = config.requestAnimationFrame,
|
|
82
|
+
cancelAnimationFrame = config.cancelAnimationFrame;
|
|
83
|
+
(0, _canvas.cleanExistedCanvas)(container, _this);
|
|
84
|
+
var canvasWidth = width;
|
|
85
|
+
var canvasHeight = height;
|
|
86
|
+
var dpr = devicePixelRatio; // use user-defined <canvas> or OffscreenCanvas
|
|
87
|
+
|
|
88
|
+
if (canvas) {
|
|
89
|
+
// infer width & height with dpr
|
|
90
|
+
dpr = devicePixelRatio || _canvas.isBrowser && window.devicePixelRatio || 1;
|
|
91
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
92
|
+
canvasWidth = width || canvas.width / dpr;
|
|
93
|
+
canvasHeight = height || canvas.height / dpr;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (requestAnimationFrame && cancelAnimationFrame) {
|
|
97
|
+
(0, _raf.patch)(requestAnimationFrame, cancelAnimationFrame);
|
|
98
|
+
}
|
|
80
99
|
|
|
81
|
-
_this.initRenderingContext(
|
|
100
|
+
_this.initRenderingContext({
|
|
101
|
+
container: container,
|
|
102
|
+
canvas: canvas,
|
|
103
|
+
width: canvasWidth,
|
|
104
|
+
height: canvasHeight,
|
|
105
|
+
renderer: renderer,
|
|
106
|
+
devicePixelRatio: dpr,
|
|
107
|
+
cursor: 'default',
|
|
108
|
+
background: background // background: 'white',
|
|
82
109
|
|
|
83
|
-
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
_this.initDefaultCamera(canvasWidth, canvasHeight);
|
|
84
113
|
|
|
85
|
-
_this.initRenderer(
|
|
114
|
+
_this.initRenderer(renderer);
|
|
86
115
|
|
|
87
116
|
return _this;
|
|
88
117
|
}
|
|
@@ -307,12 +336,10 @@ function (_super) {
|
|
|
307
336
|
Canvas.prototype.run = function () {
|
|
308
337
|
var _this = this;
|
|
309
338
|
|
|
310
|
-
var rAF = this.getConfig().requestAnimationFrame || _raf.requestAnimationFrame;
|
|
311
|
-
|
|
312
339
|
var tick = function tick() {
|
|
313
340
|
_this.render();
|
|
314
341
|
|
|
315
|
-
_this.frameId =
|
|
342
|
+
_this.frameId = (0, _raf.requestAnimationFrame)(tick);
|
|
316
343
|
};
|
|
317
344
|
|
|
318
345
|
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;
|
|
@@ -489,6 +489,16 @@ function (_super) {
|
|
|
489
489
|
return this;
|
|
490
490
|
};
|
|
491
491
|
|
|
492
|
+
DisplayObject.prototype.setRotation = function (rotation, y, z, w) {
|
|
493
|
+
this.sceneGraphService.setRotation(this, rotation, y, z, w);
|
|
494
|
+
return this;
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
DisplayObject.prototype.setLocalRotation = function (rotation, y, z, w) {
|
|
498
|
+
this.sceneGraphService.setLocalRotation(this, rotation, y, z, w);
|
|
499
|
+
return this;
|
|
500
|
+
};
|
|
501
|
+
|
|
492
502
|
DisplayObject.prototype.getRotation = function () {
|
|
493
503
|
return this.sceneGraphService.getRotation(this);
|
|
494
504
|
};
|
|
@@ -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/lib/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
|
}
|
|
@@ -42,6 +42,10 @@ function (_super) {
|
|
|
42
42
|
_this.isPrimary = false;
|
|
43
43
|
return _this;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/getCoalescedEvents
|
|
47
|
+
*/
|
|
48
|
+
|
|
45
49
|
|
|
46
50
|
FederatedPointerEvent.prototype.getCoalescedEvents = function () {
|
|
47
51
|
if (this.type === 'pointermove' || this.type === 'mousemove' || this.type === 'touchmove') {
|
|
@@ -50,6 +54,10 @@ function (_super) {
|
|
|
50
54
|
|
|
51
55
|
return [];
|
|
52
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* @see https://chromestatus.com/feature/5765569655603200
|
|
59
|
+
*/
|
|
60
|
+
|
|
53
61
|
|
|
54
62
|
FederatedPointerEvent.prototype.getPredictedEvents = function () {
|
|
55
63
|
throw new Error('getPredictedEvents is not supported!');
|
package/lib/global-module.js
CHANGED
|
@@ -154,7 +154,8 @@ var containerModule = (0, _manaSyringe.Module)(function (register) {
|
|
|
154
154
|
addPropertiesHandler(['lineDash'], _propertyHandlers.parseLineDash, // @ts-ignore
|
|
155
155
|
_propertyHandlers.mergeNumberLists, undefined);
|
|
156
156
|
addPropertiesHandler(['x1', 'x2', 'y1', 'y2', 'lineDashOffset', 'shadowOffsetX', 'shadowOffsetY'], _propertyHandlers.parseNumber, _propertyHandlers.mergeNumbers, undefined);
|
|
157
|
-
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',
|
|
157
|
+
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',
|
|
158
|
+
'wordWrap', 'wordWrapWidth', 'leading', 'textBaseline', 'textAlign', 'whiteSpace'], undefined, undefined, _propertyHandlers.updateGeometry);
|
|
158
159
|
addPropertiesHandler(['fill', 'stroke', 'shadowColor'], _propertyHandlers.parseColor, _propertyHandlers.mergeColors, undefined);
|
|
159
160
|
addPropertyHandler('clipPath', undefined, undefined, _propertyHandlers.updateClipPath);
|
|
160
161
|
addPropertyHandler('zIndex', undefined, undefined, _propertyHandlers.updateZIndex);
|
|
@@ -42,12 +42,14 @@ function updateGeometry(oldValue, newValue, object) {
|
|
|
42
42
|
x = _c === void 0 ? 0 : _c,
|
|
43
43
|
_d = _a.y,
|
|
44
44
|
y = _d === void 0 ? 0 : _d,
|
|
45
|
-
_e = _a.
|
|
46
|
-
|
|
47
|
-
_f = _a.
|
|
48
|
-
|
|
49
|
-
_g = _a.
|
|
50
|
-
|
|
45
|
+
_e = _a.z,
|
|
46
|
+
z = _e === void 0 ? 0 : _e,
|
|
47
|
+
_f = _a.offsetX,
|
|
48
|
+
offsetX = _f === void 0 ? 0 : _f,
|
|
49
|
+
_g = _a.offsetY,
|
|
50
|
+
offsetY = _g === void 0 ? 0 : _g,
|
|
51
|
+
_h = _a.offsetZ,
|
|
52
|
+
offsetZ = _h === void 0 ? 0 : _h;
|
|
51
53
|
|
|
52
54
|
object.parsedStyle.width = width;
|
|
53
55
|
object.parsedStyle.height = height;
|
|
@@ -61,23 +63,25 @@ function updateGeometry(oldValue, newValue, object) {
|
|
|
61
63
|
object.translateLocal(object.parsedStyle.offsetX, object.parsedStyle.offsetY);
|
|
62
64
|
object.parsedStyle.x = object.style.x;
|
|
63
65
|
object.parsedStyle.y = object.style.y;
|
|
66
|
+
object.parsedStyle.z = z;
|
|
64
67
|
} else {
|
|
65
68
|
object.parsedStyle.x = x;
|
|
66
69
|
object.parsedStyle.y = y;
|
|
70
|
+
object.parsedStyle.z = z;
|
|
67
71
|
} // init with content box
|
|
68
72
|
|
|
69
73
|
|
|
70
74
|
var halfExtents = _glMatrix.vec3.fromValues(width / 2, height / 2, depth / 2); // anchor is center by default, don't account for lineWidth here
|
|
71
75
|
|
|
72
76
|
|
|
73
|
-
var
|
|
74
|
-
|
|
75
|
-
lineWidth =
|
|
76
|
-
|
|
77
|
-
anchor =
|
|
78
|
-
shadowColor =
|
|
79
|
-
|
|
80
|
-
filter =
|
|
77
|
+
var _j = object.parsedStyle,
|
|
78
|
+
_k = _j.lineWidth,
|
|
79
|
+
lineWidth = _k === void 0 ? 0 : _k,
|
|
80
|
+
_l = _j.anchor,
|
|
81
|
+
anchor = _l === void 0 ? [0, 0] : _l,
|
|
82
|
+
shadowColor = _j.shadowColor,
|
|
83
|
+
_m = _j.filter,
|
|
84
|
+
filter = _m === void 0 ? [] : _m; // <Text> use textAlign & textBaseline instead of anchor
|
|
81
85
|
|
|
82
86
|
if (object.nodeName === _types.SHAPE.Text) {
|
|
83
87
|
delete object.parsedStyle.anchor;
|
|
@@ -96,16 +100,16 @@ function updateGeometry(oldValue, newValue, object) {
|
|
|
96
100
|
geometry_1.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
|
|
97
101
|
|
|
98
102
|
if (shadowColor && shadowColor.type === _color.PARSED_COLOR_TYPE.Constant) {
|
|
99
|
-
var
|
|
100
|
-
min =
|
|
101
|
-
max =
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
shadowBlur =
|
|
105
|
-
|
|
106
|
-
shadowOffsetX =
|
|
107
|
-
|
|
108
|
-
shadowOffsetY =
|
|
103
|
+
var _o = geometry_1.renderBounds,
|
|
104
|
+
min = _o.min,
|
|
105
|
+
max = _o.max;
|
|
106
|
+
var _p = object.parsedStyle,
|
|
107
|
+
_q = _p.shadowBlur,
|
|
108
|
+
shadowBlur = _q === void 0 ? 0 : _q,
|
|
109
|
+
_r = _p.shadowOffsetX,
|
|
110
|
+
shadowOffsetX = _r === void 0 ? 0 : _r,
|
|
111
|
+
_s = _p.shadowOffsetY,
|
|
112
|
+
shadowOffsetY = _s === void 0 ? 0 : _s;
|
|
109
113
|
var shadowLeft = min[0] - shadowBlur + shadowOffsetX;
|
|
110
114
|
var shadowRight = max[0] + shadowBlur + shadowOffsetX;
|
|
111
115
|
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
|
|
@@ -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;
|
|
@@ -76,72 +76,6 @@ var DefaultSceneGraphService =
|
|
|
76
76
|
function () {
|
|
77
77
|
function DefaultSceneGraphService() {
|
|
78
78
|
var _this = this;
|
|
79
|
-
/**
|
|
80
|
-
* compare two display objects by hierarchy-index and z-index
|
|
81
|
-
*
|
|
82
|
-
* use materialized path
|
|
83
|
-
* @see https://stackoverflow.com/questions/31470730/comparing-tree-nodes
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this.sort = function (object1, object2) {
|
|
88
|
-
if (!object1.parentNode) {
|
|
89
|
-
return -1;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (!object2.parentNode) {
|
|
93
|
-
return 1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
var hierarchyDiff = object1.transformable.graphDepth - object2.transformable.graphDepth;
|
|
97
|
-
var o1 = object1;
|
|
98
|
-
var o2 = object2;
|
|
99
|
-
|
|
100
|
-
if (hierarchyDiff < 0) {
|
|
101
|
-
o2 = object2.getAncestor(-hierarchyDiff);
|
|
102
|
-
|
|
103
|
-
if (o2 === o1) {
|
|
104
|
-
return -1;
|
|
105
|
-
}
|
|
106
|
-
} else if (hierarchyDiff > 0) {
|
|
107
|
-
o1 = object1.getAncestor(hierarchyDiff);
|
|
108
|
-
|
|
109
|
-
if (o2 === o1) {
|
|
110
|
-
return 1;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
while (o1 && o2 && o1.parentNode !== o2.parentNode) {
|
|
115
|
-
o1 = o1.parentNode;
|
|
116
|
-
o2 = o2.parentNode;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
var parent = o1.parentNode;
|
|
120
|
-
|
|
121
|
-
if (parent) {
|
|
122
|
-
var parentSortable = parent.sortable;
|
|
123
|
-
|
|
124
|
-
if (parentSortable) {
|
|
125
|
-
// no need to re-sort, use cached sorted children
|
|
126
|
-
if (!parentSortable.sorted) {
|
|
127
|
-
parentSortable.sorted = parent.childNodes.slice();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (parentSortable.dirty) {
|
|
131
|
-
parentSortable.sorted = parent.childNodes.slice().sort(sortByZIndex); // parentSortable.sorted.forEach(
|
|
132
|
-
// (child, i) => ((child as Element).sortable.lastSortedIndex = i),
|
|
133
|
-
// );
|
|
134
|
-
|
|
135
|
-
parentSortable.dirty = false;
|
|
136
|
-
} // return (o1 as Element).sortable.lastSortedIndex - (o2 as Element).sortable.lastSortedIndex;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return parentSortable.sorted.indexOf(o1) - parentSortable.sorted.indexOf(o2);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return -1;
|
|
144
|
-
};
|
|
145
79
|
/**
|
|
146
80
|
* rotate in world space
|
|
147
81
|
*/
|
|
@@ -180,7 +114,7 @@ function () {
|
|
|
180
114
|
|
|
181
115
|
_glMatrix.quat.invert(parentInvertRotation, parentInvertRotation);
|
|
182
116
|
|
|
183
|
-
_glMatrix.quat.multiply(
|
|
117
|
+
_glMatrix.quat.multiply(rotation, parentInvertRotation, rotation);
|
|
184
118
|
|
|
185
119
|
_glMatrix.quat.multiply(transform.localRotation, rotation, rot);
|
|
186
120
|
|
|
@@ -372,6 +306,34 @@ function () {
|
|
|
372
306
|
_this.setPosition(element, tr);
|
|
373
307
|
};
|
|
374
308
|
}();
|
|
309
|
+
|
|
310
|
+
this.setRotation = function () {
|
|
311
|
+
var parentInvertRotation = _glMatrix.quat.create();
|
|
312
|
+
|
|
313
|
+
return function (element, rotation, y, z, w) {
|
|
314
|
+
var transform = element.transformable;
|
|
315
|
+
|
|
316
|
+
if (typeof rotation === 'number') {
|
|
317
|
+
rotation = _glMatrix.quat.fromValues(rotation, y, z, w);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (element.parentNode === null || !element.parentNode.transformable) {
|
|
321
|
+
_this.setLocalRotation(element, rotation);
|
|
322
|
+
} else {
|
|
323
|
+
var parentRot = _this.getRotation(element.parentNode);
|
|
324
|
+
|
|
325
|
+
_glMatrix.quat.copy(parentInvertRotation, parentRot);
|
|
326
|
+
|
|
327
|
+
_glMatrix.quat.invert(parentInvertRotation, parentInvertRotation);
|
|
328
|
+
|
|
329
|
+
_glMatrix.quat.multiply(transform.localRotation, parentInvertRotation, rotation);
|
|
330
|
+
|
|
331
|
+
_glMatrix.quat.normalize(transform.localRotation, transform.localRotation);
|
|
332
|
+
|
|
333
|
+
_this.dirtifyLocal(element, transform);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
};
|
|
375
337
|
}
|
|
376
338
|
|
|
377
339
|
DefaultSceneGraphService.prototype.matches = function (query, root) {
|
|
@@ -454,6 +416,60 @@ function () {
|
|
|
454
416
|
child.parentNode = null;
|
|
455
417
|
}
|
|
456
418
|
};
|
|
419
|
+
/**
|
|
420
|
+
* compare two display objects by hierarchy-index and z-index
|
|
421
|
+
*
|
|
422
|
+
* use materialized path
|
|
423
|
+
* @see https://stackoverflow.com/questions/31470730/comparing-tree-nodes
|
|
424
|
+
*/
|
|
425
|
+
// sort = (object1: INode, object2: INode): number => {
|
|
426
|
+
// if (!object1.parentNode) {
|
|
427
|
+
// return -1;
|
|
428
|
+
// }
|
|
429
|
+
// if (!object2.parentNode) {
|
|
430
|
+
// return 1;
|
|
431
|
+
// }
|
|
432
|
+
// const hierarchyDiff =
|
|
433
|
+
// (object1 as Element).transformable.graphDepth - (object2 as Element).transformable.graphDepth;
|
|
434
|
+
// let o1 = object1;
|
|
435
|
+
// let o2 = object2;
|
|
436
|
+
// if (hierarchyDiff < 0) {
|
|
437
|
+
// o2 = object2.getAncestor(-hierarchyDiff)!;
|
|
438
|
+
// if (o2 === o1) {
|
|
439
|
+
// return -1;
|
|
440
|
+
// }
|
|
441
|
+
// } else if (hierarchyDiff > 0) {
|
|
442
|
+
// o1 = object1.getAncestor(hierarchyDiff)!;
|
|
443
|
+
// if (o2 === o1) {
|
|
444
|
+
// return 1;
|
|
445
|
+
// }
|
|
446
|
+
// }
|
|
447
|
+
// while (o1 && o2 && o1.parentNode !== o2.parentNode) {
|
|
448
|
+
// o1 = o1.parentNode!;
|
|
449
|
+
// o2 = o2.parentNode!;
|
|
450
|
+
// }
|
|
451
|
+
// const parent = o1.parentNode;
|
|
452
|
+
// if (parent) {
|
|
453
|
+
// const parentSortable = (parent as Element).sortable;
|
|
454
|
+
// if (parentSortable) {
|
|
455
|
+
// // no need to re-sort, use cached sorted children
|
|
456
|
+
// if (!parentSortable.sorted) {
|
|
457
|
+
// parentSortable.sorted = (parent.childNodes as IElement[]).slice();
|
|
458
|
+
// }
|
|
459
|
+
// if (parentSortable.dirty) {
|
|
460
|
+
// parentSortable.sorted = (parent.childNodes as IElement[]).slice().sort(sortByZIndex);
|
|
461
|
+
// // parentSortable.sorted.forEach(
|
|
462
|
+
// // (child, i) => ((child as Element).sortable.lastSortedIndex = i),
|
|
463
|
+
// // );
|
|
464
|
+
// parentSortable.dirty = false;
|
|
465
|
+
// }
|
|
466
|
+
// // return (o1 as Element).sortable.lastSortedIndex - (o2 as Element).sortable.lastSortedIndex;
|
|
467
|
+
// return parentSortable.sorted.indexOf(o1) - parentSortable.sorted.indexOf(o2);
|
|
468
|
+
// }
|
|
469
|
+
// }
|
|
470
|
+
// return -1;
|
|
471
|
+
// };
|
|
472
|
+
|
|
457
473
|
|
|
458
474
|
DefaultSceneGraphService.prototype.getOrigin = function (element) {
|
|
459
475
|
return element.transformable.origin;
|
|
@@ -552,6 +568,18 @@ function () {
|
|
|
552
568
|
this.dirtifyLocal(element, transform);
|
|
553
569
|
};
|
|
554
570
|
|
|
571
|
+
DefaultSceneGraphService.prototype.setLocalRotation = function (element, rotation, y, z, w) {
|
|
572
|
+
if (typeof rotation === 'number') {
|
|
573
|
+
rotation = _glMatrix.quat.fromValues(rotation, y, z, w);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
var transform = element.transformable;
|
|
577
|
+
|
|
578
|
+
_glMatrix.quat.copy(transform.localRotation, rotation);
|
|
579
|
+
|
|
580
|
+
this.dirtifyLocal(element, transform);
|
|
581
|
+
};
|
|
582
|
+
|
|
555
583
|
DefaultSceneGraphService.prototype.dirtifyLocal = function (element, transform) {
|
|
556
584
|
if (!transform.localDirtyFlag) {
|
|
557
585
|
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;
|
|
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.GeometryUpdaterFactory = exports.GeometryAABBUpdater = void 0;
|
|
7
7
|
var GeometryUpdaterFactory = 'GeometryUpdaterFactory';
|
|
8
8
|
exports.GeometryUpdaterFactory = GeometryUpdaterFactory;
|
|
9
|
-
var GeometryAABBUpdater = '
|
|
9
|
+
var GeometryAABBUpdater = 'GeometryAABBUpdater';
|
|
10
10
|
exports.GeometryAABBUpdater = GeometryAABBUpdater;
|
package/lib/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/lib/utils/canvas.d.ts
CHANGED