@antv/g-canvas 1.1.2 → 1.1.3-alpha.0

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,105 +0,0 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { CanvasConfig, ContextService, isBrowser, isString, setDOMSize } from '@antv/g';
3
- import { inject, singleton } from 'mana-syringe';
4
-
5
- var Canvas2DContextService =
6
- /** @class */
7
- function () {
8
- function Canvas2DContextService() {}
9
-
10
- Canvas2DContextService.prototype.init = function () {
11
- var _a = this.canvasConfig,
12
- container = _a.container,
13
- canvas = _a.canvas,
14
- devicePixelRatio = _a.devicePixelRatio;
15
-
16
- if (canvas) {
17
- this.$canvas = canvas;
18
-
19
- if (container && canvas.parentElement !== container) {
20
- container.appendChild(canvas);
21
- }
22
-
23
- this.$container = canvas.parentElement;
24
- this.canvasConfig.container = this.$container;
25
- } else if (container) {
26
- // create container
27
- this.$container = isString(container) ? document.getElementById(container) : container;
28
-
29
- if (this.$container) {
30
- // create canvas
31
- var $canvas = document.createElement('canvas');
32
- this.$container.appendChild($canvas);
33
-
34
- if (!this.$container.style.position) {
35
- this.$container.style.position = 'relative';
36
- }
37
-
38
- this.$canvas = $canvas;
39
- }
40
- }
41
-
42
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
43
-
44
- var dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
45
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
46
- this.dpr = dpr;
47
- this.resize(this.canvasConfig.width, this.canvasConfig.height);
48
- };
49
-
50
- Canvas2DContextService.prototype.getContext = function () {
51
- return this.context;
52
- };
53
-
54
- Canvas2DContextService.prototype.getDomElement = function () {
55
- return this.$canvas;
56
- };
57
-
58
- Canvas2DContextService.prototype.getDPR = function () {
59
- return this.dpr;
60
- };
61
-
62
- Canvas2DContextService.prototype.getBoundingClientRect = function () {
63
- if (this.$canvas.getBoundingClientRect) {
64
- return this.$canvas.getBoundingClientRect();
65
- }
66
- };
67
-
68
- Canvas2DContextService.prototype.destroy = function () {
69
- // @ts-ignore
70
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
71
- // destroy context
72
- // @ts-ignore
73
- this.$container.removeChild(this.$canvas);
74
- }
75
- };
76
-
77
- Canvas2DContextService.prototype.resize = function (width, height) {
78
- if (this.$canvas) {
79
- // set canvas width & height
80
- this.$canvas.width = this.dpr * width;
81
- this.$canvas.height = this.dpr * height; // set CSS style width & height
82
-
83
- setDOMSize(this.$canvas, width, height);
84
- var dpr = this.getDPR(); // scale all drawing operations by the dpr
85
- // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
86
-
87
- this.context.scale(dpr, dpr);
88
- }
89
- };
90
-
91
- Canvas2DContextService.prototype.applyCursorStyle = function (cursor) {
92
- if (this.$container && this.$container.style) {
93
- this.$container.style.cursor = cursor;
94
- }
95
- };
96
-
97
- __decorate([inject(CanvasConfig), __metadata("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
98
-
99
- Canvas2DContextService = __decorate([singleton({
100
- token: ContextService
101
- })], Canvas2DContextService);
102
- return Canvas2DContextService;
103
- }();
104
-
105
- export { Canvas2DContextService };
@@ -1,7 +0,0 @@
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,28 +0,0 @@
1
- import { Module } from 'mana-syringe';
2
- import { Canvas2DContextService } from './Canvas2DContextService';
3
- var containerModule = Module(function (register) {
4
- /**
5
- * implements ContextService
6
- */
7
- register(Canvas2DContextService);
8
- });
9
-
10
- var ContextRegisterPlugin =
11
- /** @class */
12
- function () {
13
- function ContextRegisterPlugin() {
14
- this.name = 'canvas-context-register';
15
- }
16
-
17
- ContextRegisterPlugin.prototype.init = function (container) {
18
- container.load(containerModule, true);
19
- };
20
-
21
- ContextRegisterPlugin.prototype.destroy = function (container) {
22
- container.unload(containerModule);
23
- };
24
-
25
- return ContextRegisterPlugin;
26
- }();
27
-
28
- export { ContextRegisterPlugin };
package/es/index.d.ts DELETED
@@ -1,10 +0,0 @@
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
- }
package/es/index.js DELETED
@@ -1,38 +0,0 @@
1
- import { __extends } from "tslib";
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
- import { ContextRegisterPlugin } from './ContextRegisterPlugin';
8
- export { DomInteraction, CanvasRenderer, CanvasPicker, HTMLRenderer };
9
-
10
- var Renderer =
11
- /** @class */
12
- function (_super) {
13
- __extends(Renderer, _super);
14
-
15
- function Renderer(config) {
16
- var _this = _super.call(this, config) || this; // register Canvas2DContext
17
-
18
-
19
- _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
20
-
21
-
22
- _this.registerPlugin(new CanvasRenderer.Plugin());
23
-
24
- _this.registerPlugin(new DomInteraction.Plugin()); // enable picking with Canvas2D API
25
-
26
-
27
- _this.registerPlugin(new CanvasPicker.Plugin()); // render HTML component
28
-
29
-
30
- _this.registerPlugin(new HTMLRenderer.Plugin());
31
-
32
- return _this;
33
- }
34
-
35
- return Renderer;
36
- }(AbstractRenderer);
37
-
38
- export { Renderer };
@@ -1,17 +0,0 @@
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,113 +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 _manaSyringe = require("mana-syringe");
13
-
14
- var Canvas2DContextService =
15
- /** @class */
16
- function () {
17
- function Canvas2DContextService() {}
18
-
19
- Canvas2DContextService.prototype.init = function () {
20
- var _a = this.canvasConfig,
21
- container = _a.container,
22
- canvas = _a.canvas,
23
- devicePixelRatio = _a.devicePixelRatio;
24
-
25
- if (canvas) {
26
- this.$canvas = canvas;
27
-
28
- if (container && canvas.parentElement !== container) {
29
- container.appendChild(canvas);
30
- }
31
-
32
- this.$container = canvas.parentElement;
33
- this.canvasConfig.container = this.$container;
34
- } else if (container) {
35
- // create container
36
- this.$container = (0, _g.isString)(container) ? document.getElementById(container) : container;
37
-
38
- if (this.$container) {
39
- // create canvas
40
- var $canvas = document.createElement('canvas');
41
- this.$container.appendChild($canvas);
42
-
43
- if (!this.$container.style.position) {
44
- this.$container.style.position = 'relative';
45
- }
46
-
47
- this.$canvas = $canvas;
48
- }
49
- }
50
-
51
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
52
-
53
- var dpr = devicePixelRatio || _g.isBrowser && window.devicePixelRatio || 1;
54
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
55
- this.dpr = dpr;
56
- this.resize(this.canvasConfig.width, this.canvasConfig.height);
57
- };
58
-
59
- Canvas2DContextService.prototype.getContext = function () {
60
- return this.context;
61
- };
62
-
63
- Canvas2DContextService.prototype.getDomElement = function () {
64
- return this.$canvas;
65
- };
66
-
67
- Canvas2DContextService.prototype.getDPR = function () {
68
- return this.dpr;
69
- };
70
-
71
- Canvas2DContextService.prototype.getBoundingClientRect = function () {
72
- if (this.$canvas.getBoundingClientRect) {
73
- return this.$canvas.getBoundingClientRect();
74
- }
75
- };
76
-
77
- Canvas2DContextService.prototype.destroy = function () {
78
- // @ts-ignore
79
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
80
- // destroy context
81
- // @ts-ignore
82
- this.$container.removeChild(this.$canvas);
83
- }
84
- };
85
-
86
- Canvas2DContextService.prototype.resize = function (width, height) {
87
- if (this.$canvas) {
88
- // set canvas width & height
89
- this.$canvas.width = this.dpr * width;
90
- this.$canvas.height = this.dpr * height; // set CSS style width & height
91
-
92
- (0, _g.setDOMSize)(this.$canvas, width, height);
93
- var dpr = this.getDPR(); // scale all drawing operations by the dpr
94
- // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
95
-
96
- this.context.scale(dpr, dpr);
97
- }
98
- };
99
-
100
- Canvas2DContextService.prototype.applyCursorStyle = function (cursor) {
101
- if (this.$container && this.$container.style) {
102
- this.$container.style.cursor = cursor;
103
- }
104
- };
105
-
106
- (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_g.CanvasConfig), (0, _tslib.__metadata)("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
107
- Canvas2DContextService = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
108
- token: _g.ContextService
109
- })], Canvas2DContextService);
110
- return Canvas2DContextService;
111
- }();
112
-
113
- exports.Canvas2DContextService = Canvas2DContextService;
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ContextRegisterPlugin = void 0;
7
-
8
- var _manaSyringe = require("mana-syringe");
9
-
10
- var _Canvas2DContextService = require("./Canvas2DContextService");
11
-
12
- var containerModule = (0, _manaSyringe.Module)(function (register) {
13
- /**
14
- * implements ContextService
15
- */
16
- register(_Canvas2DContextService.Canvas2DContextService);
17
- });
18
-
19
- var ContextRegisterPlugin =
20
- /** @class */
21
- function () {
22
- function ContextRegisterPlugin() {
23
- this.name = 'canvas-context-register';
24
- }
25
-
26
- ContextRegisterPlugin.prototype.init = function (container) {
27
- container.load(containerModule, true);
28
- };
29
-
30
- ContextRegisterPlugin.prototype.destroy = function (container) {
31
- container.unload(containerModule);
32
- };
33
-
34
- return ContextRegisterPlugin;
35
- }();
36
-
37
- exports.ContextRegisterPlugin = ContextRegisterPlugin;
package/lib/index.js DELETED
@@ -1,64 +0,0 @@
1
- "use strict";
2
-
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.Renderer = exports.HTMLRenderer = exports.DomInteraction = exports.CanvasRenderer = exports.CanvasPicker = void 0;
9
-
10
- var _tslib = require("tslib");
11
-
12
- var _g = require("@antv/g");
13
-
14
- var DomInteraction = _interopRequireWildcard(require("@antv/g-plugin-dom-interaction"));
15
-
16
- exports.DomInteraction = DomInteraction;
17
-
18
- var CanvasRenderer = _interopRequireWildcard(require("@antv/g-plugin-canvas-renderer"));
19
-
20
- exports.CanvasRenderer = CanvasRenderer;
21
-
22
- var CanvasPicker = _interopRequireWildcard(require("@antv/g-plugin-canvas-picker"));
23
-
24
- exports.CanvasPicker = CanvasPicker;
25
-
26
- var HTMLRenderer = _interopRequireWildcard(require("@antv/g-plugin-html-renderer"));
27
-
28
- exports.HTMLRenderer = HTMLRenderer;
29
-
30
- var _ContextRegisterPlugin = require("./ContextRegisterPlugin");
31
-
32
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
33
-
34
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
35
-
36
- var Renderer =
37
- /** @class */
38
- function (_super) {
39
- (0, _tslib.__extends)(Renderer, _super);
40
-
41
- function Renderer(config) {
42
- var _this = _super.call(this, config) || this; // register Canvas2DContext
43
-
44
-
45
- _this.registerPlugin(new _ContextRegisterPlugin.ContextRegisterPlugin()); // enable rendering with Canvas2D API
46
-
47
-
48
- _this.registerPlugin(new CanvasRenderer.Plugin());
49
-
50
- _this.registerPlugin(new DomInteraction.Plugin()); // enable picking with Canvas2D API
51
-
52
-
53
- _this.registerPlugin(new CanvasPicker.Plugin()); // render HTML component
54
-
55
-
56
- _this.registerPlugin(new HTMLRenderer.Plugin());
57
-
58
- return _this;
59
- }
60
-
61
- return Renderer;
62
- }(_g.AbstractRenderer);
63
-
64
- exports.Renderer = Renderer;