@antv/g-canvas 1.1.3 → 1.1.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/Canvas2DContextService.d.ts +2 -2
- package/dist/Canvas2DContextService.d.ts.map +1 -1
- package/dist/index.esm.js +200 -89
- package/dist/index.js +200 -89
- package/dist/index.umd.js +2470 -1878
- package/dist/index.umd.min.js +5 -5
- package/package.json +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import type { CanvasLike } from '@antv/g';
|
|
2
2
|
import { ContextService } from '@antv/g';
|
|
3
3
|
export declare class Canvas2DContextService implements ContextService<CanvasRenderingContext2D> {
|
|
4
4
|
private $container;
|
|
@@ -8,7 +8,7 @@ export declare class Canvas2DContextService implements ContextService<CanvasRend
|
|
|
8
8
|
private canvasConfig;
|
|
9
9
|
init(): void;
|
|
10
10
|
getContext(): CanvasRenderingContext2D;
|
|
11
|
-
getDomElement():
|
|
11
|
+
getDomElement(): CanvasLike;
|
|
12
12
|
getDPR(): number;
|
|
13
13
|
getBoundingClientRect(): DOMRect;
|
|
14
14
|
destroy(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canvas2DContextService.d.ts","sourceRoot":"","sources":["../src/Canvas2DContextService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Canvas2DContextService.d.ts","sourceRoot":"","sources":["../src/Canvas2DContextService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAgB,cAAc,EAAmC,MAAM,SAAS,CAAC;AAGxF,qBACa,sBAAuB,YAAW,cAAc,CAAC,wBAAwB,CAAC;IACrF,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,OAAO,CAAsE;IAGrF,OAAO,CAAC,YAAY,CAAe;IAEnC,IAAI;IAoCJ,UAAU;IAIV,aAAa;IAIb,MAAM;IAIN,qBAAqB;IAMrB,OAAO;IASP,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAgBpC,gBAAgB,CAAC,MAAM,EAAE,MAAM;CAKhC"}
|
package/dist/index.esm.js
CHANGED
|
@@ -14,11 +14,54 @@ export { HTMLRenderer };
|
|
|
14
14
|
import { inject, singleton, Module } from 'mana-syringe';
|
|
15
15
|
import { __decorate, __metadata } from 'tslib';
|
|
16
16
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
function _classCallCheck(instance, Constructor) {
|
|
18
|
+
if (!(instance instanceof Constructor)) {
|
|
19
|
+
throw new TypeError("Cannot call a class as a function");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function _defineProperties(target, props) {
|
|
24
|
+
for (var i = 0; i < props.length; i++) {
|
|
25
|
+
var descriptor = props[i];
|
|
26
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
27
|
+
descriptor.configurable = true;
|
|
28
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
29
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
34
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
35
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
36
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
37
|
+
writable: false
|
|
38
|
+
});
|
|
39
|
+
return Constructor;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function _inherits(subClass, superClass) {
|
|
43
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
44
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
45
|
+
}
|
|
20
46
|
|
|
21
|
-
|
|
47
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
48
|
+
constructor: {
|
|
49
|
+
value: subClass,
|
|
50
|
+
writable: true,
|
|
51
|
+
configurable: true
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(subClass, "prototype", {
|
|
55
|
+
writable: false
|
|
56
|
+
});
|
|
57
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function _getPrototypeOf(o) {
|
|
61
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
62
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
63
|
+
};
|
|
64
|
+
return _getPrototypeOf(o);
|
|
22
65
|
}
|
|
23
66
|
|
|
24
67
|
function _setPrototypeOf(o, p) {
|
|
@@ -30,8 +73,60 @@ function _setPrototypeOf(o, p) {
|
|
|
30
73
|
return _setPrototypeOf(o, p);
|
|
31
74
|
}
|
|
32
75
|
|
|
76
|
+
function _isNativeReflectConstruct() {
|
|
77
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
78
|
+
if (Reflect.construct.sham) return false;
|
|
79
|
+
if (typeof Proxy === "function") return true;
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
83
|
+
return true;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function _assertThisInitialized(self) {
|
|
90
|
+
if (self === void 0) {
|
|
91
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return self;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function _possibleConstructorReturn(self, call) {
|
|
98
|
+
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
99
|
+
return call;
|
|
100
|
+
} else if (call !== void 0) {
|
|
101
|
+
throw new TypeError("Derived constructors may only return object or undefined");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return _assertThisInitialized(self);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function _createSuper(Derived) {
|
|
108
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
109
|
+
|
|
110
|
+
return function _createSuperInternal() {
|
|
111
|
+
var Super = _getPrototypeOf(Derived),
|
|
112
|
+
result;
|
|
113
|
+
|
|
114
|
+
if (hasNativeReflectConstruct) {
|
|
115
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
116
|
+
|
|
117
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
118
|
+
} else {
|
|
119
|
+
result = Super.apply(this, arguments);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return _possibleConstructorReturn(this, result);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
33
126
|
var Canvas2DContextService = /*#__PURE__*/function () {
|
|
34
127
|
function Canvas2DContextService() {
|
|
128
|
+
_classCallCheck(this, Canvas2DContextService);
|
|
129
|
+
|
|
35
130
|
this.$container = void 0;
|
|
36
131
|
this.$canvas = void 0;
|
|
37
132
|
this.dpr = void 0;
|
|
@@ -39,94 +134,102 @@ var Canvas2DContextService = /*#__PURE__*/function () {
|
|
|
39
134
|
this.canvasConfig = void 0;
|
|
40
135
|
}
|
|
41
136
|
|
|
42
|
-
|
|
137
|
+
_createClass(Canvas2DContextService, [{
|
|
138
|
+
key: "init",
|
|
139
|
+
value: function init() {
|
|
140
|
+
var _this$canvasConfig = this.canvasConfig,
|
|
141
|
+
container = _this$canvasConfig.container,
|
|
142
|
+
canvas = _this$canvasConfig.canvas,
|
|
143
|
+
devicePixelRatio = _this$canvasConfig.devicePixelRatio;
|
|
43
144
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
container = _this$canvasConfig.container,
|
|
47
|
-
canvas = _this$canvasConfig.canvas,
|
|
48
|
-
devicePixelRatio = _this$canvasConfig.devicePixelRatio;
|
|
145
|
+
if (canvas) {
|
|
146
|
+
this.$canvas = canvas;
|
|
49
147
|
|
|
50
|
-
|
|
51
|
-
|
|
148
|
+
if (container && canvas.parentElement !== container) {
|
|
149
|
+
container.appendChild(canvas);
|
|
150
|
+
}
|
|
52
151
|
|
|
53
|
-
|
|
54
|
-
container
|
|
55
|
-
}
|
|
152
|
+
this.$container = canvas.parentElement;
|
|
153
|
+
this.canvasConfig.container = this.$container;
|
|
154
|
+
} else if (container) {
|
|
155
|
+
// create container
|
|
156
|
+
this.$container = isString(container) ? document.getElementById(container) : container;
|
|
56
157
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.$container = isString(container) ? document.getElementById(container) : container;
|
|
158
|
+
if (this.$container) {
|
|
159
|
+
// create canvas
|
|
160
|
+
var $canvas = document.createElement('canvas');
|
|
161
|
+
this.$container.appendChild($canvas);
|
|
62
162
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.$container.appendChild($canvas);
|
|
163
|
+
if (!this.$container.style.position) {
|
|
164
|
+
this.$container.style.position = 'relative';
|
|
165
|
+
}
|
|
67
166
|
|
|
68
|
-
|
|
69
|
-
this.$container.style.position = 'relative';
|
|
167
|
+
this.$canvas = $canvas;
|
|
70
168
|
}
|
|
71
|
-
|
|
72
|
-
this.$canvas = $canvas;
|
|
73
169
|
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
|
|
77
|
-
|
|
78
|
-
var dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
|
|
79
|
-
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
80
|
-
this.dpr = dpr;
|
|
81
|
-
this.resize(this.canvasConfig.width, this.canvasConfig.height);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
_proto.getContext = function getContext() {
|
|
85
|
-
return this.context;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
_proto.getDomElement = function getDomElement() {
|
|
89
|
-
return this.$canvas;
|
|
90
|
-
};
|
|
91
170
|
|
|
92
|
-
|
|
93
|
-
return this.dpr;
|
|
94
|
-
};
|
|
171
|
+
this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
|
|
95
172
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
173
|
+
var dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
|
|
174
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
175
|
+
this.dpr = dpr;
|
|
176
|
+
this.resize(this.canvasConfig.width, this.canvasConfig.height);
|
|
99
177
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
178
|
+
}, {
|
|
179
|
+
key: "getContext",
|
|
180
|
+
value: function getContext() {
|
|
181
|
+
return this.context;
|
|
182
|
+
}
|
|
183
|
+
}, {
|
|
184
|
+
key: "getDomElement",
|
|
185
|
+
value: function getDomElement() {
|
|
186
|
+
return this.$canvas;
|
|
187
|
+
}
|
|
188
|
+
}, {
|
|
189
|
+
key: "getDPR",
|
|
190
|
+
value: function getDPR() {
|
|
191
|
+
return this.dpr;
|
|
192
|
+
}
|
|
193
|
+
}, {
|
|
194
|
+
key: "getBoundingClientRect",
|
|
195
|
+
value: function getBoundingClientRect() {
|
|
196
|
+
if (this.$canvas.getBoundingClientRect) {
|
|
197
|
+
return this.$canvas.getBoundingClientRect();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}, {
|
|
201
|
+
key: "destroy",
|
|
202
|
+
value: function destroy() {
|
|
106
203
|
// @ts-ignore
|
|
107
|
-
this.$container
|
|
204
|
+
if (this.$container && this.$canvas && this.$canvas.parentNode) {
|
|
205
|
+
// destroy context
|
|
206
|
+
// @ts-ignore
|
|
207
|
+
this.$container.removeChild(this.$canvas);
|
|
208
|
+
}
|
|
108
209
|
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
210
|
+
}, {
|
|
211
|
+
key: "resize",
|
|
212
|
+
value: function resize(width, height) {
|
|
213
|
+
if (this.$canvas) {
|
|
214
|
+
// set canvas width & height
|
|
215
|
+
this.$canvas.width = this.dpr * width;
|
|
216
|
+
this.$canvas.height = this.dpr * height; // set CSS style width & height
|
|
217
|
+
|
|
218
|
+
setDOMSize(this.$canvas, width, height);
|
|
219
|
+
var dpr = this.getDPR(); // scale all drawing operations by the dpr
|
|
220
|
+
// @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
|
|
221
|
+
|
|
222
|
+
this.context.scale(dpr, dpr);
|
|
223
|
+
}
|
|
122
224
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
225
|
+
}, {
|
|
226
|
+
key: "applyCursorStyle",
|
|
227
|
+
value: function applyCursorStyle(cursor) {
|
|
228
|
+
if (this.$container && this.$container.style) {
|
|
229
|
+
this.$container.style.cursor = cursor;
|
|
230
|
+
}
|
|
128
231
|
}
|
|
129
|
-
};
|
|
232
|
+
}]);
|
|
130
233
|
|
|
131
234
|
return Canvas2DContextService;
|
|
132
235
|
}();
|
|
@@ -145,29 +248,37 @@ var containerModule = Module(function (register) {
|
|
|
145
248
|
});
|
|
146
249
|
var ContextRegisterPlugin = /*#__PURE__*/function () {
|
|
147
250
|
function ContextRegisterPlugin() {
|
|
251
|
+
_classCallCheck(this, ContextRegisterPlugin);
|
|
252
|
+
|
|
148
253
|
this.name = 'canvas-context-register';
|
|
149
254
|
}
|
|
150
255
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
container
|
|
159
|
-
|
|
256
|
+
_createClass(ContextRegisterPlugin, [{
|
|
257
|
+
key: "init",
|
|
258
|
+
value: function init(container) {
|
|
259
|
+
container.load(containerModule, true);
|
|
260
|
+
}
|
|
261
|
+
}, {
|
|
262
|
+
key: "destroy",
|
|
263
|
+
value: function destroy(container) {
|
|
264
|
+
container.unload(containerModule);
|
|
265
|
+
}
|
|
266
|
+
}]);
|
|
160
267
|
|
|
161
268
|
return ContextRegisterPlugin;
|
|
162
269
|
}();
|
|
163
270
|
|
|
164
271
|
var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
165
|
-
|
|
272
|
+
_inherits(Renderer, _AbstractRenderer);
|
|
273
|
+
|
|
274
|
+
var _super = _createSuper(Renderer);
|
|
166
275
|
|
|
167
276
|
function Renderer(config) {
|
|
168
277
|
var _this;
|
|
169
278
|
|
|
170
|
-
|
|
279
|
+
_classCallCheck(this, Renderer);
|
|
280
|
+
|
|
281
|
+
_this = _super.call(this, config); // register Canvas2DContext
|
|
171
282
|
|
|
172
283
|
_this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
|
|
173
284
|
|
|
@@ -185,7 +296,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
|
185
296
|
return _this;
|
|
186
297
|
}
|
|
187
298
|
|
|
188
|
-
return Renderer;
|
|
299
|
+
return _createClass(Renderer);
|
|
189
300
|
}(AbstractRenderer);
|
|
190
301
|
|
|
191
302
|
export { Renderer };
|