@antv/g 5.0.11 → 5.0.12
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/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 -0
- package/es/services/SceneGraphService.js +35 -1
- package/es/services/aabb/interfaces.d.ts +1 -0
- package/es/types.d.ts +2 -6
- 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/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 -0
- package/lib/services/SceneGraphService.js +41 -1
- package/lib/services/aabb/interfaces.d.ts +1 -0
- package/lib/types.d.ts +2 -6
- 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 +2 -2
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;
|
|
@@ -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
|
/**
|
|
@@ -30,6 +30,8 @@ export interface SceneGraphService {
|
|
|
30
30
|
rotateLocal: (element: INode, degrees: vec3 | number, y?: number, z?: number) => void;
|
|
31
31
|
rotate: (element: INode, degrees: vec3 | number, y?: number, z?: number) => void;
|
|
32
32
|
getRotation: (element: INode) => quat;
|
|
33
|
+
setRotation: (element: INode, rotation: quat | number, y?: number, z?: number, w?: number) => void;
|
|
34
|
+
setLocalRotation: (element: INode, rotation: quat | number, y?: number, z?: number, w?: number) => void;
|
|
33
35
|
getLocalRotation: (element: INode) => quat;
|
|
34
36
|
getWorldTransform: (element: INode, transform?: Transform) => mat4;
|
|
35
37
|
getLocalTransform: (element: INode, transform?: Transform) => mat4;
|
|
@@ -117,6 +119,8 @@ export declare class DefaultSceneGraphService implements SceneGraphService {
|
|
|
117
119
|
* @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L665-L676
|
|
118
120
|
*/
|
|
119
121
|
translate: (element: INode, translation: vec3 | number, y?: number, z?: number) => void;
|
|
122
|
+
setRotation: () => (element: INode, rotation: quat | number, y?: number, z?: number, w?: number) => void;
|
|
123
|
+
setLocalRotation(element: INode, rotation: quat | number, y?: number, z?: number, w?: number): void;
|
|
120
124
|
dirtifyLocal(element: INode, transform: Transform): void;
|
|
121
125
|
dirtifyWorld(element: INode, transform: Transform): void;
|
|
122
126
|
getPosition(element: INode): vec3;
|
|
@@ -156,7 +156,7 @@ function () {
|
|
|
156
156
|
|
|
157
157
|
quat.copy(parentInvertRotation, parentRot);
|
|
158
158
|
quat.invert(parentInvertRotation, parentInvertRotation);
|
|
159
|
-
quat.multiply(
|
|
159
|
+
quat.multiply(rotation, parentInvertRotation, rotation);
|
|
160
160
|
quat.multiply(transform.localRotation, rotation, rot);
|
|
161
161
|
quat.normalize(transform.localRotation, transform.localRotation);
|
|
162
162
|
|
|
@@ -335,6 +335,30 @@ function () {
|
|
|
335
335
|
_this.setPosition(element, tr);
|
|
336
336
|
};
|
|
337
337
|
}();
|
|
338
|
+
|
|
339
|
+
this.setRotation = function () {
|
|
340
|
+
var parentInvertRotation = quat.create();
|
|
341
|
+
return function (element, rotation, y, z, w) {
|
|
342
|
+
var transform = element.transformable;
|
|
343
|
+
|
|
344
|
+
if (typeof rotation === 'number') {
|
|
345
|
+
rotation = quat.fromValues(rotation, y, z, w);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (element.parentNode === null || !element.parentNode.transformable) {
|
|
349
|
+
_this.setLocalRotation(element, rotation);
|
|
350
|
+
} else {
|
|
351
|
+
var parentRot = _this.getRotation(element.parentNode);
|
|
352
|
+
|
|
353
|
+
quat.copy(parentInvertRotation, parentRot);
|
|
354
|
+
quat.invert(parentInvertRotation, parentInvertRotation);
|
|
355
|
+
quat.multiply(transform.localRotation, parentInvertRotation, rotation);
|
|
356
|
+
quat.normalize(transform.localRotation, transform.localRotation);
|
|
357
|
+
|
|
358
|
+
_this.dirtifyLocal(element, transform);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
};
|
|
338
362
|
}
|
|
339
363
|
|
|
340
364
|
DefaultSceneGraphService.prototype.matches = function (query, root) {
|
|
@@ -504,6 +528,16 @@ function () {
|
|
|
504
528
|
this.dirtifyLocal(element, transform);
|
|
505
529
|
};
|
|
506
530
|
|
|
531
|
+
DefaultSceneGraphService.prototype.setLocalRotation = function (element, rotation, y, z, w) {
|
|
532
|
+
if (typeof rotation === 'number') {
|
|
533
|
+
rotation = quat.fromValues(rotation, y, z, w);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
var transform = element.transformable;
|
|
537
|
+
quat.copy(transform.localRotation, rotation);
|
|
538
|
+
this.dirtifyLocal(element, transform);
|
|
539
|
+
};
|
|
540
|
+
|
|
507
541
|
DefaultSceneGraphService.prototype.dirtifyLocal = function (element, transform) {
|
|
508
542
|
if (!transform.localDirtyFlag) {
|
|
509
543
|
transform.localDirtyFlag = true;
|
package/es/types.d.ts
CHANGED
|
@@ -190,19 +190,15 @@ export interface CanvasConfig {
|
|
|
190
190
|
/**
|
|
191
191
|
* 画布宽度
|
|
192
192
|
*/
|
|
193
|
-
width
|
|
193
|
+
width?: number;
|
|
194
194
|
/**
|
|
195
195
|
* 画布高度
|
|
196
196
|
*/
|
|
197
|
-
height
|
|
197
|
+
height?: number;
|
|
198
198
|
/**
|
|
199
199
|
* 画布背景色
|
|
200
200
|
*/
|
|
201
201
|
background?: ColorType;
|
|
202
|
-
/**
|
|
203
|
-
* 是否可监听
|
|
204
|
-
*/
|
|
205
|
-
capture?: boolean;
|
|
206
202
|
/**
|
|
207
203
|
* 画布的 cursor 样式
|
|
208
204
|
*/
|
package/es/utils/canvas.d.ts
CHANGED
package/es/utils/canvas.js
CHANGED
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;
|
|
@@ -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
|