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

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 { 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
+ }
@@ -0,0 +1,6 @@
1
+ import { Syringe } from 'mana-syringe';
2
+ import { RendererPlugin } from '@antv/g';
3
+ export declare class ContextRegisterPlugin implements RendererPlugin {
4
+ init(container: Syringe.Container): void;
5
+ destroy(container: Syringe.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,204 @@
1
+ import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
2
+ import _inherits from '@babel/runtime/helpers/esm/inherits';
3
+ import _createSuper from '@babel/runtime/helpers/esm/createSuper';
4
+ import { CanvasConfig, ContextService, AbstractRenderer } from '@antv/g';
5
+ import { Plugin as Plugin$1 } from '@antv/g-plugin-dom-interaction';
6
+ import { Plugin } from '@antv/g-plugin-canvas-renderer';
7
+ import { Plugin as Plugin$2 } from '@antv/g-plugin-canvas-picker';
8
+ import { Plugin as Plugin$3 } from '@antv/g-plugin-html-renderer';
9
+ import _createClass from '@babel/runtime/helpers/esm/createClass';
10
+ import { inject, singleton, Module } from 'mana-syringe';
11
+ import { isString } from '@antv/util';
12
+
13
+ /*! *****************************************************************************
14
+ Copyright (c) Microsoft Corporation.
15
+
16
+ Permission to use, copy, modify, and/or distribute this software for any
17
+ purpose with or without fee is hereby granted.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
+ PERFORMANCE OF THIS SOFTWARE.
26
+ ***************************************************************************** */
27
+
28
+ function __decorate(decorators, target, key, desc) {
29
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
30
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31
+ 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;
32
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
33
+ }
34
+
35
+ function __metadata(metadataKey, metadataValue) {
36
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
37
+ }
38
+
39
+ var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
40
+
41
+ var PX_SUFFIX = 'px';
42
+ function setDOMSize($el, width, height) {
43
+ if (isBrowser) {
44
+ $el.style.width = width + PX_SUFFIX;
45
+ $el.style.height = height + PX_SUFFIX;
46
+ }
47
+ }
48
+
49
+ var Canvas2DContextService = /*#__PURE__*/function () {
50
+ function Canvas2DContextService() {
51
+ _classCallCheck(this, Canvas2DContextService);
52
+
53
+ this.$container = void 0;
54
+ this.$canvas = void 0;
55
+ this.dpr = void 0;
56
+ this.context = void 0;
57
+ this.canvasConfig = void 0;
58
+ }
59
+
60
+ _createClass(Canvas2DContextService, [{
61
+ key: "init",
62
+ value: function init() {
63
+ var _this$canvasConfig = this.canvasConfig,
64
+ container = _this$canvasConfig.container,
65
+ width = _this$canvasConfig.width,
66
+ height = _this$canvasConfig.height; // create container
67
+
68
+ this.$container = isString(container) ? document.getElementById(container) : container;
69
+
70
+ if (this.$container) {
71
+ // create canvas
72
+ var $canvas = document.createElement('canvas');
73
+ this.context = $canvas.getContext('2d');
74
+ this.$container.appendChild($canvas);
75
+
76
+ if (!this.$container.style.position) {
77
+ this.$container.style.position = 'relative';
78
+ }
79
+
80
+ this.$canvas = $canvas;
81
+ var dpr = window.devicePixelRatio || 1;
82
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
83
+ this.dpr = dpr;
84
+ this.resize(width, height);
85
+ }
86
+ }
87
+ }, {
88
+ key: "getContext",
89
+ value: function getContext() {
90
+ return this.context;
91
+ }
92
+ }, {
93
+ key: "getDomElement",
94
+ value: function getDomElement() {
95
+ return this.$canvas;
96
+ }
97
+ }, {
98
+ key: "getDPR",
99
+ value: function getDPR() {
100
+ return this.dpr;
101
+ }
102
+ }, {
103
+ key: "getBoundingClientRect",
104
+ value: function getBoundingClientRect() {
105
+ var _this$$canvas;
106
+
107
+ return (_this$$canvas = this.$canvas) === null || _this$$canvas === void 0 ? void 0 : _this$$canvas.getBoundingClientRect();
108
+ }
109
+ }, {
110
+ key: "destroy",
111
+ value: function destroy() {
112
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
113
+ // destroy context
114
+ this.$container.removeChild(this.$canvas);
115
+ }
116
+ }
117
+ }, {
118
+ key: "resize",
119
+ value: function resize(width, height) {
120
+ if (this.$canvas) {
121
+ // set canvas width & height
122
+ this.$canvas.width = this.dpr * width;
123
+ this.$canvas.height = this.dpr * height; // set CSS style width & height
124
+
125
+ setDOMSize(this.$canvas, width, height);
126
+ }
127
+ }
128
+ }, {
129
+ key: "applyCursorStyle",
130
+ value: function applyCursorStyle(cursor) {
131
+ if (this.$container) {
132
+ this.$container.style.cursor = cursor;
133
+ }
134
+ }
135
+ }]);
136
+
137
+ return Canvas2DContextService;
138
+ }();
139
+
140
+ __decorate([inject(CanvasConfig), __metadata("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
141
+
142
+ Canvas2DContextService = __decorate([singleton({
143
+ token: ContextService
144
+ })], Canvas2DContextService);
145
+
146
+ var containerModule = Module(function (register) {
147
+ /**
148
+ * implements ContextService
149
+ */
150
+ register(Canvas2DContextService);
151
+ });
152
+ var ContextRegisterPlugin = /*#__PURE__*/function () {
153
+ function ContextRegisterPlugin() {
154
+ _classCallCheck(this, ContextRegisterPlugin);
155
+ }
156
+
157
+ _createClass(ContextRegisterPlugin, [{
158
+ key: "init",
159
+ value: function init(container) {
160
+ container.load(containerModule);
161
+ }
162
+ }, {
163
+ key: "destroy",
164
+ value: function destroy(container) {// @ts-ignore
165
+ // container.container.unload(containerModule);
166
+ // container.remove(Canvas2DContextService);
167
+ }
168
+ }]);
169
+
170
+ return ContextRegisterPlugin;
171
+ }();
172
+
173
+ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
174
+ _inherits(Renderer, _AbstractRenderer);
175
+
176
+ var _super = _createSuper(Renderer);
177
+
178
+ function Renderer(config) {
179
+ var _this;
180
+
181
+ _classCallCheck(this, Renderer);
182
+
183
+ _this = _super.call(this, config); // register Canvas2DContext
184
+
185
+ _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
186
+
187
+
188
+ _this.registerPlugin(new Plugin());
189
+
190
+ _this.registerPlugin(new Plugin$1()); // enable picking with Canvas2D API
191
+
192
+
193
+ _this.registerPlugin(new Plugin$2()); // render HTML component
194
+
195
+
196
+ _this.registerPlugin(new Plugin$3());
197
+
198
+ return _this;
199
+ }
200
+
201
+ return Renderer;
202
+ }(AbstractRenderer);
203
+
204
+ export { Renderer };
package/dist/index.js ADDED
@@ -0,0 +1,307 @@
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;
@@ -1 +1 @@
1
- export declare const isBrowser: boolean;
1
+ export declare const isBrowser: boolean;
@@ -1 +1 @@
1
- export declare function setDOMSize($el: HTMLElement, width: number, height: number): void;
1
+ export declare function setDOMSize($el: HTMLElement, width: number, height: number): void;
package/package.json CHANGED
@@ -1,15 +1,13 @@
1
1
  {
2
2
  "name": "@antv/g-canvas",
3
- "version": "1.0.0-alpha.23",
3
+ "version": "1.0.0-alpha.27",
4
4
  "description": "A renderer implemented by Canvas 2D API",
5
- "main": "lib/index.js",
6
- "module": "es/index.js",
7
- "types": "lib/index.d.ts",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
8
  "sideEffects": false,
9
9
  "files": [
10
10
  "package.json",
11
- "es",
12
- "lib",
13
11
  "dist",
14
12
  "LICENSE",
15
13
  "README.md"
@@ -40,12 +38,14 @@
40
38
  },
41
39
  "homepage": "https://github.com/antvis/g#readme",
42
40
  "dependencies": {
43
- "@antv/g": "^1.0.0-alpha.23",
44
- "@antv/g-plugin-canvas-picker": "^1.0.0-alpha.17",
45
- "@antv/g-plugin-canvas-renderer": "^1.0.0-alpha.23",
46
- "@antv/g-plugin-dom-interaction": "^1.0.0-alpha.22",
47
- "@antv/g-plugin-html-renderer": "^1.0.0-alpha.6",
48
- "@antv/util": "^2.0.13"
41
+ "@antv/g": "^1.0.0-alpha.27",
42
+ "@antv/g-plugin-canvas-picker": "^1.0.0-alpha.21",
43
+ "@antv/g-plugin-canvas-renderer": "^1.0.0-alpha.27",
44
+ "@antv/g-plugin-dom-interaction": "^1.0.0-alpha.26",
45
+ "@antv/g-plugin-html-renderer": "^1.0.0-alpha.10",
46
+ "@antv/util": "^2.0.13",
47
+ "@babel/runtime": "^7.16.0",
48
+ "mana-syringe": "^0.1.0"
49
49
  },
50
- "gitHead": "c64e9f589805686657e64d063f80de34e276ba0b"
50
+ "gitHead": "c01101beb86f98aaa569f97c678c909d4f3faaa3"
51
51
  }
@@ -1,83 +0,0 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { CanvasConfig } from '@antv/g';
3
- import { inject, injectable } from 'inversify';
4
- import { isString } from '@antv/util';
5
- import { setDOMSize } from './utils/dom';
6
-
7
- var Canvas2DContextService = function () {
8
- function Canvas2DContextService() {}
9
-
10
- Canvas2DContextService.prototype.init = function () {
11
- var _a = this.canvasConfig,
12
- container = _a.container,
13
- width = _a.width,
14
- height = _a.height; // create container
15
-
16
- this.$container = isString(container) ? document.getElementById(container) : container;
17
-
18
- if (this.$container) {
19
- // create canvas
20
- var $canvas = document.createElement('canvas');
21
- this.context = $canvas.getContext('2d');
22
- this.$container.appendChild($canvas);
23
-
24
- if (!this.$container.style.position) {
25
- this.$container.style.position = 'relative';
26
- }
27
-
28
- this.$canvas = $canvas;
29
- var dpr = window.devicePixelRatio || 1;
30
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
31
- this.dpr = dpr;
32
- this.resize(width, height);
33
- }
34
- };
35
-
36
- Canvas2DContextService.prototype.getContext = function () {
37
- return this.context;
38
- };
39
-
40
- Canvas2DContextService.prototype.getDomElement = function () {
41
- return this.$canvas;
42
- };
43
-
44
- Canvas2DContextService.prototype.getDPR = function () {
45
- return this.dpr;
46
- };
47
-
48
- Canvas2DContextService.prototype.getBoundingClientRect = function () {
49
- var _a;
50
-
51
- return (_a = this.$canvas) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
52
- };
53
-
54
- Canvas2DContextService.prototype.destroy = function () {
55
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
56
- // destroy context
57
- this.$container.removeChild(this.$canvas);
58
- }
59
- };
60
-
61
- Canvas2DContextService.prototype.resize = function (width, height) {
62
- if (this.$canvas) {
63
- // set canvas width & height
64
- this.$canvas.width = this.dpr * width;
65
- this.$canvas.height = this.dpr * height; // set CSS style width & height
66
-
67
- setDOMSize(this.$canvas, width, height);
68
- }
69
- };
70
-
71
- Canvas2DContextService.prototype.applyCursorStyle = function (cursor) {
72
- if (this.$container) {
73
- this.$container.style.cursor = cursor;
74
- }
75
- };
76
-
77
- __decorate([inject(CanvasConfig), __metadata("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
78
-
79
- Canvas2DContextService = __decorate([injectable()], Canvas2DContextService);
80
- return Canvas2DContextService;
81
- }();
82
-
83
- export { Canvas2DContextService };
@@ -1,6 +0,0 @@
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,26 +0,0 @@
1
- import { ContainerModule } from 'inversify';
2
- import { ContextService } from '@antv/g';
3
- import { Canvas2DContextService } from './Canvas2DContextService';
4
- var containerModule = new ContainerModule(function (bind, unbind, isBound, rebind) {
5
- /**
6
- * implements ContextService
7
- */
8
- bind(Canvas2DContextService).toSelf().inSingletonScope();
9
- bind(ContextService).toService(Canvas2DContextService);
10
- });
11
-
12
- var ContextRegisterPlugin = function () {
13
- function ContextRegisterPlugin() {}
14
-
15
- ContextRegisterPlugin.prototype.init = function (container) {
16
- container.load(containerModule);
17
- };
18
-
19
- ContextRegisterPlugin.prototype.destroy = function (container) {
20
- container.unload(containerModule);
21
- };
22
-
23
- return ContextRegisterPlugin;
24
- }();
25
-
26
- export { ContextRegisterPlugin };
package/es/index.js DELETED
@@ -1,35 +0,0 @@
1
- import { __extends } from "tslib";
2
- import { AbstractRenderer } from '@antv/g';
3
- import { Plugin as DomInteractionPlugin } from '@antv/g-plugin-dom-interaction';
4
- import { Plugin as CanvasRendererPlugin } from '@antv/g-plugin-canvas-renderer';
5
- import { Plugin as CanvasPickerPlugin } from '@antv/g-plugin-canvas-picker';
6
- import { Plugin as HTMLRendererPlugin } from '@antv/g-plugin-html-renderer';
7
- import { ContextRegisterPlugin } from './ContextRegisterPlugin';
8
-
9
- var Renderer = function (_super) {
10
- __extends(Renderer, _super);
11
-
12
- function Renderer(config) {
13
- var _this = _super.call(this, config) || this; // register Canvas2DContext
14
-
15
-
16
- _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
17
-
18
-
19
- _this.registerPlugin(new CanvasRendererPlugin());
20
-
21
- _this.registerPlugin(new DomInteractionPlugin()); // enable picking with Canvas2D API
22
-
23
-
24
- _this.registerPlugin(new CanvasPickerPlugin()); // render HTML component
25
-
26
-
27
- _this.registerPlugin(new HTMLRendererPlugin());
28
-
29
- return _this;
30
- }
31
-
32
- return Renderer;
33
- }(AbstractRenderer);
34
-
35
- export { Renderer };
@@ -1 +0,0 @@
1
- export var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
package/es/utils/dom.js DELETED
@@ -1,8 +0,0 @@
1
- import { isBrowser } from './browser';
2
- var PX_SUFFIX = 'px';
3
- export function setDOMSize($el, width, height) {
4
- if (isBrowser) {
5
- $el.style.width = width + PX_SUFFIX;
6
- $el.style.height = height + PX_SUFFIX;
7
- }
8
- }
@@ -1,16 +0,0 @@
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,93 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Canvas2DContextService = void 0;
7
-
8
- var _tslib = require("tslib");
9
-
10
- var _g = require("@antv/g");
11
-
12
- var _inversify = require("inversify");
13
-
14
- var _util = require("@antv/util");
15
-
16
- var _dom = require("./utils/dom");
17
-
18
- var Canvas2DContextService = function () {
19
- function Canvas2DContextService() {}
20
-
21
- Canvas2DContextService.prototype.init = function () {
22
- var _a = this.canvasConfig,
23
- container = _a.container,
24
- width = _a.width,
25
- height = _a.height; // create container
26
-
27
- this.$container = (0, _util.isString)(container) ? document.getElementById(container) : container;
28
-
29
- if (this.$container) {
30
- // create canvas
31
- var $canvas = document.createElement('canvas');
32
- this.context = $canvas.getContext('2d');
33
- this.$container.appendChild($canvas);
34
-
35
- if (!this.$container.style.position) {
36
- this.$container.style.position = 'relative';
37
- }
38
-
39
- this.$canvas = $canvas;
40
- var dpr = window.devicePixelRatio || 1;
41
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
42
- this.dpr = dpr;
43
- this.resize(width, height);
44
- }
45
- };
46
-
47
- Canvas2DContextService.prototype.getContext = function () {
48
- return this.context;
49
- };
50
-
51
- Canvas2DContextService.prototype.getDomElement = function () {
52
- return this.$canvas;
53
- };
54
-
55
- Canvas2DContextService.prototype.getDPR = function () {
56
- return this.dpr;
57
- };
58
-
59
- Canvas2DContextService.prototype.getBoundingClientRect = function () {
60
- var _a;
61
-
62
- return (_a = this.$canvas) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
63
- };
64
-
65
- Canvas2DContextService.prototype.destroy = function () {
66
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
67
- // destroy context
68
- this.$container.removeChild(this.$canvas);
69
- }
70
- };
71
-
72
- Canvas2DContextService.prototype.resize = function (width, height) {
73
- if (this.$canvas) {
74
- // set canvas width & height
75
- this.$canvas.width = this.dpr * width;
76
- this.$canvas.height = this.dpr * height; // set CSS style width & height
77
-
78
- (0, _dom.setDOMSize)(this.$canvas, width, height);
79
- }
80
- };
81
-
82
- Canvas2DContextService.prototype.applyCursorStyle = function (cursor) {
83
- if (this.$container) {
84
- this.$container.style.cursor = cursor;
85
- }
86
- };
87
-
88
- (0, _tslib.__decorate)([(0, _inversify.inject)(_g.CanvasConfig), (0, _tslib.__metadata)("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
89
- Canvas2DContextService = (0, _tslib.__decorate)([(0, _inversify.injectable)()], Canvas2DContextService);
90
- return Canvas2DContextService;
91
- }();
92
-
93
- exports.Canvas2DContextService = Canvas2DContextService;
@@ -1,6 +0,0 @@
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,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ContextRegisterPlugin = void 0;
7
-
8
- var _inversify = require("inversify");
9
-
10
- var _g = require("@antv/g");
11
-
12
- var _Canvas2DContextService = require("./Canvas2DContextService");
13
-
14
- var containerModule = new _inversify.ContainerModule(function (bind, unbind, isBound, rebind) {
15
- /**
16
- * implements ContextService
17
- */
18
- bind(_Canvas2DContextService.Canvas2DContextService).toSelf().inSingletonScope();
19
- bind(_g.ContextService).toService(_Canvas2DContextService.Canvas2DContextService);
20
- });
21
-
22
- var ContextRegisterPlugin = function () {
23
- function ContextRegisterPlugin() {}
24
-
25
- ContextRegisterPlugin.prototype.init = function (container) {
26
- container.load(containerModule);
27
- };
28
-
29
- ContextRegisterPlugin.prototype.destroy = function (container) {
30
- container.unload(containerModule);
31
- };
32
-
33
- return ContextRegisterPlugin;
34
- }();
35
-
36
- exports.ContextRegisterPlugin = ContextRegisterPlugin;
package/lib/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { AbstractRenderer, RendererConfig } from '@antv/g';
2
- export declare class Renderer extends AbstractRenderer {
3
- constructor(config?: Partial<RendererConfig>);
4
- }
package/lib/index.js DELETED
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Renderer = void 0;
7
-
8
- var _tslib = require("tslib");
9
-
10
- var _g = require("@antv/g");
11
-
12
- var _gPluginDomInteraction = require("@antv/g-plugin-dom-interaction");
13
-
14
- var _gPluginCanvasRenderer = require("@antv/g-plugin-canvas-renderer");
15
-
16
- var _gPluginCanvasPicker = require("@antv/g-plugin-canvas-picker");
17
-
18
- var _gPluginHtmlRenderer = require("@antv/g-plugin-html-renderer");
19
-
20
- var _ContextRegisterPlugin = require("./ContextRegisterPlugin");
21
-
22
- var Renderer = function (_super) {
23
- (0, _tslib.__extends)(Renderer, _super);
24
-
25
- function Renderer(config) {
26
- var _this = _super.call(this, config) || this; // register Canvas2DContext
27
-
28
-
29
- _this.registerPlugin(new _ContextRegisterPlugin.ContextRegisterPlugin()); // enable rendering with Canvas2D API
30
-
31
-
32
- _this.registerPlugin(new _gPluginCanvasRenderer.Plugin());
33
-
34
- _this.registerPlugin(new _gPluginDomInteraction.Plugin()); // enable picking with Canvas2D API
35
-
36
-
37
- _this.registerPlugin(new _gPluginCanvasPicker.Plugin()); // render HTML component
38
-
39
-
40
- _this.registerPlugin(new _gPluginHtmlRenderer.Plugin());
41
-
42
- return _this;
43
- }
44
-
45
- return Renderer;
46
- }(_g.AbstractRenderer);
47
-
48
- exports.Renderer = Renderer;
@@ -1 +0,0 @@
1
- export declare const isBrowser: boolean;
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isBrowser = void 0;
7
- var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
8
- exports.isBrowser = isBrowser;
@@ -1 +0,0 @@
1
- export declare function setDOMSize($el: HTMLElement, width: number, height: number): void;
package/lib/utils/dom.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.setDOMSize = setDOMSize;
7
-
8
- var _browser = require("./browser");
9
-
10
- var PX_SUFFIX = 'px';
11
-
12
- function setDOMSize($el, width, height) {
13
- if (_browser.isBrowser) {
14
- $el.style.width = width + PX_SUFFIX;
15
- $el.style.height = height + PX_SUFFIX;
16
- }
17
- }