@antv/g-canvas 1.1.5 → 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/index.js CHANGED
@@ -35,11 +35,54 @@ var CanvasRenderer__namespace = /*#__PURE__*/_interopNamespace(CanvasRenderer);
35
35
  var CanvasPicker__namespace = /*#__PURE__*/_interopNamespace(CanvasPicker);
36
36
  var HTMLRenderer__namespace = /*#__PURE__*/_interopNamespace(HTMLRenderer);
37
37
 
38
- function _inheritsLoose(subClass, superClass) {
39
- subClass.prototype = Object.create(superClass.prototype);
40
- subClass.prototype.constructor = subClass;
38
+ function _classCallCheck(instance, Constructor) {
39
+ if (!(instance instanceof Constructor)) {
40
+ throw new TypeError("Cannot call a class as a function");
41
+ }
42
+ }
43
+
44
+ function _defineProperties(target, props) {
45
+ for (var i = 0; i < props.length; i++) {
46
+ var descriptor = props[i];
47
+ descriptor.enumerable = descriptor.enumerable || false;
48
+ descriptor.configurable = true;
49
+ if ("value" in descriptor) descriptor.writable = true;
50
+ Object.defineProperty(target, descriptor.key, descriptor);
51
+ }
52
+ }
41
53
 
42
- _setPrototypeOf(subClass, superClass);
54
+ function _createClass(Constructor, protoProps, staticProps) {
55
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
56
+ if (staticProps) _defineProperties(Constructor, staticProps);
57
+ Object.defineProperty(Constructor, "prototype", {
58
+ writable: false
59
+ });
60
+ return Constructor;
61
+ }
62
+
63
+ function _inherits(subClass, superClass) {
64
+ if (typeof superClass !== "function" && superClass !== null) {
65
+ throw new TypeError("Super expression must either be null or a function");
66
+ }
67
+
68
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
69
+ constructor: {
70
+ value: subClass,
71
+ writable: true,
72
+ configurable: true
73
+ }
74
+ });
75
+ Object.defineProperty(subClass, "prototype", {
76
+ writable: false
77
+ });
78
+ if (superClass) _setPrototypeOf(subClass, superClass);
79
+ }
80
+
81
+ function _getPrototypeOf(o) {
82
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
83
+ return o.__proto__ || Object.getPrototypeOf(o);
84
+ };
85
+ return _getPrototypeOf(o);
43
86
  }
44
87
 
