@antv/g-canvas 1.1.6 → 1.1.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.esm.js CHANGED
@@ -14,54 +14,11 @@ export { HTMLRenderer };
14
14
  import { inject, singleton, Module } from 'mana-syringe';
15
15
  import { __decorate, __metadata } from 'tslib';
16
16
 
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
- }
17
+ function _inheritsLoose(subClass, superClass) {
18
+ subClass.prototype = Object.create(superClass.prototype);
19
+ subClass.prototype.constructor = subClass;
46
20
 
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);
21
+ _setPrototypeOf(subClass, superClass);
65
22
  }
66
23
 
67
24
  function _setPrototypeOf(o, p) {
@@ -73,60 +30,8 @@ function _setPrototypeOf(o, p) {
73
30
  return _setPrototypeOf(o, p);
74
31
  }
75
32
 
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
-
126
33
  var Canvas2DContextService = /*#__PURE__*/function () {
127
34
  function Canvas2DContextService() {
128
- _classCallCheck(this, Canvas2DContextService);
129
-
130
35
  this.$container = void 0;
131
36
  this.$canvas = void 0;
132
37
  this.dpr = void 0;
@@ -134,102 +39,94 @@ var Canvas2DContextService = /*#__PURE__*/function () {
134
39
  this.canvasConfig = void 0;
135
40
  }
136
41
 
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;
42
+ var _proto = Canvas2DContextService.prototype;
144
43
 
145
- if (canvas) {
146
- this.$canvas = canvas;
44
+ _proto.init = function init() {
45
+ var _this$canvasConfig = this.canvasConfig,
46
+ container = _this$canvasConfig.container,
47
+ canvas = _this$canvasConfig.canvas,
48
+ devicePixelRatio = _this$canvasConfig.devicePixelRatio;
147
49
 
148
- if (container && canvas.parentElement !== container) {
149
- container.appendChild(canvas);
150
- }
50
+ if (canvas) {
51
+ this.$canvas = canvas;
151
52
 
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;
53
+ if (container && canvas.parentElement !== container) {
54
+ container.appendChild(canvas);
55
+ }
157
56
 
158
- if (this.$container) {
159
- // create canvas
160
- var $canvas = document.createElement('canvas');
161
- this.$container.appendChild($canvas);
57
+ this.$container = canvas.parentElement;
58
+ this.canvasConfig.container = this.$container;
59
+ } else if (container) {
60
+ // create container
61
+ this.$container = isString(container) ? document.getElementById(container) : container;
162
62
 
163
- if (!this.$container.style.position) {
164
- this.$container.style.position = 'relative';
165
- }
63
+ if (this.$container) {
64
+ // create canvas
65
+ var $canvas = document.createElement('canvas');
66
+ this.$container.appendChild($canvas);
166
67
 
167
- this.$canvas = $canvas;
68
+ if (!this.$container.style.position) {
69
+ this.$container.style.position = 'relative';
168
70
  }
71
+
72
+ this.$canvas = $canvas;
169
73
  }
74
+ }
170
75
 
171
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
76
+ this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
172
77
 
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);
177
- }
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
- }
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
+
92
+ _proto.getDPR = function getDPR() {
93
+ return this.dpr;
94
+ };
95
+
96
+ _proto.getBoundingClientRect = function getBoundingClientRect() {
97
+ if (this.$canvas.getBoundingClientRect) {
98
+ return this.$canvas.getBoundingClientRect();
199
99
  }
200
- }, {
201
- key: "destroy",
202
- value: function destroy() {
100
+ };
101
+
102
+ _proto.destroy = function destroy() {
103
+ // @ts-ignore
104
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
105
+ // destroy context
203
106
  // @ts-ignore
204
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
205
- // destroy context
206
- // @ts-ignore
207
- this.$container.removeChild(this.$canvas);
208
- }
107
+ this.$container.removeChild(this.$canvas);
209
108
  }
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
- }
109
+ };
110
+
111
+ _proto.resize = function resize(width, height) {
112
+ if (this.$canvas) {
113
+ // set canvas width & height
114
+ this.$canvas.width = this.dpr * width;
115
+ this.$canvas.height = this.dpr * height; // set CSS style width & height
116
+
117
+ setDOMSize(this.$canvas, width, height);
118
+ var dpr = this.getDPR(); // scale all drawing operations by the dpr
119
+ // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
120
+
121
+ this.context.scale(dpr, dpr);
224
122
  }
225
- }, {
226
- key: "applyCursorStyle",
227
- value: function applyCursorStyle(cursor) {
228
- if (this.$container && this.$container.style) {
229
- this.$container.style.cursor = cursor;
230
- }
123
+ };
124
+
125
+ _proto.applyCursorStyle = function applyCursorStyle(cursor) {
126
+ if (this.$container && this.$container.style) {
127
+ this.$container.style.cursor = cursor;
231
128
  }
232
- }]);
129
+ };
233
130
 
234
131
  return Canvas2DContextService;
235
132
  }();
@@ -248,37 +145,29 @@ var containerModule = Module(function (register) {
248
145
  });
249
146
  var ContextRegisterPlugin = /*#__PURE__*/function () {
250
147
  function ContextRegisterPlugin() {
251
- _classCallCheck(this, ContextRegisterPlugin);
252
-
253
148
  this.name = 'canvas-context-register';
254
149
  }
255
150
 
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
- }]);
151
+ var _proto = ContextRegisterPlugin.prototype;
152
+
153
+ _proto.init = function init(container) {
154
+ container.load(containerModule, true);
155
+ };
156
+
157
+ _proto.destroy = function destroy(container) {
158
+ container.unload(containerModule);
159
+ };
267
160
 
268
161
  return ContextRegisterPlugin;
269
162
  }();
270
163
 
271
164
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
272
- _inherits(Renderer, _AbstractRenderer);
273
-
274
- var _super = _createSuper(Renderer);
165
+ _inheritsLoose(Renderer, _AbstractRenderer);
275
166
 
276
167
  function Renderer(config) {
277
168
  var _this;
278
169
 
279
- _classCallCheck(this, Renderer);
280
-
281
- _this = _super.call(this, config); // register Canvas2DContext
170
+ _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
282
171
 
283
172
  _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
284
173
 
@@ -296,7 +185,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
296
185
  return _this;
297
186
  }
298
187
 
299
- return _createClass(Renderer);
188
+ return Renderer;
300
189
  }(AbstractRenderer);
301
190
 
302
191
  export { Renderer };