@antv/g 5.0.2 → 5.0.6
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.js +1 -1
- package/es/Canvas.d.ts +14 -4
- package/es/Canvas.js +18 -10
- 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/CustomElement.d.ts +10 -11
- package/es/display-objects/CustomElement.js +20 -10
- package/es/display-objects/DisplayObject.d.ts +2 -5
- package/es/display-objects/DisplayObject.js +16 -9
- package/es/display-objects/Line.d.ts +4 -0
- package/es/display-objects/Line.js +2 -0
- package/es/dom/Document.d.ts +1 -1
- package/es/dom/Element.d.ts +9 -9
- package/es/dom/Element.js +7 -4
- package/es/dom/Node.d.ts +9 -9
- package/es/dom/interfaces.d.ts +13 -9
- package/es/dom/interfaces.js +5 -0
- package/es/global-module.d.ts +4 -0
- package/es/global-module.js +58 -71
- package/es/plugins/FrustumCullingStrategy.js +3 -1
- package/es/property-handlers/localPosition.js +4 -2
- package/es/services/RenderingService.d.ts +6 -0
- package/es/services/RenderingService.js +29 -1
- package/es/types.d.ts +8 -1
- package/es/utils/interpolation.js +10 -7
- package/lib/Canvas.d.ts +14 -4
- package/lib/Canvas.js +18 -10
- 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/CustomElement.d.ts +10 -11
- package/lib/display-objects/CustomElement.js +20 -10
- package/lib/display-objects/DisplayObject.d.ts +2 -5
- package/lib/display-objects/DisplayObject.js +13 -8
- package/lib/display-objects/Line.d.ts +4 -0
- package/lib/display-objects/Line.js +2 -0
- package/lib/dom/Document.d.ts +1 -1
- package/lib/dom/Element.d.ts +9 -9
- package/lib/dom/Element.js +7 -4
- package/lib/dom/Node.d.ts +9 -9
- package/lib/dom/interfaces.d.ts +13 -9
- package/lib/dom/interfaces.js +5 -0
- package/lib/global-module.d.ts +4 -0
- package/lib/global-module.js +58 -71
- package/lib/plugins/FrustumCullingStrategy.js +2 -0
- package/lib/property-handlers/localPosition.js +4 -2
- package/lib/services/RenderingService.d.ts +6 -0
- package/lib/services/RenderingService.js +30 -1
- package/lib/types.d.ts +8 -1
- package/lib/utils/interpolation.js +7 -9
- package/package.json +3 -3
package/es/global-module.js
CHANGED
|
@@ -7,8 +7,14 @@ import { TextService } from './services/text';
|
|
|
7
7
|
import { TextUpdater } from './services/aabb/TextUpdater';
|
|
8
8
|
import { OffscreenCanvasCreator } from './services/text/OffscreenCanvasCreator';
|
|
9
9
|
import { DefaultSceneGraphSelector, SceneGraphSelector, SceneGraphSelectorFactory } from './services/SceneGraphSelector';
|
|
10
|
-
import {
|
|
10
|
+
import { // StylePropertyParserFactory,
|
|
11
|
+
// StylePropertyUpdaterFactory,
|
|
12
|
+
// StylePropertyMergerFactory,
|
|
13
|
+
clampedMergeNumbers, parseNumber, mergeColors, parseColor, updateGeometry, updateLocalPosition, updateOffsetPath, updateClipPath, updateZIndex, updateOffsetDistance, updateOrigin, updateTransform, updateTransformOrigin, parseTransform, mergeTransforms, parsePath, parsePoints, mergePaths, mergeNumbers, mergeNumberLists, parseFilter, updateAnchor, parseLineDash } from './property-handlers';
|
|
11
14
|
export var globalContainer = GlobalContainer;
|
|
15
|
+
export var stylePropertyParserFactory = {};
|
|
16
|
+
export var stylePropertyUpdaterFactory = {};
|
|
17
|
+
export var stylePropertyMergerFactory = {};
|
|
12
18
|
export var containerModule = Module(function (register) {
|
|
13
19
|
decorate(injectable(), EventEmitter); // bind DisplayObject pool
|
|
14
20
|
|
|
@@ -56,83 +62,65 @@ export var containerModule = Module(function (register) {
|
|
|
56
62
|
return cache[tagName];
|
|
57
63
|
};
|
|
58
64
|
}
|
|
59
|
-
}); // bind style property handlers
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return cache[propertyName];
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
});
|
|
65
|
+
}); // // bind style property handlers
|
|
66
|
+
// register({
|
|
67
|
+
// token: StylePropertyParserFactory,
|
|
68
|
+
// useFactory: (context) => {
|
|
69
|
+
// const cache = {};
|
|
70
|
+
// return (propertyName: string) => {
|
|
71
|
+
// if (!cache[propertyName]) {
|
|
72
|
+
// if (context.container.isBoundNamed(StylePropertyParser, propertyName)) {
|
|
73
|
+
// cache[propertyName] = context.container.getNamed(StylePropertyParser, propertyName);
|
|
74
|
+
// }
|
|
75
|
+
// }
|
|
76
|
+
// return cache[propertyName];
|
|
77
|
+
// };
|
|
78
|
+
// },
|
|
79
|
+
// });
|
|
80
|
+
// register({
|
|
81
|
+
// token: StylePropertyUpdaterFactory,
|
|
82
|
+
// useFactory: (context) => {
|
|
83
|
+
// const cache = {};
|
|
84
|
+
// return (propertyName: string) => {
|
|
85
|
+
// if (!cache[propertyName]) {
|
|
86
|
+
// if (context.container.isBoundNamed(StylePropertyUpdater, propertyName)) {
|
|
87
|
+
// cache[propertyName] = context.container.getAllNamed(StylePropertyUpdater, propertyName);
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
90
|
+
// return cache[propertyName];
|
|
91
|
+
// };
|
|
92
|
+
// },
|
|
93
|
+
// });
|
|
94
|
+
// register({
|
|
95
|
+
// token: StylePropertyMergerFactory,
|
|
96
|
+
// useFactory: (context) => {
|
|
97
|
+
// const cache = {};
|
|
98
|
+
// return (propertyName: string) => {
|
|
99
|
+
// if (!cache[propertyName]) {
|
|
100
|
+
// if (context.container.isBoundNamed(StylePropertyMerger, propertyName)) {
|
|
101
|
+
// cache[propertyName] = context.container.getNamed(StylePropertyMerger, propertyName);
|
|
102
|
+
// }
|
|
103
|
+
// }
|
|
104
|
+
// return cache[propertyName];
|
|
105
|
+
// };
|
|
106
|
+
// },
|
|
107
|
+
// });
|
|
106
108
|
|
|
107
109
|
function addPropertyHandler(property, parser, merger, updater) {
|
|
108
110
|
if (parser) {
|
|
109
|
-
register({
|
|
110
|
-
token: {
|
|
111
|
-
token: StylePropertyParser,
|
|
112
|
-
named: property
|
|
113
|
-
},
|
|
114
|
-
useValue: parser
|
|
115
|
-
});
|
|
111
|
+
stylePropertyParserFactory[property] = parser; // register({ token: { token: StylePropertyParser, named: property }, useValue: parser });
|
|
116
112
|
}
|
|
117
113
|
|
|
118
114
|
if (merger) {
|
|
119
|
-
register({
|
|
120
|
-
token: {
|
|
121
|
-
token: StylePropertyMerger,
|
|
122
|
-
named: property
|
|
123
|
-
},
|
|
124
|
-
useValue: merger
|
|
125
|
-
});
|
|
115
|
+
stylePropertyMergerFactory[property] = merger; // register({ token: { token: StylePropertyMerger, named: property }, useValue: merger });
|
|
126
116
|
}
|
|
127
117
|
|
|
128
118
|
if (updater) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
useValue: updater
|
|
135
|
-
});
|
|
119
|
+
if (!stylePropertyUpdaterFactory[property]) {
|
|
120
|
+
stylePropertyUpdaterFactory[property] = [];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
stylePropertyUpdaterFactory[property].push(updater); // register({ token: { token: StylePropertyUpdater, named: property }, useValue: updater });
|
|
136
124
|
}
|
|
137
125
|
}
|
|
138
126
|
|
|
@@ -166,8 +154,7 @@ export var containerModule = Module(function (register) {
|
|
|
166
154
|
|
|
167
155
|
addPropertyHandler('points', parsePoints, undefined, undefined); // update local position
|
|
168
156
|
|
|
169
|
-
addPropertiesHandler(['x', 'y', 'points', 'path', 'x1', 'x2', 'y1', 'y2'
|
|
170
|
-
undefined, undefined, updateLocalPosition);
|
|
157
|
+
addPropertiesHandler(['x', 'y', 'z', 'points', 'path', 'x1', 'x2', 'y1', 'y2', 'z1', 'z2'], undefined, undefined, updateLocalPosition);
|
|
171
158
|
addPropertyHandler('filter', parseFilter, undefined, undefined);
|
|
172
159
|
addPropertyHandler('anchor', undefined, undefined, updateAnchor);
|
|
173
160
|
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
1
|
+
import { __decorate } from "tslib"; // import { vec3, mat4 } from 'gl-matrix';
|
|
2
|
+
// import { inject, singleton } from 'mana-syringe';
|
|
3
|
+
|
|
2
4
|
import { vec3 } from 'gl-matrix';
|
|
3
5
|
import { singleton } from 'mana-syringe';
|
|
4
6
|
import { CullingStrategyContribution } from './CullingPlugin';
|
|
@@ -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
|
}
|
|
@@ -24,6 +24,8 @@ export declare class RenderingService {
|
|
|
24
24
|
private renderingContext;
|
|
25
25
|
private sceneGraphService;
|
|
26
26
|
private inited;
|
|
27
|
+
private stats;
|
|
28
|
+
private zIndexCounter;
|
|
27
29
|
hooks: {
|
|
28
30
|
init: AsyncSeriesHook<[], import("tapable").UnsetAdditionalOptions>;
|
|
29
31
|
prepare: SyncWaterfallHook<[DisplayObject<any, any>], import("tapable").UnsetAdditionalOptions>;
|
|
@@ -45,6 +47,10 @@ export declare class RenderingService {
|
|
|
45
47
|
pointerWheel: SyncHook<[InteractivePointerEvent], void, import("tapable").UnsetAdditionalOptions>;
|
|
46
48
|
};
|
|
47
49
|
init(): Promise<void>;
|
|
50
|
+
getStats(): {
|
|
51
|
+
total: number;
|
|
52
|
+
rendered: number;
|
|
53
|
+
};
|
|
48
54
|
render(): void;
|
|
49
55
|
private renderDisplayObject;
|
|
50
56
|
destroy(): void;
|
|
@@ -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');
|
|
@@ -19,6 +20,11 @@ var RenderingService =
|
|
|
19
20
|
function () {
|
|
20
21
|
function RenderingService() {
|
|
21
22
|
this.inited = false;
|
|
23
|
+
this.stats = {
|
|
24
|
+
total: 0,
|
|
25
|
+
rendered: 0
|
|
26
|
+
};
|
|
27
|
+
this.zIndexCounter = 0;
|
|
22
28
|
this.hooks = {
|
|
23
29
|
init: new AsyncSeriesHook(),
|
|
24
30
|
prepare: new SyncWaterfallHook(['object']),
|
|
@@ -71,7 +77,14 @@ function () {
|
|
|
71
77
|
});
|
|
72
78
|
};
|
|
73
79
|
|
|
80
|
+
RenderingService.prototype.getStats = function () {
|
|
81
|
+
return this.stats;
|
|
82
|
+
};
|
|
83
|
+
|
|
74
84
|
RenderingService.prototype.render = function () {
|
|
85
|
+
this.stats.total = 0;
|
|
86
|
+
this.stats.rendered = 0;
|
|
87
|
+
this.zIndexCounter = 0;
|
|
75
88
|
this.sceneGraphService.syncHierarchy(this.renderingContext.root);
|
|
76
89
|
|
|
77
90
|
if (this.renderingContext.renderReasons.size && this.inited) {
|
|
@@ -88,7 +101,8 @@ function () {
|
|
|
88
101
|
}
|
|
89
102
|
|
|
90
103
|
this.renderingContext.renderReasons.clear();
|
|
91
|
-
}
|
|
104
|
+
} // console.log('render objects: ', this.stats.count);
|
|
105
|
+
|
|
92
106
|
};
|
|
93
107
|
|
|
94
108
|
RenderingService.prototype.renderDisplayObject = function (displayObject) {
|
|
@@ -96,8 +110,12 @@ function () {
|
|
|
96
110
|
|
|
97
111
|
|
|
98
112
|
var objectToRender = this.hooks.prepare.call(displayObject);
|
|
113
|
+
displayObject.sortable.renderOrder = this.zIndexCounter++;
|
|
114
|
+
this.stats.total++;
|
|
99
115
|
|
|
100
116
|
if (objectToRender) {
|
|
117
|
+
this.stats.rendered++;
|
|
118
|
+
|
|
101
119
|
if (!this.renderingContext.dirty) {
|
|
102
120
|
this.renderingContext.dirty = true;
|
|
103
121
|
this.hooks.beginFrame.call();
|
|
@@ -111,10 +129,12 @@ function () {
|
|
|
111
129
|
|
|
112
130
|
|
|
113
131
|
var sortable = displayObject.sortable;
|
|
132
|
+
var renderOrderChanged = false;
|
|
114
133
|
|
|
115
134
|
if (sortable.dirty) {
|
|
116
135
|
// sortable.sorted = [...(displayObject.childNodes as IElement[])].sort(sortByZIndex);
|
|
117
136
|
sortable.sorted = displayObject.childNodes.slice().sort(sortByZIndex);
|
|
137
|
+
renderOrderChanged = true;
|
|
118
138
|
sortable.dirty = false;
|
|
119
139
|
} // recursive rendering its children
|
|
120
140
|
|
|
@@ -122,6 +142,14 @@ function () {
|
|
|
122
142
|
(sortable.sorted || displayObject.childNodes).forEach(function (child) {
|
|
123
143
|
_this.renderDisplayObject(child);
|
|
124
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
|
+
}
|
|
125
153
|
};
|
|
126
154
|
|
|
127
155
|
RenderingService.prototype.destroy = function () {
|
package/es/types.d.ts
CHANGED
|
@@ -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}
|
|
@@ -192,7 +200,6 @@ export interface CanvasConfig {
|
|
|
192
200
|
cursor?: Cursor;
|
|
193
201
|
[key: string]: any;
|
|
194
202
|
}
|
|
195
|
-
export declare type ChangeType = 'changeSize' | 'add' | 'sort' | 'clear' | 'attr' | 'show' | 'hide' | 'zIndex' | 'remove' | 'matrix' | 'clip';
|
|
196
203
|
declare type A = ['a' | 'A', number, number, number, number, number, number, number];
|
|
197
204
|
declare type C = ['c' | 'C', number, number, number, number, number, number];
|
|
198
205
|
declare type O = ['o' | 'O', number, number];
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { __read, __spreadArray } from "tslib";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { stylePropertyMergerFactory, stylePropertyParserFactory } from '../global-module'; // import {
|
|
3
|
+
// StylePropertyMergerFactory,
|
|
4
|
+
// StylePropertyParserFactory,
|
|
5
|
+
// } from '../property-handlers/interfaces';
|
|
6
|
+
|
|
4
7
|
import { parseEasingFunction } from './animation';
|
|
5
8
|
export function convertEffectInput(keyframes, timing, target) {
|
|
6
9
|
var propertySpecificKeyframeGroups = makePropertySpecificKeyframeGroups(keyframes, timing);
|
|
@@ -104,11 +107,11 @@ function makeInterpolations(propertySpecificKeyframeGroups, target) {
|
|
|
104
107
|
|
|
105
108
|
function propertyInterpolation(property, left, right, target) {
|
|
106
109
|
var parsedLeft = left;
|
|
107
|
-
var parsedRight = right;
|
|
108
|
-
|
|
109
|
-
var parser =
|
|
110
|
-
|
|
111
|
-
var merger =
|
|
110
|
+
var parsedRight = right; // const parserFactory = globalContainer.get<StylePropertyParserFactory>(StylePropertyParserFactory);
|
|
111
|
+
|
|
112
|
+
var parser = stylePropertyParserFactory[property]; // const mergerFactory = globalContainer.get<StylePropertyMergerFactory>(StylePropertyMergerFactory);
|
|
113
|
+
|
|
114
|
+
var merger = stylePropertyMergerFactory[property]; // if (left == 'initial' || right == 'initial') {
|
|
112
115
|
// if (left == 'initial')
|
|
113
116
|
// left = initialValues[ucProperty];
|
|
114
117
|
// if (right == 'initial')
|
package/lib/Canvas.d.ts
CHANGED
|
@@ -7,8 +7,9 @@ import { EventService } from './services/EventService';
|
|
|
7
7
|
import { Camera } from './camera';
|
|
8
8
|
import type { AbstractRenderer } from './AbstractRenderer';
|
|
9
9
|
import type { PointLike } from './shapes';
|
|
10
|
+
import type { IChildNode } from './dom';
|
|
10
11
|
import { Document, EventTarget } from './dom';
|
|
11
|
-
import type {
|
|
12
|
+
import type { ICanvas } from './dom/interfaces';
|
|
12
13
|
import { CustomElementRegistry } from './dom/CustomElementRegistry';
|
|
13
14
|
export declare enum CanvasEvent {
|
|
14
15
|
READY = "ready",
|
|
@@ -41,6 +42,11 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
41
42
|
* rAF in auto rendering
|
|
42
43
|
*/
|
|
43
44
|
private frameId?;
|
|
45
|
+
/**
|
|
46
|
+
* cache here since inversify's resolving is very slow
|
|
47
|
+
*/
|
|
48
|
+
private eventService;
|
|
49
|
+
private renderingService;
|
|
44
50
|
constructor(config: CanvasConfig);
|
|
45
51
|
private initRenderingContext;
|
|
46
52
|
private initDefaultCamera;
|
|
@@ -59,6 +65,10 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
59
65
|
getEventService(): EventService;
|
|
60
66
|
getRenderingService(): RenderingService;
|
|
61
67
|
getRenderingContext(): RenderingContext;
|
|
68
|
+
getStats(): {
|
|
69
|
+
total: number;
|
|
70
|
+
rendered: number;
|
|
71
|
+
};
|
|
62
72
|
getComputedStyle(node: DisplayObject): any;
|
|
63
73
|
destroy(destroyScenegraph?: boolean): void;
|
|
64
74
|
/**
|
|
@@ -68,9 +78,9 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
68
78
|
*/
|
|
69
79
|
changeSize(width: number, height: number): void;
|
|
70
80
|
resize(width: number, height: number): void;
|
|
71
|
-
appendChild<T extends
|
|
72
|
-
insertBefore<T extends
|
|
73
|
-
removeChild<T extends
|
|
81
|
+
appendChild<T extends IChildNode>(child: T, index?: number): T;
|
|
82
|
+
insertBefore<T extends IChildNode, N extends IChildNode>(newChild: T, refChild: N | null): T;
|
|
83
|
+
removeChild<T extends IChildNode>(child: T, destroy?: boolean): T;
|
|
74
84
|
removeChildren(destroy?: boolean): void;
|
|
75
85
|
render(): void;
|
|
76
86
|
private run;
|
package/lib/Canvas.js
CHANGED
|
@@ -71,9 +71,12 @@ 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)(
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
var mergedConfig = (0, _tslib.__assign)({
|
|
75
|
+
width: 300,
|
|
76
|
+
height: 150,
|
|
77
|
+
cursor: 'default',
|
|
78
|
+
background: 'white'
|
|
79
|
+
}, config);
|
|
77
80
|
|
|
78
81
|
_this.initRenderingContext(mergedConfig);
|
|
79
82
|
|
|
@@ -119,8 +122,7 @@ function (_super) {
|
|
|
119
122
|
|
|
120
123
|
Canvas.prototype.initDefaultCamera = function (width, height) {
|
|
121
124
|
// 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
|
|
125
|
+
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
126
|
|
|
125
127
|
var context = this.container.get(_RenderingContext.RenderingContext);
|
|
126
128
|
camera.on(_camera.CAMERA_EVENT.Updated, function () {
|
|
@@ -163,17 +165,21 @@ function (_super) {
|
|
|
163
165
|
};
|
|
164
166
|
|
|
165
167
|
Canvas.prototype.getEventService = function () {
|
|
166
|
-
return this.
|
|
168
|
+
return this.eventService;
|
|
167
169
|
};
|
|
168
170
|
|
|
169
171
|
Canvas.prototype.getRenderingService = function () {
|
|
170
|
-
return this.
|
|
172
|
+
return this.renderingService;
|
|
171
173
|
};
|
|
172
174
|
|
|
173
175
|
Canvas.prototype.getRenderingContext = function () {
|
|
174
176
|
return this.container.get(_RenderingContext.RenderingContext);
|
|
175
177
|
};
|
|
176
178
|
|
|
179
|
+
Canvas.prototype.getStats = function () {
|
|
180
|
+
return this.getRenderingService().getStats();
|
|
181
|
+
};
|
|
182
|
+
|
|
177
183
|
Canvas.prototype.getComputedStyle = function (node) {
|
|
178
184
|
return node.parsedStyle;
|
|
179
185
|
};
|
|
@@ -224,9 +230,10 @@ function (_super) {
|
|
|
224
230
|
|
|
225
231
|
var camera = this.container.get(_camera.DefaultCamera);
|
|
226
232
|
var projectionMode = camera.getProjectionMode();
|
|
233
|
+
camera.setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0);
|
|
227
234
|
|
|
228
235
|
if (projectionMode === _camera.CAMERA_PROJECTION_MODE.ORTHOGRAPHIC) {
|
|
229
|
-
camera.
|
|
236
|
+
camera.setOrthographic(width / -2, width / 2, height / 2, height / -2, camera.getNear(), camera.getFar());
|
|
230
237
|
} else {
|
|
231
238
|
camera.setAspect(width / height);
|
|
232
239
|
}
|
|
@@ -296,9 +303,10 @@ function (_super) {
|
|
|
296
303
|
this.loadRendererContainerModule(renderer); // init context
|
|
297
304
|
|
|
298
305
|
var contextService = this.container.get(_services.ContextService);
|
|
299
|
-
|
|
306
|
+
this.renderingService = this.container.get(_RenderingService.RenderingService);
|
|
307
|
+
this.eventService = this.container.get(_EventService.EventService);
|
|
300
308
|
contextService.init();
|
|
301
|
-
renderingService.init().then(function () {
|
|
309
|
+
this.renderingService.init().then(function () {
|
|
302
310
|
_this.emit(CanvasEvent.READY, {});
|
|
303
311
|
});
|
|
304
312
|
|
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;
|
package/lib/camera/Camera.js
CHANGED
|
@@ -155,7 +155,7 @@ function (_super) {
|
|
|
155
155
|
|
|
156
156
|
_this.fov = 30;
|
|
157
157
|
_this.near = 0.1;
|
|
158
|
-
_this.far =
|
|
158
|
+
_this.far = 1000;
|
|
159
159
|
_this.aspect = 1;
|
|
160
160
|
_this.projectionMatrix = _glMatrix.mat4.create();
|
|
161
161
|
_this.projectionMatrixInverse = _glMatrix.mat4.create();
|
|
@@ -182,6 +182,10 @@ function (_super) {
|
|
|
182
182
|
return _this;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
Camera.prototype.isOrtho = function () {
|
|
186
|
+
return this.projectionMode === CAMERA_PROJECTION_MODE.ORTHOGRAPHIC;
|
|
187
|
+
};
|
|
188
|
+
|
|
185
189
|
Camera.prototype.clone = function () {
|
|
186
190
|
var camera = new Camera();
|
|
187
191
|
camera.setType(this.type, undefined); // camera.interactor = this.interactor;
|
|
@@ -317,6 +321,7 @@ function (_super) {
|
|
|
317
321
|
|
|
318
322
|
Camera.prototype.setFov = function (fov) {
|
|
319
323
|
this.setPerspective(this.near, this.far, fov, this.aspect);
|
|
324
|
+
return this;
|
|
320
325
|
};
|
|
321
326
|
|
|
322
327
|
Camera.prototype.setAspect = function (aspect) {
|
|
@@ -424,10 +429,11 @@ function (_super) {
|
|
|
424
429
|
top -= this.view.offsetY * height / fullHeight;
|
|
425
430
|
width *= this.view.width / fullWidth;
|
|
426
431
|
height *= this.view.height / fullHeight;
|
|
427
|
-
}
|
|
432
|
+
}
|
|
428
433
|
|
|
434
|
+
(0, _math.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
|
|
429
435
|
|
|
430
|
-
|
|
436
|
+
_glMatrix.mat4.scale(this.projectionMatrix, this.projectionMatrix, _glMatrix.vec3.fromValues(1, -1, 1));
|
|
431
437
|
|
|
432
438
|
_glMatrix.mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
|
|
433
439
|
|
|
@@ -461,7 +467,10 @@ function (_super) {
|
|
|
461
467
|
bottom = top - scaleH * this.view.height;
|
|
462
468
|
}
|
|
463
469
|
|
|
464
|
-
_glMatrix.mat4.ortho(this.projectionMatrix, left, right, bottom, top, near, far);
|
|
470
|
+
_glMatrix.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
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
_glMatrix.mat4.scale(this.projectionMatrix, this.projectionMatrix, _glMatrix.vec3.fromValues(1, -1, 1));
|
|
465
474
|
|
|
466
475
|
_glMatrix.mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
|
|
467
476
|
|
|
@@ -1033,7 +1042,7 @@ function (_super) {
|
|
|
1033
1042
|
|
|
1034
1043
|
var rotZ = _glMatrix.quat.setAxisAngle(_glMatrix.quat.create(), [0, 0, 1], -this.roll * Math.PI / 180);
|
|
1035
1044
|
|
|
1036
|
-
_glMatrix.mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, _glMatrix.vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.
|
|
1045
|
+
_glMatrix.mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, _glMatrix.vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.top - this.bottom) / 2 - position[1], 0), _glMatrix.vec3.fromValues(this.zoom, this.zoom, 1), position);
|
|
1037
1046
|
};
|
|
1038
1047
|
|
|
1039
1048
|
Camera.ProjectionMode = {
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { DisplayObject } from './DisplayObject';
|
|
2
2
|
import type { DisplayObjectConfig } from '../dom/interfaces';
|
|
3
|
-
export interface CustomElement<CustomElementStyleProps> {
|
|
4
|
-
/**
|
|
5
|
-
* fired after element insert into DOM tree
|
|
6
|
-
*/
|
|
7
|
-
connectedCallback?: () => void;
|
|
8
|
-
/**
|
|
9
|
-
* fired before element removed from DOM tree
|
|
10
|
-
*/
|
|
11
|
-
disconnectedCallback?: () => void;
|
|
12
|
-
attributeChangedCallback?: <Key extends keyof CustomElementStyleProps>(name: Key, oldValue: CustomElementStyleProps[Key], newValue: CustomElementStyleProps[Key]) => void;
|
|
13
|
-
}
|
|
14
3
|
/**
|
|
15
4
|
* shadow root
|
|
16
5
|
* @see https://yuque.antfin-inc.com/antv/czqvg5/pgqipg
|
|
17
6
|
*/
|
|
18
7
|
export declare abstract class CustomElement<CustomElementStyleProps> extends DisplayObject<CustomElementStyleProps> {
|
|
19
8
|
constructor(config: DisplayObjectConfig<CustomElementStyleProps>);
|
|
9
|
+
/**
|
|
10
|
+
* fired after element insert into DOM tree
|
|
11
|
+
*/
|
|
12
|
+
connectedCallback?(): void;
|
|
13
|
+
/**
|
|
14
|
+
* fired before element removed from DOM tree
|
|
15
|
+
*/
|
|
16
|
+
disconnectedCallback?(): void;
|
|
17
|
+
attributeChangedCallback?<Key extends keyof CustomElementStyleProps>(name: Key, oldValue: CustomElementStyleProps[Key], newValue: CustomElementStyleProps[Key]): void;
|
|
20
18
|
private handleMounted;
|
|
19
|
+
private handleUnmounted;
|
|
21
20
|
private handleAttributeChanged;
|
|
22
21
|
}
|
|
@@ -23,14 +23,24 @@ function (_super) {
|
|
|
23
23
|
function CustomElement(config) {
|
|
24
24
|
var _this = _super.call(this, config) || this;
|
|
25
25
|
|
|
26
|
-
_this.handleMounted = function () {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
_this.connectedCallback
|
|
26
|
+
_this.handleMounted = function (e) {
|
|
27
|
+
if (e.target === e.currentTarget) {
|
|
28
|
+
// this.shadowNodes.forEach((node) => {
|
|
29
|
+
// // every child and its children should turn into a shadow node
|
|
30
|
+
// // a shadow node doesn't mean to be unrenderable, it's just unsearchable in scenegraph
|
|
31
|
+
// node.shadow = true;
|
|
32
|
+
// });
|
|
33
|
+
if (_this.connectedCallback) {
|
|
34
|
+
_this.connectedCallback();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
_this.handleUnmounted = function (e) {
|
|
40
|
+
if (e.target === e.currentTarget) {
|
|
41
|
+
if (_this.disconnectedCallback) {
|
|
42
|
+
_this.disconnectedCallback();
|
|
43
|
+
}
|
|
34
44
|
}
|
|
35
45
|
}; // private handleChildInserted = (e: FederatedEvent) => {
|
|
36
46
|
// (e.target as DisplayObject).forEach((node) => {
|
|
@@ -71,11 +81,11 @@ function (_super) {
|
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
if (_this.connectedCallback) {
|
|
74
|
-
_this.addEventListener(_interfaces.ElementEvent.
|
|
84
|
+
_this.addEventListener(_interfaces.ElementEvent.MOUNTED, _this.handleMounted);
|
|
75
85
|
}
|
|
76
86
|
|
|
77
87
|
if (_this.disconnectedCallback) {
|
|
78
|
-
_this.addEventListener(_interfaces.ElementEvent.
|
|
88
|
+
_this.addEventListener(_interfaces.ElementEvent.UNMOUNTED, _this.handleUnmounted);
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
return _this;
|