45
88
  function _setPrototypeOf(o, p) {
@@ -51,8 +94,60 @@ function _setPrototypeOf(o, p) {
51
94
  return _setPrototypeOf(o, p);
52
95
  }
53
96
 
97
+ function _isNativeReflectConstruct() {
98
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
99
+ if (Reflect.construct.sham) return false;
100
+ if (typeof Proxy === "function") return true;
101
+
102
+ try {
103
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
104
+ return true;
105
+ } catch (e) {
106
+ return false;
107
+ }
108
+ }
109
+
110
+ function _assertThisInitialized(self) {
111
+ if (self === void 0) {
112
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
113
+ }
114
+
115
+ return self;
116
+ }
117
+
118
+ function _possibleConstructorReturn(self, call) {
119
+ if (call && (typeof call === "object" || typeof call === "function")) {
120
+ return call;
121
+ } else if (call !== void 0) {
122
+ throw new TypeError("Derived constructors may only return object or undefined");
123
+ }
124
+
125
+ return _assertThisInitialized(self);
126
+ }
127
+
128
+ function _createSuper(Derived) {
129
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
130
+
131
+ return function _createSuperInternal() {
132
+ var Super = _getPrototypeOf(Derived),
133
+ result;
134
+
135
+ if (hasNativeReflectConstruct) {
136
+ var NewTarget = _getPrototypeOf(this).constructor;
137
+
138
+ result = Reflect.construct(Super, arguments, NewTarget);
139
+ } else {
140
+ result = Super.apply(this, arguments);
141
+ }
142
+
143
+ return _possibleConstructorReturn(this, result);
144
+ };
145
+ }
146
+
54
147
  var Canvas2DContextService = /*#__PURE__*/function () {
55
148
  function Canvas2DContextService() {
149
+ _classCallCheck(this, Canvas2DContextService);
150
+
56
151
  this.$container = void 0;
57
152
  this.$canvas = void 0;
58
153
  this.dpr = void 0;
@@ -60,94 +155,102 @@ var Canvas2DContextService = /*#__PURE__*/function () {
60
155
  this.canvasConfig = void 0;
61
156
  }
62
157
 
63
- var _proto = Canvas2DContextService.prototype;
158
+ _createClass(Canvas2DContextService, [{
159
+ key: "init",
160
+ value: function init() {
161
+ var _this$canvasConfig = this.canvasConfig,
162
+ container = _this$canvasConfig.container,
163
+ canvas = _this$canvasConfig.canvas,
164
+ devicePixelRatio = _this$canvasConfig.devicePixelRatio;
64
165
 
65
- _proto.init = function init() {
66
- var _this$canvasConfig = this.canvasConfig,
67
- container = _this$canvasConfig.container,
68
- canvas = _this$canvasConfig.canvas,
69
- devicePixelRatio = _this$canvasConfig.devicePixelRatio;
166
+ if (canvas) {
167
+ this.$canvas = canvas;
70
168
 
71
- if (canvas) {
72
- this.$canvas = canvas;
169
+ if (container && canvas.parentElement !== container) {
170
+ container.appendChild(canvas);
171
+ }
73
172
 
74
- if (container && canvas.parentElement !== container) {
75
- container.appendChild(canvas);
76
- }
173
+ this.$container = canvas.parentElement;
174
+ this.canvasConfig.container = this.$container;
175
+ } else if (container) {
176
+ // create container
177
+ this.$container = g.isString(container) ? document.getElementById(container) : container;
77
178
 
78
- this.$container = canvas.parentElement;
79
- this.canvasConfig.container = this.$container;
80
- } else if (container) {
81
- // create container
82
- this.$container = g.isString(container) ? document.getElementById(container) : container;
179
+ if (this.$container) {
180
+ // create canvas
181
+ var $canvas = document.createElement('canvas');
182
+ this.$container.appendChild($canvas);
83
183
 
84
- if (this.$container) {
85
- // create canvas
86
- var $canvas = document.createElement('canvas');
87
- this.$container.appendChild($canvas);
184
+ if (!this.$container.style.position) {
185
+ this.$container.style.position = 'relative';
186
+ }
88
187
 
89
- if (!this.$container.style.position) {
90
- this.$container.style.position = 'relative';
188
+ this.$canvas = $canvas;
91
189
  }
92
-
93
- this.$canvas = $canvas;
94
190
  }
95
- }
96
-
97
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
98
-
99
- var dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
100
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
101
- this.dpr = dpr;
102
- this.resize(this.canvasConfig.width, this.canvasConfig.height);
103
- };
104
-
105
- _proto.getContext = function getContext() {
106
- return this.context;
107
- };
108
-
109
- _proto.getDomElement = function getDomElement() {
110
- return this.$canvas;
111
- };
112
191
 
113
- _proto.getDPR = function getDPR() {
114
- return this.dpr;
115
- };
192
+ this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
116
193
 
117
- _proto.getBoundingClientRect = function getBoundingClientRect() {
118
- if (this.$canvas.getBoundingClientRect) {
119
- return this.$canvas.getBoundingClientRect();
194
+ var dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
195
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
196
+ this.dpr = dpr;
197
+ this.resize(this.canvasConfig.width, this.canvasConfig.height);
120
198
  }
121
- };
122
-
123
- _proto.destroy = function destroy() {
124
- // @ts-ignore
125
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
126
- // destroy context
199
+ }, {
200
+ key: "getContext",
201
+ value: function getContext() {
202
+ return this.context;
203
+ }
204
+ }, {
205
+ key: "getDomElement",
206
+ value: function getDomElement() {
207
+ return this.$canvas;
208
+ }
209
+ }, {
210
+ key: "getDPR",
211
+ value: function getDPR() {
212
+ return this.dpr;
213
+ }
214
+ }, {
215
+ key: "getBoundingClientRect",
216
+ value: function getBoundingClientRect() {
217
+ if (this.$canvas.getBoundingClientRect) {
218
+ return this.$canvas.getBoundingClientRect();
219
+ }
220
+ }
221
+ }, {
222
+ key: "destroy",
223
+ value: function destroy() {
127
224
  // @ts-ignore
128
- this.$container.removeChild(this.$canvas);
225
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
226
+ // destroy context
227
+ // @ts-ignore
228
+ this.$container.removeChild(this.$canvas);
229
+ }
129
230
  }
130
- };
131
-
132
- _proto.resize = function resize(width, height) {
133
- if (this.$canvas) {
134
- // set canvas width & height
135
- this.$canvas.width = this.dpr * width;
136
- this.$canvas.height = this.dpr * height; // set CSS style width & height
137
-
138
- g.setDOMSize(this.$canvas, width, height);
139
- var dpr = this.getDPR(); // scale all drawing operations by the dpr
140
- // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
141
-
142
- this.context.scale(dpr, dpr);
231
+ }, {
232
+ key: "resize",
233
+ value: function resize(width, height) {
234
+ if (this.$canvas) {
235
+ // set canvas width & height
236
+ this.$canvas.width = this.dpr * width;
237
+ this.$canvas.height = this.dpr * height; // set CSS style width & height
238
+
239
+ g.setDOMSize(this.$canvas, width, height);
240
+ var dpr = this.getDPR(); // scale all drawing operations by the dpr
241
+ // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
242
+
243
+ this.context.scale(dpr, dpr);
244
+ }
143
245
  }
144
- };
145
-
146
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
147
- if (this.$container && this.$container.style) {
148
- this.$container.style.cursor = cursor;
246
+ }, {
247
+ key: "applyCursorStyle",
248
+ value: function applyCursorStyle(cursor) {
249
+ if (this.$container && this.$container.style) {
250
+ this.$container.style.cursor = cursor;
251
+ }
149
252
  }
150
- };
253
+ }]);
151
254
 
152
255
  return Canvas2DContextService;
153
256
  }();
@@ -166,29 +269,37 @@ var containerModule = manaSyringe.Module(function (register) {
166
269
  });
167
270
  var ContextRegisterPlugin = /*#__PURE__*/function () {
168
271
  function ContextRegisterPlugin() {
272
+ _classCallCheck(this, ContextRegisterPlugin);
273
+
169
274
  this.name = 'canvas-context-register';
170
275
  }
171
276
 
172
- var _proto = ContextRegisterPlugin.prototype;
173
-
174
- _proto.init = function init(container) {
175
- container.load(containerModule, true);
176
- };
177
-
178
- _proto.destroy = function destroy(container) {
179
- container.unload(containerModule);
180
- };
277
+ _createClass(ContextRegisterPlugin, [{
278
+ key: "init",
279
+ value: function init(container) {
280
+ container.load(containerModule, true);
281
+ }
282
+ }, {
283
+ key: "destroy",
284
+ value: function destroy(container) {
285
+ container.unload(containerModule);
286
+ }
287
+ }]);
181
288
 
182
289
  return ContextRegisterPlugin;
183
290
  }();
184
291
 
185
292
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
186
- _inheritsLoose(Renderer, _AbstractRenderer);
293
+ _inherits(Renderer, _AbstractRenderer);
294
+
295
+ var _super = _createSuper(Renderer);
187
296
 
188
297
  function Renderer(config) {
189
298
  var _this;
190
299
 
191
- _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
300
+ _classCallCheck(this, Renderer);
301
+
302
+ _this = _super.call(this, config); // register Canvas2DContext
192
303
 
193
304
  _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
194
305
 
@@ -206,7 +317,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
206
317
  return _this;
207
318
  }
208
319
 
209
- return Renderer;
320
+ return _createClass(Renderer);
210
321
  }(g.AbstractRenderer);
211
322
 
212
323
  exports.DomInteraction = DomInteraction__namespace;