@antv/g 5.0.5 → 5.0.9
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 +15 -0
- package/es/Canvas.d.ts +4 -2
- package/es/Canvas.js +11 -5
- package/es/camera/Camera.d.ts +2 -1
- package/es/camera/Camera.js +13 -5
- package/es/components/Sortable.d.ts +4 -0
- package/es/components/Sortable.js +5 -0
- package/es/display-objects/Line.d.ts +6 -0
- package/es/display-objects/Line.js +7 -8
- package/es/display-objects/Path.js +3 -7
- package/es/display-objects/Polyline.js +3 -7
- package/es/display-objects/Text.js +3 -7
- package/es/dom/EventTarget.d.ts +1 -1
- package/es/dom/EventTarget.js +1 -1
- package/es/dom/interfaces.d.ts +5 -1
- package/es/dom/interfaces.js +5 -0
- package/es/global-module.js +1 -2
- package/es/property-handlers/localPosition.js +4 -2
- package/es/services/RenderingService.d.ts +1 -0
- package/es/services/RenderingService.js +14 -0
- package/es/services/SceneGraphService.js +4 -4
- package/es/types.d.ts +10 -2
- package/es/types.js +16 -0
- package/lib/Canvas.d.ts +4 -2
- package/lib/Canvas.js +11 -5
- package/lib/camera/Camera.d.ts +2 -1
- package/lib/camera/Camera.js +14 -5
- package/lib/components/Sortable.d.ts +4 -0
- package/lib/components/Sortable.js +5 -0
- package/lib/display-objects/Line.d.ts +6 -0
- package/lib/display-objects/Line.js +6 -7
- package/lib/display-objects/Path.js +2 -6
- package/lib/display-objects/Polyline.js +2 -6
- package/lib/display-objects/Text.js +2 -6
- package/lib/dom/EventTarget.d.ts +1 -1
- package/lib/dom/EventTarget.js +1 -1
- package/lib/dom/interfaces.d.ts +5 -1
- package/lib/dom/interfaces.js +5 -0
- package/lib/global-module.js +1 -2
- package/lib/property-handlers/localPosition.js +4 -2
- package/lib/services/RenderingService.d.ts +1 -0
- package/lib/services/RenderingService.js +15 -0
- package/lib/services/SceneGraphService.js +4 -4
- package/lib/types.d.ts +10 -2
- package/lib/types.js +19 -1
- package/package.json +4 -4
- package/dist/index.umd.js +0 -15
package/es/Canvas.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Cursor } from './types';
|
|
1
2
|
import { CanvasConfig } from './types';
|
|
2
3
|
import { DisplayObject } from './display-objects/DisplayObject';
|
|
3
4
|
import { ContextService } from './services';
|
|
@@ -5,7 +6,7 @@ import { RenderingService } from './services/RenderingService';
|
|
|
5
6
|
import { RenderingContext } from './services/RenderingContext';
|
|
6
7
|
import { EventService } from './services/EventService';
|
|
7
8
|
import { Camera } from './camera';
|
|
8
|
-
import type {
|
|
9
|
+
import type { IRenderer } from './AbstractRenderer';
|
|
9
10
|
import type { PointLike } from './shapes';
|
|
10
11
|
import type { IChildNode } from './dom';
|
|
11
12
|
import { Document, EventTarget } from './dom';
|
|
@@ -87,7 +88,8 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
87
88
|
private initRenderer;
|
|
88
89
|
private loadCommonContainerModule;
|
|
89
90
|
private loadRendererContainerModule;
|
|
90
|
-
setRenderer(renderer:
|
|
91
|
+
setRenderer(renderer: IRenderer): void;
|
|
92
|
+
setCursor(cursor: Cursor): void;
|
|
91
93
|
private unmountChildren;
|
|
92
94
|
private mountChildren;
|
|
93
95
|
client2Viewport(client: PointLike): PointLike;
|
package/es/Canvas.js
CHANGED
|
@@ -50,9 +50,11 @@ function (_super) {
|
|
|
50
50
|
_this.customElements = new CustomElementRegistry();
|
|
51
51
|
cleanExistedCanvas(config.container, _this);
|
|
52
52
|
|
|
53
|
-
var mergedConfig = __assign(
|
|
53
|
+
var mergedConfig = __assign({
|
|
54
|
+
width: 300,
|
|
55
|
+
height: 150,
|
|
54
56
|
cursor: 'default'
|
|
55
|
-
});
|
|
57
|
+
}, config);
|
|
56
58
|
|
|
57
59
|
_this.initRenderingContext(mergedConfig);
|
|
58
60
|
|
|
@@ -98,8 +100,7 @@ function (_super) {
|
|
|
98
100
|
|
|
99
101
|
Canvas.prototype.initDefaultCamera = function (width, height) {
|
|
100
102
|
// set a default ortho camera
|
|
101
|
-
var camera = new Camera().setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0)
|
|
102
|
-
.setOrthographic(width / -2, width / 2, height / -2, height / 2, 0.1, 1000); // redraw when camera changed
|
|
103
|
+
var camera = new Camera().setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0).setOrthographic(width / -2, width / 2, height / 2, height / -2, 0.1, 1000); // redraw when camera changed
|
|
103
104
|
|
|
104
105
|
var context = this.container.get(RenderingContext);
|
|
105
106
|
camera.on(CAMERA_EVENT.Updated, function () {
|
|
@@ -207,9 +208,10 @@ function (_super) {
|
|
|
207
208
|
|
|
208
209
|
var camera = this.container.get(DefaultCamera);
|
|
209
210
|
var projectionMode = camera.getProjectionMode();
|
|
211
|
+
camera.setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0);
|
|
210
212
|
|
|
211
213
|
if (projectionMode === CAMERA_PROJECTION_MODE.ORTHOGRAPHIC) {
|
|
212
|
-
camera.
|
|
214
|
+
camera.setOrthographic(width / -2, width / 2, height / 2, height / -2, camera.getNear(), camera.getFar());
|
|
213
215
|
} else {
|
|
214
216
|
camera.setAspect(width / height);
|
|
215
217
|
}
|
|
@@ -338,6 +340,10 @@ function (_super) {
|
|
|
338
340
|
this.initRenderer(renderer);
|
|
339
341
|
};
|
|
340
342
|
|
|
343
|
+
Canvas.prototype.setCursor = function (cursor) {
|
|
344
|
+
this.getContextService().applyCursorStyle(cursor);
|
|
345
|
+
};
|
|
346
|
+
|
|
341
347
|
Canvas.prototype.unmountChildren = function (parent) {
|
|
342
348
|
var path = [];
|
|
343
349
|
parent.forEach(function (child) {
|
package/es/camera/Camera.d.ts
CHANGED
|
@@ -129,6 +129,7 @@ export declare class Camera extends EventEmitter {
|
|
|
129
129
|
* ortho matrix for Canvas2D & SVG
|
|
130
130
|
*/
|
|
131
131
|
private orthoMatrix;
|
|
132
|
+
isOrtho(): boolean;
|
|
132
133
|
clone(): Camera;
|
|
133
134
|
getProjectionMode(): CAMERA_PROJECTION_MODE;
|
|
134
135
|
getPerspective(): mat4;
|
|
@@ -167,7 +168,7 @@ export declare class Camera extends EventEmitter {
|
|
|
167
168
|
* 设置相机矩阵
|
|
168
169
|
*/
|
|
169
170
|
setMatrix(matrix: mat4): this;
|
|
170
|
-
setFov(fov: number):
|
|
171
|
+
setFov(fov: number): this;
|
|
171
172
|
setAspect(aspect: number): this;
|
|
172
173
|
setNear(near: number): this;
|
|
173
174
|
setFar(far: number): this;
|
package/es/camera/Camera.js
CHANGED
|
@@ -136,7 +136,7 @@ function (_super) {
|
|
|
136
136
|
|
|
137
137
|
_this.fov = 30;
|
|
138
138
|
_this.near = 0.1;
|
|
139
|
-
_this.far =
|
|
139
|
+
_this.far = 1000;
|
|
140
140
|
_this.aspect = 1;
|
|
141
141
|
_this.projectionMatrix = mat4.create();
|
|
142
142
|
_this.projectionMatrixInverse = mat4.create();
|
|
@@ -163,6 +163,10 @@ function (_super) {
|
|
|
163
163
|
return _this;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
Camera.prototype.isOrtho = function () {
|
|
167
|
+
return this.projectionMode === CAMERA_PROJECTION_MODE.ORTHOGRAPHIC;
|
|
168
|
+
};
|
|
169
|
+
|
|
166
170
|
Camera.prototype.clone = function () {
|
|
167
171
|
var camera = new Camera();
|
|
168
172
|
camera.setType(this.type, undefined); // camera.interactor = this.interactor;
|
|
@@ -297,6 +301,7 @@ function (_super) {
|
|
|
297
301
|
|
|
298
302
|
Camera.prototype.setFov = function (fov) {
|
|
299
303
|
this.setPerspective(this.near, this.far, fov, this.aspect);
|
|
304
|
+
return this;
|
|
300
305
|
};
|
|
301
306
|
|
|
302
307
|
Camera.prototype.setAspect = function (aspect) {
|
|
@@ -404,10 +409,11 @@ function (_super) {
|
|
|
404
409
|
top -= this.view.offsetY * height / fullHeight;
|
|
405
410
|
width *= this.view.width / fullWidth;
|
|
406
411
|
height *= this.view.height / fullHeight;
|
|
407
|
-
}
|
|
412
|
+
}
|
|
408
413
|
|
|
414
|
+
makePerspective(this.projectionMatrix, left, left + width, top, top - height, near, this.far); // flipY since the origin of OpenGL/WebGL is bottom-left compared with top-left in Canvas2D
|
|
409
415
|
|
|
410
|
-
|
|
416
|
+
mat4.scale(this.projectionMatrix, this.projectionMatrix, vec3.fromValues(1, -1, 1));
|
|
411
417
|
mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
|
|
412
418
|
this.emit(CAMERA_EVENT.Updated);
|
|
413
419
|
return this;
|
|
@@ -439,7 +445,9 @@ function (_super) {
|
|
|
439
445
|
bottom = top - scaleH * this.view.height;
|
|
440
446
|
}
|
|
441
447
|
|
|
442
|
-
mat4.ortho(this.projectionMatrix, left, right, bottom, top, near, far);
|
|
448
|
+
mat4.ortho(this.projectionMatrix, left, right, bottom, top, near, far); // flipY since the origin of OpenGL/WebGL is bottom-left compared with top-left in Canvas2D
|
|
449
|
+
|
|
450
|
+
mat4.scale(this.projectionMatrix, this.projectionMatrix, vec3.fromValues(1, -1, 1));
|
|
443
451
|
mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
|
|
444
452
|
|
|
445
453
|
this._getOrthoMatrix();
|
|
@@ -960,7 +968,7 @@ function (_super) {
|
|
|
960
968
|
|
|
961
969
|
var position = this.position;
|
|
962
970
|
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], -this.roll * Math.PI / 180);
|
|
963
|
-
mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.
|
|
971
|
+
mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.top - this.bottom) / 2 - position[1], 0), vec3.fromValues(this.zoom, this.zoom, 1), position);
|
|
964
972
|
};
|
|
965
973
|
|
|
966
974
|
Camera.ProjectionMode = {
|
|
@@ -7,14 +7,20 @@ export interface LineStyleProps extends BaseStyleProps {
|
|
|
7
7
|
y1: number;
|
|
8
8
|
x2: number;
|
|
9
9
|
y2: number;
|
|
10
|
+
z1?: number;
|
|
11
|
+
z2?: number;
|
|
12
|
+
isBillboard?: boolean;
|
|
10
13
|
}
|
|
11
14
|
export interface ParsedLineStyleProps extends ParsedBaseStyleProps {
|
|
12
15
|
x1: number;
|
|
13
16
|
y1: number;
|
|
14
17
|
x2: number;
|
|
15
18
|
y2: number;
|
|
19
|
+
z1?: number;
|
|
20
|
+
z2?: number;
|
|
16
21
|
defX: number;
|
|
17
22
|
defY: number;
|
|
23
|
+
isBillboard?: boolean;
|
|
18
24
|
}
|
|
19
25
|
export declare class Line extends DisplayObject<LineStyleProps, ParsedLineStyleProps> {
|
|
20
26
|
constructor({ style, ...rest }: DisplayObjectConfig<LineStyleProps>);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __assign, __extends, __rest } from "tslib";
|
|
2
2
|
import { Line as LineUtil } from '@antv/g-math';
|
|
3
|
-
import { SHAPE } from '../types';
|
|
3
|
+
import { SHAPE, LINE_CAP, LINE_JOIN } from '../types';
|
|
4
4
|
import { DisplayObject } from './DisplayObject';
|
|
5
5
|
import { Point } from '../shapes';
|
|
6
6
|
|
|
@@ -20,13 +20,12 @@ function (_super) {
|
|
|
20
20
|
y1: 0,
|
|
21
21
|
x2: 0,
|
|
22
22
|
y2: 0,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
,
|
|
26
|
-
lineCap:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
lineWidth: 1
|
|
23
|
+
z1: 0,
|
|
24
|
+
z2: 0,
|
|
25
|
+
lineJoin: LINE_JOIN.Miter,
|
|
26
|
+
lineCap: LINE_CAP.Butt,
|
|
27
|
+
lineWidth: 1,
|
|
28
|
+
isBillboard: false
|
|
30
29
|
}, style)
|
|
31
30
|
}, rest)) || this;
|
|
32
31
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __assign, __extends, __rest } from "tslib";
|
|
2
|
-
import { SHAPE } from '../types';
|
|
2
|
+
import { SHAPE, LINE_CAP, LINE_JOIN } from '../types';
|
|
3
3
|
import { DisplayObject } from './DisplayObject';
|
|
4
4
|
import { Point } from '../shapes';
|
|
5
5
|
import { Cubic as CubicUtil } from '@antv/g-math';
|
|
@@ -18,12 +18,8 @@ function (_super) {
|
|
|
18
18
|
type: SHAPE.Path,
|
|
19
19
|
style: __assign({
|
|
20
20
|
path: '',
|
|
21
|
-
lineJoin:
|
|
22
|
-
|
|
23
|
-
,
|
|
24
|
-
lineCap: "butt"
|
|
25
|
-
/* Butt */
|
|
26
|
-
,
|
|
21
|
+
lineJoin: LINE_JOIN.Miter,
|
|
22
|
+
lineCap: LINE_CAP.Butt,
|
|
27
23
|
lineWidth: 1
|
|
28
24
|
}, style)
|
|
29
25
|
}, rest)) || this;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __assign, __extends, __rest } from "tslib";
|
|
2
2
|
import { Line as LineUtil } from '@antv/g-math';
|
|
3
|
-
import { SHAPE } from '../types';
|
|
3
|
+
import { SHAPE, LINE_CAP, LINE_JOIN } from '../types';
|
|
4
4
|
import { DisplayObject } from './DisplayObject';
|
|
5
5
|
import { Point } from '../shapes';
|
|
6
6
|
|
|
@@ -17,12 +17,8 @@ function (_super) {
|
|
|
17
17
|
type: SHAPE.Polyline,
|
|
18
18
|
style: __assign({
|
|
19
19
|
points: [],
|
|
20
|
-
lineJoin:
|
|
21
|
-
|
|
22
|
-
,
|
|
23
|
-
lineCap: "butt"
|
|
24
|
-
/* Butt */
|
|
25
|
-
,
|
|
20
|
+
lineJoin: LINE_JOIN.Miter,
|
|
21
|
+
lineCap: LINE_CAP.Butt,
|
|
26
22
|
lineWidth: 1
|
|
27
23
|
}, style)
|
|
28
24
|
}, rest)) || this;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __assign, __extends, __rest } from "tslib";
|
|
2
|
-
import { SHAPE } from '../types';
|
|
2
|
+
import { SHAPE, LINE_JOIN, LINE_CAP } from '../types';
|
|
3
3
|
import { DisplayObject } from './DisplayObject';
|
|
4
4
|
|
|
5
5
|
var Text =
|
|
@@ -31,12 +31,8 @@ function (_super) {
|
|
|
31
31
|
fill: '#000',
|
|
32
32
|
letterSpacing: 0,
|
|
33
33
|
lineHeight: 0,
|
|
34
|
-
lineJoin:
|
|
35
|
-
|
|
36
|
-
,
|
|
37
|
-
lineCap: "butt"
|
|
38
|
-
/* Butt */
|
|
39
|
-
,
|
|
34
|
+
lineJoin: LINE_JOIN.Miter,
|
|
35
|
+
lineCap: LINE_CAP.Butt,
|
|
40
36
|
lineWidth: 0,
|
|
41
37
|
miterLimit: 10,
|
|
42
38
|
padding: 0,
|
package/es/dom/EventTarget.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare class EventTarget implements IEventTarget {
|
|
|
27
27
|
*/
|
|
28
28
|
off(type: string, listener: EventListenerOrEventListenerObject | ((...args: any[]) => void), options?: boolean | AddEventListenerOptions): this;
|
|
29
29
|
removeAllEventListeners(): void;
|
|
30
|
-
removeEventListener(type: string, listener
|
|
30
|
+
removeEventListener(type: string, listener?: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): this;
|
|
31
31
|
/**
|
|
32
32
|
* @deprecated
|
|
33
33
|
* @alias dispatchEvent
|
package/es/dom/EventTarget.js
CHANGED
|
@@ -110,7 +110,7 @@ function () {
|
|
|
110
110
|
var capture = isBoolean(options) && options || isObject(options) && options.capture;
|
|
111
111
|
var context = isFunction(listener) ? undefined : listener;
|
|
112
112
|
type = capture ? type + "capture" : type;
|
|
113
|
-
listener = isFunction(listener) ? listener : listener.handleEvent;
|
|
113
|
+
listener = isFunction(listener) ? listener : listener === null || listener === void 0 ? void 0 : listener.handleEvent;
|
|
114
114
|
this.emitter.off(type, listener, context);
|
|
115
115
|
return this;
|
|
116
116
|
};
|
package/es/dom/interfaces.d.ts
CHANGED
|
@@ -31,7 +31,11 @@ export declare enum ElementEvent {
|
|
|
31
31
|
CHILD_REMOVED = "child-removed",
|
|
32
32
|
MOUNTED = "mounted",
|
|
33
33
|
UNMOUNTED = "unmounted",
|
|
34
|
-
BOUNDS_CHANGED = "bounds-changed"
|
|
34
|
+
BOUNDS_CHANGED = "bounds-changed",
|
|
35
|
+
/**
|
|
36
|
+
* trigger when z-index changed
|
|
37
|
+
*/
|
|
38
|
+
RENDER_ORDER_CHANGED = "render-order-changed"
|
|
35
39
|
}
|
|
36
40
|
export interface IEventTarget {
|
|
37
41
|
emitter: EventEmitter;
|
package/es/dom/interfaces.js
CHANGED
|
@@ -29,4 +29,9 @@ export var ElementEvent;
|
|
|
29
29
|
ElementEvent["MOUNTED"] = "mounted";
|
|
30
30
|
ElementEvent["UNMOUNTED"] = "unmounted";
|
|
31
31
|
ElementEvent["BOUNDS_CHANGED"] = "bounds-changed";
|
|
32
|
+
/**
|
|
33
|
+
* trigger when z-index changed
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
ElementEvent["RENDER_ORDER_CHANGED"] = "render-order-changed";
|
|
32
37
|
})(ElementEvent || (ElementEvent = {}));
|
package/es/global-module.js
CHANGED
|
@@ -154,8 +154,7 @@ export var containerModule = Module(function (register) {
|
|
|
154
154
|
|
|
155
155
|
addPropertyHandler('points', parsePoints, undefined, undefined); // update local position
|
|
156
156
|
|
|
157
|
-
addPropertiesHandler(['x', 'y', 'points', 'path', 'x1', 'x2', 'y1', 'y2'
|
|
158
|
-
undefined, undefined, updateLocalPosition);
|
|
157
|
+
addPropertiesHandler(['x', 'y', 'z', 'points', 'path', 'x1', 'x2', 'y1', 'y2', 'z1', 'z2'], undefined, undefined, updateLocalPosition);
|
|
159
158
|
addPropertyHandler('filter', parseFilter, undefined, undefined);
|
|
160
159
|
addPropertyHandler('anchor', undefined, undefined, updateAnchor);
|
|
161
160
|
});
|
|
@@ -3,7 +3,9 @@ export function updateLocalPosition(oldValue, newValue, object) {
|
|
|
3
3
|
_b = _a.x,
|
|
4
4
|
x = _b === void 0 ? 0 : _b,
|
|
5
5
|
_c = _a.y,
|
|
6
|
-
y = _c === void 0 ? 0 : _c
|
|
6
|
+
y = _c === void 0 ? 0 : _c,
|
|
7
|
+
_d = _a.z,
|
|
8
|
+
z = _d === void 0 ? 0 : _d; // update local position when x/y changed
|
|
7
9
|
|
|
8
|
-
object.setLocalPosition(x, y);
|
|
10
|
+
object.setLocalPosition(x, y, z);
|
|
9
11
|
}
|
|
@@ -25,6 +25,7 @@ export declare class RenderingService {
|
|
|
25
25
|
private sceneGraphService;
|
|
26
26
|
private inited;
|
|
27
27
|
private stats;
|
|
28
|
+
private zIndexCounter;
|
|
28
29
|
hooks: {
|
|
29
30
|
init: AsyncSeriesHook<[], import("tapable").UnsetAdditionalOptions>;
|
|
30
31
|
prepare: SyncWaterfallHook<[DisplayObject<any, any>], import("tapable").UnsetAdditionalOptions>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __awaiter, __decorate, __generator, __metadata } from "tslib";
|
|
2
2
|
import { inject, singleton, contrib, Syringe, Contribution } from 'mana-syringe';
|
|
3
3
|
import { SyncHook, SyncWaterfallHook, AsyncSeriesHook, AsyncSeriesWaterfallHook } from 'tapable';
|
|
4
|
+
import { ElementEvent } from '../dom';
|
|
4
5
|
import { RenderingContext, RENDER_REASON } from './RenderingContext';
|
|
5
6
|
import { SceneGraphService, sortByZIndex } from './SceneGraphService';
|
|
6
7
|
export var RenderingPluginContribution = Syringe.defineToken('RenderingPluginContribution');
|
|
@@ -23,6 +24,7 @@ function () {
|
|
|
23
24
|
total: 0,
|
|
24
25
|
rendered: 0
|
|
25
26
|
};
|
|
27
|
+
this.zIndexCounter = 0;
|
|
26
28
|
this.hooks = {
|
|
27
29
|
init: new AsyncSeriesHook(),
|
|
28
30
|
prepare: new SyncWaterfallHook(['object']),
|
|
@@ -82,6 +84,7 @@ function () {
|
|
|
82
84
|
RenderingService.prototype.render = function () {
|
|
83
85
|
this.stats.total = 0;
|
|
84
86
|
this.stats.rendered = 0;
|
|
87
|
+
this.zIndexCounter = 0;
|
|
85
88
|
this.sceneGraphService.syncHierarchy(this.renderingContext.root);
|
|
86
89
|
|
|
87
90
|
if (this.renderingContext.renderReasons.size && this.inited) {
|
|
@@ -107,6 +110,7 @@ function () {
|
|
|
107
110
|
|
|
108
111
|
|
|
109
112
|
var objectToRender = this.hooks.prepare.call(displayObject);
|
|
113
|
+
displayObject.sortable.renderOrder = this.zIndexCounter++;
|
|
110
114
|
this.stats.total++;
|
|
111
115
|
|
|
112
116
|
if (objectToRender) {
|
|
@@ -125,10 +129,12 @@ function () {
|
|
|
125
129
|
|
|
126
130
|
|
|
127
131
|
var sortable = displayObject.sortable;
|
|
132
|
+
var renderOrderChanged = false;
|
|
128
133
|
|
|
129
134
|
if (sortable.dirty) {
|
|
130
135
|
// sortable.sorted = [...(displayObject.childNodes as IElement[])].sort(sortByZIndex);
|
|
131
136
|
sortable.sorted = displayObject.childNodes.slice().sort(sortByZIndex);
|
|
137
|
+
renderOrderChanged = true;
|
|
132
138
|
sortable.dirty = false;
|
|
133
139
|
} // recursive rendering its children
|
|
134
140
|
|
|
@@ -136,6 +142,14 @@ function () {
|
|
|
136
142
|
(sortable.sorted || displayObject.childNodes).forEach(function (child) {
|
|
137
143
|
_this.renderDisplayObject(child);
|
|
138
144
|
});
|
|
145
|
+
|
|
146
|
+
if (renderOrderChanged) {
|
|
147
|
+
displayObject.forEach(function (child) {
|
|
148
|
+
child.emit(ElementEvent.RENDER_ORDER_CHANGED, {
|
|
149
|
+
renderOrder: child.sortable.renderOrder
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
139
153
|
};
|
|
140
154
|
|
|
141
155
|
RenderingService.prototype.destroy = function () {
|
|
@@ -144,7 +144,7 @@ function () {
|
|
|
144
144
|
|
|
145
145
|
var transform = element.transformable;
|
|
146
146
|
|
|
147
|
-
if (element.parentNode === null) {
|
|
147
|
+
if (element.parentNode === null || !element.parentNode.transformable) {
|
|
148
148
|
_this.rotateLocal(element, degrees);
|
|
149
149
|
} else {
|
|
150
150
|
var rotation = quat.create();
|
|
@@ -214,7 +214,7 @@ function () {
|
|
|
214
214
|
|
|
215
215
|
var transform = element.transformable;
|
|
216
216
|
|
|
217
|
-
if (element.parentNode === null) {
|
|
217
|
+
if (element.parentNode === null || !element.parentNode.transformable) {
|
|
218
218
|
_this.setLocalEulerAngles(element, degrees);
|
|
219
219
|
} else {
|
|
220
220
|
quat.fromEuler(transform.localRotation, degrees[0], degrees[1], degrees[2]);
|
|
@@ -285,7 +285,7 @@ function () {
|
|
|
285
285
|
|
|
286
286
|
transform.position = position;
|
|
287
287
|
|
|
288
|
-
if (element.parentNode === null) {
|
|
288
|
+
if (element.parentNode === null || !element.parentNode.transformable) {
|
|
289
289
|
vec3.copy(transform.localPosition, position);
|
|
290
290
|
} else {
|
|
291
291
|
var parentTransform = element.parentNode.transformable;
|
|
@@ -547,7 +547,7 @@ function () {
|
|
|
547
547
|
return transform.worldTransform;
|
|
548
548
|
}
|
|
549
549
|
|
|
550
|
-
if (element.parentNode) {
|
|
550
|
+
if (element.parentNode && element.parentNode.transformable) {
|
|
551
551
|
this.getWorldTransform(element.parentNode);
|
|
552
552
|
}
|
|
553
553
|
|
package/es/types.d.ts
CHANGED
|
@@ -25,12 +25,12 @@ export interface EventPosition {
|
|
|
25
25
|
x: number;
|
|
26
26
|
y: number;
|
|
27
27
|
}
|
|
28
|
-
export declare
|
|
28
|
+
export declare enum LINE_CAP {
|
|
29
29
|
Butt = "butt",
|
|
30
30
|
Round = "round",
|
|
31
31
|
Square = "square"
|
|
32
32
|
}
|
|
33
|
-
export declare
|
|
33
|
+
export declare enum LINE_JOIN {
|
|
34
34
|
Bevel = "bevel",
|
|
35
35
|
Round = "round",
|
|
36
36
|
Miter = "miter"
|
|
@@ -44,6 +44,10 @@ export interface BaseStyleProps {
|
|
|
44
44
|
* y in local space
|
|
45
45
|
*/
|
|
46
46
|
y?: number;
|
|
47
|
+
/**
|
|
48
|
+
* z in local space
|
|
49
|
+
*/
|
|
50
|
+
z?: number;
|
|
47
51
|
/**
|
|
48
52
|
* the origin of rotation and scaling, default to (0, 0)
|
|
49
53
|
*/
|
|
@@ -180,6 +184,10 @@ export interface CanvasConfig {
|
|
|
180
184
|
* @type {number}
|
|
181
185
|
*/
|
|
182
186
|
height: number;
|
|
187
|
+
/**
|
|
188
|
+
* 画布背景色
|
|
189
|
+
*/
|
|
190
|
+
background?: ColorType;
|
|
183
191
|
/**
|
|
184
192
|
* 是否可监听
|
|
185
193
|
* @type {boolean}
|
package/es/types.js
CHANGED
|
@@ -14,4 +14,20 @@ export var SHAPE;
|
|
|
14
14
|
SHAPE["HTML"] = "html";
|
|
15
15
|
})(SHAPE || (SHAPE = {}));
|
|
16
16
|
|
|
17
|
+
export var LINE_CAP;
|
|
18
|
+
|
|
19
|
+
(function (LINE_CAP) {
|
|
20
|
+
LINE_CAP["Butt"] = "butt";
|
|
21
|
+
LINE_CAP["Round"] = "round";
|
|
22
|
+
LINE_CAP["Square"] = "square";
|
|
23
|
+
})(LINE_CAP || (LINE_CAP = {}));
|
|
24
|
+
|
|
25
|
+
export var LINE_JOIN;
|
|
26
|
+
|
|
27
|
+
(function (LINE_JOIN) {
|
|
28
|
+
LINE_JOIN["Bevel"] = "bevel";
|
|
29
|
+
LINE_JOIN["Round"] = "round";
|
|
30
|
+
LINE_JOIN["Miter"] = "miter";
|
|
31
|
+
})(LINE_JOIN || (LINE_JOIN = {}));
|
|
32
|
+
|
|
17
33
|
export var CanvasConfig = 'CanvasConfig';
|
package/lib/Canvas.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Cursor } from './types';
|
|
1
2
|
import { CanvasConfig } from './types';
|
|
2
3
|
import { DisplayObject } from './display-objects/DisplayObject';
|
|
3
4
|
import { ContextService } from './services';
|
|
@@ -5,7 +6,7 @@ import { RenderingService } from './services/RenderingService';
|
|
|
5
6
|
import { RenderingContext } from './services/RenderingContext';
|
|
6
7
|
import { EventService } from './services/EventService';
|
|
7
8
|
import { Camera } from './camera';
|
|
8
|
-
import type {
|
|
9
|
+
import type { IRenderer } from './AbstractRenderer';
|
|
9
10
|
import type { PointLike } from './shapes';
|
|
10
11
|
import type { IChildNode } from './dom';
|
|
11
12
|
import { Document, EventTarget } from './dom';
|
|
@@ -87,7 +88,8 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
87
88
|
private initRenderer;
|
|
88
89
|
private loadCommonContainerModule;
|
|
89
90
|
private loadRendererContainerModule;
|
|
90
|
-
setRenderer(renderer:
|
|
91
|
+
setRenderer(renderer: IRenderer): void;
|
|
92
|
+
setCursor(cursor: Cursor): void;
|
|
91
93
|
private unmountChildren;
|
|
92
94
|
private mountChildren;
|
|
93
95
|
client2Viewport(client: PointLike): PointLike;
|
package/lib/Canvas.js
CHANGED
|
@@ -71,9 +71,11 @@ function (_super) {
|
|
|
71
71
|
|
|
72
72
|
_this.customElements = new _CustomElementRegistry.CustomElementRegistry();
|
|
73
73
|
(0, _canvas.cleanExistedCanvas)(config.container, _this);
|
|
74
|
-
var mergedConfig = (0, _tslib.__assign)(
|
|
74
|
+
var mergedConfig = (0, _tslib.__assign)({
|
|
75
|
+
width: 300,
|
|
76
|
+
height: 150,
|
|
75
77
|
cursor: 'default'
|
|
76
|
-
});
|
|
78
|
+
}, config);
|
|
77
79
|
|
|
78
80
|
_this.initRenderingContext(mergedConfig);
|
|
79
81
|
|
|
@@ -119,8 +121,7 @@ function (_super) {
|
|
|
119
121
|
|
|
120
122
|
Canvas.prototype.initDefaultCamera = function (width, height) {
|
|
121
123
|
// set a default ortho camera
|
|
122
|
-
var camera = new _camera.Camera().setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0)
|
|
123
|
-
.setOrthographic(width / -2, width / 2, height / -2, height / 2, 0.1, 1000); // redraw when camera changed
|
|
124
|
+
var camera = new _camera.Camera().setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0).setOrthographic(width / -2, width / 2, height / 2, height / -2, 0.1, 1000); // redraw when camera changed
|
|
124
125
|
|
|
125
126
|
var context = this.container.get(_RenderingContext.RenderingContext);
|
|
126
127
|
camera.on(_camera.CAMERA_EVENT.Updated, function () {
|
|
@@ -228,9 +229,10 @@ function (_super) {
|
|
|
228
229
|
|
|
229
230
|
var camera = this.container.get(_camera.DefaultCamera);
|
|
230
231
|
var projectionMode = camera.getProjectionMode();
|
|
232
|
+
camera.setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0);
|
|
231
233
|
|
|
232
234
|
if (projectionMode === _camera.CAMERA_PROJECTION_MODE.ORTHOGRAPHIC) {
|
|
233
|
-
camera.
|
|
235
|
+
camera.setOrthographic(width / -2, width / 2, height / 2, height / -2, camera.getNear(), camera.getFar());
|
|
234
236
|
} else {
|
|
235
237
|
camera.setAspect(width / height);
|
|
236
238
|
}
|
|
@@ -359,6 +361,10 @@ function (_super) {
|
|
|
359
361
|
this.initRenderer(renderer);
|
|
360
362
|
};
|
|
361
363
|
|
|
364
|
+
Canvas.prototype.setCursor = function (cursor) {
|
|
365
|
+
this.getContextService().applyCursorStyle(cursor);
|
|
366
|
+
};
|
|
367
|
+
|
|
362
368
|
Canvas.prototype.unmountChildren = function (parent) {
|
|
363
369
|
var path = [];
|
|
364
370
|
parent.forEach(function (child) {
|
package/lib/camera/Camera.d.ts
CHANGED
|
@@ -129,6 +129,7 @@ export declare class Camera extends EventEmitter {
|
|
|
129
129
|
* ortho matrix for Canvas2D & SVG
|
|
130
130
|
*/
|
|
131
131
|
private orthoMatrix;
|
|
132
|
+
isOrtho(): boolean;
|
|
132
133
|
clone(): Camera;
|
|
133
134
|
getProjectionMode(): CAMERA_PROJECTION_MODE;
|
|
134
135
|
getPerspective(): mat4;
|
|
@@ -167,7 +168,7 @@ export declare class Camera extends EventEmitter {
|
|
|
167
168
|
* 设置相机矩阵
|
|
168
169
|
*/
|
|
169
170
|
setMatrix(matrix: mat4): this;
|
|
170
|
-
setFov(fov: number):
|
|
171
|
+
setFov(fov: number): this;
|
|
171
172
|
setAspect(aspect: number): this;
|
|
172
173
|
setNear(near: number): this;
|
|
173
174
|
setFar(far: number): this;
|