@antv/g-canvas 1.1.2 → 1.1.3

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,17 +1,18 @@
1
- /// <reference types="offscreencanvas" />
2
- import { ContextService } from '@antv/g';
3
- export declare class Canvas2DContextService implements ContextService<CanvasRenderingContext2D> {
4
- private $container;
5
- private $canvas;
6
- private dpr;
7
- private context;
8
- private canvasConfig;
9
- init(): void;
10
- getContext(): CanvasRenderingContext2D;
11
- getDomElement(): OffscreenCanvas | HTMLCanvasElement;
12
- getDPR(): number;
13
- getBoundingClientRect(): DOMRect;
14
- destroy(): void;
15
- resize(width: number, height: number): void;
16
- applyCursorStyle(cursor: string): void;
17
- }
1
+ /// <reference types="offscreencanvas" />
2
+ import { ContextService } from '@antv/g';
3
+ export declare class Canvas2DContextService implements ContextService<CanvasRenderingContext2D> {
4
+ private $container;
5
+ private $canvas;
6
+ private dpr;
7
+ private context;
8
+ private canvasConfig;
9
+ init(): void;
10
+ getContext(): CanvasRenderingContext2D;
11
+ getDomElement(): OffscreenCanvas | HTMLCanvasElement;
12
+ getDPR(): number;
13
+ getBoundingClientRect(): DOMRect;
14
+ destroy(): void;
15
+ resize(width: number, height: number): void;
16
+ applyCursorStyle(cursor: string): void;
17
+ }
18
+ //# sourceMappingURL=Canvas2DContextService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Canvas2DContextService.d.ts","sourceRoot":"","sources":["../src/Canvas2DContextService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAgB,cAAc,EAAmC,MAAM,SAAS,CAAC;AAGxF,qBACa,sBAAuB,YAAW,cAAc,CAAC,wBAAwB,CAAC;IACrF,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,OAAO,CAA6C;IAC5D,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,OAAO,CAAsE;IAGrF,OAAO,CAAC,YAAY,CAAe;IAEnC,IAAI;IAoCJ,UAAU;IAIV,aAAa;IAIb,MAAM;IAIN,qBAAqB;IAMrB,OAAO;IASP,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAgBpC,gBAAgB,CAAC,MAAM,EAAE,MAAM;CAKhC"}
@@ -1,7 +1,8 @@
1
- import type { Syringe } from 'mana-syringe';
2
- import type { RendererPlugin } from '@antv/g';
3
- export declare class ContextRegisterPlugin implements RendererPlugin {
4
- name: string;
5
- init(container: Syringe.Container): void;
6
- destroy(container: Syringe.Container): void;
7
- }
1
+ import type { Syringe } from 'mana-syringe';
2
+ import type { RendererPlugin } from '@antv/g';
3
+ export declare class ContextRegisterPlugin implements RendererPlugin {
4
+ name: string;
5
+ init(container: Syringe.Container): void;
6
+ destroy(container: Syringe.Container): void;
7
+ }
8
+ //# sourceMappingURL=ContextRegisterPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextRegisterPlugin.d.ts","sourceRoot":"","sources":["../src/ContextRegisterPlugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAU9C,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,IAAI,SAA6B;IACjC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,GAAG,IAAI;IAGxC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,GAAG,IAAI;CAG5C"}
@@ -1,10 +1,11 @@
1
- import type { RendererConfig } from '@antv/g';
2
- import { AbstractRenderer } from '@antv/g';
3
- import * as DomInteraction from '@antv/g-plugin-dom-interaction';
4
- import * as CanvasRenderer from '@antv/g-plugin-canvas-renderer';
5
- import * as CanvasPicker from '@antv/g-plugin-canvas-picker';
6
- import * as HTMLRenderer from '@antv/g-plugin-html-renderer';
7
- export { DomInteraction, CanvasRenderer, CanvasPicker, HTMLRenderer };
8
- export declare class Renderer extends AbstractRenderer {
9
- constructor(config?: Partial<RendererConfig>);
10
- }
1
+ import type { RendererConfig } from '@antv/g';
2
+ import { AbstractRenderer } from '@antv/g';
3
+ import * as DomInteraction from '@antv/g-plugin-dom-interaction';
4
+ import * as CanvasRenderer from '@antv/g-plugin-canvas-renderer';
5
+ import * as CanvasPicker from '@antv/g-plugin-canvas-picker';
6
+ import * as HTMLRenderer from '@antv/g-plugin-html-renderer';
7
+ export { DomInteraction, CanvasRenderer, CanvasPicker, HTMLRenderer };
8
+ export declare class Renderer extends AbstractRenderer {
9
+ constructor(config?: Partial<RendererConfig>);
10
+ }
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,YAAY,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,YAAY,MAAM,8BAA8B,CAAC;AAG7D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AAEtE,qBAAa,QAAS,SAAQ,gBAAgB;gBAChC,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;CAc7C"}
@@ -0,0 +1,191 @@
1
+ import { CanvasConfig, ContextService, isString, setDOMSize, isBrowser, AbstractRenderer } from '@antv/g';
2
+ import { Plugin as Plugin$1 } from '@antv/g-plugin-dom-interaction';
3
+ import * as DomInteraction from '@antv/g-plugin-dom-interaction';
4
+ export { DomInteraction };
5
+ import { Plugin } from '@antv/g-plugin-canvas-renderer';
6
+ import * as CanvasRenderer from '@antv/g-plugin-canvas-renderer';
7
+ export { CanvasRenderer };
8
+ import { Plugin as Plugin$2 } from '@antv/g-plugin-canvas-picker';
9
+ import * as CanvasPicker from '@antv/g-plugin-canvas-picker';
10
+ export { CanvasPicker };
11
+ import { Plugin as Plugin$3 } from '@antv/g-plugin-html-renderer';
12
+ import * as HTMLRenderer from '@antv/g-plugin-html-renderer';
13
+ export { HTMLRenderer };
14
+ import { inject, singleton, Module } from 'mana-syringe';
15
+ import { __decorate, __metadata } from 'tslib';
16
+
17
+ function _inheritsLoose(subClass, superClass) {
18
+ subClass.prototype = Object.create(superClass.prototype);
19
+ subClass.prototype.constructor = subClass;
20
+
21
+ _setPrototypeOf(subClass, superClass);
22
+ }
23
+
24
+ function _setPrototypeOf(o, p) {
25
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
26
+ o.__proto__ = p;
27
+ return o;
28
+ };
29
+
30
+ return _setPrototypeOf(o, p);
31
+ }
32
+
33
+ var Canvas2DContextService = /*#__PURE__*/function () {
34
+ function Canvas2DContextService() {
35
+ this.$container = void 0;
36
+ this.$canvas = void 0;
37
+ this.dpr = void 0;
38
+ this.context = void 0;
39
+ this.canvasConfig = void 0;
40
+ }
41
+
42
+ var _proto = Canvas2DContextService.prototype;
43
+
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;
49
+
50
+ if (canvas) {
51
+ this.$canvas = canvas;
52
+
53
+ if (container && canvas.parentElement !== container) {
54
+ container.appendChild(canvas);
55
+ }
56
+
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;
62
+
63
+ if (this.$container) {
64
+ // create canvas
65
+ var $canvas = document.createElement('canvas');
66
+ this.$container.appendChild($canvas);
67
+
68
+ if (!this.$container.style.position) {
69
+ this.$container.style.position = 'relative';
70
+ }
71
+
72
+ this.$canvas = $canvas;
73
+ }
74
+ }
75
+
76
+ this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
77
+
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();
99
+ }
100
+ };
101
+
102
+ _proto.destroy = function destroy() {
103
+ // @ts-ignore
104
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
105
+ // destroy context
106
+ // @ts-ignore
107
+ this.$container.removeChild(this.$canvas);
108
+ }
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);
122
+ }
123
+ };
124
+
125
+ _proto.applyCursorStyle = function applyCursorStyle(cursor) {
126
+ if (this.$container && this.$container.style) {
127
+ this.$container.style.cursor = cursor;
128
+ }
129
+ };
130
+
131
+ return Canvas2DContextService;
132
+ }();
133
+
134
+ __decorate([inject(CanvasConfig), __metadata("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
135
+
136
+ Canvas2DContextService = __decorate([singleton({
137
+ token: ContextService
138
+ })], Canvas2DContextService);
139
+
140
+ var containerModule = Module(function (register) {
141
+ /**
142
+ * implements ContextService
143
+ */
144
+ register(Canvas2DContextService);
145
+ });
146
+ var ContextRegisterPlugin = /*#__PURE__*/function () {
147
+ function ContextRegisterPlugin() {
148
+ this.name = 'canvas-context-register';
149
+ }
150
+
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
+ };
160
+
161
+ return ContextRegisterPlugin;
162
+ }();
163
+
164
+ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
165
+ _inheritsLoose(Renderer, _AbstractRenderer);
166
+
167
+ function Renderer(config) {
168
+ var _this;
169
+
170
+ _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
171
+
172
+ _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
173
+
174
+
175
+ _this.registerPlugin(new Plugin());
176
+
177
+ _this.registerPlugin(new Plugin$1()); // enable picking with Canvas2D API
178
+
179
+
180
+ _this.registerPlugin(new Plugin$2()); // render HTML component
181
+
182
+
183
+ _this.registerPlugin(new Plugin$3());
184
+
185
+ return _this;
186
+ }
187
+
188
+ return Renderer;
189
+ }(AbstractRenderer);
190
+
191
+ export { Renderer };
package/dist/index.js ADDED
@@ -0,0 +1,216 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var g = require('@antv/g');
6
+ var DomInteraction = require('@antv/g-plugin-dom-interaction');
7
+ var CanvasRenderer = require('@antv/g-plugin-canvas-renderer');
8
+ var CanvasPicker = require('@antv/g-plugin-canvas-picker');
9
+ var HTMLRenderer = require('@antv/g-plugin-html-renderer');
10
+ var manaSyringe = require('mana-syringe');
11
+ var tslib = require('tslib');
12
+
13
+ function _interopNamespace(e) {
14
+ if (e && e.__esModule) return e;
15
+ var n = Object.create(null);
16
+ if (e) {
17
+ Object.keys(e).forEach(function (k) {
18
+ if (k !== 'default') {
19
+ var d = Object.getOwnPropertyDescriptor(e, k);
20
+ Object.defineProperty(n, k, d.get ? d : {
21
+ enumerable: true,
22
+ get: function () {
23
+ return e[k];
24
+ }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ n['default'] = e;
30
+ return Object.freeze(n);
31
+ }
32
+
33
+ var DomInteraction__namespace = /*#__PURE__*/_interopNamespace(DomInteraction);
34
+ var CanvasRenderer__namespace = /*#__PURE__*/_interopNamespace(CanvasRenderer);
35
+ var CanvasPicker__namespace = /*#__PURE__*/_interopNamespace(CanvasPicker);
36
+ var HTMLRenderer__namespace = /*#__PURE__*/_interopNamespace(HTMLRenderer);
37
+
38
+ function _inheritsLoose(subClass, superClass) {
39
+ subClass.prototype = Object.create(superClass.prototype);
40
+ subClass.prototype.constructor = subClass;
41
+
42
+ _setPrototypeOf(subClass, superClass);
43
+ }
44
+
45
+ function _setPrototypeOf(o, p) {
46
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
47
+ o.__proto__ = p;
48
+ return o;
49
+ };
50
+
51
+ return _setPrototypeOf(o, p);
52
+ }
53
+
54
+ var Canvas2DContextService = /*#__PURE__*/function () {
55
+ function Canvas2DContextService() {
56
+ this.$container = void 0;
57
+ this.$canvas = void 0;
58
+ this.dpr = void 0;
59
+ this.context = void 0;
60
+ this.canvasConfig = void 0;
61
+ }
62
+
63
+ var _proto = Canvas2DContextService.prototype;
64
+
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;
70
+
71
+ if (canvas) {
72
+ this.$canvas = canvas;
73
+
74
+ if (container && canvas.parentElement !== container) {
75
+ container.appendChild(canvas);
76
+ }
77
+
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;
83
+
84
+ if (this.$container) {
85
+ // create canvas
86
+ var $canvas = document.createElement('canvas');
87
+ this.$container.appendChild($canvas);
88
+
89
+ if (!this.$container.style.position) {
90
+ this.$container.style.position = 'relative';
91
+ }
92
+
93
+ this.$canvas = $canvas;
94
+ }
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
+
113
+ _proto.getDPR = function getDPR() {
114
+ return this.dpr;
115
+ };
116
+
117
+ _proto.getBoundingClientRect = function getBoundingClientRect() {
118
+ if (this.$canvas.getBoundingClientRect) {
119
+ return this.$canvas.getBoundingClientRect();
120
+ }
121
+ };
122
+
123
+ _proto.destroy = function destroy() {
124
+ // @ts-ignore
125
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
126
+ // destroy context
127
+ // @ts-ignore
128
+ this.$container.removeChild(this.$canvas);
129
+ }
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);
143
+ }
144
+ };
145
+
146
+ _proto.applyCursorStyle = function applyCursorStyle(cursor) {
147
+ if (this.$container && this.$container.style) {
148
+ this.$container.style.cursor = cursor;
149
+ }
150
+ };
151
+
152
+ return Canvas2DContextService;
153
+ }();
154
+
155
+ tslib.__decorate([manaSyringe.inject(g.CanvasConfig), tslib.__metadata("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
156
+
157
+ Canvas2DContextService = tslib.__decorate([manaSyringe.singleton({
158
+ token: g.ContextService
159
+ })], Canvas2DContextService);
160
+
161
+ var containerModule = manaSyringe.Module(function (register) {
162
+ /**
163
+ * implements ContextService
164
+ */
165
+ register(Canvas2DContextService);
166
+ });
167
+ var ContextRegisterPlugin = /*#__PURE__*/function () {
168
+ function ContextRegisterPlugin() {
169
+ this.name = 'canvas-context-register';
170
+ }
171
+
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
+ };
181
+
182
+ return ContextRegisterPlugin;
183
+ }();
184
+
185
+ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
186
+ _inheritsLoose(Renderer, _AbstractRenderer);
187
+
188
+ function Renderer(config) {
189
+ var _this;
190
+
191
+ _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
192
+
193
+ _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
194
+
195
+
196
+ _this.registerPlugin(new CanvasRenderer.Plugin());
197
+
198
+ _this.registerPlugin(new DomInteraction.Plugin()); // enable picking with Canvas2D API
199
+
200
+
201
+ _this.registerPlugin(new CanvasPicker.Plugin()); // render HTML component
202
+
203
+
204
+ _this.registerPlugin(new HTMLRenderer.Plugin());
205
+
206
+ return _this;
207
+ }
208
+
209
+ return Renderer;
210
+ }(g.AbstractRenderer);
211
+
212
+ exports.DomInteraction = DomInteraction__namespace;
213
+ exports.CanvasRenderer = CanvasRenderer__namespace;
214
+ exports.CanvasPicker = CanvasPicker__namespace;
215
+ exports.HTMLRenderer = HTMLRenderer__namespace;
216
+ exports.Renderer = Renderer;