@antv/g 5.0.3 → 5.0.7
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 +9 -0
- package/es/Canvas.js +16 -9
- 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/DisplayObject.d.ts +2 -5
- package/es/display-objects/DisplayObject.js +16 -9
- 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/Element.d.ts +10 -10
- package/es/dom/Element.js +7 -4
- package/es/dom/Node.d.ts +7 -7
- package/es/dom/interfaces.d.ts +21 -17
- 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/services/SceneGraphService.js +4 -4
- package/es/types.d.ts +10 -3
- package/es/types.js +16 -0
- package/es/utils/interpolation.js +10 -7
- package/lib/Canvas.d.ts +9 -0
- package/lib/Canvas.js +16 -9
- 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/DisplayObject.d.ts +2 -5
- package/lib/display-objects/DisplayObject.js +13 -8
- 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/Element.d.ts +10 -10
- package/lib/dom/Element.js +7 -4
- package/lib/dom/Node.d.ts +7 -7
- package/lib/dom/interfaces.d.ts +21 -17
- 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/services/SceneGraphService.js +4 -4
- package/lib/types.d.ts +10 -3
- package/lib/types.js +19 -1
- package/lib/utils/interpolation.js +7 -9
- package/package.json +3 -3
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.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
import type { StylePropertyParser, StylePropertyMerger, StylePropertyUpdater } from './property-handlers';
|
|
1
2
|
export declare const globalContainer: import("mana-syringe").Container;
|
|
3
|
+
export declare const stylePropertyParserFactory: Record<string, StylePropertyParser<any, any>>;
|
|
4
|
+
export declare const stylePropertyUpdaterFactory: Record<string, StylePropertyUpdater<any>[]>;
|
|
5
|
+
export declare const stylePropertyMergerFactory: Record<string, StylePropertyMerger<any, any>>;
|
|
2
6
|
export declare const containerModule: import("mana-syringe").SyringeModule;
|
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 () {
|
|
@@ -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}
|
|
@@ -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];
|
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';
|
|
@@ -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
|
@@ -42,6 +42,11 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
42
42
|
* rAF in auto rendering
|
|
43
43
|
*/
|
|
44
44
|
private frameId?;
|
|
45
|
+
/**
|
|
46
|
+
* cache here since inversify's resolving is very slow
|
|
47
|
+
*/
|
|
48
|
+
private eventService;
|
|
49
|
+
private renderingService;
|
|
45
50
|
constructor(config: CanvasConfig);
|
|
46
51
|
private initRenderingContext;
|
|
47
52
|
private initDefaultCamera;
|
|
@@ -60,6 +65,10 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
60
65
|
getEventService(): EventService;
|
|
61
66
|
getRenderingService(): RenderingService;
|
|
62
67
|
getRenderingContext(): RenderingContext;
|
|
68
|
+
getStats(): {
|
|
69
|
+
total: number;
|
|
70
|
+
rendered: number;
|
|
71
|
+
};
|
|
63
72
|
getComputedStyle(node: DisplayObject): any;
|
|
64
73
|
destroy(destroyScenegraph?: boolean): void;
|
|
65
74
|
/**
|
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 () {
|
|
@@ -163,17 +164,21 @@ function (_super) {
|
|
|
163
164
|
};
|
|
164
165
|
|
|
165
166
|
Canvas.prototype.getEventService = function () {
|
|
166
|
-
return this.
|
|
167
|
+
return this.eventService;
|
|
167
168
|
};
|
|
168
169
|
|
|
169
170
|
Canvas.prototype.getRenderingService = function () {
|
|
170
|
-
return this.
|
|
171
|
+
return this.renderingService;
|
|
171
172
|
};
|
|
172
173
|
|
|
173
174
|
Canvas.prototype.getRenderingContext = function () {
|
|
174
175
|
return this.container.get(_RenderingContext.RenderingContext);
|
|
175
176
|
};
|
|
176
177
|
|
|
178
|
+
Canvas.prototype.getStats = function () {
|
|
179
|
+
return this.getRenderingService().getStats();
|
|
180
|
+
};
|
|
181
|
+
|
|
177
182
|
Canvas.prototype.getComputedStyle = function (node) {
|
|
178
183
|
return node.parsedStyle;
|
|
179
184
|
};
|
|
@@ -224,9 +229,10 @@ function (_super) {
|
|
|
224
229
|
|
|
225
230
|
var camera = this.container.get(_camera.DefaultCamera);
|
|
226
231
|
var projectionMode = camera.getProjectionMode();
|
|
232
|
+
camera.setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0);
|
|
227
233
|
|
|
228
234
|
if (projectionMode === _camera.CAMERA_PROJECTION_MODE.ORTHOGRAPHIC) {
|
|
229
|
-
camera.
|
|
235
|
+
camera.setOrthographic(width / -2, width / 2, height / 2, height / -2, camera.getNear(), camera.getFar());
|
|
230
236
|
} else {
|
|
231
237
|
camera.setAspect(width / height);
|
|
232
238
|
}
|
|
@@ -296,9 +302,10 @@ function (_super) {
|
|
|
296
302
|
this.loadRendererContainerModule(renderer); // init context
|
|
297
303
|
|
|
298
304
|
var contextService = this.container.get(_services.ContextService);
|
|
299
|
-
|
|
305
|
+
this.renderingService = this.container.get(_RenderingService.RenderingService);
|
|
306
|
+
this.eventService = this.container.get(_EventService.EventService);
|
|
300
307
|
contextService.init();
|
|
301
|
-
renderingService.init().then(function () {
|
|
308
|
+
this.renderingService.init().then(function () {
|
|
302
309
|
_this.emit(CanvasEvent.READY, {});
|
|
303
310
|
});
|
|
304
311
|
|
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 = {
|