@antv/g-canvas 1.0.0-alpha.3 → 1.0.0-alpha.34

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.
@@ -0,0 +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;
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,97 @@
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 _util = require("@antv/util");
15
+
16
+ var _dom = require("./utils/dom");
17
+
18
+ var Canvas2DContextService =
19
+ /** @class */
20
+ function () {
21
+ function Canvas2DContextService() {}
22
+
23
+ Canvas2DContextService.prototype.init = function () {
24
+ var _a = this.canvasConfig,
25
+ container = _a.container,
26
+ width = _a.width,
27
+ height = _a.height; // create container
28
+
29
+ this.$container = (0, _util.isString)(container) ? document.getElementById(container) : container;
30
+
31
+ if (this.$container) {
32
+ // create canvas
33
+ var $canvas = document.createElement('canvas');
34
+ this.context = $canvas.getContext('2d');
35
+ this.$container.appendChild($canvas);
36
+
37
+ if (!this.$container.style.position) {
38
+ this.$container.style.position = 'relative';
39
+ }
40
+
41
+ this.$canvas = $canvas;
42
+ var dpr = window.devicePixelRatio || 1;
43
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
44
+ this.dpr = dpr;
45
+ this.resize(width, height);
46
+ }
47
+ };
48
+
49
+ Canvas2DContextService.prototype.getContext = function () {
50
+ return this.context;
51
+ };
52
+
53
+ Canvas2DContextService.prototype.getDomElement = function () {
54
+ return this.$canvas;
55
+ };
56
+
57
+ Canvas2DContextService.prototype.getDPR = function () {
58
+ return this.dpr;
59
+ };
60
+
61
+ Canvas2DContextService.prototype.getBoundingClientRect = function () {
62
+ var _a;
63
+
64
+ return (_a = this.$canvas) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
65
+ };
66
+
67
+ Canvas2DContextService.prototype.destroy = function () {
68
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
69
+ // destroy context
70
+ this.$container.removeChild(this.$canvas);
71
+ }
72
+ };
73
+
74
+ Canvas2DContextService.prototype.resize = function (width, height) {
75
+ if (this.$canvas) {
76
+ // set canvas width & height
77
+ this.$canvas.width = this.dpr * width;
78
+ this.$canvas.height = this.dpr * height; // set CSS style width & height
79
+
80
+ (0, _dom.setDOMSize)(this.$canvas, width, height);
81
+ }
82
+ };
83
+
84
+ Canvas2DContextService.prototype.applyCursorStyle = function (cursor) {
85
+ if (this.$container) {
86
+ this.$container.style.cursor = cursor;
87
+ }
88
+ };
89
+
90
+ (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_g.CanvasConfig), (0, _tslib.__metadata)("design:type", Object)], Canvas2DContextService.prototype, "canvasConfig", void 0);
91
+ Canvas2DContextService = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
92
+ token: _g.ContextService
93
+ })], Canvas2DContextService);
94
+ return Canvas2DContextService;
95
+ }();
96
+
97
+ exports.Canvas2DContextService = Canvas2DContextService;
@@ -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
+ }
@@ -0,0 +1,37 @@
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
+
24
+ ContextRegisterPlugin.prototype.init = function (container) {
25
+ container.load(containerModule, true);
26
+ };
27
+
28
+ ContextRegisterPlugin.prototype.destroy = function (container) {
29
+ container.remove(_Canvas2DContextService.Canvas2DContextService); // @ts-ignore
30
+ // container.container.unload(containerModule);
31
+ // container.remove(Canvas2DContextService);
32
+ };
33
+
34
+ return ContextRegisterPlugin;
35
+ }();
36
+
37
+ exports.ContextRegisterPlugin = ContextRegisterPlugin;
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { AbstractRenderer, RendererConfig } from '@antv/g';
2
+ import * as DomInteraction from '@antv/g-plugin-dom-interaction';
3
+ import * as CanvasRenderer from '@antv/g-plugin-canvas-renderer';
4
+ import * as CanvasPicker from '@antv/g-plugin-canvas-picker';
5
+ import * as HTMLRenderer from '@antv/g-plugin-html-renderer';
6
+ export { DomInteraction, CanvasRenderer, CanvasPicker, HTMLRenderer };
7
+ export declare class Renderer extends AbstractRenderer {
8
+ constructor(config?: Partial<RendererConfig>);
9
+ }
package/lib/index.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _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;
@@ -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,17 +1,16 @@
1
1
  {
2
2
  "name": "@antv/g-canvas",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.34",
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",
9
- "sideEffects": false,
5
+ "main": "lib/index.js",
6
+ "module": "es/index.esm.js",
7
+ "types": "es/index.d.ts",
8
+ "unpkg": "dist/index.umd.js",
10
9
  "files": [
11
10
  "package.json",
12
- "esm",
13
- "lib",
14
11
  "dist",
12
+ "es",
13
+ "lib",
15
14
  "LICENSE",
16
15
  "README.md"
17
16
  ],
@@ -41,11 +40,20 @@
41
40
  },
42
41
  "homepage": "https://github.com/antvis/g#readme",
43
42
  "dependencies": {
44
- "@antv/g": "^1.0.0-alpha.3",
45
- "@antv/g-plugin-canvas-picker": "^1.0.0-alpha.2",
46
- "@antv/g-plugin-canvas-renderer": "^1.0.0-alpha.3",
47
- "@antv/g-plugin-dom-interaction": "^1.0.0-alpha.3",
48
- "@antv/util": "^2.0.13"
43
+ "@antv/g": "^1.0.0-alpha.34",
44
+ "@antv/g-plugin-canvas-picker": "^1.0.0-alpha.28",
45
+ "@antv/g-plugin-canvas-renderer": "^1.0.0-alpha.34",
46
+ "@antv/g-plugin-dom-interaction": "^1.0.0-alpha.33",
47
+ "@antv/g-plugin-html-renderer": "^1.0.0-alpha.17",
48
+ "@antv/util": "^2.0.13",
49
+ "@babel/runtime": "^7.16.3"
50
+ },
51
+ "peerDependencies": {
52
+ "@antv/g": "^1.0.0-alpha.27",
53
+ "mana-syringe": "^0.2.2"
54
+ },
55
+ "scripts": {
56
+ "umd": "webpack"
49
57
  },
50
- "gitHead": "c9511b4923b5575a3d301012989b860618bbc10c"
58
+ "gitHead": "da03f9640aab7165eb9b46215df8883b13d17ecb"
51
59
  }
package/dist/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
- }