@antv/g-canvas 1.0.0-alpha.27 → 1.0.0-alpha.30

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 DELETED
@@ -1,307 +0,0 @@
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 manaSyringe = require('mana-syringe');
11
- var util = require('@antv/util');
12
-
13
- function _classCallCheck(instance, Constructor) {
14
- if (!(instance instanceof Constructor)) {
15
- throw new TypeError("Cannot call a class as a function");
16
- }
17
- }
18
-
19
- function _defineProperties(target, props) {
20
- for (var i = 0; i < props.length; i++) {
21
- var descriptor = props[i];
22
- descriptor.enumerable = descriptor.enumerable || false;
23
- descriptor.configurable = true;
24
- if ("value" in descriptor) descriptor.writable = true;
25
- Object.defineProperty(target, descriptor.key, descriptor);
26
- }
27
- }
28
-
29
- function _createClass(Constructor, protoProps, staticProps) {
30
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
31
- if (staticProps) _defineProperties(Constructor, staticProps);
32
- return Constructor;
33
- }
34
-
35
- function _inherits(subClass, superClass) {
36
- if (typeof superClass !== "function" && superClass !== null) {
37
- throw new TypeError("Super expression must either be null or a function");
38
- }
39
-
40
- subClass.prototype = Object.create(superClass && superClass.prototype, {
41
- constructor: {
42
- value: subClass,
43
- writable: true,
44
- configurable: true
45
- }
46
- });
47
- if (superClass) _setPrototypeOf(subClass, superClass);
48
- }
49
-
50
- function _getPrototypeOf(o) {
51
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
52
- return o.__proto__ || Object.getPrototypeOf(o);
53
- };
54
- return _getPrototypeOf(o);
55
- }
56
-
57
- function _setPrototypeOf(o, p) {
58
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
59
- o.__proto__ = p;
60
- return o;
61
- };
62
-
63
- return _setPrototypeOf(o, p);
64
- }
65
-
66
- function _isNativeReflectConstruct() {
67
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
68
- if (Reflect.construct.sham) return false;
69
- if (typeof Proxy === "function") return true;
70
-
71
- try {
72
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
73
- return true;
74
- } catch (e) {
75
- return false;
76
- }
77
- }
78
-
79
- function _assertThisInitialized(self) {
80
- if (self === void 0) {
81
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
82
- }
83
-
84
- return self;
85
- }
86
-
87
- function _possibleConstructorReturn(self, call) {
88
- if (call && (typeof call === "object" || typeof call === "function")) {
89
- return call;
90
- } else if (call !== void 0) {
91
- throw new TypeError("Derived constructors may only return object or undefined");
92
- }
93
-
94
- return _assertThisInitialized(self);
95
- }
96
-
97
- function _createSuper(Derived) {
98
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
99
-
100
- return function _createSuperInternal() {
101
- var Super = _getPrototypeOf(Derived),
102
- result;
103
-
104
- if (hasNativeReflectConstruct) {
105
- var NewTarget = _getPrototypeOf(this).constructor;
106
-
107
- result = Reflect.construct(Super, arguments, NewTarget);
108
- } else {
109
- result = Super.apply(this, arguments);
110
- }
111
-
112
- return _possibleConstructorReturn(this, result);
113
- };
114
- }
115
-
116
- /*! *****************************************************************************
117
- Copyright (c) Microsoft Corporation.
118
-
119
- Permission to use, copy, modify, and/or distribute this software for any
120
- purpose with or without fee is hereby granted.
121
-
122
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
123
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
124
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
125
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
126
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
127
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
128
- PERFORMANCE OF THIS SOFTWARE.
129
- ***************************************************************************** */
130
-
131
- function __decorate(decorators, target, key, desc) {
132
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
133
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
134
- 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;
135
- return c > 3 && r && Object.defineProperty(target, key, r), r;
136
- }
137
-
138
- function __metadata(metadataKey, metadataValue) {
139
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
140
- }
141
-
142
- var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
143
-
144
- var PX_SUFFIX = 'px';
145
- function setDOMSize($el, width, height) {
146
- if (isBrowser) {
147
- $el.style.width = width + PX_SUFFIX;
148
- $el.style.height = height + PX_SUFFIX;
149
- }
150
- }
151
-
152
- var Canvas2DContextService = /*#__PURE__*/function () {
153
- function Canvas2DContextService() {
154
- _classCallCheck(this, Canvas2DContextService);
155
-
156
- this.$container = void 0;
157
- this.$canvas = void 0;
158
- this.dpr = void 0;
159
- this.context = void 0;
160
- this.canvasConfig = void 0;
161
- }
162
-
163
- _createClass(Canvas2DContextService, [{
164
- key: "init",
165
- value: function init() {
166
- var _this$canvasConfig = this.canvasConfig,
167
- container = _this$canvasConfig.container,
168
- width = _this$canvasConfig.width,
169
- height = _this$canvasConfig.height; // create container
170
-
171
- this.$container = util.isString(container) ? document.getElementById(container) : container;
172
-
173
- if (this.$container) {
174
- // create canvas
175
- var $canvas = document.createElement('canvas');
176
- this.context = $canvas.getContext('2d');
177
- this.$container.appendChild($canvas);
178
-
179
- if (!this.$container.style.position) {
180
- this.$container.style.position = 'relative';
181
- }
182
-
183
- this.$canvas = $canvas;
184
- var dpr = window.devicePixelRatio || 1;
185
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
186
- this.dpr = dpr;
187
- this.resize(width, height);
188
- }
189
- }
190
- }, {
191
- key: "getContext",
192
- value: function getContext() {
193
- return this.context;
194
- }
195
- }, {
196
- key: "getDomElement",
197
- value: function getDomElement() {
198
- return this.$canvas;
199
- }
200
- }, {
201
- key: "getDPR",
202
- value: function getDPR() {
203
- return this.dpr;
204
- }
205
- }, {
206
- key: "getBoundingClientRect",
207
- value: function getBoundingClientRect() {
208
- var _this$$canvas;
209
-
210
- return (_this$$canvas = this.$canvas) === null || _this$$canvas === void 0 ? void 0 : _this$$canvas.getBoundingClientRect();
211
- }
212
- }, {
213
- key: "destroy",
214
- value: function destroy() {
215
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
216
- // destroy context
217
- this.$container.removeChild(this.$canvas);
218
- }
219
- }
220
- }, {
221
- key: "resize",
222
- value: function resize(width, height) {
223
- if (this.$canvas) {
224
- // set canvas width & height
225
- this.$canvas.width = this.dpr * width;
226
- this.$canvas.height = this.dpr * height; // set CSS style width & height
227
-
228
- setDOMSize(this.$canvas, width, height);
229
- }
230
- }
231
- }, {
232
- key: "applyCursorStyle",
233
- value: function applyCursorStyle(cursor) {
234
- if (this.$container) {
235
- this.$container.style.cursor = cursor;
236
- }
237
- }
238
- }]);
239
-
240
- return Canvas2DContextService;
241
- }();
242
-
243
- __decorate([manaSyringe.inject(g.CanvasConfig), __metadata("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
244
-
245
- Canvas2DContextService = __decorate([manaSyringe.singleton({
246
- token: g.ContextService
247
- })], Canvas2DContextService);
248
-
249
- var containerModule = manaSyringe.Module(function (register) {
250
- /**
251
- * implements ContextService
252
- */
253
- register(Canvas2DContextService);
254
- });
255
- var ContextRegisterPlugin = /*#__PURE__*/function () {
256
- function ContextRegisterPlugin() {
257
- _classCallCheck(this, ContextRegisterPlugin);
258
- }
259
-
260
- _createClass(ContextRegisterPlugin, [{
261
- key: "init",
262
- value: function init(container) {
263
- container.load(containerModule);
264
- }
265
- }, {
266
- key: "destroy",
267
- value: function destroy(container) {// @ts-ignore
268
- // container.container.unload(containerModule);
269
- // container.remove(Canvas2DContextService);
270
- }
271
- }]);
272
-
273
- return ContextRegisterPlugin;
274
- }();
275
-
276
- var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
277
- _inherits(Renderer, _AbstractRenderer);
278
-
279
- var _super = _createSuper(Renderer);
280
-
281
- function Renderer(config) {
282
- var _this;
283
-
284
- _classCallCheck(this, Renderer);
285
-
286
- _this = _super.call(this, config); // register Canvas2DContext
287
-
288
- _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
289
-
290
-
291
- _this.registerPlugin(new gPluginCanvasRenderer.Plugin());
292
-
293
- _this.registerPlugin(new gPluginDomInteraction.Plugin()); // enable picking with Canvas2D API
294
-
295
-
296
- _this.registerPlugin(new gPluginCanvasPicker.Plugin()); // render HTML component
297
-
298
-
299
- _this.registerPlugin(new gPluginHtmlRenderer.Plugin());
300
-
301
- return _this;
302
- }
303
-
304
- return Renderer;
305
- }(g.AbstractRenderer);
306
-
307
- exports.Renderer = Renderer;