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

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 { 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 | null;
10
- getDomElement(): HTMLCanvasElement | null;
11
- getDPR(): number;
12
- getBoundingClientRect(): DOMRect;
13
- destroy(): void;
14
- resize(width: number, height: number): void;
15
- applyCursorStyle(cursor: string): void;
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
+ }
@@ -0,0 +1,83 @@
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 };
@@ -0,0 +1,6 @@
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
+ }
@@ -0,0 +1,26 @@
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 };
@@ -1,4 +1,4 @@
1
- import { AbstractRenderer, RendererConfig } from '@antv/g';
2
- export declare class Renderer extends AbstractRenderer {
3
- constructor(config: RendererConfig);
4
- }
1
+ import { AbstractRenderer, RendererConfig } from '@antv/g';
2
+ export declare class Renderer extends AbstractRenderer {
3
+ constructor(config?: Partial<RendererConfig>);
4
+ }
package/es/index.js ADDED
@@ -0,0 +1,35 @@
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 +1 @@
1
- export declare const isBrowser: boolean;
1
+ export declare const isBrowser: boolean;
@@ -0,0 +1 @@
1
+ export var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
@@ -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;
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +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
+ }
@@ -0,0 +1,93 @@
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;
@@ -0,0 +1,6 @@
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
+ }
@@ -0,0 +1,36 @@
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 ADDED
@@ -0,0 +1,4 @@
1
+ import { AbstractRenderer, RendererConfig } from '@antv/g';
2
+ export declare class Renderer extends AbstractRenderer {
3
+ constructor(config?: Partial<RendererConfig>);
4
+ }
package/lib/index.js ADDED
@@ -0,0 +1,48 @@
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;
@@ -0,0 +1 @@
1
+ export declare const isBrowser: boolean;
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1 @@
1
+ export declare function setDOMSize($el: HTMLElement, width: number, height: number): void;
@@ -0,0 +1,17 @@
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
+ }
package/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "@antv/g-canvas",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.23",
4
4
  "description": "A renderer implemented by Canvas 2D API",
5
- "main": "dist/index.js",
6
- "module": "dist/index.esm.js",
7
- "types": "dist/index.d.ts",
8
- "unpkg": "dist/index.umd.min.js",
5
+ "main": "lib/index.js",
6
+ "module": "es/index.js",
7
+ "types": "lib/index.d.ts",
9
8
  "sideEffects": false,
10
9
  "files": [
11
10
  "package.json",
12
- "esm",
11
+ "es",
13
12
  "lib",
14
13
  "dist",
15
14
  "LICENSE",
@@ -41,11 +40,12 @@
41
40
  },
42
41
  "homepage": "https://github.com/antvis/g#readme",
43
42
  "dependencies": {
44
- "@antv/g": "^1.0.0-alpha.2",
45
- "@antv/g-plugin-canvas-picker": "^1.0.0-alpha.2",
46
- "@antv/g-plugin-canvas-renderer": "^1.0.0-alpha.2",
47
- "@antv/g-plugin-dom-interaction": "^1.0.0-alpha.2",
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
48
  "@antv/util": "^2.0.13"
49
49
  },
50
- "gitHead": "2fe2253d4f856f456d8a4e4929b1dba6fd42de8a"
50
+ "gitHead": "c64e9f589805686657e64d063f80de34e276ba0b"
51
51
  }