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