@antv/g-canvas 1.0.0-alpha.21 → 1.0.0-alpha.25

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.
@@ -1,16 +1,16 @@
1
- import type { ContextService } from '@antv/g';
2
- export declare class Canvas2DContextService implements ContextService<CanvasRenderingContext2D> {
3
- private $container;
4
- private $canvas;
5
- private dpr;
6
- private context;
7
- private canvasConfig;
8
- init(): void;
9
- getContext(): CanvasRenderingContext2D;
10
- getDomElement(): HTMLCanvasElement;
11
- getDPR(): number;
12
- getBoundingClientRect(): DOMRect;
13
- destroy(): void;
14
- resize(width: number, height: number): void;
15
- applyCursorStyle(cursor: string): void;
16
- }
1
+ import type { ContextService } from '@antv/g';
2
+ export declare class Canvas2DContextService implements ContextService<CanvasRenderingContext2D> {
3
+ private $container;
4
+ private $canvas;
5
+ private dpr;
6
+ private context;
7
+ private canvasConfig;
8
+ init(): void;
9
+ getContext(): CanvasRenderingContext2D;
10
+ getDomElement(): HTMLCanvasElement;
11
+ getDPR(): number;
12
+ getBoundingClientRect(): DOMRect;
13
+ destroy(): void;
14
+ resize(width: number, height: number): void;
15
+ applyCursorStyle(cursor: string): void;
16
+ }
@@ -1,6 +1,6 @@
1
- import { Container } from 'inversify';
2
- import { RendererPlugin } from '@antv/g';
3
- export declare class ContextRegisterPlugin implements RendererPlugin {
4
- init(container: Container): void;
5
- destroy(container: Container): void;
6
- }
1
+ import { Container } from 'inversify';
2
+ import { RendererPlugin } from '@antv/g';
3
+ export declare class ContextRegisterPlugin implements RendererPlugin {
4
+ init(container: Container): void;
5
+ destroy(container: Container): void;
6
+ }
@@ -1,4 +1,4 @@
1
- import { AbstractRenderer, RendererConfig } from '@antv/g';
2
- export declare class Renderer extends AbstractRenderer {
3
- constructor(config?: Partial<RendererConfig>);
4
- }
1
+ import { AbstractRenderer, RendererConfig } from '@antv/g';
2
+ export declare class Renderer extends AbstractRenderer {
3
+ constructor(config?: Partial<RendererConfig>);
4
+ }
@@ -0,0 +1,461 @@
1
+ import { CanvasConfig, ContextService, AbstractRenderer } from '@antv/g';
2
+ import { Plugin as Plugin$1 } from '@antv/g-plugin-dom-interaction';
3
+ import { Plugin } from '@antv/g-plugin-canvas-renderer';
4
+ import { Plugin as Plugin$2 } from '@antv/g-plugin-canvas-picker';
5
+ import { Plugin as Plugin$3 } from '@antv/g-plugin-html-renderer';
6
+ import { isString } from '@antv/util';
7
+
8
+ function _classCallCheck(instance, Constructor) {
9
+ if (!(instance instanceof Constructor)) {
10
+ throw new TypeError("Cannot call a class as a function");
11
+ }
12
+ }
13
+
14
+ function _defineProperties(target, props) {
15
+ for (var i = 0; i < props.length; i++) {
16
+ var descriptor = props[i];
17
+ descriptor.enumerable = descriptor.enumerable || false;
18
+ descriptor.configurable = true;
19
+ if ("value" in descriptor) descriptor.writable = true;
20
+ Object.defineProperty(target, descriptor.key, descriptor);
21
+ }
22
+ }
23
+
24
+ function _createClass(Constructor, protoProps, staticProps) {
25
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
26
+ if (staticProps) _defineProperties(Constructor, staticProps);
27
+ return Constructor;
28
+ }
29
+
30
+ function _inherits(subClass, superClass) {
31
+ if (typeof superClass !== "function" && superClass !== null) {
32
+ throw new TypeError("Super expression must either be null or a function");
33
+ }
34
+
35
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
36
+ constructor: {
37
+ value: subClass,
38
+ writable: true,
39
+ configurable: true
40
+ }
41
+ });
42
+ if (superClass) _setPrototypeOf(subClass, superClass);
43
+ }
44
+
45
+ function _getPrototypeOf(o) {
46
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
47
+ return o.__proto__ || Object.getPrototypeOf(o);
48
+ };
49
+ return _getPrototypeOf(o);
50
+ }
51
+
52
+ function _setPrototypeOf(o, p) {
53
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
54
+ o.__proto__ = p;
55
+ return o;
56
+ };
57
+
58
+ return _setPrototypeOf(o, p);
59
+ }
60
+
61
+ function _isNativeReflectConstruct() {
62
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
63
+ if (Reflect.construct.sham) return false;
64
+ if (typeof Proxy === "function") return true;
65
+
66
+ try {
67
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
68
+ return true;
69
+ } catch (e) {
70
+ return false;
71
+ }
72
+ }
73
+
74
+ function _assertThisInitialized(self) {
75
+ if (self === void 0) {
76
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
77
+ }
78
+
79
+ return self;
80
+ }
81
+
82
+ function _possibleConstructorReturn(self, call) {
83
+ if (call && (typeof call === "object" || typeof call === "function")) {
84
+ return call;
85
+ } else if (call !== void 0) {
86
+ throw new TypeError("Derived constructors may only return object or undefined");
87
+ }
88
+
89
+ return _assertThisInitialized(self);
90
+ }
91
+
92
+ function _createSuper(Derived) {
93
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
94
+
95
+ return function _createSuperInternal() {
96
+ var Super = _getPrototypeOf(Derived),
97
+ result;
98
+
99
+ if (hasNativeReflectConstruct) {
100
+ var NewTarget = _getPrototypeOf(this).constructor;
101
+
102
+ result = Reflect.construct(Super, arguments, NewTarget);
103
+ } else {
104
+ result = Super.apply(this, arguments);
105
+ }
106
+
107
+ return _possibleConstructorReturn(this, result);
108
+ };
109
+ }
110
+
111
+ var NAMED_TAG = "named";
112
+ var INJECT_TAG = "inject";
113
+ var TAGGED = "inversify:tagged";
114
+ var TAGGED_PROP = "inversify:tagged_props";
115
+ var PARAM_TYPES = "inversify:paramtypes";
116
+ var DESIGN_PARAM_TYPES = "design:paramtypes";
117
+
118
+ var idCounter = 0;
119
+ function id() {
120
+ return idCounter++;
121
+ }
122
+
123
+ var DUPLICATED_INJECTABLE_DECORATOR = "Cannot apply @injectable decorator multiple times.";
124
+ var DUPLICATED_METADATA = "Metadata key was used more than once in a parameter:";
125
+ var UNDEFINED_INJECT_ANNOTATION = function (name) {
126
+ return "@inject called with undefined this could mean that the class " + name + " has " +
127
+ "a circular dependency problem. You can use a LazyServiceIdentifer to " +
128
+ "overcome this limitation.";
129
+ };
130
+ var INVALID_DECORATOR_OPERATION = "The @inject @multiInject @tagged and @named decorators " +
131
+ "must be applied to the parameters of a class constructor or a class property.";
132
+
133
+ var Metadata = (function () {
134
+ function Metadata(key, value) {
135
+ this.key = key;
136
+ this.value = value;
137
+ }
138
+ Metadata.prototype.toString = function () {
139
+ if (this.key === NAMED_TAG) {
140
+ return "named: " + this.value.toString() + " ";
141
+ }
142
+ else {
143
+ return "tagged: { key:" + this.key.toString() + ", value: " + this.value + " }";
144
+ }
145
+ };
146
+ return Metadata;
147
+ }());
148
+
149
+ function tagParameter(annotationTarget, propertyName, parameterIndex, metadata) {
150
+ var metadataKey = TAGGED;
151
+ _tagParameterOrProperty(metadataKey, annotationTarget, propertyName, metadata, parameterIndex);
152
+ }
153
+ function tagProperty(annotationTarget, propertyName, metadata) {
154
+ var metadataKey = TAGGED_PROP;
155
+ _tagParameterOrProperty(metadataKey, annotationTarget.constructor, propertyName, metadata);
156
+ }
157
+ function _tagParameterOrProperty(metadataKey, annotationTarget, propertyName, metadata, parameterIndex) {
158
+ var paramsOrPropertiesMetadata = {};
159
+ var isParameterDecorator = (typeof parameterIndex === "number");
160
+ var key = (parameterIndex !== undefined && isParameterDecorator) ? parameterIndex.toString() : propertyName;
161
+ if (isParameterDecorator && propertyName !== undefined) {
162
+ throw new Error(INVALID_DECORATOR_OPERATION);
163
+ }
164
+ if (Reflect.hasOwnMetadata(metadataKey, annotationTarget)) {
165
+ paramsOrPropertiesMetadata = Reflect.getMetadata(metadataKey, annotationTarget);
166
+ }
167
+ var paramOrPropertyMetadata = paramsOrPropertiesMetadata[key];
168
+ if (!Array.isArray(paramOrPropertyMetadata)) {
169
+ paramOrPropertyMetadata = [];
170
+ }
171
+ else {
172
+ for (var _i = 0, paramOrPropertyMetadata_1 = paramOrPropertyMetadata; _i < paramOrPropertyMetadata_1.length; _i++) {
173
+ var m = paramOrPropertyMetadata_1[_i];
174
+ if (m.key === metadata.key) {
175
+ throw new Error(DUPLICATED_METADATA + " " + m.key.toString());
176
+ }
177
+ }
178
+ }
179
+ paramOrPropertyMetadata.push(metadata);
180
+ paramsOrPropertiesMetadata[key] = paramOrPropertyMetadata;
181
+ Reflect.defineMetadata(metadataKey, paramsOrPropertiesMetadata, annotationTarget);
182
+ }
183
+
184
+ function inject(serviceIdentifier) {
185
+ return function (target, targetKey, index) {
186
+ if (serviceIdentifier === undefined) {
187
+ throw new Error(UNDEFINED_INJECT_ANNOTATION(target.name));
188
+ }
189
+ var metadata = new Metadata(INJECT_TAG, serviceIdentifier);
190
+ if (typeof index === "number") {
191
+ tagParameter(target, targetKey, index, metadata);
192
+ }
193
+ else {
194
+ tagProperty(target, targetKey, metadata);
195
+ }
196
+ };
197
+ }
198
+
199
+ var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from) {
200
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
201
+ to[j] = from[i];
202
+ return to;
203
+ };
204
+
205
+ var __spreadArray$1 = (undefined && undefined.__spreadArray) || function (to, from) {
206
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
207
+ to[j] = from[i];
208
+ return to;
209
+ };
210
+
211
+ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
212
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
213
+ return new (P || (P = Promise))(function (resolve, reject) {
214
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
215
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
216
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
217
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
218
+ });
219
+ };
220
+ var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
221
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
222
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
223
+ function verb(n) { return function (v) { return step([n, v]); }; }
224
+ function step(op) {
225
+ if (f) throw new TypeError("Generator is already executing.");
226
+ while (_) try {
227
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
228
+ if (y = 0, t) op = [op[0] & 2, t.value];
229
+ switch (op[0]) {
230
+ case 0: case 1: t = op; break;
231
+ case 4: _.label++; return { value: op[1], done: false };
232
+ case 5: _.label++; y = op[1]; op = [0]; continue;
233
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
234
+ default:
235
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
236
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
237
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
238
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
239
+ if (t[2]) _.ops.pop();
240
+ _.trys.pop(); continue;
241
+ }
242
+ op = body.call(thisArg, _);
243
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
244
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
245
+ }
246
+ };
247
+ var __spreadArray$2 = (undefined && undefined.__spreadArray) || function (to, from) {
248
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
249
+ to[j] = from[i];
250
+ return to;
251
+ };
252
+
253
+ var ContainerModule = (function () {
254
+ function ContainerModule(registry) {
255
+ this.id = id();
256
+ this.registry = registry;
257
+ }
258
+ return ContainerModule;
259
+ }());
260
+
261
+ function injectable() {
262
+ return function (target) {
263
+ if (Reflect.hasOwnMetadata(PARAM_TYPES, target)) {
264
+ throw new Error(DUPLICATED_INJECTABLE_DECORATOR);
265
+ }
266
+ var types = Reflect.getMetadata(DESIGN_PARAM_TYPES, target) || [];
267
+ Reflect.defineMetadata(PARAM_TYPES, types, target);
268
+ return target;
269
+ };
270
+ }
271
+
272
+ /*! *****************************************************************************
273
+ Copyright (c) Microsoft Corporation.
274
+
275
+ Permission to use, copy, modify, and/or distribute this software for any
276
+ purpose with or without fee is hereby granted.
277
+
278
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
279
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
280
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
281
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
282
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
283
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
284
+ PERFORMANCE OF THIS SOFTWARE.
285
+ ***************************************************************************** */
286
+
287
+ function __decorate(decorators, target, key, desc) {
288
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
289
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
290
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
291
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
292
+ }
293
+
294
+ function __metadata(metadataKey, metadataValue) {
295
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
296
+ }
297
+
298
+ var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
299
+
300
+ var PX_SUFFIX = 'px';
301
+ function setDOMSize($el, width, height) {
302
+ if (isBrowser) {
303
+ $el.style.width = width + PX_SUFFIX;
304
+ $el.style.height = height + PX_SUFFIX;
305
+ }
306
+ }
307
+
308
+ var Canvas2DContextService = /*#__PURE__*/function () {
309
+ function Canvas2DContextService() {
310
+ _classCallCheck(this, Canvas2DContextService);
311
+
312
+ this.$container = void 0;
313
+ this.$canvas = void 0;
314
+ this.dpr = void 0;
315
+ this.context = void 0;
316
+ this.canvasConfig = void 0;
317
+ }
318
+
319
+ _createClass(Canvas2DContextService, [{
320
+ key: "init",
321
+ value: function init() {
322
+ var _this$canvasConfig = this.canvasConfig,
323
+ container = _this$canvasConfig.container,
324
+ width = _this$canvasConfig.width,
325
+ height = _this$canvasConfig.height; // create container
326
+
327
+ this.$container = isString(container) ? document.getElementById(container) : container;
328
+
329
+ if (this.$container) {
330
+ // create canvas
331
+ var $canvas = document.createElement('canvas');
332
+ this.context = $canvas.getContext('2d');
333
+ this.$container.appendChild($canvas);
334
+
335
+ if (!this.$container.style.position) {
336
+ this.$container.style.position = 'relative';
337
+ }
338
+
339
+ this.$canvas = $canvas;
340
+ var dpr = window.devicePixelRatio || 1;
341
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
342
+ this.dpr = dpr;
343
+ this.resize(width, height);
344
+ }
345
+ }
346
+ }, {
347
+ key: "getContext",
348
+ value: function getContext() {
349
+ return this.context;
350
+ }
351
+ }, {
352
+ key: "getDomElement",
353
+ value: function getDomElement() {
354
+ return this.$canvas;
355
+ }
356
+ }, {
357
+ key: "getDPR",
358
+ value: function getDPR() {
359
+ return this.dpr;
360
+ }
361
+ }, {
362
+ key: "getBoundingClientRect",
363
+ value: function getBoundingClientRect() {
364
+ var _this$$canvas;
365
+
366
+ return (_this$$canvas = this.$canvas) === null || _this$$canvas === void 0 ? void 0 : _this$$canvas.getBoundingClientRect();
367
+ }
368
+ }, {
369
+ key: "destroy",
370
+ value: function destroy() {
371
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
372
+ // destroy context
373
+ this.$container.removeChild(this.$canvas);
374
+ }
375
+ }
376
+ }, {
377
+ key: "resize",
378
+ value: function resize(width, height) {
379
+ if (this.$canvas) {
380
+ // set canvas width & height
381
+ this.$canvas.width = this.dpr * width;
382
+ this.$canvas.height = this.dpr * height; // set CSS style width & height
383
+
384
+ setDOMSize(this.$canvas, width, height);
385
+ }
386
+ }
387
+ }, {
388
+ key: "applyCursorStyle",
389
+ value: function applyCursorStyle(cursor) {
390
+ if (this.$container) {
391
+ this.$container.style.cursor = cursor;
392
+ }
393
+ }
394
+ }]);
395
+
396
+ return Canvas2DContextService;
397
+ }();
398
+
399
+ __decorate([inject(CanvasConfig), __metadata("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
400
+
401
+ Canvas2DContextService = __decorate([injectable()], Canvas2DContextService);
402
+
403
+ var containerModule = new ContainerModule(function (bind, unbind, isBound, rebind) {
404
+ /**
405
+ * implements ContextService
406
+ */
407
+ bind(Canvas2DContextService).toSelf().inSingletonScope();
408
+ bind(ContextService).toService(Canvas2DContextService);
409
+ });
410
+ var ContextRegisterPlugin = /*#__PURE__*/function () {
411
+ function ContextRegisterPlugin() {
412
+ _classCallCheck(this, ContextRegisterPlugin);
413
+ }
414
+
415
+ _createClass(ContextRegisterPlugin, [{
416
+ key: "init",
417
+ value: function init(container) {
418
+ container.load(containerModule);
419
+ }
420
+ }, {
421
+ key: "destroy",
422
+ value: function destroy(container) {
423
+ container.unload(containerModule);
424
+ }
425
+ }]);
426
+
427
+ return ContextRegisterPlugin;
428
+ }();
429
+
430
+ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
431
+ _inherits(Renderer, _AbstractRenderer);
432
+
433
+ var _super = _createSuper(Renderer);
434
+
435
+ function Renderer(config) {
436
+ var _this;
437
+
438
+ _classCallCheck(this, Renderer);
439
+
440
+ _this = _super.call(this, config); // register Canvas2DContext
441
+
442
+ _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
443
+
444
+
445
+ _this.registerPlugin(new Plugin());
446
+
447
+ _this.registerPlugin(new Plugin$1()); // enable picking with Canvas2D API
448
+
449
+
450
+ _this.registerPlugin(new Plugin$2()); // render HTML component
451
+
452
+
453
+ _this.registerPlugin(new Plugin$3());
454
+
455
+ return _this;
456
+ }
457
+
458
+ return Renderer;
459
+ }(AbstractRenderer);
460
+
461
+ export { Renderer };